1
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
9#include "gl/GrGLInterface.h"
10#include "gl/GrGLAssembleInterface.h"
11#include <dlfcn.h>
12
13class 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 (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(ctx);
49    const GLProcGetter* getter = (const GLProcGetter*) ctx;
50    return getter->getProc(name);
51}
52
53const GrGLInterface* GrGLCreateNativeInterface() {
54    GLProcGetter getter;
55    return GrGLAssembleGLESInterface(&getter, ios_get_gl_proc);
56}
57