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

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

Issue 1919993002: Added --deepColor option to SampleApp, triggers creation of a ten-bit/channel buffer on Windows. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 7 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
« no previous file with comments | « src/utils/win/SkWGL.h ('k') | src/views/SkWindow.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 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkTypes.h" 8 #include "SkTypes.h"
9 #if defined(SK_BUILD_FOR_WIN32) 9 #if defined(SK_BUILD_FOR_WIN32)
10 10
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 wglDeleteContext(dummyGLRC); 281 wglDeleteContext(dummyGLRC);
282 destroy_dummy_window(dummyWND); 282 destroy_dummy_window(dummyWND);
283 } 283 }
284 284
285 wglMakeCurrent(prevDC, prevGLRC); 285 wglMakeCurrent(prevDC, prevGLRC);
286 } 286 }
287 287
288 /////////////////////////////////////////////////////////////////////////////// 288 ///////////////////////////////////////////////////////////////////////////////
289 289
290 static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions, 290 static void get_pixel_formats_to_try(HDC dc, const SkWGLExtensions& extensions,
291 bool doubleBuffered, int msaaSampleCount, 291 bool doubleBuffered, int msaaSampleCount, b ool deepColor,
292 int formatsToTry[2]) { 292 int formatsToTry[2]) {
293 int iAttrs[] = { 293 auto appendAttr = [](SkTDArray<int>& attrs, int attr, int value) {
294 SK_WGL_DRAW_TO_WINDOW, TRUE, 294 attrs.push(attr);
295 SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE), 295 attrs.push(value);
296 SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
297 SK_WGL_SUPPORT_OPENGL, TRUE,
298 SK_WGL_COLOR_BITS, 24,
299 SK_WGL_ALPHA_BITS, 8,
300 SK_WGL_STENCIL_BITS, 8,
301 0, 0
302 }; 296 };
303 297
298 SkTDArray<int> iAttrs;
299 appendAttr(iAttrs, SK_WGL_DRAW_TO_WINDOW, TRUE);
300 appendAttr(iAttrs, SK_WGL_DOUBLE_BUFFER, (doubleBuffered ? TRUE : FALSE));
301 appendAttr(iAttrs, SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION);
302 appendAttr(iAttrs, SK_WGL_SUPPORT_OPENGL, TRUE);
303 if (deepColor) {
304 appendAttr(iAttrs, SK_WGL_RED_BITS, 10);
305 appendAttr(iAttrs, SK_WGL_GREEN_BITS, 10);
306 appendAttr(iAttrs, SK_WGL_BLUE_BITS, 10);
307 appendAttr(iAttrs, SK_WGL_ALPHA_BITS, 2);
308 } else {
309 appendAttr(iAttrs, SK_WGL_COLOR_BITS, 24);
310 appendAttr(iAttrs, SK_WGL_ALPHA_BITS, 8);
311 }
312 appendAttr(iAttrs, SK_WGL_STENCIL_BITS, 8);
313
304 float fAttrs[] = {0, 0}; 314 float fAttrs[] = {0, 0};
305 315
306 // Get a MSAA format if requested and possible. 316 // Get a MSAA format if requested and possible.
307 if (msaaSampleCount > 0 && 317 if (msaaSampleCount > 0 &&
308 extensions.hasExtension(dc, "WGL_ARB_multisample")) { 318 extensions.hasExtension(dc, "WGL_ARB_multisample")) {
309 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs); 319 SkTDArray<int> msaaIAttrs = iAttrs;
310 int msaaIAttrs[kIAttrsCount + 4]; 320 appendAttr(msaaIAttrs, SK_WGL_SAMPLE_BUFFERS, TRUE);
311 memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount); 321 appendAttr(msaaIAttrs, SK_WGL_SAMPLES, msaaSampleCount);
312 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] && 322 appendAttr(msaaIAttrs, 0, 0);
313 0 == msaaIAttrs[kIAttrsCount - 1]);
314 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
315 msaaIAttrs[kIAttrsCount - 1] = TRUE;
316 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
317 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
318 msaaIAttrs[kIAttrsCount + 2] = 0;
319 msaaIAttrs[kIAttrsCount + 3] = 0;
320 unsigned int num; 323 unsigned int num;
321 int formats[64]; 324 int formats[64];
322 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num); 325 extensions.choosePixelFormat(dc, msaaIAttrs.begin(), fAttrs, 64, formats , &num);
323 num = SkTMin(num, 64U); 326 num = SkTMin(num, 64U);
324 formatsToTry[0] = extensions.selectFormat(formats, num, dc, msaaSampleCo unt); 327 formatsToTry[0] = extensions.selectFormat(formats, num, dc, msaaSampleCo unt);
325 } 328 }
326 329
327 // Get a non-MSAA format 330 // Get a non-MSAA format
328 int* format = -1 == formatsToTry[0] ? &formatsToTry[0] : &formatsToTry[1]; 331 int* format = -1 == formatsToTry[0] ? &formatsToTry[0] : &formatsToTry[1];
329 unsigned int num; 332 unsigned int num;
330 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, format, &num); 333 appendAttr(iAttrs, 0, 0);
334 extensions.choosePixelFormat(dc, iAttrs.begin(), fAttrs, 1, format, &num);
331 } 335 }
332 336
333 static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextR equest contextType) { 337 static HGLRC create_gl_context(HDC dc, SkWGLExtensions extensions, SkWGLContextR equest contextType) {
334 HDC prevDC = wglGetCurrentDC(); 338 HDC prevDC = wglGetCurrentDC();
335 HGLRC prevGLRC = wglGetCurrentContext(); 339 HGLRC prevGLRC = wglGetCurrentContext();
336 340
337 HGLRC glrc = nullptr; 341 HGLRC glrc = nullptr;
338 if (kGLES_SkWGLContextRequest == contextType) { 342 if (kGLES_SkWGLContextRequest == contextType) {
339 if (!extensions.hasExtension(dc, "WGL_EXT_create_context_es2_profile")) { 343 if (!extensions.hasExtension(dc, "WGL_EXT_create_context_es2_profile")) {
340 wglMakeCurrent(prevDC, prevGLRC); 344 wglMakeCurrent(prevDC, prevGLRC);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 390
387 wglMakeCurrent(prevDC, prevGLRC); 391 wglMakeCurrent(prevDC, prevGLRC);
388 392
389 // This might help make the context non-vsynced. 393 // This might help make the context non-vsynced.
390 if (extensions.hasExtension(dc, "WGL_EXT_swap_control")) { 394 if (extensions.hasExtension(dc, "WGL_EXT_swap_control")) {
391 extensions.swapInterval(-1); 395 extensions.swapInterval(-1);
392 } 396 }
393 return glrc; 397 return glrc;
394 } 398 }
395 399
396 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contex tType) { 400 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool deepColor,
401 SkWGLContextRequest contextType) {
397 SkWGLExtensions extensions; 402 SkWGLExtensions extensions;
398 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) { 403 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
399 return nullptr; 404 return nullptr;
400 } 405 }
401 406
402 BOOL set = FALSE; 407 BOOL set = FALSE;
403 408
404 int pixelFormatsToTry[] = { -1, -1 }; 409 int pixelFormatsToTry[] = { -1, -1 };
405 get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, pixelFormats ToTry); 410 get_pixel_formats_to_try(dc, extensions, true, msaaSampleCount, deepColor, p ixelFormatsToTry);
406 for (int f = 0; 411 for (int f = 0;
407 !set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsTo Try); 412 !set && -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFormatsTo Try);
408 ++f) { 413 ++f) {
409 PIXELFORMATDESCRIPTOR pfd; 414 PIXELFORMATDESCRIPTOR pfd;
410 DescribePixelFormat(dc, pixelFormatsToTry[f], sizeof(pfd), &pfd); 415 DescribePixelFormat(dc, pixelFormatsToTry[f], sizeof(pfd), &pfd);
411 set = SetPixelFormat(dc, pixelFormatsToTry[f], &pfd); 416 set = SetPixelFormat(dc, pixelFormatsToTry[f], &pfd);
412 } 417 }
413 418
414 if (!set) { 419 if (!set) {
415 return nullptr; 420 return nullptr;
416 } 421 }
417 422
418 return create_gl_context(dc, extensions, contextType);} 423 return create_gl_context(dc, extensions, contextType);}
419 424
420 SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCou nt, 425 SkWGLPbufferContext* SkWGLPbufferContext::Create(HDC parentDC, int msaaSampleCou nt,
421 SkWGLContextRequest contextType ) { 426 SkWGLContextRequest contextType ) {
422 SkWGLExtensions extensions; 427 SkWGLExtensions extensions;
423 if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") || 428 if (!extensions.hasExtension(parentDC, "WGL_ARB_pixel_format") ||
424 !extensions.hasExtension(parentDC, "WGL_ARB_pbuffer")) { 429 !extensions.hasExtension(parentDC, "WGL_ARB_pbuffer")) {
425 return nullptr; 430 return nullptr;
426 } 431 }
427 432
428 // try for single buffer first 433 // try for single buffer first
429 for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) { 434 for (int dblBuffer = 0; dblBuffer < 2; ++dblBuffer) {
430 int pixelFormatsToTry[] = { -1, -1 }; 435 int pixelFormatsToTry[] = { -1, -1 };
431 get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSam pleCount, 436 get_pixel_formats_to_try(parentDC, extensions, (0 != dblBuffer), msaaSam pleCount,
432 pixelFormatsToTry); 437 false, pixelFormatsToTry);
433 for (int f = 0; -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFo rmatsToTry); ++f) { 438 for (int f = 0; -1 != pixelFormatsToTry[f] && f < SK_ARRAY_COUNT(pixelFo rmatsToTry); ++f) {
434 HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormatsToTry [f], 1, 1, nullptr); 439 HPBUFFER pbuf = extensions.createPbuffer(parentDC, pixelFormatsToTry [f], 1, 1, nullptr);
435 if (0 != pbuf) { 440 if (0 != pbuf) {
436 HDC dc = extensions.getPbufferDC(pbuf); 441 HDC dc = extensions.getPbufferDC(pbuf);
437 if (dc) { 442 if (dc) {
438 HGLRC glrc = create_gl_context(dc, extensions, contextType); 443 HGLRC glrc = create_gl_context(dc, extensions, contextType);
439 if (glrc) { 444 if (glrc) {
440 return new SkWGLPbufferContext(pbuf, dc, glrc); 445 return new SkWGLPbufferContext(pbuf, dc, glrc);
441 } 446 }
442 extensions.releasePbufferDC(pbuf, dc); 447 extensions.releasePbufferDC(pbuf, dc);
(...skipping 12 matching lines...) Expand all
455 fExtensions.destroyPbuffer(fPbuffer); 460 fExtensions.destroyPbuffer(fPbuffer);
456 } 461 }
457 462
458 SkWGLPbufferContext::SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc) 463 SkWGLPbufferContext::SkWGLPbufferContext(HPBUFFER pbuffer, HDC dc, HGLRC glrc)
459 : fPbuffer(pbuffer) 464 : fPbuffer(pbuffer)
460 , fDC(dc) 465 , fDC(dc)
461 , fGLRC(glrc) { 466 , fGLRC(glrc) {
462 } 467 }
463 468
464 #endif//defined(SK_BUILD_FOR_WIN32) 469 #endif//defined(SK_BUILD_FOR_WIN32)
OLDNEW
« no previous file with comments | « src/utils/win/SkWGL.h ('k') | src/views/SkWindow.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698