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

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

Issue 640283004: Refactor SkGLContext to be actually extendable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: win compile fix. 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/iOS/SkCreatePlatformGLContext_iOS.mm ('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/SkCreatePlatformGLContext_mac.cpp
diff --git a/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
index 35ec2762968b9df918b26491b7a4485e9c8a592e..5ae1aeb3c7255b26250e23a8e06a3a790c7e55a7 100644
--- a/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
+++ b/src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp
@@ -14,39 +14,18 @@ namespace {
class MacGLContext : public SkGLContext {
public:
MacGLContext();
-
- virtual ~MacGLContext();
-
+ virtual ~MacGLContext() SK_OVERRIDE;
virtual void makeCurrent() const SK_OVERRIDE;
virtual void swapBuffers() const SK_OVERRIDE;
-protected:
- virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_OVERRIDE;
- virtual void destroyGLContext() SK_OVERRIDE;
private:
+ void destroyGLContext();
+
CGLContextObj fContext;
};
MacGLContext::MacGLContext()
: fContext(NULL) {
-}
-
-MacGLContext::~MacGLContext() {
- this->destroyGLContext();
-}
-
-void MacGLContext::destroyGLContext() {
- if (fContext) {
- CGLReleaseContext(fContext);
- }
-}
-
-const GrGLInterface* MacGLContext::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,
@@ -61,7 +40,7 @@ const GrGLInterface* MacGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
if (NULL == pixFormat) {
SkDebugf("CGLChoosePixelFormat failed.");
- return NULL;
+ return;
}
CGLCreateContext(pixFormat, NULL, &fContext);
@@ -69,19 +48,34 @@ const GrGLInterface* MacGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
if (NULL == fContext) {
SkDebugf("CGLCreateContext failed.");
- return NULL;
+ return;
}
CGLSetCurrentContext(fContext);
- const GrGLInterface* interface = GrGLCreateNativeInterface();
- if (NULL == interface) {
+ fGL.reset(GrGLCreateNativeInterface());
+ if (NULL == fGL.get()) {
SkDebugf("Context could not create GL interface.\n");
this->destroyGLContext();
- return NULL;
+ return;
+ }
+ if (!fGL->validate()) {
+ SkDebugf("Context could not validate GL interface.\n");
+ this->destroyGLContext();
+ return;
}
+}
- return interface;
+MacGLContext::~MacGLContext() {
+ this->destroyGLContext();
+}
+
+void MacGLContext::destroyGLContext() {
+ fGL.reset(NULL);
+ if (fContext) {
+ CGLReleaseContext(fContext);
+ fContext = NULL;
+ }
}
void MacGLContext::makeCurrent() const {
@@ -94,6 +88,14 @@ void MacGLContext::swapBuffers() const {
} // anonymous namespace
-SkGLContext* SkCreatePlatformGLContext() {
- return SkNEW(MacGLContext);
+SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
+ if (kGLES_GrGLStandard == forcedGpuAPI) {
+ return NULL;
+ }
+ MacGLContext* ctx = SkNEW(MacGLContext);
+ if (!ctx->isValid()) {
+ SkDELETE(ctx);
+ return NULL;
+ }
+ return ctx;
}
« no previous file with comments | « src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm ('k') | src/gpu/gl/mesa/SkMesaGLContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698