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