1 /**************************************************************************
3 * Copyright 2011 LunarG, Inc.
6 * Based on glretrace_glx.cpp, which has
8 * Copyright 2011 Jose Fonseca
10 * Permission is hereby granted, free of charge, to any person obtaining a copy
11 * of this software and associated documentation files (the "Software"), to deal
12 * in the Software without restriction, including without limitation the rights
13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14 * copies of the Software, and to permit persons to whom the Software is
15 * furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included in
18 * all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 **************************************************************************/
32 #include "retrace.hpp"
33 #include "glretrace.hpp"
36 #ifndef EGL_OPENGL_ES_API
37 #define EGL_OPENGL_ES_API 0x30A0
38 #define EGL_OPENVG_API 0x30A1
39 #define EGL_OPENGL_API 0x30A2
43 using namespace glretrace;
46 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
47 typedef std::map<unsigned long long, glws::Context *> ContextMap;
48 static DrawableMap drawable_map;
49 static ContextMap context_map;
51 static unsigned int current_api = EGL_OPENGL_ES_API;
53 static glws::Drawable *
54 getDrawable(unsigned long long surface_ptr) {
55 if (surface_ptr == 0) {
59 DrawableMap::const_iterator it;
60 it = drawable_map.find(surface_ptr);
62 return (it != drawable_map.end()) ? it->second : NULL;
65 static glws::Context *
66 getContext(unsigned long long context_ptr) {
67 if (context_ptr == 0) {
71 ContextMap::const_iterator it;
72 it = context_map.find(context_ptr);
74 return (it != context_map.end()) ? it->second : NULL;
77 static void retrace_eglCreateWindowSurface(trace::Call &call) {
78 unsigned long long orig_surface = call.ret->toUIntPtr();
80 glws::Drawable *drawable = glws::createDrawable(glretrace::visual);
81 drawable_map[orig_surface] = drawable;
84 static void retrace_eglDestroySurface(trace::Call &call) {
85 unsigned long long orig_surface = call.arg(1).toUIntPtr();
87 DrawableMap::iterator it;
88 it = drawable_map.find(orig_surface);
90 if (it != drawable_map.end()) {
92 drawable_map.erase(it);
96 static void retrace_eglBindAPI(trace::Call &call) {
97 current_api = call.arg(0).toUInt();
100 static void retrace_eglCreateContext(trace::Call &call) {
101 if (current_api != EGL_OPENGL_API) {
102 retrace::warning(call) << "only OpenGL is supported. Aborting...\n";
107 unsigned long long orig_context = call.ret->toUIntPtr();
108 glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
110 glws::Context *context = glws::createContext(glretrace::visual, share_context);
111 context_map[orig_context] = context;
114 static void retrace_eglDestroyContext(trace::Call &call) {
115 unsigned long long orig_context = call.arg(1).toUIntPtr();
117 ContextMap::iterator it;
118 it = context_map.find(orig_context);
120 if (it != context_map.end()) {
122 context_map.erase(it);
126 static void retrace_eglMakeCurrent(trace::Call &call) {
127 glws::Drawable *new_drawable = getDrawable(call.arg(1).toUIntPtr());
128 glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
130 if (new_drawable == drawable && new_context == context) {
134 if (drawable && context) {
136 if (!double_buffer) {
137 frame_complete(call);
141 bool result = glws::makeCurrent(new_drawable, new_context);
143 if (new_drawable && new_context && result) {
144 drawable = new_drawable;
145 context = new_context;
153 static void retrace_eglSwapBuffers(trace::Call &call) {
154 frame_complete(call);
157 drawable->swapBuffers();
163 const retrace::Entry glretrace::egl_callbacks[] = {
164 {"eglGetError", &retrace::ignore},
165 {"eglGetDisplay", &retrace::ignore},
166 {"eglInitialize", &retrace::ignore},
167 {"eglTerminate", &retrace::ignore},
168 {"eglQueryString", &retrace::ignore},
169 {"eglGetConfigs", &retrace::ignore},
170 {"eglChooseConfig", &retrace::ignore},
171 {"eglGetConfigAttrib", &retrace::ignore},
172 {"eglCreateWindowSurface", &retrace_eglCreateWindowSurface},
173 //{"eglCreatePbufferSurface", &retrace::ignore},
174 //{"eglCreatePixmapSurface", &retrace::ignore},
175 {"eglDestroySurface", &retrace_eglDestroySurface},
176 {"eglQuerySurface", &retrace::ignore},
177 {"eglBindAPI", &retrace_eglBindAPI},
178 {"eglQueryAPI", &retrace::ignore},
179 //{"eglWaitClient", &retrace::ignore},
180 //{"eglReleaseThread", &retrace::ignore},
181 //{"eglCreatePbufferFromClientBuffer", &retrace::ignore},
182 //{"eglSurfaceAttrib", &retrace::ignore},
183 //{"eglBindTexImage", &retrace::ignore},
184 //{"eglReleaseTexImage", &retrace::ignore},
185 {"eglSwapInterval", &retrace::ignore},
186 {"eglCreateContext", &retrace_eglCreateContext},
187 {"eglDestroyContext", &retrace_eglDestroyContext},
188 {"eglMakeCurrent", &retrace_eglMakeCurrent},
189 {"eglGetCurrentContext", &retrace::ignore},
190 {"eglGetCurrentSurface", &retrace::ignore},
191 {"eglGetCurrentDisplay", &retrace::ignore},
192 {"eglQueryContext", &retrace::ignore},
193 {"eglWaitGL", &retrace::ignore},
194 {"eglWaitNative", &retrace::ignore},
195 {"eglSwapBuffers", &retrace_eglSwapBuffers},
196 //{"eglCopyBuffers", &retrace::ignore},
197 {"eglGetProcAddress", &retrace::ignore},