]> git.cworth.org Git - apitrace/blob - glretrace_egl.cpp
Add depth info to the surfaces.
[apitrace] / glretrace_egl.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 LunarG, Inc.
4  * All Rights Reserved.
5  *
6  * Based on glretrace_glx.cpp, which has
7  *
8  *   Copyright 2011 Jose Fonseca
9  *
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:
16  *
17  * The above copyright notice and this permission notice shall be included in
18  * all copies or substantial portions of the Software.
19  *
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
26  * THE SOFTWARE.
27  *
28  **************************************************************************/
29
30
31 #include "glproc.hpp"
32 #include "retrace.hpp"
33 #include "glretrace.hpp"
34 #include "os.hpp"
35
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
40 #endif
41
42
43 using namespace glretrace;
44
45
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;
50
51 static unsigned int current_api = EGL_OPENGL_ES_API;
52
53 static glws::Drawable *
54 getDrawable(unsigned long long surface_ptr) {
55     if (surface_ptr == 0) {
56         return NULL;
57     }
58
59     DrawableMap::const_iterator it;
60     it = drawable_map.find(surface_ptr);
61
62     return (it != drawable_map.end()) ? it->second : NULL;
63 }
64
65 static glws::Context *
66 getContext(unsigned long long context_ptr) {
67     if (context_ptr == 0) {
68         return NULL;
69     }
70
71     ContextMap::const_iterator it;
72     it = context_map.find(context_ptr);
73
74     return (it != context_map.end()) ? it->second : NULL;
75 }
76
77 static void retrace_eglCreateWindowSurface(trace::Call &call) {
78     unsigned long long orig_surface = call.ret->toUIntPtr();
79
80     glws::Drawable *drawable = glws::createDrawable(glretrace::visual);
81     drawable_map[orig_surface] = drawable;
82 }
83
84 static void retrace_eglDestroySurface(trace::Call &call) {
85     unsigned long long orig_surface = call.arg(1).toUIntPtr();
86
87     DrawableMap::iterator it;
88     it = drawable_map.find(orig_surface);
89
90     if (it != drawable_map.end()) {
91         delete it->second;
92         drawable_map.erase(it);
93     }
94 }
95
96 static void retrace_eglBindAPI(trace::Call &call) {
97     current_api = call.arg(0).toUInt();
98 }
99
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";
103         os::abort();
104         return;
105     }
106
107     unsigned long long orig_context = call.ret->toUIntPtr();
108     glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
109
110     glws::Context *context = glws::createContext(glretrace::visual, share_context);
111     context_map[orig_context] = context;
112 }
113
114 static void retrace_eglDestroyContext(trace::Call &call) {
115     unsigned long long orig_context = call.arg(1).toUIntPtr();
116
117     ContextMap::iterator it;
118     it = context_map.find(orig_context);
119
120     if (it != context_map.end()) {
121         delete it->second;
122         context_map.erase(it);
123     }
124 }
125
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());
129
130     if (new_drawable == drawable && new_context == context) {
131         return;
132     }
133
134     if (drawable && context) {
135         glFlush();
136         if (!double_buffer) {
137             frame_complete(call);
138         }
139     }
140
141     bool result = glws::makeCurrent(new_drawable, new_context);
142
143     if (new_drawable && new_context && result) {
144         drawable = new_drawable;
145         context = new_context;
146     } else {
147         drawable = NULL;
148         context = NULL;
149     }
150 }
151
152
153 static void retrace_eglSwapBuffers(trace::Call &call) {
154     frame_complete(call);
155
156     if (double_buffer) {
157         drawable->swapBuffers();
158     } else {
159         glFlush();
160     }
161 }
162
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},
198     {NULL, NULL},
199 };