OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Igalia S.L. | 2 * Copyright (C) 2011 Igalia S.L. |
3 * | 3 * |
4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or |
5 * modify it under the terms of the GNU Lesser General Public | 5 * modify it under the terms of the GNU Lesser General Public |
6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either |
7 * version 2.1 of the License, or (at your option) any later version. | 7 * version 2.1 of the License, or (at your option) any later version. |
8 * | 8 * |
9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 * Lesser General Public License for more details. | 12 * Lesser General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU Lesser General Public | 14 * You should have received a copy of the GNU Lesser General Public |
15 * License along with this library; if not, write to the Free Software | 15 * License along with this library; if not, write to the Free Software |
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U
SA | 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U
SA |
17 */ | 17 */ |
18 | 18 |
19 #include "config.h" | 19 #include "config.h" |
20 #if USE(3D_GRAPHICS) || defined(QT_OPENGL_SHIMS) | 20 #if USE(3D_GRAPHICS) |
21 | 21 |
22 #define DISABLE_SHIMS | 22 #define DISABLE_SHIMS |
23 #include "OpenGLShims.h" | 23 #include "OpenGLShims.h" |
24 | 24 |
25 #if !PLATFORM(QT) | |
26 #include <dlfcn.h> | 25 #include <dlfcn.h> |
27 #endif | |
28 | |
29 #include <wtf/text/CString.h> | 26 #include <wtf/text/CString.h> |
30 #include <wtf/text/WTFString.h> | 27 #include <wtf/text/WTFString.h> |
31 | 28 |
32 namespace WebCore { | 29 namespace WebCore { |
33 | 30 |
34 OpenGLFunctionTable* openGLFunctionTable() | 31 OpenGLFunctionTable* openGLFunctionTable() |
35 { | 32 { |
36 static OpenGLFunctionTable table; | 33 static OpenGLFunctionTable table; |
37 return &table; | 34 return &table; |
38 } | 35 } |
39 | 36 |
40 #if PLATFORM(QT) | |
41 static void* getProcAddress(const char* procName) | |
42 { | |
43 return reinterpret_cast<void*>(QOpenGLContext::currentContext()->getProcAddr
ess(procName)); | |
44 } | |
45 #else | |
46 typedef void* (*glGetProcAddressType) (const char* procName); | 37 typedef void* (*glGetProcAddressType) (const char* procName); |
47 static void* getProcAddress(const char* procName) | 38 static void* getProcAddress(const char* procName) |
48 { | 39 { |
49 static bool initialized = false; | 40 static bool initialized = false; |
50 static glGetProcAddressType getProcAddressFunction = 0; | 41 static glGetProcAddressType getProcAddressFunction = 0; |
51 | 42 |
52 if (!initialized) { | 43 if (!initialized) { |
53 getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsym(RT
LD_DEFAULT, "glXGetProcAddress")); | 44 getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsym(RT
LD_DEFAULT, "glXGetProcAddress")); |
54 if (!getProcAddressFunction) | 45 if (!getProcAddressFunction) |
55 getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsy
m(RTLD_DEFAULT, "glXGetProcAddressARB")); | 46 getProcAddressFunction = reinterpret_cast<glGetProcAddressType>(dlsy
m(RTLD_DEFAULT, "glXGetProcAddressARB")); |
56 } | 47 } |
57 | 48 |
58 if (!getProcAddressFunction) | 49 if (!getProcAddressFunction) |
59 return dlsym(RTLD_DEFAULT, procName); | 50 return dlsym(RTLD_DEFAULT, procName); |
60 return getProcAddressFunction(procName); | 51 return getProcAddressFunction(procName); |
61 } | 52 } |
62 #endif | |
63 | 53 |
64 static void* lookupOpenGLFunctionAddress(const char* functionName, bool* success
= 0) | 54 static void* lookupOpenGLFunctionAddress(const char* functionName, bool* success
= 0) |
65 { | 55 { |
66 if (success && !*success) | 56 if (success && !*success) |
67 return 0; | 57 return 0; |
68 | 58 |
69 void* target = getProcAddress(functionName); | 59 void* target = getProcAddress(functionName); |
70 if (target) | 60 if (target) |
71 return target; | 61 return target; |
72 | 62 |
(...skipping 19 matching lines...) Expand all Loading... |
92 target = getProcAddress(fullFunctionName.utf8().data()); | 82 target = getProcAddress(fullFunctionName.utf8().data()); |
93 #endif | 83 #endif |
94 | 84 |
95 // A null address is still a failure case. | 85 // A null address is still a failure case. |
96 if (!target && success) | 86 if (!target && success) |
97 *success = false; | 87 *success = false; |
98 | 88 |
99 return target; | 89 return target; |
100 } | 90 } |
101 | 91 |
102 #if PLATFORM(QT) && defined(QT_OPENGL_ES_2) | |
103 | |
104 // With Angle only EGL/GLES2 extensions are available through eglGetProcAddress,
not the regular standardized functions. | |
105 #define ASSIGN_FUNCTION_TABLE_ENTRY(FunctionName, success) \ | |
106 openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(:
:FunctionName) | |
107 | |
108 #else | |
109 | |
110 #define ASSIGN_FUNCTION_TABLE_ENTRY(FunctionName, success) \ | 92 #define ASSIGN_FUNCTION_TABLE_ENTRY(FunctionName, success) \ |
111 openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(l
ookupOpenGLFunctionAddress(#FunctionName, &success)) | 93 openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(l
ookupOpenGLFunctionAddress(#FunctionName, &success)) |
112 | 94 |
113 #endif | |
114 | |
115 #define ASSIGN_FUNCTION_TABLE_ENTRY_EXT(FunctionName) \ | 95 #define ASSIGN_FUNCTION_TABLE_ENTRY_EXT(FunctionName) \ |
116 openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(l
ookupOpenGLFunctionAddress(#FunctionName)) | 96 openGLFunctionTable()->FunctionName = reinterpret_cast<FunctionName##Type>(l
ookupOpenGLFunctionAddress(#FunctionName)) |
117 | 97 |
118 bool initializeOpenGLShims() | 98 bool initializeOpenGLShims() |
119 { | 99 { |
120 static bool success = true; | 100 static bool success = true; |
121 static bool initialized = false; | 101 static bool initialized = false; |
122 if (initialized) | 102 if (initialized) |
123 return success; | 103 return success; |
124 | 104 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttribPointer, success); | 211 ASSIGN_FUNCTION_TABLE_ENTRY(glVertexAttribPointer, success); |
232 | 212 |
233 if (!success) | 213 if (!success) |
234 LOG_ERROR("Could not initialize OpenGL shims"); | 214 LOG_ERROR("Could not initialize OpenGL shims"); |
235 return success; | 215 return success; |
236 } | 216 } |
237 | 217 |
238 } // namespace WebCore | 218 } // namespace WebCore |
239 | 219 |
240 #endif // USE(3D_GRAPHICS) | 220 #endif // USE(3D_GRAPHICS) |
OLD | NEW |