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