blob: 006a846e2f202bb4a974bb872b6691523d80849f [file] [log] [blame]
José Fonseca43648602011-05-15 12:56:59 +01001##########################################################################
2#
3# Copyright 2011 VMware, Inc.
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
José Fonseca1b6c8752012-04-15 14:33:00 +010027"""CGL tracing generator."""
José Fonseca43648602011-05-15 12:56:59 +010028
29
José Fonseca452d3252012-04-14 15:55:40 +010030from gltrace import GlTracer
José Fonseca81301932012-11-11 00:10:20 +000031from specs.stdapi import Module, API
José Fonsecabd86a222011-09-27 09:21:38 +010032from specs.glapi import glapi
33from specs.cglapi import cglapi
José Fonseca43648602011-05-15 12:56:59 +010034
35
36class CglTracer(GlTracer):
37
José Fonseca54f304a2012-01-14 19:33:08 +000038 def isFunctionPublic(self, function):
José Fonseca1b6c8752012-04-15 14:33:00 +010039 # all OpenGL symbols are visible on MacOSX
José Fonseca43648602011-05-15 12:56:59 +010040 return True
41
Imre Deaka4c698d2012-05-23 10:56:06 +030042 def traceFunctionImplBody(self, function):
Imre Deaka4c698d2012-05-23 10:56:06 +030043 if function.name == 'CGLReleaseContext':
44 # Unlike other GL APIs like EGL or GLX, CGL will make the context
45 # not current if it's the current context.
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010046 print(' if (_CGLGetContextRetainCount(ctx) == 1) {')
47 print(' if (gltrace::releaseContext((uintptr_t)ctx)) {')
48 print(' if (_CGLGetCurrentContext() == ctx) {')
49 print(' gltrace::clearContext();')
50 print(' }')
51 print(' }')
52 print(' }')
Imre Deaka4c698d2012-05-23 10:56:06 +030053
54 if function.name == 'CGLDestroyContext':
55 # The same rule applies here about the as for CGLReleaseContext.
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010056 print(' if (gltrace::releaseContext((uintptr_t)ctx)) {')
57 print(' if (_CGLGetCurrentContext() == ctx) {')
58 print(' gltrace::clearContext();')
59 print(' }')
60 print(' }')
Imre Deaka4c698d2012-05-23 10:56:06 +030061
José Fonseca53eb3182012-07-09 10:47:16 +010062 GlTracer.traceFunctionImplBody(self, function)
63
64 if function.name == 'CGLCreateContext':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010065 print(' if (_result == kCGLNoError) {')
Robert Tarasov6ccf5bb2020-01-10 12:31:25 -080066 print(' gltrace::createContext((uintptr_t)*ctx, (uintptr_t)share);')
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010067 print(' }')
José Fonseca53eb3182012-07-09 10:47:16 +010068
69 if function.name == 'CGLSetCurrentContext':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010070 print(' if (_result == kCGLNoError) {')
71 print(' if (ctx != NULL) {')
72 print(' gltrace::setContext((uintptr_t)ctx);')
73 print(' } else {')
74 print(' gltrace::clearContext();')
75 print(' }')
76 print(' }')
José Fonseca53eb3182012-07-09 10:47:16 +010077
78 if function.name == 'CGLRetainContext':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010079 print(' gltrace::retainContext((uintptr_t)ctx);')
José Fonseca53eb3182012-07-09 10:47:16 +010080
José Fonseca43648602011-05-15 12:56:59 +010081
82if __name__ == '__main__':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010083 print()
84 print('#include <stdlib.h>')
85 print('#include <string.h>')
86 print()
87 print('#include "trace_writer_local.hpp"')
88 print()
89 print('// To validate our prototypes')
90 print('#define GL_GLEXT_PROTOTYPES')
91 print()
92 print('#include "glproc.hpp"')
93 print('#include "glsize.hpp"')
94 print()
José Fonseca43648602011-05-15 12:56:59 +010095
José Fonseca81301932012-11-11 00:10:20 +000096 module = Module()
97 module.mergeModule(cglapi)
98 module.mergeModule(glapi)
José Fonseca43648602011-05-15 12:56:59 +010099 api = API()
José Fonseca81301932012-11-11 00:10:20 +0000100 api.addModule(module)
José Fonseca43648602011-05-15 12:56:59 +0100101 tracer = CglTracer()
José Fonseca1b6c8752012-04-15 14:33:00 +0100102 tracer.traceApi(api)
José Fonseca43648602011-05-15 12:56:59 +0100103
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100104 print(r'''
José Fonseca43648602011-05-15 12:56:59 +0100105
José Fonseca43648602011-05-15 12:56:59 +0100106PUBLIC
107void * gll_noop = 0;
108
José Fonsecaaa5ba932014-06-24 11:33:59 +0100109
110__attribute__((constructor))
111static void
112_init(void) {
113 /*
José Fonsecaa3e46142014-12-04 22:08:24 +0000114 * XXX: Setting DYLD_IMAGE_SUFFIX to anything (even an empty string)
115 * changes dlopen behavior causing our trick of symlinking a temporary file
116 * to the real OpenGL framework to stop working, leading to infinite
117 * recursion.
118 */
119 if (getenv("DYLD_IMAGE_SUFFIX")) {
120 os::log("error: tracing with DYLD_IMAGE_SUFFIX not supported.\n");
121 os::abort();
122 }
123
124 /*
José Fonsecaaa5ba932014-06-24 11:33:59 +0100125 * XXX: Temporary workaround for
126 * https://github.com/apitrace/apitrace/issues/278#issuecomment-46889575
127 * until we have a better way of intercepting applications that
128 * dlopen("libGL.dylib") directly.
129 */
130 setenv("SDL_OPENGL_LIBRARY", "/System/Library/Frameworks/OpenGL.framework/OpenGL", 1);
131}
132
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +0100133''')