aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/iOS
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-03-30 09:26:24 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-03-30 09:26:24 -0700
commit6f70d43719d0583d486a000f66e915c10a6b83a2 (patch)
tree6f9511faa88ca6d44932e1a247fc10c0f297a3e0 /src/gpu/gl/iOS
parentfe3456cb006110d045b26ff3f8681b893a757b58 (diff)
Revert of Move SkGLContext and some GrGLInterface implementations to skgputest module (patchset #13 id:240001 of https://codereview.chromium.org/1815823002/ )
Reason for revert: red bots Original issue's description: > Move SkGLContext and some GrGLInterface implementations to skgputest module > > BUG=skia: > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1815823002 > CQ_EXTRA_TRYBOTS=client.skia.compile:Build-Ubuntu-GCC-x86_64-Release-CMake-Trybot,Build-Mac-Clang-x86_64-Release-CMake-Trybot > > Committed: https://skia.googlesource.com/skia/+/fe3456cb006110d045b26ff3f8681b893a757b58 TBR=jvanverth@google.com,bsalomon@google.com # Skipping CQ checks because original CL landed less than 1 days ago. NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true BUG=skia: Review URL: https://codereview.chromium.org/1845473004
Diffstat (limited to 'src/gpu/gl/iOS')
-rw-r--r--src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
new file mode 100644
index 0000000000..54dc59af03
--- /dev/null
+++ b/src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm
@@ -0,0 +1,106 @@
+
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "gl/SkGLContext.h"
+#import <OpenGLES/EAGL.h>
+#include <dlfcn.h>
+
+#define EAGLCTX ((EAGLContext*)(fEAGLContext))
+
+namespace {
+
+class IOSGLContext : public SkGLContext {
+public:
+ IOSGLContext();
+ ~IOSGLContext() override;
+
+private:
+ void destroyGLContext();
+
+ void onPlatformMakeCurrent() const override;
+ void onPlatformSwapBuffers() const override;
+ GrGLFuncPtr onPlatformGetProcAddress(const char*) const override;
+
+ void* fEAGLContext;
+ void* fGLLibrary;
+};
+
+IOSGLContext::IOSGLContext()
+ : fEAGLContext(NULL)
+ , fGLLibrary(RTLD_DEFAULT) {
+
+ fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
+ [EAGLContext setCurrentContext:EAGLCTX];
+
+ SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface());
+ if (NULL == gl.get()) {
+ SkDebugf("Failed to create gl interface");
+ this->destroyGLContext();
+ return;
+ }
+ if (!gl->validate()) {
+ SkDebugf("Failed to validate gl interface");
+ this->destroyGLContext();
+ return;
+ }
+
+ fGLLibrary = dlopen(
+ "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib",
+ RTLD_LAZY);
+
+ this->init(gl.release());
+}
+
+IOSGLContext::~IOSGLContext() {
+ this->teardown();
+ this->destroyGLContext();
+}
+
+void IOSGLContext::destroyGLContext() {
+ if (fEAGLContext) {
+ if ([EAGLContext currentContext] == EAGLCTX) {
+ [EAGLContext setCurrentContext:nil];
+ }
+ [EAGLCTX release];
+ fEAGLContext = NULL;
+ }
+ if (RTLD_DEFAULT != fGLLibrary) {
+ dlclose(fGLLibrary);
+ }
+}
+
+
+void IOSGLContext::onPlatformMakeCurrent() const {
+ if (![EAGLContext setCurrentContext:EAGLCTX]) {
+ SkDebugf("Could not set the context.\n");
+ }
+}
+
+void IOSGLContext::onPlatformSwapBuffers() const { }
+
+GrGLFuncPtr IOSGLContext::onPlatformGetProcAddress(const char* procName) const {
+ return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName));
+}
+
+} // anonymous namespace
+
+SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI, SkGLContext* shareContext) {
+ SkASSERT(!shareContext);
+ if (shareContext) {
+ return NULL;
+ }
+ if (kGL_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ IOSGLContext* ctx = new IOSGLContext;
+ if (!ctx->isValid()) {
+ delete ctx;
+ return NULL;
+ }
+ return ctx;
+}