Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Unified Diff: src/gpu/gl/mac/SkNativeGLContext_mac.cpp

Issue 639793002: Revert of Make the Sk GL context class an abstract base class (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp ('k') | src/gpu/gl/mesa/SkMesaGLContext.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/gl/mac/SkNativeGLContext_mac.cpp
diff --git a/src/gpu/gl/mac/SkNativeGLContext_mac.cpp b/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..f63471c16a38275606103ed92ebd7b80fad73670
--- /dev/null
+++ b/src/gpu/gl/mac/SkNativeGLContext_mac.cpp
@@ -0,0 +1,84 @@
+
+/*
+ * 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/SkNativeGLContext.h"
+#include "AvailabilityMacros.h"
+
+SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
+ fOldCGLContext = CGLGetCurrentContext();
+}
+
+SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
+ CGLSetCurrentContext(fOldCGLContext);
+}
+
+///////////////////////////////////////////////////////////////////////////////
+
+SkNativeGLContext::SkNativeGLContext()
+ : fContext(NULL) {
+}
+
+SkNativeGLContext::~SkNativeGLContext() {
+ this->destroyGLContext();
+}
+
+void SkNativeGLContext::destroyGLContext() {
+ if (fContext) {
+ CGLReleaseContext(fContext);
+ }
+}
+
+const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
+ SkASSERT(NULL == fContext);
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+
+ CGLPixelFormatAttribute attributes[] = {
+#if MAC_OS_X_VERSION_10_7
+ kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core,
+#endif
+ kCGLPFADoubleBuffer,
+ (CGLPixelFormatAttribute)0
+ };
+ CGLPixelFormatObj pixFormat;
+ GLint npix;
+
+ CGLChoosePixelFormat(attributes, &pixFormat, &npix);
+
+ if (NULL == pixFormat) {
+ SkDebugf("CGLChoosePixelFormat failed.");
+ return NULL;
+ }
+
+ CGLCreateContext(pixFormat, NULL, &fContext);
+ CGLReleasePixelFormat(pixFormat);
+
+ if (NULL == fContext) {
+ SkDebugf("CGLCreateContext failed.");
+ return NULL;
+ }
+
+ CGLSetCurrentContext(fContext);
+
+ const GrGLInterface* interface = GrGLCreateNativeInterface();
+ if (NULL == interface) {
+ SkDebugf("Context could not create GL interface.\n");
+ this->destroyGLContext();
+ return NULL;
+ }
+
+ return interface;
+}
+
+void SkNativeGLContext::makeCurrent() const {
+ CGLSetCurrentContext(fContext);
+}
+
+void SkNativeGLContext::swapBuffers() const {
+ CGLFlushDrawable(fContext);
+}
« no previous file with comments | « src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp ('k') | src/gpu/gl/mesa/SkMesaGLContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698