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

Side by Side Diff: src/utils/win/SkWGL_win.cpp

Issue 12455009: Unify wgl context creation. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « src/gpu/gl/win/SkNativeGLContext_win.cpp ('k') | src/views/win/SkOSWindow_win.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkWGL.h" 9 #include "SkWGL.h"
10 10
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 GET_PROC(GetPixelFormatAttribfv, ARB); 256 GET_PROC(GetPixelFormatAttribfv, ARB);
257 GET_PROC(CreateContextAttribs, ARB); 257 GET_PROC(CreateContextAttribs, ARB);
258 258
259 wglMakeCurrent(dummyDC, NULL); 259 wglMakeCurrent(dummyDC, NULL);
260 wglDeleteContext(dummyGLRC); 260 wglDeleteContext(dummyGLRC);
261 destroy_dummy_window(dummyWND); 261 destroy_dummy_window(dummyWND);
262 } 262 }
263 263
264 wglMakeCurrent(prevDC, prevGLRC); 264 wglMakeCurrent(prevDC, prevGLRC);
265 } 265 }
266
267 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile) {
268 SkWGLExtensions extensions;
269 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
270 return NULL;
271 }
272
273 HDC prevDC = wglGetCurrentDC();
274 HGLRC prevGLRC = wglGetCurrentContext();
275 PIXELFORMATDESCRIPTOR pfd;
276
277 int format = 0;
278
279 static const int iAttrs[] = {
280 SK_WGL_DRAW_TO_WINDOW, TRUE,
281 SK_WGL_DOUBLE_BUFFER, TRUE,
282 SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
283 SK_WGL_SUPPORT_OPENGL, TRUE,
284 SK_WGL_COLOR_BITS, 24,
285 SK_WGL_ALPHA_BITS, 8,
286 SK_WGL_STENCIL_BITS, 8,
287 0, 0
288 };
289
290 float fAttrs[] = {0, 0};
291
292 if (msaaSampleCount > 0 &&
293 extensions.hasExtension(dc, "WGL_ARB_multisample")) {
294 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
295 int msaaIAttrs[kIAttrsCount + 6];
296 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount);
297 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
298 0 == msaaIAttrs[kIAttrsCount - 1]);
299 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
300 msaaIAttrs[kIAttrsCount - 1] = TRUE;
301 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
302 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
303 if (extensions.hasExtension(dc, "WGL_NV_multisample_coverage")) {
304 msaaIAttrs[kIAttrsCount + 2] = SK_WGL_COLOR_SAMPLES;
305 // We want the fewest number of color samples possible.
306 // Passing 0 gives only the formats where all samples are color
307 // samples.
308 msaaIAttrs[kIAttrsCount + 3] = 1;
309 msaaIAttrs[kIAttrsCount + 4] = 0;
310 msaaIAttrs[kIAttrsCount + 5] = 0;
311 } else {
312 msaaIAttrs[kIAttrsCount + 2] = 0;
313 msaaIAttrs[kIAttrsCount + 3] = 0;
314 }
315 unsigned int num;
316 int formats[64];
317 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
318 num = min(num,64);
319 int formatToTry = extensions.selectFormat(formats,
320 num,
321 dc,
322 msaaSampleCount);
323 DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd);
324 if (SetPixelFormat(dc, formatToTry, &pfd)) {
325 format = formatToTry;
326 }
327 }
328
329 if (0 == format) {
robertphillips 2013/03/05 18:46:22 // Either MSAA wasn't requested or creation failed
bsalomon 2013/03/05 18:52:21 Done.
330 unsigned int num;
331 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num);
332 DescribePixelFormat(dc, format, sizeof(pfd), &pfd);
333 BOOL set = SetPixelFormat(dc, format, &pfd);
334 SkASSERT(TRUE == set);
335 }
336
337 HGLRC glrc = NULL;
338 if (preferCoreProfile && extensions.hasExtension(dc, "WGL_ARB_create_context ")) {
339 static const int kCoreGLVersions[] = {
340 4, 3,
341 4, 2,
342 4, 1,
343 4, 0,
344 3, 3,
345 3, 2,
346 };
347 int coreProfileAttribs[] = {
348 SK_WGL_CONTEXT_MAJOR_VERSION, -1,
349 SK_WGL_CONTEXT_MINOR_VERSION, -1,
350 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT,
351 0,
352 };
353 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) {
354 coreProfileAttribs[1] = kCoreGLVersions[2 * v];
355 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1];
356 glrc = extensions.createContextAttribs(dc, NULL, coreProfileAttribs) ;
357 if (NULL != glrc) {
358 break;
359 }
360 }
361 }
362
363 if (NULL == glrc) {
364 glrc = wglCreateContext(dc);
365 }
366 SkASSERT(glrc);
367
368 wglMakeCurrent(prevDC, prevGLRC);
369 return glrc;
370 }
OLDNEW
« no previous file with comments | « src/gpu/gl/win/SkNativeGLContext_win.cpp ('k') | src/views/win/SkOSWindow_win.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698