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