OLD | NEW |
| (Empty) |
1 | |
2 /* | |
3 * Copyright 2012 Google Inc. | |
4 * | |
5 * Use of this source code is governed by a BSD-style license that can be | |
6 * found in the LICENSE file. | |
7 */ | |
8 | |
9 #include "gl/SkGLContext.h" | |
10 #import <OpenGLES/EAGL.h> | |
11 | |
12 #define EAGLCTX ((EAGLContext*)(fEAGLContext)) | |
13 | |
14 namespace { | |
15 | |
16 class IOSNativeGLContext : public SkNativeGLContext { | |
17 public: | |
18 IOSNativeGLContext(); | |
19 | |
20 virtual ~IOSNativeGLContext(); | |
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 IOSNativeGLContext::IOSNativeGLContext() | |
33 : fEAGLContext(NULL) { | |
34 } | |
35 | |
36 IOSNativeGLContext::~IOSNativeGLContext() { | |
37 this->destroyGLContext(); | |
38 } | |
39 | |
40 void IOSNativeGLContext::destroyGLContext() { | |
41 if (fEAGLContext) { | |
42 if ([EAGLContext currentContext] == EAGLCTX) { | |
43 [EAGLContext setCurrentContext:nil]; | |
44 } | |
45 [EAGLCTX release]; | |
46 fEAGLContext = NULL; | |
47 } | |
48 } | |
49 | |
50 const GrGLInterface* IOSNativeGLContext::createGLContext(GrGLStandard forcedGpuA
PI) { | |
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 | |
67 void IOSNativeGLContext::makeCurrent() const { | |
68 if (![EAGLContext setCurrentContext:EAGLCTX]) { | |
69 SkDebugf("Could not set the context.\n"); | |
70 } | |
71 } | |
72 | |
73 void IOSNativeGLContext::swapBuffers() const { } | |
74 | |
75 } // anonymous namespace | |
76 | |
77 | |
78 SkNativeGLContext* SkCreatePlatformGLContext() { | |
79 return SkNEW(IOSNativeGLContext); | |
80 } | |
81 | |
OLD | NEW |