OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2012 Google Inc. | 3 * Copyright 2012 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "gl/GrGLInterface.h" | 9 #include "gl/GrGLInterface.h" |
10 #include "gl/GrGLAssembleInterface.h" | 10 #include "gl/GrGLAssembleInterface.h" |
11 #include "../ports/SkOSLibrary.h" | 11 #include "../ports/SkOSLibrary.h" |
12 | 12 |
13 #include <EGL/egl.h> | 13 #include <EGL/egl.h> |
14 | 14 |
15 namespace { | |
16 struct Libs { | |
17 void* fGLLib; | |
18 void* fEGLLib; | |
19 }; | |
20 } | |
21 | |
22 static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { | 15 static GrGLFuncPtr angle_get_gl_proc(void* ctx, const char name[]) { |
23 const Libs* libs = reinterpret_cast<const Libs*>(ctx); | 16 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(ctx, name); |
24 GrGLFuncPtr proc = (GrGLFuncPtr) GetProcedureAddress(libs->fGLLib, name); | |
25 if (proc) { | 17 if (proc) { |
26 return proc; | 18 return proc; |
27 } | 19 } |
28 proc = (GrGLFuncPtr) GetProcedureAddress(libs->fEGLLib, name); | |
29 if (proc) { | |
30 return proc; | |
31 } | |
32 return eglGetProcAddress(name); | 20 return eglGetProcAddress(name); |
33 } | 21 } |
34 | 22 |
35 const GrGLInterface* GrGLCreateANGLEInterface() { | 23 const GrGLInterface* GrGLCreateANGLEInterface() { |
36 static Libs gLibs = { nullptr, nullptr }; | 24 static void* gANGLELib = nullptr; |
37 | 25 |
38 if (nullptr == gLibs.fGLLib) { | 26 if (nullptr == gANGLELib) { |
39 // We load the ANGLE library and never let it go | 27 // We load the ANGLE library and never let it go |
40 #if defined _WIN32 | 28 #if defined _WIN32 |
41 gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dll"); | 29 gANGLELib = DynamicLoadLibrary("libGLESv2.dll"); |
42 gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dll"); | |
43 #elif defined SK_BUILD_FOR_MAC | 30 #elif defined SK_BUILD_FOR_MAC |
44 gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.dylib"); | 31 gANGLELib = DynamicLoadLibrary("libGLESv2.dylib"); |
45 gLibs.fEGLLib = DynamicLoadLibrary("libEGL.dylib"); | |
46 #else | 32 #else |
47 gLibs.fGLLib = DynamicLoadLibrary("libGLESv2.so"); | 33 gANGLELib = DynamicLoadLibrary("libGLESv2.so"); |
48 gLibs.fGLLib = DynamicLoadLibrary("libEGL.so"); | 34 #endif // defined _WIN32 |
49 #endif | |
50 } | 35 } |
51 | 36 |
52 if (nullptr == gLibs.fGLLib || nullptr == gLibs.fEGLLib) { | 37 if (nullptr == gANGLELib) { |
53 // We can't setup the interface correctly w/o the so | 38 // We can't setup the interface correctly w/o the so |
54 return nullptr; | 39 return nullptr; |
55 } | 40 } |
56 | 41 |
57 return GrGLAssembleGLESInterface(&gLibs, angle_get_gl_proc); | 42 return GrGLAssembleGLESInterface(gANGLELib, angle_get_gl_proc); |
58 } | 43 } |
OLD | NEW |