OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 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 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 #include "gl/GLContext.h" | 10 #include "gl/GLTestContext.h" |
11 #include "AvailabilityMacros.h" | 11 #include "AvailabilityMacros.h" |
12 | 12 |
13 #include <OpenGL/OpenGL.h> | 13 #include <OpenGL/OpenGL.h> |
14 #include <dlfcn.h> | 14 #include <dlfcn.h> |
15 | 15 |
16 namespace { | 16 namespace { |
17 class MacGLContext : public sk_gpu_test::GLContext { | 17 class MacGLTestContext : public sk_gpu_test::GLTestContext { |
18 public: | 18 public: |
19 MacGLContext(); | 19 MacGLTestContext(); |
20 ~MacGLContext() override; | 20 ~MacGLTestContext() 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 CGLContextObj fContext; | 29 CGLContextObj fContext; |
30 void* fGLLibrary; | 30 void* fGLLibrary; |
31 }; | 31 }; |
32 | 32 |
33 MacGLContext::MacGLContext() | 33 MacGLTestContext::MacGLTestContext() |
34 : fContext(nullptr) | 34 : fContext(nullptr) |
35 , fGLLibrary(RTLD_DEFAULT) { | 35 , fGLLibrary(RTLD_DEFAULT) { |
36 CGLPixelFormatAttribute attributes[] = { | 36 CGLPixelFormatAttribute attributes[] = { |
37 #if MAC_OS_X_VERSION_10_7 | 37 #if MAC_OS_X_VERSION_10_7 |
38 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, | 38 kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core
, |
39 #endif | 39 #endif |
40 kCGLPFADoubleBuffer, | 40 kCGLPFADoubleBuffer, |
41 (CGLPixelFormatAttribute)0 | 41 (CGLPixelFormatAttribute)0 |
42 }; | 42 }; |
43 CGLPixelFormatObj pixFormat; | 43 CGLPixelFormatObj pixFormat; |
(...skipping 28 matching lines...) Expand all Loading... |
72 return; | 72 return; |
73 } | 73 } |
74 | 74 |
75 fGLLibrary = dlopen( | 75 fGLLibrary = dlopen( |
76 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", | 76 "/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.
dylib", |
77 RTLD_LAZY); | 77 RTLD_LAZY); |
78 | 78 |
79 this->init(gl.release()); | 79 this->init(gl.release()); |
80 } | 80 } |
81 | 81 |
82 MacGLContext::~MacGLContext() { | 82 MacGLTestContext::~MacGLTestContext() { |
83 this->teardown(); | 83 this->teardown(); |
84 this->destroyGLContext(); | 84 this->destroyGLContext(); |
85 } | 85 } |
86 | 86 |
87 void MacGLContext::destroyGLContext() { | 87 void MacGLTestContext::destroyGLContext() { |
88 if (fContext) { | 88 if (fContext) { |
89 CGLReleaseContext(fContext); | 89 CGLReleaseContext(fContext); |
90 fContext = nullptr; | 90 fContext = nullptr; |
91 } | 91 } |
92 if (RTLD_DEFAULT != fGLLibrary) { | 92 if (RTLD_DEFAULT != fGLLibrary) { |
93 dlclose(fGLLibrary); | 93 dlclose(fGLLibrary); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void MacGLContext::onPlatformMakeCurrent() const { | 97 void MacGLTestContext::onPlatformMakeCurrent() const { |
98 CGLSetCurrentContext(fContext); | 98 CGLSetCurrentContext(fContext); |
99 } | 99 } |
100 | 100 |
101 void MacGLContext::onPlatformSwapBuffers() const { | 101 void MacGLTestContext::onPlatformSwapBuffers() const { |
102 CGLFlushDrawable(fContext); | 102 CGLFlushDrawable(fContext); |
103 } | 103 } |
104 | 104 |
105 GrGLFuncPtr MacGLContext::onPlatformGetProcAddress(const char* procName) const { | 105 GrGLFuncPtr MacGLTestContext::onPlatformGetProcAddress(const char* procName) con
st { |
106 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); | 106 return reinterpret_cast<GrGLFuncPtr>(dlsym(fGLLibrary, procName)); |
107 } | 107 } |
108 | 108 |
109 } // anonymous namespace | 109 } // anonymous namespace |
110 | 110 |
111 namespace sk_gpu_test { | 111 namespace sk_gpu_test { |
112 GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext* shareCo
ntext) { | 112 GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
| 113 GLTestContext* shareContext) { |
113 SkASSERT(!shareContext); | 114 SkASSERT(!shareContext); |
114 if (shareContext) { | 115 if (shareContext) { |
115 return nullptr; | 116 return nullptr; |
116 } | 117 } |
117 | 118 |
118 if (kGLES_GrGLStandard == forcedGpuAPI) { | 119 if (kGLES_GrGLStandard == forcedGpuAPI) { |
119 return nullptr; | 120 return nullptr; |
120 } | 121 } |
121 MacGLContext* ctx = new MacGLContext; | 122 MacGLTestContext* ctx = new MacGLTestContext; |
122 if (!ctx->isValid()) { | 123 if (!ctx->isValid()) { |
123 delete ctx; | 124 delete ctx; |
124 return nullptr; | 125 return nullptr; |
125 } | 126 } |
126 return ctx; | 127 return ctx; |
127 } | 128 } |
128 } // namespace sk_gpu_test | 129 } // namespace sk_gpu_test |
OLD | NEW |