epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 2 | /* |
bsalomon | a721c81 | 2014-08-26 11:35:23 -0700 | [diff] [blame^] | 3 | * Copyright 2014 Google Inc. |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
tomhudson@google.com | 6c8c34e | 2012-02-14 15:31:03 +0000 | [diff] [blame] | 9 | #include "gl/GrGLInterface.h" |
bsalomon | a721c81 | 2014-08-26 11:35:23 -0700 | [diff] [blame^] | 10 | #include "gl/GrGLAssembleInterface.h" |
| 11 | #include <dlfcn.h> |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 12 | |
bsalomon | a721c81 | 2014-08-26 11:35:23 -0700 | [diff] [blame^] | 13 | class GLLoader { |
| 14 | public: |
| 15 | GLLoader() { |
| 16 | fLibrary = dlopen( |
| 17 | "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib", |
| 18 | RTLD_LAZY); |
| 19 | } |
| 20 | |
| 21 | ~GLLoader() { |
| 22 | if (NULL != fLibrary) { |
| 23 | dlclose(fLibrary); |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | void* handle() const { |
| 28 | return NULL == fLibrary ? RTLD_DEFAULT : fLibrary; |
| 29 | } |
| 30 | |
| 31 | private: |
| 32 | void* fLibrary; |
| 33 | }; |
| 34 | |
| 35 | class GLProcGetter { |
| 36 | public: |
| 37 | GLProcGetter() {} |
| 38 | |
| 39 | GrGLFuncPtr getProc(const char name[]) const { |
| 40 | return (GrGLFuncPtr) dlsym(fLoader.handle(), name); |
| 41 | } |
| 42 | |
| 43 | private: |
| 44 | GLLoader fLoader; |
| 45 | }; |
| 46 | |
| 47 | static GrGLFuncPtr ios_get_gl_proc(void* ctx, const char name[]) { |
| 48 | SkASSERT(NULL != ctx); |
| 49 | const GLProcGetter* getter = (const GLProcGetter*) ctx; |
| 50 | return getter->getProc(name); |
| 51 | } |
yangsu@google.com | bd3e320 | 2011-07-13 22:05:00 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | cca3c8f | 2012-09-28 16:56:28 +0000 | [diff] [blame] | 53 | const GrGLInterface* GrGLCreateNativeInterface() { |
bsalomon | a721c81 | 2014-08-26 11:35:23 -0700 | [diff] [blame^] | 54 | GLProcGetter getter; |
| 55 | return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc); |
bsalomon@google.com | 6fb736f | 2011-09-16 18:51:57 +0000 | [diff] [blame] | 56 | } |