• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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:
GLLoader()14     GLLoader() {
15         fLibrary = dlopen(
16             "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
17             RTLD_LAZY);
18     }
19 
~GLLoader()20     ~GLLoader() {
21         if (fLibrary) {
22             dlclose(fLibrary);
23         }
24     }
25 
handle() const26     void* handle() const {
27         return nullptr == fLibrary ? RTLD_DEFAULT : fLibrary;
28     }
29 
30 private:
31     void* fLibrary;
32 };
33 
34 class GLProcGetter {
35 public:
GLProcGetter()36     GLProcGetter() {}
37 
getProc(const char name[]) const38     GrGLFuncPtr getProc(const char name[]) const {
39         return (GrGLFuncPtr) dlsym(fLoader.handle(), name);
40     }
41 
42 private:
43     GLLoader fLoader;
44 };
45 
ios_get_gl_proc(void * ctx,const char name[])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 
GrGLCreateNativeInterface()52 const GrGLInterface* GrGLCreateNativeInterface() {
53     GLProcGetter getter;
54     return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc);
55 }
56