blob: 5afcae94cec4f82303923d6bfb0b2ccd056cd64c [file] [log] [blame]
bsalomon@google.combd7c6412011-12-01 16:34:28 +00001
2/*
3 * Copyright 2011 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
mtklein1ee76512015-11-02 10:20:27 -08009#include "SkTypes.h"
10#if defined(SK_BUILD_FOR_WIN32)
11
bsalomon@google.combd7c6412011-12-01 16:34:28 +000012#include "SkWGL.h"
13
bsalomon@google.com8a189b02012-04-17 12:43:00 +000014#include "SkTDArray.h"
15#include "SkTSearch.h"
bsalomon@google.com20f7f172013-05-17 19:05:03 +000016#include "SkTSort.h"
bsalomon@google.com8a189b02012-04-17 12:43:00 +000017
bsalomon@google.combd7c6412011-12-01 16:34:28 +000018bool SkWGLExtensions::hasExtension(HDC dc, const char* ext) const {
halcanary96fcdcc2015-08-27 07:41:13 -070019 if (nullptr == this->fGetExtensionsString) {
bsalomon@google.combd7c6412011-12-01 16:34:28 +000020 return false;
21 }
22 if (!strcmp("WGL_ARB_extensions_string", ext)) {
23 return true;
24 }
25 const char* extensionString = this->getExtensionsString(dc);
robertphillips@google.comadacc702013-10-14 21:53:24 +000026 size_t extLength = strlen(ext);
bsalomon@google.combd7c6412011-12-01 16:34:28 +000027
28 while (true) {
robertphillips@google.comadacc702013-10-14 21:53:24 +000029 size_t n = strcspn(extensionString, " ");
bsalomon@google.combd7c6412011-12-01 16:34:28 +000030 if (n == extLength && 0 == strncmp(ext, extensionString, n)) {
31 return true;
32 }
33 if (0 == extensionString[n]) {
34 return false;
35 }
36 extensionString += n+1;
37 }
38
39 return false;
40}
41
42const char* SkWGLExtensions::getExtensionsString(HDC hdc) const {
43 return fGetExtensionsString(hdc);
44}
45
46BOOL SkWGLExtensions::choosePixelFormat(HDC hdc,
47 const int* piAttribIList,
48 const FLOAT* pfAttribFList,
49 UINT nMaxFormats,
50 int* piFormats,
51 UINT* nNumFormats) const {
52 return fChoosePixelFormat(hdc, piAttribIList, pfAttribFList,
53 nMaxFormats, piFormats, nNumFormats);
54}
55
56BOOL SkWGLExtensions::getPixelFormatAttribiv(HDC hdc,
57 int iPixelFormat,
58 int iLayerPlane,
59 UINT nAttributes,
60 const int *piAttributes,
61 int *piValues) const {
62 return fGetPixelFormatAttribiv(hdc, iPixelFormat, iLayerPlane,
63 nAttributes, piAttributes, piValues);
64}
65
66BOOL SkWGLExtensions::getPixelFormatAttribfv(HDC hdc,
67 int iPixelFormat,
68 int iLayerPlane,
69 UINT nAttributes,
70 const int *piAttributes,
71 float *pfValues) const {
72 return fGetPixelFormatAttribfv(hdc, iPixelFormat, iLayerPlane,
73 nAttributes, piAttributes, pfValues);
74}
75HGLRC SkWGLExtensions::createContextAttribs(HDC hDC,
76 HGLRC hShareContext,
77 const int *attribList) const {
78 return fCreateContextAttribs(hDC, hShareContext, attribList);
79}
80
bsalomon9245b7e2014-07-01 07:20:11 -070081BOOL SkWGLExtensions::swapInterval(int interval) const {
82 return fSwapInterval(interval);
83}
84
85HPBUFFER SkWGLExtensions::createPbuffer(HDC hDC,
86 int iPixelFormat,
87 int iWidth,
88 int iHeight,
89 const int *piAttribList) const {
90 return fCreatePbuffer(hDC, iPixelFormat, iWidth, iHeight, piAttribList);
91}
92
93HDC SkWGLExtensions::getPbufferDC(HPBUFFER hPbuffer) const {
94 return fGetPbufferDC(hPbuffer);
95}
96
97int SkWGLExtensions::releasePbufferDC(HPBUFFER hPbuffer, HDC hDC) const {
98 return fReleasePbufferDC(hPbuffer, hDC);
99}
100
101BOOL SkWGLExtensions::destroyPbuffer(HPBUFFER hPbuffer) const {
102 return fDestroyPbuffer(hPbuffer);
103}
104
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000105namespace {
106
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000107struct PixelFormat {
108 int fFormat;
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000109 int fSampleCnt;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000110 int fChoosePixelFormatRank;
111};
112
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000113bool pf_less(const PixelFormat& a, const PixelFormat& b) {
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000114 if (a.fSampleCnt < b.fSampleCnt) {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000115 return true;
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000116 } else if (b.fSampleCnt < a.fSampleCnt) {
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000117 return false;
118 } else if (a.fChoosePixelFormatRank < b.fChoosePixelFormatRank) {
119 return true;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000120 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000121 return false;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000122}
123}
124
125int SkWGLExtensions::selectFormat(const int formats[],
126 int formatCount,
127 HDC dc,
bsalomon9245b7e2014-07-01 07:20:11 -0700128 int desiredSampleCount) const {
aleksandar.stojiljkovic2944fbb2015-11-05 07:48:12 -0800129 if (formatCount <= 0) {
130 return -1;
131 }
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000132 PixelFormat desiredFormat = {
133 0,
134 desiredSampleCount,
135 0,
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000136 };
137 SkTDArray<PixelFormat> rankedFormats;
138 rankedFormats.setCount(formatCount);
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000139 for (int i = 0; i < formatCount; ++i) {
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000140 static const int kQueryAttr = SK_WGL_SAMPLES;
141 int numSamples;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000142 this->getPixelFormatAttribiv(dc,
143 formats[i],
144 0,
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000145 1,
146 &kQueryAttr,
147 &numSamples);
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000148 rankedFormats[i].fFormat = formats[i];
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000149 rankedFormats[i].fSampleCnt = numSamples;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000150 rankedFormats[i].fChoosePixelFormatRank = i;
151 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000152 SkTQSort(rankedFormats.begin(),
153 rankedFormats.begin() + rankedFormats.count() - 1,
154 SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>());
155 int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(),
156 rankedFormats.count(),
157 desiredFormat,
158 sizeof(PixelFormat));
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000159 if (idx < 0) {
160 idx = ~idx;
161 }
162 return rankedFormats[idx].fFormat;
163}
164
165
166namespace {
167
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000168#if defined(UNICODE)
169 #define STR_LIT(X) L## #X
170#else
171 #define STR_LIT(X) #X
172#endif
173
174#define DUMMY_CLASS STR_LIT("DummyClass")
175
176HWND create_dummy_window() {
halcanary96fcdcc2015-08-27 07:41:13 -0700177 HMODULE module = GetModuleHandle(nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000178 HWND dummy;
179 RECT windowRect;
180 windowRect.left = 0;
181 windowRect.right = 8;
182 windowRect.top = 0;
183 windowRect.bottom = 8;
184
185 WNDCLASS wc;
186
187 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
188 wc.lpfnWndProc = (WNDPROC) DefWindowProc;
189 wc.cbClsExtra = 0;
190 wc.cbWndExtra = 0;
191 wc.hInstance = module;
halcanary96fcdcc2015-08-27 07:41:13 -0700192 wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
193 wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
194 wc.hbrBackground = nullptr;
195 wc.lpszMenuName = nullptr;
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000196 wc.lpszClassName = DUMMY_CLASS;
197
198 if(!RegisterClass(&wc)) {
199 return 0;
200 }
201
202 DWORD style, exStyle;
203 exStyle = WS_EX_CLIENTEDGE;
204 style = WS_SYSMENU;
205
206 AdjustWindowRectEx(&windowRect, style, false, exStyle);
207 if(!(dummy = CreateWindowEx(exStyle,
208 DUMMY_CLASS,
209 STR_LIT("DummyWindow"),
210 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
211 0, 0,
212 windowRect.right-windowRect.left,
213 windowRect.bottom-windowRect.top,
halcanary96fcdcc2015-08-27 07:41:13 -0700214 nullptr, nullptr,
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000215 module,
halcanary96fcdcc2015-08-27 07:41:13 -0700216 nullptr))) {
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000217 UnregisterClass(DUMMY_CLASS, module);
halcanary96fcdcc2015-08-27 07:41:13 -0700218 return nullptr;
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000219 }
220 ShowWindow(dummy, SW_HIDE);
221
222 return dummy;
223}
224
225void destroy_dummy_window(HWND dummy) {
226 DestroyWindow(dummy);
halcanary96fcdcc2015-08-27 07:41:13 -0700227 HMODULE module = GetModuleHandle(nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000228 UnregisterClass(DUMMY_CLASS, module);
229}
230}
231
232#define GET_PROC(NAME, SUFFIX) f##NAME = \
233 (##NAME##Proc) wglGetProcAddress("wgl" #NAME #SUFFIX)
234
235SkWGLExtensions::SkWGLExtensions()
halcanary96fcdcc2015-08-27 07:41:13 -0700236 : fGetExtensionsString(nullptr)
237 , fChoosePixelFormat(nullptr)
238 , fGetPixelFormatAttribfv(nullptr)
239 , fGetPixelFormatAttribiv(nullptr)
240 , fCreateContextAttribs(nullptr)
241 , fSwapInterval(nullptr)
242 , fCreatePbuffer(nullptr)
243 , fGetPbufferDC(nullptr)
244 , fReleasePbufferDC(nullptr)
245 , fDestroyPbuffer(nullptr)
bsalomon9245b7e2014-07-01 07:20:11 -0700246 {
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000247 HDC prevDC = wglGetCurrentDC();
248 HGLRC prevGLRC = wglGetCurrentContext();
249
250 PIXELFORMATDESCRIPTOR dummyPFD;
251
252 ZeroMemory(&dummyPFD, sizeof(dummyPFD));
253 dummyPFD.nSize = sizeof(dummyPFD);
254 dummyPFD.nVersion = 1;
255 dummyPFD.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
256 dummyPFD.iPixelType = PFD_TYPE_RGBA;
257 dummyPFD.cColorBits = 32;
258 dummyPFD.cDepthBits = 0;
259 dummyPFD.cStencilBits = 8;
260 dummyPFD.iLayerType = PFD_MAIN_PLANE;
261 HWND dummyWND = create_dummy_window();
262 if (dummyWND) {
263 HDC dummyDC = GetDC(dummyWND);
264 int dummyFormat = ChoosePixelFormat(dummyDC, &dummyPFD);
265 SetPixelFormat(dummyDC, dummyFormat, &dummyPFD);
266 HGLRC dummyGLRC = wglCreateContext(dummyDC);
267 SkASSERT(dummyGLRC);
268 wglMakeCurrent(dummyDC, dummyGLRC);
269
270 GET_PROC(GetExtensionsString, ARB);
271 GET_PROC(ChoosePixelFormat, ARB);
272 GET_PROC(GetPixelFormatAttribiv, ARB);
273 GET_PROC(GetPixelFormatAttribfv, ARB);
274 GET_PROC(CreateContextAttribs, ARB);
bsalomon9245b7e2014-07-01 07:20:11 -0700275 GET_PROC(SwapInterval, EXT);
276 GET_PROC(CreatePbuffer, ARB);
277 GET_PROC(GetPbufferDC, ARB);
278 GET_PROC(ReleasePbufferDC, ARB);
279 GET_PROC(DestroyPbuffer, ARB);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000280
halcanary96fcdcc2015-08-27 07:41:13 -0700281 wglMakeCurrent(dummyDC, nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000282 wglDeleteContext(dummyGLRC);
283 destroy_dummy_window(dummyWND);
284 }
285
286 wglMakeCurrent(prevDC, prevGLRC);
287}
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000288
bsalomon9245b7e2014-07-01 07:20:11 -0700289///////////////////////////////////////////////////////////////////////////////
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000290
bsalomon9245b7e2014-07-01 07:20:11 -0700291static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions,
292 bool doubleBuffered, int msaaSampleCount,
293 int formatsToTry[2]) {
294 int iAttrs[] = {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000295 SK_WGL_DRAW_TO_WINDOW, TRUE,
bsalomon9245b7e2014-07-01 07:20:11 -0700296 SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE),
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000297 SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
298 SK_WGL_SUPPORT_OPENGL, TRUE,
299 SK_WGL_COLOR_BITS, 24,
300 SK_WGL_ALPHA_BITS, 8,
301 SK_WGL_STENCIL_BITS, 8,
302 0, 0
303 };
304
305 float fAttrs[] = {0, 0};
306
bsalomon9245b7e2014-07-01 07:20:11 -0700307 // Get a MSAA format if requested and possible.
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000308 if (msaaSampleCount > 0 &&
309 extensions.hasExtension(dc, "WGL_ARB_multisample")) {
310 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000311 int msaaIAttrs[kIAttrsCount + 4];
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000312 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount);
313 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
314 0 == msaaIAttrs[kIAttrsCount - 1]);
315 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
316 msaaIAttrs[kIAttrsCount - 1] = TRUE;
317 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
318 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000319 msaaIAttrs[kIAttrsCount + 2] = 0;
320 msaaIAttrs[kIAttrsCount + 3] = 0;
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000321 unsigned int num;
322 int formats[64];
323 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
bsalomon@google.comf3f2d162013-07-31 18:52:31 +0000324 num = SkTMin(num, 64U);
bsalomon9245b7e2014-07-01 07:20:11 -0700325 formatsToTry[0] = extensions.selectFormat(formats, num, dc, msaaSampleCount);
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000326 }
327
bsalomon9245b7e2014-07-01 07:20:11 -0700328 // Get a non-MSAA format
329 int* format = -1 == formatsToTry[0] ? &formatsToTry[0] : &formatsToTry[1];
330 unsigned int num;
331 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, format, &num);
332}
333
334static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextRequest contextType) {
335 HDC prevDC = wglGetCurrentDC();
336 HGLRC prevGLRC = wglGetCurrentContext();
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000337
halcanary96fcdcc2015-08-27 07:41:13 -0700338 HGLRC glrc = nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700339 if (kGLES_SkWGLContextRequest == contextType) {
340 if (!extensions.hasExtension(dc, "WGL_EXT_create_context_es2_profile")) {
bsalomon9245b7e2014-07-01 07:20:11 -0700341 wglMakeCurrent(prevDC, prevGLRC);
halcanary96fcdcc2015-08-27 07:41:13 -0700342 return nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700343 }
344 static const int glesAttribs[] = {
345 SK_WGL_CONTEXT_MAJOR_VERSION, 3,
346 SK_WGL_CONTEXT_MINOR_VERSION, 0,
347 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_ES2_PROFILE_BIT,
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000348 0,
349 };
halcanary96fcdcc2015-08-27 07:41:13 -0700350 glrc = extensions.createContextAttribs(dc, nullptr, glesAttribs);
351 if (nullptr == glrc) {
bsalomon9245b7e2014-07-01 07:20:11 -0700352 wglMakeCurrent(prevDC, prevGLRC);
halcanary96fcdcc2015-08-27 07:41:13 -0700353 return nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700354 }
355 } else {
356 if (kGLPreferCoreProfile_SkWGLContextRequest == contextType &&
357 extensions.hasExtension(dc, "WGL_ARB_create_context")) {
358 static const int kCoreGLVersions[] = {
359 4, 3,
360 4, 2,
361 4, 1,
362 4, 0,
363 3, 3,
364 3, 2,
365 };
366 int coreProfileAttribs[] = {
367 SK_WGL_CONTEXT_MAJOR_VERSION, -1,
368 SK_WGL_CONTEXT_MINOR_VERSION, -1,
369 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT,
370 0,
371 };
372 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) {
373 coreProfileAttribs[1] = kCoreGLVersions[2 * v];
374 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1];
halcanary96fcdcc2015-08-27 07:41:13 -0700375 glrc = extensions.createContextAttribs(dc, nullptr, coreProfileAttribs);
bsalomon49f085d2014-09-05 13:34:00 -0700376 if (glrc) {
kkinnunen80549fc2014-06-30 06:36:31 -0700377 break;
378 }
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000379 }
380 }
381 }
382
halcanary96fcdcc2015-08-27 07:41:13 -0700383 if (nullptr == glrc) {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000384 glrc = wglCreateContext(dc);
385 }
386 SkASSERT(glrc);
387
388 wglMakeCurrent(prevDC, prevGLRC);
bsalomon9245b7e2014-07-01 07:20:11 -0700389
390 // This might help make the context non-vsynced.
391 if (extensions.hasExtension(dc, "WGL_EXT_swap_control")) {
392 extensions.swapInterval(-1);
393 }
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000394 return glrc;
395}
bsalomon9245b7e2014-07-01 07:20:11 -0700396
397HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contextType) {
398 SkWGLExtensions extensions;
399 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
halcanary96fcdcc2015-08-27 07:41:13 -0700400 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700401 }
402
403 BOOL set = FALSE;
404
405 int pixelFormatsToTry[] = { -1, -1 };
406 get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, pixelFormatsToTry);
407 for (int f = 0;
408 !set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry);
409 ++f) {
410 PIXELFORMATDESCRIPTOR pfd;
411 DescribePixelFormat(dc, pixelFormatsToTry[f], sizeof(pfd), &pfd);
412 set = SetPixelFormat(dc, pixelFormatsToTry[f], &pfd);
413 }
414
415 if (!set) {
halcanary96fcdcc2015-08-27 07:41:13 -0700416 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700417 }
418
419 return create_gl_context(dc, extensions, contextType);}
420
421SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCount,
422 SkWGLContextRequest contextType) {
423 SkWGLExtensions extensions;
424 if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") ||
425 !extensions.hasExtension(parentDC, "WGL_ARB_pbuffer")) {
halcanary96fcdcc2015-08-27 07:41:13 -0700426 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700427 }
428
429 // try for single buffer first
430 for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) {
431 int pixelFormatsToTry[] = { -1, -1 };
432 get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSampleCount,
433 pixelFormatsToTry);
434 for (int f = 0; -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry); ++f) {
halcanary96fcdcc2015-08-27 07:41:13 -0700435 HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormatsToTry[f], 1, 1, nullptr);
bsalomon9245b7e2014-07-01 07:20:11 -0700436 if (0 != pbuf) {
437 HDC dc = extensions.getPbufferDC(pbuf);
bsalomon49f085d2014-09-05 13:34:00 -0700438 if (dc) {
bsalomon9245b7e2014-07-01 07:20:11 -0700439 HGLRC glrc = create_gl_context(dc, extensions, contextType);
bsalomon49f085d2014-09-05 13:34:00 -0700440 if (glrc) {
halcanary385fe4d2015-08-26 13:07:48 -0700441 return new SkWGLPbufferContext(pbuf, dc, glrc);
bsalomon9245b7e2014-07-01 07:20:11 -0700442 }
443 extensions.releasePbufferDC(pbuf, dc);
444 }
445 extensions.destroyPbuffer(pbuf);
446 }
447 }
448 }
halcanary96fcdcc2015-08-27 07:41:13 -0700449 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700450}
451
452SkWGLPbufferContext::~SkWGLPbufferContext() {
453 SkASSERT(fExtensions.hasExtension(fDC, "WGL_ARB_pbuffer"));
454 wglDeleteContext(fGLRC);
455 fExtensions.releasePbufferDC(fPbuffer, fDC);
456 fExtensions.destroyPbuffer(fPbuffer);
457}
458
459SkWGLPbufferContext::SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc)
460 : fPbuffer(pbuffer)
461 , fDC(dc)
462 , fGLRC(glrc) {
463}
mtklein1ee76512015-11-02 10:20:27 -0800464
465#endif//defined(SK_BUILD_FOR_WIN32)