| OLD | NEW |
| 1 | 1 |
| 2 /* | 2 /* |
| 3 * Copyright 2014 Google Inc. | 3 * Copyright 2014 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 <dlfcn.h> | 11 #include <dlfcn.h> |
| 12 | 12 |
| 13 class GLLoader { | 13 class GLLoader { |
| 14 public: | 14 public: |
| 15 GLLoader() { | 15 GLLoader() { |
| 16 fLibrary = dlopen( | 16 fLibrary = dlopen( |
| 17 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/li
bGL.dylib", | 17 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/li
bGL.dylib", |
| 18 RTLD_LAZY); | 18 RTLD_LAZY); |
| 19 } | 19 } |
| 20 | 20 |
| 21 ~GLLoader() { | 21 ~GLLoader() { |
| 22 if (fLibrary) { | 22 if (fLibrary) { |
| 23 dlclose(fLibrary); | 23 dlclose(fLibrary); |
| 24 } | 24 } |
| 25 } | 25 } |
| 26 | 26 |
| 27 void* handle() const { | 27 void* handle() const { |
| 28 return NULL == fLibrary ? RTLD_DEFAULT : fLibrary; | 28 return nullptr == fLibrary ? RTLD_DEFAULT : fLibrary; |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 void* fLibrary; | 32 void* fLibrary; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 class GLProcGetter { | 35 class GLProcGetter { |
| 36 public: | 36 public: |
| 37 GLProcGetter() {} | 37 GLProcGetter() {} |
| 38 | 38 |
| 39 GrGLFuncPtr getProc(const char name[]) const { | 39 GrGLFuncPtr getProc(const char name[]) const { |
| 40 return (GrGLFuncPtr) dlsym(fLoader.handle(), name); | 40 return (GrGLFuncPtr) dlsym(fLoader.handle(), name); |
| 41 } | 41 } |
| 42 | 42 |
| 43 private: | 43 private: |
| 44 GLLoader fLoader; | 44 GLLoader fLoader; |
| 45 }; | 45 }; |
| 46 | 46 |
| 47 static GrGLFuncPtr ios_get_gl_proc(void* ctx, const char name[]) { | 47 static GrGLFuncPtr ios_get_gl_proc(void* ctx, const char name[]) { |
| 48 SkASSERT(ctx); | 48 SkASSERT(ctx); |
| 49 const GLProcGetter* getter = (const GLProcGetter*) ctx; | 49 const GLProcGetter* getter = (const GLProcGetter*) ctx; |
| 50 return getter->getProc(name); | 50 return getter->getProc(name); |
| 51 } | 51 } |
| 52 | 52 |
| 53 const GrGLInterface* GrGLCreateNativeInterface() { | 53 const GrGLInterface* GrGLCreateNativeInterface() { |
| 54 GLProcGetter getter; | 54 GLProcGetter getter; |
| 55 return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc); | 55 return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc); |
| 56 } | 56 } |
| OLD | NEW |