aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp')
-rw-r--r--src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp b/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
new file mode 100644
index 0000000000..7220b136c5
--- /dev/null
+++ b/src/gpu/gl/mac/GrGLMakeNativeInterface_mac.cpp
@@ -0,0 +1,63 @@
+/*
+ * 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 "SkTypes.h"
+#if defined(SK_BUILD_FOR_MAC)
+
+
+#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 (fLibrary) {
+ dlclose(fLibrary);
+ }
+ }
+
+ void* handle() const {
+ return nullptr == 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(ctx);
+ const GLProcGetter* getter = (const GLProcGetter*) ctx;
+ return getter->getProc(name);
+}
+
+sk_sp<const GrGLInterface> GrGLMakeNativeInterface() {
+ GLProcGetter getter;
+ return GrGLAssembleGLInterface(&getter, mac_get_gl_proc);
+}
+
+const GrGLInterface* GrGLCreateNativeInterface() { return GrGLMakeNativeInterface().release(); }
+
+#endif//defined(SK_BUILD_FOR_MAC)