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

Side by Side Diff: src/gpu/gl/iOS/SkCreatePlatformGLContext_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: fix android link problem and ios compile problem 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
« no previous file with comments | « src/gpu/gl/glx/SkNativeGLContext_glx.cpp ('k') | src/gpu/gl/iOS/SkNativeGLContext_iOS.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 14 namespace {
15 fEAGLContext = [EAGLContext currentContext];
16 if (EAGLCTX) {
17 [EAGLCTX retain];
18 }
19 }
20 15
21 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { 16 class IOSGLContext : public SkGLContext {
22 if (EAGLCTX) { 17 public:
23 [EAGLContext setCurrentContext:EAGLCTX]; 18 IOSGLContext();
24 [EAGLCTX release];
25 }
26 }
27 19
28 /////////////////////////////////////////////////////////////////////////////// 20 virtual ~IOSGLContext();
29 21
30 SkNativeGLContext::SkNativeGLContext() 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 IOSGLContext::IOSGLContext()
31 : fEAGLContext(NULL) { 33 : fEAGLContext(NULL) {
32 } 34 }
33 35
34 SkNativeGLContext::~SkNativeGLContext() { 36 IOSGLContext::~IOSGLContext() {
35 this->destroyGLContext(); 37 this->destroyGLContext();
36 } 38 }
37 39
38 void SkNativeGLContext::destroyGLContext() { 40 void IOSGLContext::destroyGLContext() {
39 if (fEAGLContext) { 41 if (fEAGLContext) {
40 if ([EAGLContext currentContext] == EAGLCTX) { 42 if ([EAGLContext currentContext] == EAGLCTX) {
41 [EAGLContext setCurrentContext:nil]; 43 [EAGLContext setCurrentContext:nil];
42 } 44 }
43 [EAGLCTX release]; 45 [EAGLCTX release];
44 fEAGLContext = NULL; 46 fEAGLContext = NULL;
45 } 47 }
46 } 48 }
47 49
48 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP I) { 50 const GrGLInterface* IOSGLContext::createGLContext(GrGLStandard forcedGpuAPI) {
49 if (kGL_GrGLStandard == forcedGpuAPI) { 51 if (kGL_GrGLStandard == forcedGpuAPI) {
50 return NULL; 52 return NULL;
51 } 53 }
52 54
53 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 55 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
54 [EAGLContext setCurrentContext:EAGLCTX]; 56 [EAGLContext setCurrentContext:EAGLCTX];
55 57
56 const GrGLInterface* interface = GrGLCreateNativeInterface(); 58 const GrGLInterface* interface = GrGLCreateNativeInterface();
57 if (!interface) { 59 if (!interface) {
58 SkDebugf("Failed to create gl interface"); 60 SkDebugf("Failed to create gl interface");
59 this->destroyGLContext(); 61 this->destroyGLContext();
60 return NULL; 62 return NULL;
61 } 63 }
62 return interface; 64 return interface;
63 } 65 }
64 66
65 void SkNativeGLContext::makeCurrent() const { 67 void IOSGLContext::makeCurrent() const {
66 if (![EAGLContext setCurrentContext:EAGLCTX]) { 68 if (![EAGLContext setCurrentContext:EAGLCTX]) {
67 SkDebugf("Could not set the context.\n"); 69 SkDebugf("Could not set the context.\n");
68 } 70 }
69 } 71 }
70 72
71 void SkNativeGLContext::swapBuffers() const { } 73 void IOSGLContext::swapBuffers() const { }
74
75 } // anonymous namespace
76
77
78 SkGLContext* SkCreatePlatformGLContext() {
79 return SkNEW(IOSGLContext);
80 }
81
OLDNEW
« no previous file with comments | « src/gpu/gl/glx/SkNativeGLContext_glx.cpp ('k') | src/gpu/gl/iOS/SkNativeGLContext_iOS.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698