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