1 /**************************************************************************
3 * Copyright 2011 Jose Fonseca
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 **************************************************************************/
28 #include "retrace.hpp"
29 #include "glretrace.hpp"
32 using namespace glretrace;
35 typedef std::map<unsigned long, glws::Drawable *> DrawableMap;
36 typedef std::map<unsigned long long, glws::Context *> ContextMap;
37 static DrawableMap drawable_map;
38 static ContextMap context_map;
41 static glws::Drawable *
42 getDrawable(unsigned long drawable_id) {
43 if (drawable_id == 0) {
47 DrawableMap::const_iterator it;
48 it = drawable_map.find(drawable_id);
49 if (it == drawable_map.end()) {
50 return (drawable_map[drawable_id] = glws::createDrawable(visual));
56 static glws::Context *
57 getContext(unsigned long long context_ptr) {
58 if (context_ptr == 0) {
62 ContextMap::const_iterator it;
63 it = context_map.find(context_ptr);
64 if (it == context_map.end()) {
65 return (context_map[context_ptr] = glws::createContext(visual, NULL));
71 static void retrace_glXCreateContext(trace::Call &call) {
72 unsigned long long orig_context = call.ret->toUIntPtr();
73 glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
75 glws::Context *context = glws::createContext(glretrace::visual, share_context);
76 context_map[orig_context] = context;
79 static void retrace_glXCreateContextAttribsARB(trace::Call &call) {
80 unsigned long long orig_context = call.ret->toUIntPtr();
81 glws::Context *share_context = getContext(call.arg(2).toUIntPtr());
83 glws::Context *context = glws::createContext(glretrace::visual, share_context);
84 context_map[orig_context] = context;
87 static void retrace_glXMakeCurrent(trace::Call &call) {
88 glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
89 glws::Context *new_context = getContext(call.arg(2).toUIntPtr());
91 if (new_drawable == drawable && new_context == context) {
95 if (drawable && context) {
102 bool result = glws::makeCurrent(new_drawable, new_context);
104 if (new_drawable && new_context && result) {
105 drawable = new_drawable;
106 context = new_context;
114 static void retrace_glXDestroyContext(trace::Call &call) {
115 glws::Context *context = getContext(call.arg(1).toUIntPtr());
124 static void retrace_glXSwapBuffers(trace::Call &call) {
125 frame_complete(call);
127 drawable->swapBuffers();
133 static void retrace_glXCreateNewContext(trace::Call &call) {
134 unsigned long long orig_context = call.ret->toUIntPtr();
135 glws::Context *share_context = getContext(call.arg(3).toUIntPtr());
137 glws::Context *context = glws::createContext(glretrace::visual, share_context);
138 context_map[orig_context] = context;
141 static void retrace_glXMakeContextCurrent(trace::Call &call) {
142 glws::Drawable *new_drawable = getDrawable(call.arg(1).toUInt());
143 glws::Context *new_context = getContext(call.arg(3).toUIntPtr());
145 if (new_drawable == drawable && new_context == context) {
149 if (drawable && context) {
151 if (!double_buffer) {
152 frame_complete(call);
156 bool result = glws::makeCurrent(new_drawable, new_context);
158 if (new_drawable && new_context && result) {
159 drawable = new_drawable;
160 context = new_context;
167 const retrace::Entry glretrace::glx_callbacks[] = {
168 //{"glXBindChannelToWindowSGIX", &retrace_glXBindChannelToWindowSGIX},
169 //{"glXBindSwapBarrierNV", &retrace_glXBindSwapBarrierNV},
170 //{"glXBindSwapBarrierSGIX", &retrace_glXBindSwapBarrierSGIX},
171 //{"glXBindTexImageEXT", &retrace_glXBindTexImageEXT},
172 //{"glXChannelRectSGIX", &retrace_glXChannelRectSGIX},
173 //{"glXChannelRectSyncSGIX", &retrace_glXChannelRectSyncSGIX},
174 {"glXChooseFBConfig", &retrace::ignore},
175 {"glXChooseFBConfigSGIX", &retrace::ignore},
176 {"glXChooseVisual", &retrace::ignore},
177 //{"glXCopyContext", &retrace_glXCopyContext},
178 //{"glXCopyImageSubDataNV", &retrace_glXCopyImageSubDataNV},
179 //{"glXCopySubBufferMESA", &retrace_glXCopySubBufferMESA},
180 {"glXCreateContextAttribsARB", &retrace_glXCreateContextAttribsARB},
181 {"glXCreateContext", &retrace_glXCreateContext},
182 //{"glXCreateContextWithConfigSGIX", &retrace_glXCreateContextWithConfigSGIX},
183 //{"glXCreateGLXPbufferSGIX", &retrace_glXCreateGLXPbufferSGIX},
184 //{"glXCreateGLXPixmap", &retrace_glXCreateGLXPixmap},
185 //{"glXCreateGLXPixmapWithConfigSGIX", &retrace_glXCreateGLXPixmapWithConfigSGIX},
186 {"glXCreateNewContext", &retrace_glXCreateNewContext},
187 //{"glXCreatePbuffer", &retrace_glXCreatePbuffer},
188 //{"glXCreatePixmap", &retrace_glXCreatePixmap},
189 //{"glXCreateWindow", &retrace_glXCreateWindow},
190 //{"glXCushionSGI", &retrace_glXCushionSGI},
191 {"glXDestroyContext", &retrace_glXDestroyContext},
192 //{"glXDestroyGLXPbufferSGIX", &retrace_glXDestroyGLXPbufferSGIX},
193 //{"glXDestroyGLXPixmap", &retrace_glXDestroyGLXPixmap},
194 //{"glXDestroyPbuffer", &retrace_glXDestroyPbuffer},
195 //{"glXDestroyPixmap", &retrace_glXDestroyPixmap},
196 //{"glXDestroyWindow", &retrace_glXDestroyWindow},
197 //{"glXFreeContextEXT", &retrace_glXFreeContextEXT},
198 {"glXGetAGPOffsetMESA", &retrace::ignore},
199 {"glXGetClientString", &retrace::ignore},
200 {"glXGetConfig", &retrace::ignore},
201 {"glXGetContextIDEXT", &retrace::ignore},
202 {"glXGetCurrentContext", &retrace::ignore},
203 {"glXGetCurrentDisplayEXT", &retrace::ignore},
204 {"glXGetCurrentDisplay", &retrace::ignore},
205 {"glXGetCurrentDrawable", &retrace::ignore},
206 {"glXGetCurrentReadDrawable", &retrace::ignore},
207 {"glXGetCurrentReadDrawableSGI", &retrace::ignore},
208 {"glXGetFBConfigAttrib", &retrace::ignore},
209 {"glXGetFBConfigAttribSGIX", &retrace::ignore},
210 {"glXGetFBConfigFromVisualSGIX", &retrace::ignore},
211 {"glXGetFBConfigs", &retrace::ignore},
212 {"glXGetMscRateOML", &retrace::ignore},
213 {"glXGetProcAddressARB", &retrace::ignore},
214 {"glXGetProcAddress", &retrace::ignore},
215 {"glXGetSelectedEvent", &retrace::ignore},
216 {"glXGetSelectedEventSGIX", &retrace::ignore},
217 {"glXGetSyncValuesOML", &retrace::ignore},
218 {"glXGetVideoSyncSGI", &retrace::ignore},
219 {"glXGetVisualFromFBConfig", &retrace::ignore},
220 {"glXGetVisualFromFBConfigSGIX", &retrace::ignore},
221 //{"glXImportContextEXT", &retrace_glXImportContextEXT},
222 {"glXIsDirect", &retrace::ignore},
223 //{"glXJoinSwapGroupNV", &retrace_glXJoinSwapGroupNV},
224 //{"glXJoinSwapGroupSGIX", &retrace_glXJoinSwapGroupSGIX},
225 {"glXMakeContextCurrent", &retrace_glXMakeContextCurrent},
226 //{"glXMakeCurrentReadSGI", &retrace_glXMakeCurrentReadSGI},
227 {"glXMakeCurrent", &retrace_glXMakeCurrent},
228 {"glXQueryChannelDeltasSGIX", &retrace::ignore},
229 {"glXQueryChannelRectSGIX", &retrace::ignore},
230 {"glXQueryContextInfoEXT", &retrace::ignore},
231 {"glXQueryContext", &retrace::ignore},
232 {"glXQueryDrawable", &retrace::ignore},
233 {"glXQueryExtension", &retrace::ignore},
234 {"glXQueryExtensionsString", &retrace::ignore},
235 {"glXQueryFrameCountNV", &retrace::ignore},
236 {"glXQueryGLXPbufferSGIX", &retrace::ignore},
237 {"glXQueryMaxSwapBarriersSGIX", &retrace::ignore},
238 {"glXQueryMaxSwapGroupsNV", &retrace::ignore},
239 {"glXQueryServerString", &retrace::ignore},
240 {"glXQuerySwapGroupNV", &retrace::ignore},
241 {"glXQueryVersion", &retrace::ignore},
242 //{"glXReleaseBuffersMESA", &retrace_glXReleaseBuffersMESA},
243 //{"glXReleaseTexImageEXT", &retrace_glXReleaseTexImageEXT},
244 //{"glXResetFrameCountNV", &retrace_glXResetFrameCountNV},
245 //{"glXSelectEvent", &retrace_glXSelectEvent},
246 //{"glXSelectEventSGIX", &retrace_glXSelectEventSGIX},
247 //{"glXSet3DfxModeMESA", &retrace_glXSet3DfxModeMESA},
248 //{"glXSwapBuffersMscOML", &retrace_glXSwapBuffersMscOML},
249 {"glXSwapBuffers", &retrace_glXSwapBuffers},
250 //{"glXSwapIntervalEXT", &retrace_glXSwapIntervalEXT},
251 //{"glXSwapIntervalSGI", &retrace_glXSwapIntervalSGI},
252 //{"glXUseXFont", &retrace_glXUseXFont},
253 {"glXWaitForMscOML", &retrace::ignore},
254 {"glXWaitForSbcOML", &retrace::ignore},
255 {"glXWaitGL", &retrace::ignore},
256 {"glXWaitVideoSyncSGI", &retrace::ignore},
257 {"glXWaitX", &retrace::ignore},