forked from apitrace/apitrace
-
Notifications
You must be signed in to change notification settings - Fork 0
/
glretrace_egl.cpp
257 lines (218 loc) · 8 KB
/
glretrace_egl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
/**************************************************************************
*
* Copyright 2011 LunarG, Inc.
* All Rights Reserved.
*
* Based on glretrace_glx.cpp, which has
*
* Copyright 2011 Jose Fonseca
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**************************************************************************/
#include "glproc.hpp"
#include "retrace.hpp"
#include "glretrace.hpp"
#include "os.hpp"
#ifndef EGL_OPENGL_ES_API
#define EGL_OPENGL_ES_API 0x30A0
#define EGL_OPENVG_API 0x30A1
#define EGL_OPENGL_API 0x30A2
#define EGL_CONTEXT_CLIENT_VERSION 0x3098
#endif
using namespace glretrace;
typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
typedef std::map<unsigned long long, glws::Context *> ContextMap;
typedef std::map<unsigned long long, glws::Profile> ProfileMap;
static DrawableMap drawable_map;
static ContextMap context_map;
static ProfileMap profile_map;
static unsigned int current_api = EGL_OPENGL_ES_API;
static glws::Profile last_profile = glws::PROFILE_COMPAT;
static glws::Drawable *
getDrawable(unsigned long long surface_ptr) {
if (surface_ptr == 0) {
return NULL;
}
DrawableMap::const_iterator it;
it = drawable_map.find(surface_ptr);
return (it != drawable_map.end()) ? it->second : NULL;
}
static glws::Context *
getContext(unsigned long long context_ptr) {
if (context_ptr == 0) {
return NULL;
}
ContextMap::const_iterator it;
it = context_map.find(context_ptr);
return (it != context_map.end()) ? it->second : NULL;
}
static void retrace_eglCreateWindowSurface(trace::Call &call) {
unsigned long long orig_surface = call.ret->toUIntPtr();
unsigned long long orig_config = call.arg(1).toUIntPtr();
ProfileMap::iterator it = profile_map.find(orig_config);
glws::Profile profile;
// If the requested config is associated with a profile, use that
// profile. Otherwise, assume that the last used profile is what
// the user wants.
if (it != profile_map.end()) {
profile = it->second;
} else {
profile = last_profile;
}
glws::Drawable *drawable = glws::createDrawable(glretrace::visual[profile]);
drawable_map[orig_surface] = drawable;
}
static void retrace_eglDestroySurface(trace::Call &call) {
unsigned long long orig_surface = call.arg(1).toUIntPtr();
DrawableMap::iterator it;
it = drawable_map.find(orig_surface);
if (it != drawable_map.end()) {
delete it->second;
drawable_map.erase(it);
}
}
static void retrace_eglBindAPI(trace::Call &call) {
current_api = call.arg(0).toUInt();
}
static void retrace_eglCreateContext(trace::Call &call) {
unsigned long long orig_context = call.ret->toUIntPtr();
unsigned long long orig_config = call.arg(1).toUIntPtr();
glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
trace::Array *attrib_array = dynamic_cast<trace::Array *>(&call.arg(3));
glws::Profile profile;
switch (current_api) {
case EGL_OPENGL_API:
profile = glws::PROFILE_COMPAT;
break;
case EGL_OPENGL_ES_API:
default:
profile = glws::PROFILE_ES1;
if (attrib_array) {
for (int i = 0; i < attrib_array->values.size(); i += 2) {
int v = attrib_array->values[i]->toSInt();
if (v == EGL_CONTEXT_CLIENT_VERSION) {
v = attrib_array->values[i + 1]->toSInt();
if (v == 2)
profile = glws::PROFILE_ES2;
break;
}
}
}
break;
}
glws::Context *context = glws::createContext(glretrace::visual[profile], share_context, profile);
if (!context) {
const char *name;
switch (profile) {
case glws::PROFILE_COMPAT:
name = "OpenGL";
break;
case glws::PROFILE_ES1:
name = "OpenGL ES 1.1";
break;
case glws::PROFILE_ES2:
name = "OpenGL ES 2.0";
break;
default:
name = "unknown";
break;
}
retrace::warning(call) << "Failed to create " << name << " context.\n";
os::abort();
}
context_map[orig_context] = context;
profile_map[orig_config] = profile;
last_profile = profile;
}
static void retrace_eglDestroyContext(trace::Call &call) {
unsigned long long orig_context = call.arg(1).toUIntPtr();
ContextMap::iterator it;
it = context_map.find(orig_context);
if (it != context_map.end()) {
delete it->second;
context_map.erase(it);
}
}
static void retrace_eglMakeCurrent(trace::Call &call) {
glws::Drawable *new_drawable = getDrawable(call.arg(1).toUIntPtr());
glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
if (new_drawable == drawable && new_context == context) {
return;
}
if (drawable && context) {
glFlush();
if (!double_buffer) {
frame_complete(call);
}
}
bool result = glws::makeCurrent(new_drawable, new_context);
if (new_drawable && new_context && result) {
drawable = new_drawable;
context = new_context;
} else {
drawable = NULL;
context = NULL;
}
}
static void retrace_eglSwapBuffers(trace::Call &call) {
frame_complete(call);
if (double_buffer) {
drawable->swapBuffers();
} else {
glFlush();
}
}
const retrace::Entry glretrace::egl_callbacks[] = {
{"eglGetError", &retrace::ignore},
{"eglGetDisplay", &retrace::ignore},
{"eglInitialize", &retrace::ignore},
{"eglTerminate", &retrace::ignore},
{"eglQueryString", &retrace::ignore},
{"eglGetConfigs", &retrace::ignore},
{"eglChooseConfig", &retrace::ignore},
{"eglGetConfigAttrib", &retrace::ignore},
{"eglCreateWindowSurface", &retrace_eglCreateWindowSurface},
//{"eglCreatePbufferSurface", &retrace::ignore},
//{"eglCreatePixmapSurface", &retrace::ignore},
{"eglDestroySurface", &retrace_eglDestroySurface},
{"eglQuerySurface", &retrace::ignore},
{"eglBindAPI", &retrace_eglBindAPI},
{"eglQueryAPI", &retrace::ignore},
//{"eglWaitClient", &retrace::ignore},
//{"eglReleaseThread", &retrace::ignore},
//{"eglCreatePbufferFromClientBuffer", &retrace::ignore},
//{"eglSurfaceAttrib", &retrace::ignore},
//{"eglBindTexImage", &retrace::ignore},
//{"eglReleaseTexImage", &retrace::ignore},
{"eglSwapInterval", &retrace::ignore},
{"eglCreateContext", &retrace_eglCreateContext},
{"eglDestroyContext", &retrace_eglDestroyContext},
{"eglMakeCurrent", &retrace_eglMakeCurrent},
{"eglGetCurrentContext", &retrace::ignore},
{"eglGetCurrentSurface", &retrace::ignore},
{"eglGetCurrentDisplay", &retrace::ignore},
{"eglQueryContext", &retrace::ignore},
{"eglWaitGL", &retrace::ignore},
{"eglWaitNative", &retrace::ignore},
{"eglSwapBuffers", &retrace_eglSwapBuffers},
//{"eglCopyBuffers", &retrace::ignore},
{"eglGetProcAddress", &retrace::ignore},
{NULL, NULL},
};