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