]> git.cworth.org Git - apitrace/blob - glretrace_cgl.cpp
Silence warnings due to unused variables.
[apitrace] / glretrace_cgl.cpp
1 /**************************************************************************
2  *
3  * Copyright 2011 Jose Fonseca
4  * All Rights Reserved.
5  *
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:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
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
22  * THE SOFTWARE.
23  *
24  **************************************************************************/
25
26
27 #include <string.h>
28
29 #include "glproc.hpp"
30 #include "retrace.hpp"
31 #include "glretrace.hpp"
32
33
34 using namespace glretrace;
35
36
37 typedef std::map<unsigned long long, glws::Drawable *> DrawableMap;
38 typedef std::map<unsigned long long, glws::Context *> ContextMap;
39 static DrawableMap drawable_map;
40 static ContextMap context_map;
41 static glws::Context *sharedContext = NULL;
42
43
44 static glws::Drawable *
45 getDrawable(unsigned long drawable_id) {
46     if (drawable_id == 0) {
47         return NULL;
48     }
49
50     DrawableMap::const_iterator it;
51     it = drawable_map.find(drawable_id);
52     if (it == drawable_map.end()) {
53         return (drawable_map[drawable_id] = ws->createDrawable(visual));
54     }
55
56     return it->second;
57 }
58
59
60 static glws::Context *
61 getContext(unsigned long long ctx) {
62     if (ctx == 0) {
63         return NULL;
64     }
65
66     ContextMap::const_iterator it;
67     it = context_map.find(ctx);
68     if (it == context_map.end()) {
69         glws::Context *context;
70         context_map[ctx] = context = ws->createContext(visual, sharedContext);
71         if (!sharedContext) {
72             sharedContext = context;
73         }
74         return context;
75     }
76
77     return it->second;
78 }
79
80 static void retrace_CGLSetCurrentContext(Trace::Call &call) {
81     unsigned long long ctx = call.arg(0).toUIntPtr();
82
83     /*
84      * XXX: Frame termination is mostly a guess, because we don't trace enough
85      * of the CGL API to know that.
86      */
87     if (drawable && context) {
88         if (double_buffer) {
89             drawable->swapBuffers();
90         } else {
91             glFlush();
92         }
93
94         frame_complete(call.no);
95     }
96
97     glws::Drawable *new_drawable = getDrawable(ctx);
98     glws::Context *new_context = getContext(ctx);
99
100     bool result = ws->makeCurrent(new_drawable, new_context);
101
102     if (new_drawable && new_context && result) {
103         drawable = new_drawable;
104         context = new_context;
105     } else {
106         drawable = NULL;
107         context = NULL;
108     }
109 }
110
111
112 void glretrace::retrace_call_cgl(Trace::Call &call) {
113     const char *name = call.name().c_str();
114
115     if (strcmp(name, "CGLSetCurrentContext") == 0) {
116        retrace_CGLSetCurrentContext(call);
117        return;
118     }
119
120     if (strcmp(name, "CGLGetCurrentContext") == 0) {
121        return;
122     }
123
124     retrace::retrace_unknown(call);
125 }
126