]> git.cworth.org Git - apitrace/blob - dispatch/glproc_egl.cpp
glretrace: Always pass a format appropriate for the internalFormat when reading pixels.
[apitrace] / dispatch / glproc_egl.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 "glproc.hpp"
28
29
30 #if !defined(_WIN32)
31 #include "dlopen.hpp"
32 #endif
33
34
35 /*
36  * Handle to the true OpenGL library.
37  * XXX: Not really used yet.
38  */
39 #if defined(_WIN32)
40 HMODULE _libGlHandle = NULL;
41 #else
42 void *_libGlHandle = NULL;
43 #endif
44
45
46
47 #if defined(_WIN32)
48
49 #error Unsupported
50
51 #elif defined(__APPLE__)
52
53 #error Unsupported
54
55 #else
56
57 /*
58  * Lookup a public EGL/GL/GLES symbol
59  *
60  * The spec states that eglGetProcAddress should only be used for non-core
61  * (extensions) entry-points.  Core entry-points should be taken directly from
62  * the API specific libraries.
63  *
64  * We cannot tell here which API a symbol is meant for here (as some are
65  * exported by many).  So this code assumes that the appropriate shared
66  * libraries have been loaded previously (either dlopened with RTLD_GLOBAL, or
67  * as part of the executable dependencies), and that their symbols available
68  * for quering via dlsym(RTLD_NEXT, ...).
69  */
70 void *
71 _getPublicProcAddress(const char *procName)
72 {
73 #if defined(ANDROID)
74     /*
75      * Android does not support LD_PRELOAD.  It is assumed that applications
76      * are explicitely loading egltrace.so.
77      */
78
79     if (procName[0] == 'e' && procName[1] == 'g' && procName[2] == 'l') {
80         static void *libEGL = NULL;
81         if (!libEGL) {
82             libEGL = _dlopen("libEGL.so", RTLD_LOCAL | RTLD_LAZY);
83             if (!libEGL) {
84                 return NULL;
85             }
86         }
87         return dlsym(libEGL, procName);
88     }
89
90     if (procName[0] == 'g' && procName[1] == 'l') {
91         /* TODO: Use GLESv1/GLESv2 on a per-context basis. */
92         static void *sym = NULL;
93
94         static void *libGLESv2 = NULL;
95         if (!libGLESv2) {
96             libGLESv2 = _dlopen("libGLESv2.so", RTLD_LOCAL | RTLD_LAZY);
97         }
98         if (libGLESv2) {
99             sym = dlsym(libGLESv2, procName);
100         }
101         if (sym) {
102             return sym;
103         }
104
105         static void *libGLESv1 = NULL;
106         if (!libGLESv1) {
107             libGLESv1 = _dlopen("libGLESv1_CM.so", RTLD_LOCAL | RTLD_LAZY);
108         }
109         if (libGLESv1) {
110             sym = dlsym(libGLESv1, procName);
111         }
112         if (sym) {
113             return sym;
114         }
115     }
116
117     return NULL;
118 #else
119     return dlsym(RTLD_NEXT, procName);
120 #endif
121 }
122
123 /*
124  * Lookup a private EGL/GL/GLES symbol
125  *
126  * Private symbols should always be available through eglGetProcAddress, and
127  * they are guaranteed to work with any context bound (regardless of the API).
128  *
129  * However, per issue#57, eglGetProcAddress returns garbage on some
130  * implementations, and the spec states that implementations may choose to also
131  * export extension functions publicly, so we always attempt dlsym before
132  * eglGetProcAddress to mitigate that.
133  */
134 void *
135 _getPrivateProcAddress(const char *procName)
136 {
137     void *proc;
138     proc = _getPublicProcAddress(procName);
139     if (!proc &&
140         ((procName[0] == 'e' && procName[1] == 'g' && procName[2] == 'l') ||
141          (procName[0] == 'g' && procName[1] == 'l'))) {
142         proc = (void *) _eglGetProcAddress(procName);
143     }
144
145     return proc;
146 }
147
148 #endif