OLD | NEW |
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 "GLContext.h" | 9 #include "GLTestContext.h" |
10 #import <OpenGLES/EAGL.h> | 10 #import <OpenGLES/EAGL.h> |
11 #include <dlfcn.h> | 11 #include <dlfcn.h> |
12 | 12 |
13 #define EAGLCTX ((EAGLContext*)(fEAGLContext)) | 13 #define EAGLCTX ((EAGLContext*)(fEAGLContext)) |
14 | 14 |
15 namespace { | 15 namespace { |
16 | 16 |
17 class IOSGLContext : public sk_gpu_test::GLContext { | 17 class IOSGLTestContext : public sk_gpu_test::GLTestContext { |
18 public: | 18 public: |
19 IOSGLContext(); | 19 IOSGLTestContext(); |
20 ~IOSGLContext() override; | 20 ~IOSGLTestContext() override; |
21 | 21 |
22 private: | 22 private: |
23 void destroyGLContext(); | 23 void destroyGLContext(); |
24 | 24 |
25 void onPlatformMakeCurrent() const override; | 25 void onPlatformMakeCurrent() const override; |
26 void onPlatformSwapBuffers() const override; | 26 void onPlatformSwapBuffers() const override; |
27 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; | 27 GrGLFuncPtr onPlatformGetProcAddress(const char*) const override; |
28 | 28 |
29 void* fEAGLContext; | 29 void* fEAGLContext; |
30 void* fGLLibrary; | 30 void* fGLLibrary; |
31 }; | 31 }; |
32 | 32 |
33 IOSGLContext::IOSGLContext() | 33 IOSGLTestContext::IOSGLTestContext() |
34 : fEAGLContext(NULL) | 34 : fEAGLContext(NULL) |
35 , fGLLibrary(RTLD_DEFAULT) { | 35 , fGLLibrary(RTLD_DEFAULT) { |
36 | 36 |
37 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; | 37 fEAGLContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; |
38 [EAGLContext setCurrentContext:EAGLCTX]; | 38 [EAGLContext setCurrentContext:EAGLCTX]; |
39 | 39 |
40 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); | 40 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); |
41 if (NULL == gl.get()) { | 41 if (NULL == gl.get()) { |
42 SkDebugf("Failed to create gl interface"); | 42 SkDebugf("Failed to create gl interface"); |
43 this->destroyGLContext(); | 43 this->destroyGLContext(); |
44 return; | 44 return; |
45 } | 45 } |
46 if (!gl->validate()) { | 46 if (!gl->validate()) { |
47 SkDebugf("Failed to validate gl interface"); | 47 SkDebugf("Failed to validate gl interface"); |
48 this->destroyGLContext(); | 48 this->destroyGLContext(); |
49 return; | 49 return; |
50 } | 50 } |
51 | 51 |
52 fGLLibrary = dlopen( | 52 fGLLibrary = dlopen( |
53 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", | 53 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", |
54 RTLD_LAZY); | 54 RTLD_LAZY); |
55 | 55 |
56 this->init(gl.release()); | 56 this->init(gl.release()); |
57 } | 57 } |
58 | 58 |
59 IOSGLContext::~IOSGLContext() { | 59 IOSGLTestContext::~IOSGLTestContext() { |
60 this->teardown(); | 60 this->teardown(); |
61 this->destroyGLContext(); | 61 this->destroyGLContext(); |
62 } | 62 } |
63 | 63 |
64 void IOSGLContext::destroyGLContext() { | 64 void IOSGLTestContext::destroyGLContext() { |
65 if (fEAGLContext) { | 65 if (fEAGLContext) { |
66 if ([EAGLContext currentContext] == EAGLCTX) { | 66 if ([EAGLContext currentContext] == EAGLCTX) { |
67 [EAGLContext setCurrentContext:nil]; | 67 [EAGLContext setCurrentContext:nil]; |
68 } | 68 } |
69 [EAGLCTX release]; | 69 [EAGLCTX release]; |
70 fEAGLContext = NULL; | 70 fEAGLContext = NULL; |
71 } | 71 } |
72 if (RTLD_DEFAULT != fGLLibrary) { | 72 if (RTLD_DEFAULT != fGLLibrary) { |
73 dlclose(fGLLibrary); | 73 dlclose(fGLLibrary); |
74 } | 74 } |
75 } | 75 } |
76 | 76 |
77 | 77 |
78 void IOSGLContext::onPlatformMakeCurrent() const { | 78 void IOSGLTestContext::onPlatformMakeCurrent() const { |
79 if (![EAGLContext setCurrentContext:EAGLCTX]) { | 79 if (![EAGLContext setCurrentContext:EAGLCTX]) { |
80 SkDebugf("Could not set the context.\n"); | 80 SkDebugf("Could not set the context.\n"); |
81 } | 81 } |
82 } | 82 } |
83 | 83 |
84 void IOSGLContext::onPlatformSwapBuffers() const { } | 84 void IOSGLTestContext::onPlatformSwapBuffers() const { } |
85 | 85 |
86 GrGLFuncPtr IOSGLContext::onPlatformGetProcAddress(const char* procName) const { | 86 GrGLFuncPtr IOSGLTestContext::onPlatformGetProcAddress(const char* procName) con
st { |
87 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); | 87 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); |
88 } | 88 } |
89 | 89 |
90 } // anonymous namespace | 90 } // anonymous namespace |
91 | 91 |
92 namespace sk_gpu_test { | 92 namespace sk_gpu_test { |
93 GLContext *CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo
ntext) { | 93 GLTestContext *CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
| 94 GLTestContext *shareContext) { |
94 SkASSERT(!shareContext); | 95 SkASSERT(!shareContext); |
95 if (shareContext) { | 96 if (shareContext) { |
96 return NULL; | 97 return NULL; |
97 } | 98 } |
98 if (kGL_GrGLStandard == forcedGpuAPI) { | 99 if (kGL_GrGLStandard == forcedGpuAPI) { |
99 return NULL; | 100 return NULL; |
100 } | 101 } |
101 IOSGLContext *ctx = new IOSGLContext; | 102 IOSGLTestContext *ctx = new IOSGLTestContext; |
102 if (!ctx->isValid()) { | 103 if (!ctx->isValid()) { |
103 delete ctx; | 104 delete ctx; |
104 return NULL; | 105 return NULL; |
105 } | 106 } |
106 return ctx; | 107 return ctx; |
107 } | 108 } |
108 } | 109 } |
OLD | NEW |