1 2 /* 3 * Copyright 2014 Google Inc. 4 * 5 * Use of this source code is governed by a BSD-style license that can be 6 * found in the LICENSE file. 7 */ 8 9 #include "gl/GrGLInterface.h" 10 #include "gl/GrGLAssembleInterface.h" 11 #include <dlfcn.h> 12 13 class GLLoader { 14 public: GLLoader()15 GLLoader() { 16 fLibrary = dlopen( 17 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", 18 RTLD_LAZY); 19 } 20 ~GLLoader()21 ~GLLoader() { 22 if (fLibrary) { 23 dlclose(fLibrary); 24 } 25 } 26 handle() const27 void* handle() const { 28 return nullptr == fLibrary ? RTLD_DEFAULT : fLibrary; 29 } 30 31 private: 32 void* fLibrary; 33 }; 34 35 class GLProcGetter { 36 public: GLProcGetter()37 GLProcGetter() {} 38 getProc(const char name[]) const39 GrGLFuncPtr getProc(const char name[]) const { 40 return (GrGLFuncPtr) dlsym(fLoader.handle(), name); 41 } 42 43 private: 44 GLLoader fLoader; 45 }; 46 ios_get_gl_proc(void * ctx,const char name[])47static GrGLFuncPtr ios_get_gl_proc(void* ctx, const char name[]) { 48 SkASSERT(ctx); 49 const GLProcGetter* getter = (const GLProcGetter*) ctx; 50 return getter->getProc(name); 51 } 52 GrGLCreateNativeInterface()53const GrGLInterface* GrGLCreateNativeInterface() { 54 GLProcGetter getter; 55 return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc); 56 } 57