| 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/SkGLContext.h" | 9 #include "gl/SkGLContext.h" |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 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 WinGLContext::gWC = 0; |
| 40 | 40 |
| 41 WinGLContext::WinGLContext(GrGLStandard forcedGpuAPI) | 41 WinGLContext::WinGLContext(GrGLStandard forcedGpuAPI) |
| 42 : fWindow(NULL) | 42 : fWindow(nullptr) |
| 43 , fDeviceContext(NULL) | 43 , fDeviceContext(nullptr) |
| 44 , fGlRenderContext(0) | 44 , fGlRenderContext(0) |
| 45 , fPbufferContext(NULL) { | 45 , fPbufferContext(nullptr) { |
| 46 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); | 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; |
| 52 wc.hbrBackground = NULL; | 52 wc.hbrBackground = nullptr; |
| 53 wc.hCursor = LoadCursor(NULL, IDC_ARROW); | 53 wc.hCursor = LoadCursor(nullptr, IDC_ARROW); |
| 54 wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | 54 wc.hIcon = LoadIcon(nullptr, IDI_APPLICATION); |
| 55 wc.hInstance = hInstance; | 55 wc.hInstance = hInstance; |
| 56 wc.lpfnWndProc = (WNDPROC) DefWindowProc; | 56 wc.lpfnWndProc = (WNDPROC) DefWindowProc; |
| 57 wc.lpszClassName = TEXT("Griffin"); | 57 wc.lpszClassName = TEXT("Griffin"); |
| 58 wc.lpszMenuName = NULL; | 58 wc.lpszMenuName = nullptr; |
| 59 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; | 59 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; |
| 60 | 60 |
| 61 gWC = RegisterClass(&wc); | 61 gWC = RegisterClass(&wc); |
| 62 if (!gWC) { | 62 if (!gWC) { |
| 63 SkDebugf("Could not register window class.\n"); | 63 SkDebugf("Could not register window class.\n"); |
| 64 return; | 64 return; |
| 65 } | 65 } |
| 66 } | 66 } |
| 67 | 67 |
| 68 if (!(fWindow = CreateWindow(TEXT("Griffin"), | 68 if (!(fWindow = CreateWindow(TEXT("Griffin"), |
| 69 TEXT("The Invisible Man"), | 69 TEXT("The Invisible Man"), |
| 70 WS_OVERLAPPEDWINDOW, | 70 WS_OVERLAPPEDWINDOW, |
| 71 0, 0, 1, 1, | 71 0, 0, 1, 1, |
| 72 NULL, NULL, | 72 nullptr, nullptr, |
| 73 hInstance, NULL))) { | 73 hInstance, nullptr))) { |
| 74 SkDebugf("Could not create window.\n"); | 74 SkDebugf("Could not create window.\n"); |
| 75 return; | 75 return; |
| 76 } | 76 } |
| 77 | 77 |
| 78 if (!(fDeviceContext = GetDC(fWindow))) { | 78 if (!(fDeviceContext = GetDC(fWindow))) { |
| 79 SkDebugf("Could not get device context.\n"); | 79 SkDebugf("Could not get device context.\n"); |
| 80 this->destroyGLContext(); | 80 this->destroyGLContext(); |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 // Requesting a Core profile would bar us from using NVPR. So we request | 83 // Requesting a Core profile would bar us from using NVPR. So we request |
| 84 // compatibility profile or GL ES. | 84 // compatibility profile or GL ES. |
| 85 SkWGLContextRequest contextType = | 85 SkWGLContextRequest contextType = |
| 86 kGLES_GrGLStandard == forcedGpuAPI ? | 86 kGLES_GrGLStandard == forcedGpuAPI ? |
| 87 kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRe
quest; | 87 kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRe
quest; |
| 88 | 88 |
| 89 fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType
); | 89 fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType
); |
| 90 | 90 |
| 91 HDC dc; | 91 HDC dc; |
| 92 HGLRC glrc; | 92 HGLRC glrc; |
| 93 | 93 |
| 94 if (NULL == fPbufferContext) { | 94 if (nullptr == fPbufferContext) { |
| 95 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextTy
pe))) { | 95 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextTy
pe))) { |
| 96 SkDebugf("Could not create rendering context.\n"); | 96 SkDebugf("Could not create rendering context.\n"); |
| 97 this->destroyGLContext(); | 97 this->destroyGLContext(); |
| 98 return; | 98 return; |
| 99 } | 99 } |
| 100 dc = fDeviceContext; | 100 dc = fDeviceContext; |
| 101 glrc = fGlRenderContext; | 101 glrc = fGlRenderContext; |
| 102 } else { | 102 } else { |
| 103 ReleaseDC(fWindow, fDeviceContext); | 103 ReleaseDC(fWindow, fDeviceContext); |
| 104 fDeviceContext = 0; | 104 fDeviceContext = 0; |
| 105 DestroyWindow(fWindow); | 105 DestroyWindow(fWindow); |
| 106 fWindow = 0; | 106 fWindow = 0; |
| 107 | 107 |
| 108 dc = fPbufferContext->getDC(); | 108 dc = fPbufferContext->getDC(); |
| 109 glrc = fPbufferContext->getGLRC(); | 109 glrc = fPbufferContext->getGLRC(); |
| 110 } | 110 } |
| 111 | 111 |
| 112 if (!(wglMakeCurrent(dc, glrc))) { | 112 if (!(wglMakeCurrent(dc, glrc))) { |
| 113 SkDebugf("Could not set the context.\n"); | 113 SkDebugf("Could not set the context.\n"); |
| 114 this->destroyGLContext(); | 114 this->destroyGLContext(); |
| 115 return; | 115 return; |
| 116 } | 116 } |
| 117 | 117 |
| 118 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); | 118 SkAutoTUnref<const GrGLInterface> gl(GrGLCreateNativeInterface()); |
| 119 if (NULL == gl.get()) { | 119 if (nullptr == gl.get()) { |
| 120 SkDebugf("Could not create GL interface.\n"); | 120 SkDebugf("Could not create GL interface.\n"); |
| 121 this->destroyGLContext(); | 121 this->destroyGLContext(); |
| 122 return; | 122 return; |
| 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 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 WinGLContext::onPlatformMakeCurrent() const { |
| 155 HDC dc; | 155 HDC dc; |
| 156 HGLRC glrc; | 156 HGLRC glrc; |
| 157 | 157 |
| 158 if (NULL == 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 WinGLContext::onPlatformSwapBuffers() const { |
| 172 HDC dc; | 172 HDC dc; |
| 173 | 173 |
| 174 if (NULL == 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 WinGLContext::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 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { | 190 SkGLContext* SkCreatePlatformGLContext(GrGLStandard forcedGpuAPI) { |
| 191 WinGLContext* ctx = new WinGLContext(forcedGpuAPI); | 191 WinGLContext* ctx = new WinGLContext(forcedGpuAPI); |
| 192 if (!ctx->isValid()) { | 192 if (!ctx->isValid()) { |
| 193 delete ctx; | 193 delete ctx; |
| 194 return NULL; | 194 return nullptr; |
| 195 } | 195 } |
| 196 return ctx; | 196 return ctx; |
| 197 } | 197 } |
| 198 | 198 |
| OLD | NEW |