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

Side by Side Diff: src/gpu/gl/iOS/SkCreatePlatformGLContext_iOS.mm

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 unified diff | Download patch
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "gl/SkGLContext.h" 9 #include "gl/SkGLContext.h"
10 #import <OpenGLES/EAGL.h> 10 #import <OpenGLES/EAGL.h>
11 11
12 #define EAGLCTX ((EAGLContext*)(fEAGLContext)) 12 #define EAGLCTX ((EAGLContext*)(fEAGLContext))
13 13
14 namespace { 14 namespace {
15 15
16 class IOSGLContext : public SkGLContext { 16 class IOSGLContext : public SkGLContext {
17 public: 17 public:
18 IOSGLContext(); 18 IOSGLContext();
19 19 virtual ~IOSGLContext() SK_OVERRIDE;
20 virtual ~IOSGLContext();
21
22 virtual void makeCurrent() const SK_OVERRIDE; 20 virtual void makeCurrent() const SK_OVERRIDE;
23 virtual void swapBuffers() const SK_OVERRIDE; 21 virtual void swapBuffers() const SK_OVERRIDE;
24 protected:
25 virtual const GrGLInterface* createGLContext(GrGLStandard forcedGpuAPI) SK_O VERRIDE;
26 virtual void destroyGLContext() SK_OVERRIDE;
27 22
28 private: 23 private:
24 void destroyGLContext();
25
29 void* fEAGLContext; 26 void* fEAGLContext;
30 }; 27 };
31 28
32 IOSGLContext::IOSGLContext() 29 IOSGLContext::IOSGLContext()
33 : fEAGLContext(NULL) { 30 : fEAGLContext(NULL) {
31
32 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
33 [EAGLContext setCurrentContext:EAGLCTX];
34
35 fGL.reset(GrGLCreateNativeInterface());
36 if (NULL == fGL.get()) {
37 SkDebugf("Failed to create gl interface");
38 this->destroyGLContext();
39 return;
40 }
41 if (!fGL->validate()) {
42 SkDebugf("Failed to validate gl interface");
43 this->destroyGLContext();
44 return;
45 }
34 } 46 }
35 47
36 IOSGLContext::~IOSGLContext() { 48 IOSGLContext::~IOSGLContext() {
37 this->destroyGLContext(); 49 this->destroyGLContext();
38 } 50 }
39 51
40 void IOSGLContext::destroyGLContext() { 52 void IOSGLContext::destroyGLContext() {
53 fGL.reset(NULL);
41 if (fEAGLContext) { 54 if (fEAGLContext) {
42 if ([EAGLContext currentContext] == EAGLCTX) { 55 if ([EAGLContext currentContext] == EAGLCTX) {
43 [EAGLContext setCurrentContext:nil]; 56 [EAGLContext setCurrentContext:nil];
44 } 57 }
45 [EAGLCTX release]; 58 [EAGLCTX release];
46 fEAGLContext = NULL; 59 fEAGLContext = NULL;
47 } 60 }
48 } 61 }
49 62
50 const GrGLInterface* IOSGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
51 if (kGL_GrGLStandard == forcedGpuAPI) {
52 return NULL;
53 }
54
55 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
56 [EAGLContext setCurrentContext:EAGLCTX];
57
58 const GrGLInterface* interface = GrGLCreateNativeInterface();
59 if (!interface) {
60 SkDebugf("Failed to create gl interface");
61 this->destroyGLContext();
62 return NULL;
63 }
64 return interface;
65 }
66 63
67 void IOSGLContext::makeCurrent() const { 64 void IOSGLContext::makeCurrent() const {
68 if (![EAGLContext setCurrentContext:EAGLCTX]) { 65 if (![EAGLContext setCurrentContext:EAGLCTX]) {
69 SkDebugf("Could not set the context.\n"); 66 SkDebugf("Could not set the context.\n");
70 } 67 }
71 } 68 }
72 69
73 void IOSGLContext::swapBuffers() const { } 70 void IOSGLContext::swapBuffers() const { }
74 71
75 } // anonymous namespace 72 } // anonymous namespace
76 73
77 74 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) {
78 SkGLContext* SkCreatePlatformGLContext() { 75 if (kGL_GrGLStandard == forcedGpuAPI) {
79 return SkNEW(IOSGLContext); 76 return NULL;
77 }
78 IOSGLContext* ctx = SkNEW(IOSGLContext);
79 if (!ctx->isValid()) {
80 SkDELETE(ctx);
81 return NULL;
82 }
83 return ctx;
80 } 84 }
81 85
OLDNEW
« no previous file with comments | « src/gpu/gl/glx/SkCreatePlatformGLContext_glx.cpp ('k') | src/gpu/gl/mac/SkCreatePlatformGLContext_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698