gfx/skia/trunk/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp
author George Wright <george@mozilla.com>
Mon, 28 Jul 2014 15:06:12 -0400
changeset 220765 883cd6be06d294600562435ebea87d2804bca957
parent 193135 dfba3a2480bc41639c0c4e8ef0f90e9925661b18
permissions -rw-r--r--
[PATCH 08/15] Bug 1017113 - Update Skia to 2014-07-28 r=upstream


/*
 * Copyright 2011 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#include "gl/GrGLInterface.h"
#include "gl/GrGLAssembleInterface.h"

#include <dlfcn.h>

class GLLoader {
public:
    GLLoader() {
        fLibrary = dlopen(
                    "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
                    RTLD_LAZY);
    }

    ~GLLoader() {
        if (NULL != fLibrary) {
            dlclose(fLibrary);
        }
    }

    void* handle() const {
        return NULL == fLibrary ? RTLD_DEFAULT : fLibrary;
    }

private:
    void* fLibrary;
};

class GLProcGetter {
public:
    GLProcGetter() {}

    GrGLFuncPtr getProc(const char name[]) const {
        return (GrGLFuncPtr) dlsym(fLoader.handle(), name);
    }

private:
    GLLoader fLoader;
};

static GrGLFuncPtr mac_get_gl_proc(void* ctx, const char name[]) {
    SkASSERT(NULL != ctx);
    const GLProcGetter* getter = (const GLProcGetter*) ctx;
    return getter->getProc(name);
}

const GrGLInterface* GrGLCreateNativeInterface() {
    GLProcGetter getter;
    return GrGLAssembleGLInterface(&getter, mac_get_gl_proc);
}