blob: 024a631acc7a102fe66478731528e26b92776bbc [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
yangsu@google.combd3e3202011-07-13 22:05:00 +00002/*
bsalomona721c812014-08-26 11:35:23 -07003 * Copyright 2014 Google Inc.
epoger@google.comec3ed6a2011-07-28 14:26:00 +00004 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
yangsu@google.combd3e3202011-07-13 22:05:00 +00007 */
8
tomhudson@google.com6c8c34e2012-02-14 15:31:03 +00009#include "gl/GrGLInterface.h"
bsalomona721c812014-08-26 11:35:23 -070010#include "gl/GrGLAssembleInterface.h"
11#include <dlfcn.h>
yangsu@google.combd3e3202011-07-13 22:05:00 +000012
bsalomona721c812014-08-26 11:35:23 -070013class GLLoader {
14public:
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
31private:
32 void* fLibrary;
33};
34
35class GLProcGetter {
36public:
37 GLProcGetter() {}
38
39 GrGLFuncPtr getProc(const char name[]) const {
40 return (GrGLFuncPtr) dlsym(fLoader.handle(), name);
41 }
42
43private:
44 GLLoader fLoader;
45};
46
47static 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.combd3e3202011-07-13 22:05:00 +000052
bsalomon@google.comcca3c8f2012-09-28 16:56:28 +000053const GrGLInterface* GrGLCreateNativeInterface() {
bsalomona721c812014-08-26 11:35:23 -070054 GLProcGetter getter;
55 return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc);
bsalomon@google.com6fb736f2011-09-16 18:51:57 +000056}