Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(142)

Side by Side Diff: src/gpu/gl/win/SkNativeGLContext_win.cpp

Issue 336863009: When performing offscreen rendering on windows, attempt to use a pbuffer context. (Closed) Base URL: https://skia.googlesource.com/skia.git@klein
Patch Set: Address initial comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/SkNativeGLContext.h" 9 #include "gl/SkNativeGLContext.h"
10 #include "SkWGL.h"
11 10
12 #define WIN32_LEAN_AND_MEAN 11 #define WIN32_LEAN_AND_MEAN
13 #include <windows.h> 12 #include <windows.h>
14 13
15 SkNativeGLContext::AutoContextRestore::AutoContextRestore() { 14 SkNativeGLContext::AutoContextRestore::AutoContextRestore() {
16 fOldHGLRC = wglGetCurrentContext(); 15 fOldHGLRC = wglGetCurrentContext();
17 fOldHDC = wglGetCurrentDC(); 16 fOldHDC = wglGetCurrentDC();
18 } 17 }
19 18
20 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() { 19 SkNativeGLContext::AutoContextRestore::~AutoContextRestore() {
21 wglMakeCurrent(fOldHDC, fOldHGLRC); 20 wglMakeCurrent(fOldHDC, fOldHGLRC);
22 } 21 }
23 22
24 /////////////////////////////////////////////////////////////////////////////// 23 ///////////////////////////////////////////////////////////////////////////////
25 24
26 ATOM SkNativeGLContext::gWC = 0; 25 ATOM SkNativeGLContext::gWC = 0;
27 26
28 SkNativeGLContext::SkNativeGLContext() 27 SkNativeGLContext::SkNativeGLContext()
29 : fWindow(NULL) 28 : fWindow(NULL)
30 , fDeviceContext(NULL) 29 , fDeviceContext(NULL)
31 , fGlRenderContext(0) { 30 , fGlRenderContext(0)
31 , fPbufferContext(NULL) {
32 } 32 }
33 33
34 SkNativeGLContext::~SkNativeGLContext() { 34 SkNativeGLContext::~SkNativeGLContext() {
35 this->destroyGLContext(); 35 this->destroyGLContext();
36 } 36 }
37 37
38 void SkNativeGLContext::destroyGLContext() { 38 void SkNativeGLContext::destroyGLContext() {
39 SkSafeSetNull(fPbufferContext);
39 if (fGlRenderContext) { 40 if (fGlRenderContext) {
40 wglDeleteContext(fGlRenderContext); 41 wglDeleteContext(fGlRenderContext);
42 fGlRenderContext = 0;
41 } 43 }
42 if (fWindow && fDeviceContext) { 44 if (fWindow && fDeviceContext) {
43 ReleaseDC(fWindow, fDeviceContext); 45 ReleaseDC(fWindow, fDeviceContext);
46 fDeviceContext = 0;
44 } 47 }
45 if (fWindow) { 48 if (fWindow) {
46 DestroyWindow(fWindow); 49 DestroyWindow(fWindow);
50 fWindow = 0;
47 } 51 }
48 } 52 }
49 53
50 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP I) { 54 const GrGLInterface* SkNativeGLContext::createGLContext(GrGLStandard forcedGpuAP I) {
51 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL); 55 HINSTANCE hInstance = (HINSTANCE)GetModuleHandle(NULL);
52 56
53 if (!gWC) { 57 if (!gWC) {
54 WNDCLASS wc; 58 WNDCLASS wc;
55 wc.cbClsExtra = 0; 59 wc.cbClsExtra = 0;
56 wc.cbWndExtra = 0; 60 wc.cbWndExtra = 0;
(...skipping 27 matching lines...) Expand all
84 SkDebugf("Could not get device context.\n"); 88 SkDebugf("Could not get device context.\n");
85 this->destroyGLContext(); 89 this->destroyGLContext();
86 return NULL; 90 return NULL;
87 } 91 }
88 // Requesting a Core profile would bar us from using NVPR. So we request 92 // Requesting a Core profile would bar us from using NVPR. So we request
89 // compatibility profile or GL ES. 93 // compatibility profile or GL ES.
90 SkWGLContextRequest contextType = 94 SkWGLContextRequest contextType =
91 kGLES_GrGLStandard == forcedGpuAPI ? 95 kGLES_GrGLStandard == forcedGpuAPI ?
92 kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRe quest; 96 kGLES_SkWGLContextRequest : kGLPreferCompatibilityProfile_SkWGLContextRe quest;
93 97
94 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextType)) ) { 98 fPbufferContext = SkWGLPbufferContext::Create(fDeviceContext, 0, contextType );
95 SkDebugf("Could not create rendering context.\n"); 99
100 HDC dc;
101 HGLRC glrc;
102
103 if (NULL == fPbufferContext) {
104 if (!(fGlRenderContext = SkCreateWGLContext(fDeviceContext, 0, contextTy pe))) {
105 SkDebugf("Could not create rendering context.\n");
106 this->destroyGLContext();
107 return NULL;
108 }
109 dc = fDeviceContext;
110 glrc = fGlRenderContext;
111 } else {
112 ReleaseDC(fWindow, fDeviceContext);
113 fDeviceContext = 0;
114 DestroyWindow(fWindow);
115 fWindow = 0;
116
117 dc = fPbufferContext->getDC();
118 glrc = fPbufferContext->getGLRC();
119 }
120
121 if (!(wglMakeCurrent(dc, glrc))) {
122 SkDebugf("Could not set the context.\n");
96 this->destroyGLContext(); 123 this->destroyGLContext();
97 return NULL; 124 return NULL;
98 } 125 }
99 126
100 if (!(wglMakeCurrent(fDeviceContext, fGlRenderContext))) {
101 SkDebugf("Could not set the context.\n");
102 this->destroyGLContext();
103 return NULL;
104 }
105 const GrGLInterface* interface = GrGLCreateNativeInterface(); 127 const GrGLInterface* interface = GrGLCreateNativeInterface();
106 if (NULL == interface) { 128 if (NULL == interface) {
107 SkDebugf("Could not create GL interface.\n"); 129 SkDebugf("Could not create GL interface.\n");
108 this->destroyGLContext(); 130 this->destroyGLContext();
109 return NULL; 131 return NULL;
110 } 132 }
111 133
112 return interface; 134 return interface;
113 } 135 }
114 136
115 void SkNativeGLContext::makeCurrent() const { 137 void SkNativeGLContext::makeCurrent() const {
116 if (!wglMakeCurrent(fDeviceContext, fGlRenderContext)) { 138 HDC dc;
139 HGLRC glrc;
140
141 if (NULL == fPbufferContext) {
142 dc = fDeviceContext;
143 glrc = fGlRenderContext;
144 } else {
145 dc = fPbufferContext->getDC();
146 glrc = fPbufferContext->getGLRC();
147 }
148
149 if (!wglMakeCurrent(dc, glrc)) {
117 SkDebugf("Could not create rendering context.\n"); 150 SkDebugf("Could not create rendering context.\n");
118 } 151 }
119 } 152 }
120 153
121 void SkNativeGLContext::swapBuffers() const { 154 void SkNativeGLContext::swapBuffers() const {
122 if (!SwapBuffers(fDeviceContext)) { 155 HDC dc;
156
157 if (NULL == fPbufferContext) {
158 dc = fDeviceContext;
159 } else {
160 dc = fPbufferContext->getDC();
161 }
162 if (!SwapBuffers(dc)) {
123 SkDebugf("Could not complete SwapBuffers.\n"); 163 SkDebugf("Could not complete SwapBuffers.\n");
124 } 164 }
125 } 165 }
OLDNEW
« no previous file with comments | « include/utils/SkWGL.h ('k') | src/utils/win/SkWGL_win.cpp » ('j') | src/utils/win/SkWGL_win.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698