/[pcsx2_0.9.7]/trunk/plugins/zzogl-pg/opengl/Profile.h
ViewVC logotype

Contents of /trunk/plugins/zzogl-pg/opengl/Profile.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 280 - (show annotations) (download)
Thu Dec 23 12:02:12 2010 UTC (9 years, 2 months ago) by william
File MIME type: text/plain
File size: 4012 byte(s)
re-commit (had local access denied errors when committing)
1 /* ZZ Open GL graphics plugin
2 * Copyright (c)2009-2010 zeydlitz@gmail.com, arcum42@gmail.com
3 * Based on Zerofrog's ZeroGS KOSMOS (c)2005-2008
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20 #ifndef PROFILE_H_INCLUDED
21 #define PROFILE_H_INCLUDED
22
23 #include "Util.h"
24
25 #if !defined(ZEROGS_DEVBUILD)
26 #define g_bWriteProfile 0
27 #else
28 extern bool g_bWriteProfile;
29 #endif
30
31 extern u64 luPerfFreq;
32
33
34 // Copied from Utilities; remove later.
35 #ifdef __LINUX__
36
37 #include <sys/time.h>
38 #include <sys/timeb.h> // ftime(), struct timeb
39
40 inline unsigned long timeGetTime()
41 {
42 timeb t;
43 ftime(&t);
44
45 return (unsigned long)(t.time*1000 + t.millitm);
46 }
47
48 inline unsigned long timeGetPreciseTime()
49 {
50 timespec t;
51 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &t);
52
53 return t.tv_nsec;
54 }
55
56 static __forceinline void InitCPUTicks()
57 {
58 }
59
60 static __forceinline u64 GetTickFrequency()
61 {
62 return 1000000; // unix measures in microseconds
63 }
64
65 static __forceinline u64 GetCPUTicks()
66 {
67
68 struct timeval t;
69 gettimeofday(&t, NULL);
70 return ((u64)t.tv_sec*GetTickFrequency()) + t.tv_usec;
71 }
72
73 #else
74 static __aligned16 LARGE_INTEGER lfreq;
75
76 inline unsigned long timeGetPreciseTime()
77 {
78 // Implement later.
79 return 0;
80 }
81
82 static __forceinline void InitCPUTicks()
83 {
84 QueryPerformanceFrequency(&lfreq);
85 }
86
87 static __forceinline u64 GetTickFrequency()
88 {
89 return lfreq.QuadPart;
90 }
91
92 static __forceinline u64 GetCPUTicks()
93 {
94 LARGE_INTEGER count;
95 QueryPerformanceCounter(&count);
96 return count.QuadPart;
97 }
98
99 #endif
100
101 // IMPORTANT: For every Register there must be an End
102 void DVProfRegister(char* pname); // first checks if this profiler exists in g_listProfilers
103 void DVProfEnd(u32 dwUserData);
104 void DVProfWrite(char* pfilename, u32 frames = 0);
105 void DVProfClear(); // clears all the profilers
106
107 #define DVPROFILE
108 #ifdef DVPROFILE
109
110 class DVProfileFunc
111 {
112 public:
113 u32 dwUserData;
114 DVProfileFunc(char* pname) { DVProfRegister(pname); dwUserData = 0; }
115 DVProfileFunc(char* pname, u32 dwUserData) : dwUserData(dwUserData) { DVProfRegister(pname); }
116 ~DVProfileFunc() { DVProfEnd(dwUserData); }
117 };
118
119 #else
120
121 class DVProfileFunc
122 {
123
124 public:
125 u32 dwUserData;
126 static __forceinline DVProfileFunc(char* pname) {}
127 static __forceinline DVProfileFunc(char* pname, u32 dwUserData) { }
128 ~DVProfileFunc() {}
129 };
130
131 #endif
132
133
134 template <typename T>
135 class CInterfacePtr
136 {
137
138 public:
139 inline CInterfacePtr() : ptr(NULL) {}
140 inline explicit CInterfacePtr(T* newptr) : ptr(newptr) { if (ptr != NULL) ptr->AddRef(); }
141 inline ~CInterfacePtr() { if (ptr != NULL) ptr->Release(); }
142 inline T* operator*() { assert(ptr != NULL); return *ptr; }
143 inline T* operator->() { return ptr; }
144 inline T* get() { return ptr; }
145
146 inline void release()
147 {
148 if (ptr != NULL) { ptr->Release(); ptr = NULL; }
149 }
150
151 inline operator T*() { return ptr; }
152 inline bool operator==(T* rhs) { return ptr == rhs; }
153 inline bool operator!=(T* rhs) { return ptr != rhs; }
154
155 inline CInterfacePtr& operator= (T* newptr)
156 {
157 if (ptr != NULL) ptr->Release();
158
159 ptr = newptr;
160
161 if (ptr != NULL) ptr->AddRef();
162
163 return *this;
164 }
165
166 private:
167 T* ptr;
168 };
169
170 extern void InitProfile();
171
172 #endif // PROFILE_H_INCLUDED

  ViewVC Help
Powered by ViewVC 1.1.22