blob: bc22795e2ffb3bb57f2240b492f92004ca512a55 [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 {
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000129 PixelFormat desiredFormat = {
130 0,
131 desiredSampleCount,
132 0,
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000133 };
134 SkTDArray<PixelFormat> rankedFormats;
135 rankedFormats.setCount(formatCount);
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000136 for (int i = 0; i < formatCount; ++i) {
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000137 static const int kQueryAttr = SK_WGL_SAMPLES;
138 int numSamples;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000139 this->getPixelFormatAttribiv(dc,
140 formats[i],
141 0,
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000142 1,
143 &kQueryAttr,
144 &numSamples);
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000145 rankedFormats[i].fFormat = formats[i];
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000146 rankedFormats[i].fSampleCnt = numSamples;
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000147 rankedFormats[i].fChoosePixelFormatRank = i;
148 }
bsalomon@google.com20f7f172013-05-17 19:05:03 +0000149 SkTQSort(rankedFormats.begin(),
150 rankedFormats.begin() + rankedFormats.count() - 1,
151 SkTLessFunctionToFunctorAdaptor<PixelFormat, pf_less>());
152 int idx = SkTSearch<PixelFormat, pf_less>(rankedFormats.begin(),
153 rankedFormats.count(),
154 desiredFormat,
155 sizeof(PixelFormat));
bsalomon@google.com8a189b02012-04-17 12:43:00 +0000156 if (idx < 0) {
157 idx = ~idx;
158 }
159 return rankedFormats[idx].fFormat;
160}
161
162
163namespace {
164
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000165#if defined(UNICODE)
166 #define STR_LIT(X) L## #X
167#else
168 #define STR_LIT(X) #X
169#endif
170
171#define DUMMY_CLASS STR_LIT("DummyClass")
172
173HWND create_dummy_window() {
halcanary96fcdcc2015-08-27 07:41:13 -0700174 HMODULE module = GetModuleHandle(nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000175 HWND dummy;
176 RECT windowRect;
177 windowRect.left = 0;
178 windowRect.right = 8;
179 windowRect.top = 0;
180 windowRect.bottom = 8;
181
182 WNDCLASS wc;
183
184 wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
185 wc.lpfnWndProc = (WNDPROC) DefWindowProc;
186 wc.cbClsExtra = 0;
187 wc.cbWndExtra = 0;
188 wc.hInstance = module;
halcanary96fcdcc2015-08-27 07:41:13 -0700189 wc.hIcon = LoadIcon(nullptr, IDI_WINLOGO);
190 wc.hCursor = LoadCursor(nullptr, IDC_ARROW);
191 wc.hbrBackground = nullptr;
192 wc.lpszMenuName = nullptr;
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000193 wc.lpszClassName = DUMMY_CLASS;
194
195 if(!RegisterClass(&wc)) {
196 return 0;
197 }
198
199 DWORD style, exStyle;
200 exStyle = WS_EX_CLIENTEDGE;
201 style = WS_SYSMENU;
202
203 AdjustWindowRectEx(&windowRect, style, false, exStyle);
204 if(!(dummy = CreateWindowEx(exStyle,
205 DUMMY_CLASS,
206 STR_LIT("DummyWindow"),
207 WS_CLIPSIBLINGS | WS_CLIPCHILDREN | style,
208 0, 0,
209 windowRect.right-windowRect.left,
210 windowRect.bottom-windowRect.top,
halcanary96fcdcc2015-08-27 07:41:13 -0700211 nullptr, nullptr,
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000212 module,
halcanary96fcdcc2015-08-27 07:41:13 -0700213 nullptr))) {
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000214 UnregisterClass(DUMMY_CLASS, module);
halcanary96fcdcc2015-08-27 07:41:13 -0700215 return nullptr;
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000216 }
217 ShowWindow(dummy, SW_HIDE);
218
219 return dummy;
220}
221
222void destroy_dummy_window(HWND dummy) {
223 DestroyWindow(dummy);
halcanary96fcdcc2015-08-27 07:41:13 -0700224 HMODULE module = GetModuleHandle(nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000225 UnregisterClass(DUMMY_CLASS, module);
226}
227}
228
229#define GET_PROC(NAME, SUFFIX) f##NAME = \
230 (##NAME##Proc) wglGetProcAddress("wgl" #NAME #SUFFIX)
231
232SkWGLExtensions::SkWGLExtensions()
halcanary96fcdcc2015-08-27 07:41:13 -0700233 : fGetExtensionsString(nullptr)
234 , fChoosePixelFormat(nullptr)
235 , fGetPixelFormatAttribfv(nullptr)
236 , fGetPixelFormatAttribiv(nullptr)
237 , fCreateContextAttribs(nullptr)
238 , fSwapInterval(nullptr)
239 , fCreatePbuffer(nullptr)
240 , fGetPbufferDC(nullptr)
241 , fReleasePbufferDC(nullptr)
242 , fDestroyPbuffer(nullptr)
bsalomon9245b7e2014-07-01 07:20:11 -0700243 {
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000244 HDC prevDC = wglGetCurrentDC();
245 HGLRC prevGLRC = wglGetCurrentContext();
246
247 PIXELFORMATDESCRIPTOR dummyPFD;
248
249 ZeroMemory(&dummyPFD, sizeof(dummyPFD));
250 dummyPFD.nSize = sizeof(dummyPFD);
251 dummyPFD.nVersion = 1;
252 dummyPFD.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
253 dummyPFD.iPixelType = PFD_TYPE_RGBA;
254 dummyPFD.cColorBits = 32;
255 dummyPFD.cDepthBits = 0;
256 dummyPFD.cStencilBits = 8;
257 dummyPFD.iLayerType = PFD_MAIN_PLANE;
258 HWND dummyWND = create_dummy_window();
259 if (dummyWND) {
260 HDC dummyDC = GetDC(dummyWND);
261 int dummyFormat = ChoosePixelFormat(dummyDC, &dummyPFD);
262 SetPixelFormat(dummyDC, dummyFormat, &dummyPFD);
263 HGLRC dummyGLRC = wglCreateContext(dummyDC);
264 SkASSERT(dummyGLRC);
265 wglMakeCurrent(dummyDC, dummyGLRC);
266
267 GET_PROC(GetExtensionsString, ARB);
268 GET_PROC(ChoosePixelFormat, ARB);
269 GET_PROC(GetPixelFormatAttribiv, ARB);
270 GET_PROC(GetPixelFormatAttribfv, ARB);
271 GET_PROC(CreateContextAttribs, ARB);
bsalomon9245b7e2014-07-01 07:20:11 -0700272 GET_PROC(SwapInterval, EXT);
273 GET_PROC(CreatePbuffer, ARB);
274 GET_PROC(GetPbufferDC, ARB);
275 GET_PROC(ReleasePbufferDC, ARB);
276 GET_PROC(DestroyPbuffer, ARB);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000277
halcanary96fcdcc2015-08-27 07:41:13 -0700278 wglMakeCurrent(dummyDC, nullptr);
bsalomon@google.combd7c6412011-12-01 16:34:28 +0000279 wglDeleteContext(dummyGLRC);
280 destroy_dummy_window(dummyWND);
281 }
282
283 wglMakeCurrent(prevDC, prevGLRC);
284}
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000285
bsalomon9245b7e2014-07-01 07:20:11 -0700286///////////////////////////////////////////////////////////////////////////////
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000287
bsalomon9245b7e2014-07-01 07:20:11 -0700288static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions,
289 bool doubleBuffered, int msaaSampleCount,
290 int formatsToTry[2]) {
291 int iAttrs[] = {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000292 SK_WGL_DRAW_TO_WINDOW, TRUE,
bsalomon9245b7e2014-07-01 07:20:11 -0700293 SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE),
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000294 SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
295 SK_WGL_SUPPORT_OPENGL, TRUE,
296 SK_WGL_COLOR_BITS, 24,
297 SK_WGL_ALPHA_BITS, 8,
298 SK_WGL_STENCIL_BITS, 8,
299 0, 0
300 };
301
302 float fAttrs[] = {0, 0};
303
bsalomon9245b7e2014-07-01 07:20:11 -0700304 // Get a MSAA format if requested and possible.
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000305 if (msaaSampleCount > 0 &&
306 extensions.hasExtension(dc, "WGL_ARB_multisample")) {
307 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000308 int msaaIAttrs[kIAttrsCount + 4];
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000309 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount);
310 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
311 0 == msaaIAttrs[kIAttrsCount - 1]);
312 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
313 msaaIAttrs[kIAttrsCount - 1] = TRUE;
314 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
315 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
commit-bot@chromium.org040fd8f2013-09-06 20:00:41 +0000316 msaaIAttrs[kIAttrsCount + 2] = 0;
317 msaaIAttrs[kIAttrsCount + 3] = 0;
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000318 unsigned int num;
319 int formats[64];
320 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
bsalomon@google.comf3f2d162013-07-31 18:52:31 +0000321 num = SkTMin(num, 64U);
bsalomon9245b7e2014-07-01 07:20:11 -0700322 formatsToTry[0] = extensions.selectFormat(formats, num, dc, msaaSampleCount);
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000323 }
324
bsalomon9245b7e2014-07-01 07:20:11 -0700325 // Get a non-MSAA format
326 int* format = -1 == formatsToTry[0] ? &formatsToTry[0] : &formatsToTry[1];
327 unsigned int num;
328 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, format, &num);
329}
330
331static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextRequest contextType) {
332 HDC prevDC = wglGetCurrentDC();
333 HGLRC prevGLRC = wglGetCurrentContext();
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000334
halcanary96fcdcc2015-08-27 07:41:13 -0700335 HGLRC glrc = nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700336 if (kGLES_SkWGLContextRequest == contextType) {
337 if (!extensions.hasExtension(dc, "WGL_EXT_create_context_es2_profile")) {
bsalomon9245b7e2014-07-01 07:20:11 -0700338 wglMakeCurrent(prevDC, prevGLRC);
halcanary96fcdcc2015-08-27 07:41:13 -0700339 return nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700340 }
341 static const int glesAttribs[] = {
342 SK_WGL_CONTEXT_MAJOR_VERSION, 3,
343 SK_WGL_CONTEXT_MINOR_VERSION, 0,
344 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_ES2_PROFILE_BIT,
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000345 0,
346 };
halcanary96fcdcc2015-08-27 07:41:13 -0700347 glrc = extensions.createContextAttribs(dc, nullptr, glesAttribs);
348 if (nullptr == glrc) {
bsalomon9245b7e2014-07-01 07:20:11 -0700349 wglMakeCurrent(prevDC, prevGLRC);
halcanary96fcdcc2015-08-27 07:41:13 -0700350 return nullptr;
kkinnunen80549fc2014-06-30 06:36:31 -0700351 }
352 } else {
353 if (kGLPreferCoreProfile_SkWGLContextRequest == contextType &&
354 extensions.hasExtension(dc, "WGL_ARB_create_context")) {
355 static const int kCoreGLVersions[] = {
356 4, 3,
357 4, 2,
358 4, 1,
359 4, 0,
360 3, 3,
361 3, 2,
362 };
363 int coreProfileAttribs[] = {
364 SK_WGL_CONTEXT_MAJOR_VERSION, -1,
365 SK_WGL_CONTEXT_MINOR_VERSION, -1,
366 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT,
367 0,
368 };
369 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) {
370 coreProfileAttribs[1] = kCoreGLVersions[2 * v];
371 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1];
halcanary96fcdcc2015-08-27 07:41:13 -0700372 glrc = extensions.createContextAttribs(dc, nullptr, coreProfileAttribs);
bsalomon49f085d2014-09-05 13:34:00 -0700373 if (glrc) {
kkinnunen80549fc2014-06-30 06:36:31 -0700374 break;
375 }
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000376 }
377 }
378 }
379
halcanary96fcdcc2015-08-27 07:41:13 -0700380 if (nullptr == glrc) {
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000381 glrc = wglCreateContext(dc);
382 }
383 SkASSERT(glrc);
384
385 wglMakeCurrent(prevDC, prevGLRC);
bsalomon9245b7e2014-07-01 07:20:11 -0700386
387 // This might help make the context non-vsynced.
388 if (extensions.hasExtension(dc, "WGL_EXT_swap_control")) {
389 extensions.swapInterval(-1);
390 }
bsalomon@google.comb7f20f22013-03-05 19:13:09 +0000391 return glrc;
392}
bsalomon9245b7e2014-07-01 07:20:11 -0700393
394HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contextType) {
395 SkWGLExtensions extensions;
396 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
halcanary96fcdcc2015-08-27 07:41:13 -0700397 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700398 }
399
400 BOOL set = FALSE;
401
402 int pixelFormatsToTry[] = { -1, -1 };
403 get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, pixelFormatsToTry);
404 for (int f = 0;
405 !set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry);
406 ++f) {
407 PIXELFORMATDESCRIPTOR pfd;
408 DescribePixelFormat(dc, pixelFormatsToTry[f], sizeof(pfd), &pfd);
409 set = SetPixelFormat(dc, pixelFormatsToTry[f], &pfd);
410 }
411
412 if (!set) {
halcanary96fcdcc2015-08-27 07:41:13 -0700413 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700414 }
415
416 return create_gl_context(dc, extensions, contextType);}
417
418SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCount,
419 SkWGLContextRequest contextType) {
420 SkWGLExtensions extensions;
421 if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") ||
422 !extensions.hasExtension(parentDC, "WGL_ARB_pbuffer")) {
halcanary96fcdcc2015-08-27 07:41:13 -0700423 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700424 }
425
426 // try for single buffer first
427 for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) {
428 int pixelFormatsToTry[] = { -1, -1 };
429 get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSampleCount,
430 pixelFormatsToTry);
431 for (int f = 0; -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsToTry); ++f) {
halcanary96fcdcc2015-08-27 07:41:13 -0700432 HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormatsToTry[f], 1, 1, nullptr);
bsalomon9245b7e2014-07-01 07:20:11 -0700433 if (0 != pbuf) {
434 HDC dc = extensions.getPbufferDC(pbuf);
bsalomon49f085d2014-09-05 13:34:00 -0700435 if (dc) {
bsalomon9245b7e2014-07-01 07:20:11 -0700436 HGLRC glrc = create_gl_context(dc, extensions, contextType);
bsalomon49f085d2014-09-05 13:34:00 -0700437 if (glrc) {
halcanary385fe4d2015-08-26 13:07:48 -0700438 return new SkWGLPbufferContext(pbuf, dc, glrc);
bsalomon9245b7e2014-07-01 07:20:11 -0700439 }
440 extensions.releasePbufferDC(pbuf, dc);
441 }
442 extensions.destroyPbuffer(pbuf);
443 }
444 }
445 }
halcanary96fcdcc2015-08-27 07:41:13 -0700446 return nullptr;
bsalomon9245b7e2014-07-01 07:20:11 -0700447}
448
449SkWGLPbufferContext::~SkWGLPbufferContext() {
450 SkASSERT(fExtensions.hasExtension(fDC, "WGL_ARB_pbuffer"));
451 wglDeleteContext(fGLRC);
452 fExtensions.releasePbufferDC(fPbuffer, fDC);
453 fExtensions.destroyPbuffer(fPbuffer);
454}
455
456SkWGLPbufferContext::SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc)
457 : fPbuffer(pbuffer)
458 , fDC(dc)
459 , fGLRC(glrc) {
460}
mtklein1ee76512015-11-02 10:20:27 -0800461
462#endif//defined(SK_BUILD_FOR_WIN32)