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

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

Issue 630843002: 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 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/SkNativeGLContext.h" 9 #include "gl/SkNativeGLContext.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 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 14 namespace {
15
16 class SkNativeGLContextIOS : public SkNativeGLContext {
17 public:
18 SkNativeGLContextIOS();
19
20 virtual ~SkNativeGLContextIOS();
21
22 virtual void makeCurrent() const SK_OVERRIDE;
23 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
28 private:
29 void* fEAGLContext;
30 };
31
32 SkNativeGLContextIOS::AutoContextRestore::AutoContextRestore() {
15 fEAGLContext = [EAGLContext currentContext]; 33 fEAGLContext = [EAGLContext currentContext];
16 if (EAGLCTX) { 34 if (EAGLCTX) {
17 [EAGLCTX retain]; 35 [EAGLCTX retain];
18 } 36 }
19 } 37 }
20 38
21 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { 39 SkNativeGLContextIOS::AutoContextRestore::~AutoContextRestore() {
22 if (EAGLCTX) { 40 if (EAGLCTX) {
23 [EAGLContext setCurrentContext:EAGLCTX]; 41 [EAGLContext setCurrentContext:EAGLCTX];
24 [EAGLCTX release]; 42 [EAGLCTX release];
25 } 43 }
26 } 44 }
27 45
28 /////////////////////////////////////////////////////////////////////////////// 46 ///////////////////////////////////////////////////////////////////////////////
29 47
30 SkNativeGLContext::SkNativeGLContext() 48 SkNativeGLContextIOS::SkNativeGLContextIOS()
31 : fEAGLContext(NULL) { 49 : fEAGLContext(NULL) {
32 } 50 }
33 51
34 SkNativeGLContext::~SkNativeGLContext() { 52 SkNativeGLContextIOS::~SkNativeGLContextIOS() {
35 this->destroyGLContext(); 53 this->destroyGLContext();
36 } 54 }
37 55
38 void SkNativeGLContext::destroyGLContext() { 56 void SkNativeGLContextIOS::destroyGLContext() {
39 if (fEAGLContext) { 57 if (fEAGLContext) {
40 if ([EAGLContext currentContext] == EAGLCTX) { 58 if ([EAGLContext currentContext] == EAGLCTX) {
41 [EAGLContext setCurrentContext:nil]; 59 [EAGLContext setCurrentContext:nil];
42 } 60 }
43 [EAGLCTX release]; 61 [EAGLCTX release];
44 fEAGLContext = NULL; 62 fEAGLContext = NULL;
45 } 63 }
46 } 64 }
47 65
48 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP I) { 66 const GrGLInterface* SkNativeGLContextIOS::createGLContext(GrGLStandard forcedGp uAPI) {
49 if (kGL_GrGLStandard == forcedGpuAPI) { 67 if (kGL_GrGLStandard == forcedGpuAPI) {
50 return NULL; 68 return NULL;
51 } 69 }
52 70
53 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 71 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
54 [EAGLContext setCurrentContext:EAGLCTX]; 72 [EAGLContext setCurrentContext:EAGLCTX];
55 73
56 const GrGLInterface* interface = GrGLCreateNativeInterface(); 74 const GrGLInterface* interface = GrGLCreateNativeInterface();
57 if (!interface) { 75 if (!interface) {
58 SkDebugf("Failed to create gl interface"); 76 SkDebugf("Failed to create gl interface");
59 this->destroyGLContext(); 77 this->destroyGLContext();
60 return NULL; 78 return NULL;
61 } 79 }
62 return interface; 80 return interface;
63 } 81 }
64 82
65 void SkNativeGLContext::makeCurrent() const { 83 void SkNativeGLContextIOS::makeCurrent() const {
66 if (![EAGLContext setCurrentContext:EAGLCTX]) { 84 if (![EAGLContext setCurrentContext:EAGLCTX]) {
67 SkDebugf("Could not set the context.\n"); 85 SkDebugf("Could not set the context.\n");
68 } 86 }
69 } 87 }
70 88
71 void SkNativeGLContext::swapBuffers() const { } 89 void SkNativeGLContextIOS::swapBuffers() const { }
90
91 } // anonymous namespace
92
93
94 SkNativeGLContext* SkCreateGLContext() {
95 return SkNEW(SkNativeGLContextIOS);
96 }
97
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698