| 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 | 8 |
| 9 #include "gl/GLContext.h" | 9 #include "gl/GLTestContext.h" |
| 10 | 10 |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 #include <GL/GL.h> | 12 #include <GL/GL.h> |
| 13 #include "win/SkWGL.h" | 13 #include "win/SkWGL.h" |
| 14 | 14 |
| 15 #define WIN32_LEAN_AND_MEAN | 15 #define WIN32_LEAN_AND_MEAN |
| 16 #include <windows.h> | 16 #include <windows.h> |
| 17 | 17 |
| 18 namespace { | 18 namespace { |
| 19 | 19 |
| 20 class WinGLContext : public sk_gpu_test::GLContext { | 20 class WinGLTestContext : public sk_gpu_test::GLTestContext { |
| 21 public: | 21 public: |
| 22 WinGLContext(GrGLStandard forcedGpuAPI); | 22 WinGLTestContext(GrGLStandard forcedGpuAPI); |
| 23 » ~WinGLContext() override; | 23 » ~WinGLTestContext() override; |
| 24 | 24 |
| 25 private: | 25 private: |
| 26 void destroyGLContext(); | 26 void destroyGLContext(); |
| 27 | 27 |
| 28 void onPlatformMakeCurrent() const override; | 28 void onPlatformMakeCurrent() const override; |
| 29 void onPlatformSwapBuffers() const override; | 29 void onPlatformSwapBuffers() const override; |
| 30 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; | 30 GrGLFuncPtr onPlatformGetProcAddress(const char* name) const override; |
| 31 | 31 |
| 32 HWND fWindow; | 32 HWND fWindow; |
| 33 HDC fDeviceContext; | 33 HDC fDeviceContext; |
| 34 HGLRC fGlRenderContext; | 34 HGLRC fGlRenderContext; |
| 35 static ATOM gWC; | 35 static ATOM gWC; |
| 36 SkWGLPbufferContext* fPbufferContext; | 36 SkWGLPbufferContext* fPbufferContext; |
| 37 }; | 37 }; |
| 38 | 38 |
| 39 ATOM WinGLContext::gWC = 0; | 39 ATOM WinGLTestContext::gWC = 0; |
| 40 | 40 |
| 41 WinGLContext::WinGLContext(GrGLStandard forcedGpuAPI) | 41 WinGLTestContext::WinGLTestContext(GrGLStandard forcedGpuAPI) |
| 42 : fWindow(nullptr) | 42 : fWindow(nullptr) |
| 43 , fDeviceContext(nullptr) | 43 , fDeviceContext(nullptr) |
| 44 , fGlRenderContext(0) | 44 , fGlRenderContext(0) |
| 45 , fPbufferContext(nullptr) { | 45 , fPbufferContext(nullptr) { |
| 46 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(nullptr); | 46 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(nullptr); |
| 47 | 47 |
| 48 if (!gWC) { | 48 if (!gWC) { |
| 49 WNDCLASS wc; | 49 WNDCLASS wc; |
| 50 wc.cbClsExtra = 0; | 50 wc.cbClsExtra = 0; |
| 51 wc.cbWndExtra = 0; | 51 wc.cbWndExtra = 0; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 } | 123 } |
| 124 if (!gl->validate()) { | 124 if (!gl->validate()) { |
| 125 SkDebugf("Could not validate GL interface.\n"); | 125 SkDebugf("Could not validate GL interface.\n"); |
| 126 this->destroyGLContext(); | 126 this->destroyGLContext(); |
| 127 return; | 127 return; |
| 128 } | 128 } |
| 129 | 129 |
| 130 this->init(gl.release()); | 130 this->init(gl.release()); |
| 131 } | 131 } |
| 132 | 132 |
| 133 WinGLContext::~WinGLContext() { | 133 WinGLTestContext::~WinGLTestContext() { |
| 134 this->teardown(); | 134 this->teardown(); |
| 135 this->destroyGLContext(); | 135 this->destroyGLContext(); |
| 136 } | 136 } |
| 137 | 137 |
| 138 void WinGLContext::destroyGLContext() { | 138 void WinGLTestContext::destroyGLContext() { |
| 139 SkSafeSetNull(fPbufferContext); | 139 SkSafeSetNull(fPbufferContext); |
| 140 if (fGlRenderContext) { | 140 if (fGlRenderContext) { |
| 141 wglDeleteContext(fGlRenderContext); | 141 wglDeleteContext(fGlRenderContext); |
| 142 fGlRenderContext = 0; | 142 fGlRenderContext = 0; |
| 143 } | 143 } |
| 144 if (fWindow && fDeviceContext) { | 144 if (fWindow && fDeviceContext) { |
| 145 ReleaseDC(fWindow, fDeviceContext); | 145 ReleaseDC(fWindow, fDeviceContext); |
| 146 fDeviceContext = 0; | 146 fDeviceContext = 0; |
| 147 } | 147 } |
| 148 if (fWindow) { | 148 if (fWindow) { |
| 149 DestroyWindow(fWindow); | 149 DestroyWindow(fWindow); |
| 150 fWindow = 0; | 150 fWindow = 0; |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 | 153 |
| 154 void WinGLContext::onPlatformMakeCurrent() const { | 154 void WinGLTestContext::onPlatformMakeCurrent() const { |
| 155 HDC dc; | 155 HDC dc; |
| 156 HGLRC glrc; | 156 HGLRC glrc; |
| 157 | 157 |
| 158 if (nullptr == fPbufferContext) { | 158 if (nullptr == fPbufferContext) { |
| 159 dc = fDeviceContext; | 159 dc = fDeviceContext; |
| 160 glrc = fGlRenderContext; | 160 glrc = fGlRenderContext; |
| 161 } else { | 161 } else { |
| 162 dc = fPbufferContext->getDC(); | 162 dc = fPbufferContext->getDC(); |
| 163 glrc = fPbufferContext->getGLRC(); | 163 glrc = fPbufferContext->getGLRC(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 if (!wglMakeCurrent(dc, glrc)) { | 166 if (!wglMakeCurrent(dc, glrc)) { |
| 167 SkDebugf("Could not create rendering context.\n"); | 167 SkDebugf("Could not create rendering context.\n"); |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 void WinGLContext::onPlatformSwapBuffers() const { | 171 void WinGLTestContext::onPlatformSwapBuffers() const { |
| 172 HDC dc; | 172 HDC dc; |
| 173 | 173 |
| 174 if (nullptr == fPbufferContext) { | 174 if (nullptr == fPbufferContext) { |
| 175 dc = fDeviceContext; | 175 dc = fDeviceContext; |
| 176 } else { | 176 } else { |
| 177 dc = fPbufferContext->getDC(); | 177 dc = fPbufferContext->getDC(); |
| 178 } | 178 } |
| 179 if (!SwapBuffers(dc)) { | 179 if (!SwapBuffers(dc)) { |
| 180 SkDebugf("Could not complete SwapBuffers.\n"); | 180 SkDebugf("Could not complete SwapBuffers.\n"); |
| 181 } | 181 } |
| 182 } | 182 } |
| 183 | 183 |
| 184 GrGLFuncPtr WinGLContext::onPlatformGetProcAddress(const char* name) const { | 184 GrGLFuncPtr WinGLTestContext::onPlatformGetProcAddress(const char* name) const { |
| 185 return reinterpret_cast<GrGLFuncPtr>(wglGetProcAddress(name)); | 185 return reinterpret_cast<GrGLFuncPtr>(wglGetProcAddress(name)); |
| 186 } | 186 } |
| 187 | 187 |
| 188 } // anonymous namespace | 188 } // anonymous namespace |
| 189 | 189 |
| 190 namespace sk_gpu_test { | 190 namespace sk_gpu_test { |
| 191 GLContext* CreatePlatformGLContext(GrGLStandard forcedGpuAPI, GLContext *shareCo
ntext) { | 191 GLTestContext* CreatePlatformGLTestContext(GrGLStandard forcedGpuAPI, |
| 192 GLTestContext *shareContext) { |
| 192 SkASSERT(!shareContext); | 193 SkASSERT(!shareContext); |
| 193 if (shareContext) { | 194 if (shareContext) { |
| 194 return nullptr; | 195 return nullptr; |
| 195 } | 196 } |
| 196 WinGLContext *ctx = new WinGLContext(forcedGpuAPI); | 197 WinGLTestContext *ctx = new WinGLTestContext(forcedGpuAPI); |
| 197 if (!ctx->isValid()) { | 198 if (!ctx->isValid()) { |
| 198 delete ctx; | 199 delete ctx; |
| 199 return nullptr; | 200 return nullptr; |
| 200 } | 201 } |
| 201 return ctx; | 202 return ctx; |
| 202 } | 203 } |
| 203 } // namespace sk_gpu_test | 204 } // namespace sk_gpu_test |
| 204 | 205 |
| OLD | NEW |