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