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