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

Side by Side Diff: src/views/win/SkOSWindow_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
« src/utils/win/SkWGL_win.cpp ('K') | « src/utils/win/SkWGL_win.cpp ('k') | no next file » | 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 #include "SkTypes.h" 8 #include "SkTypes.h"
9 9
10 #if defined(SK_BUILD_FOR_WIN) 10 #if defined(SK_BUILD_FOR_WIN)
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 gTimer = NULL; 316 gTimer = NULL;
317 } 317 }
318 if (delay) 318 if (delay)
319 { 319 {
320 gTimer = SetTimer(NULL, 0, delay, sk_timer_proc); 320 gTimer = SetTimer(NULL, 0, delay, sk_timer_proc);
321 //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer); 321 //SkDebugf("SetTimer of %d returned %d\n", delay, gTimer);
322 } 322 }
323 } 323 }
324 324
325 #if SK_SUPPORT_GPU 325 #if SK_SUPPORT_GPU
326 HGLRC create_gl(HWND hwnd, int msaaSampleCount) {
327
328 HDC dc = GetDC(hwnd);
329
330 SkWGLExtensions extensions;
331 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
332 return NULL;
333 }
334
335 HDC prevDC = wglGetCurrentDC();
336 HGLRC prevGLRC = wglGetCurrentContext();
337 PIXELFORMATDESCRIPTOR pfd;
338
339 int format = 0;
340
341 static const GLint iAttrs[] = {
342 SK_WGL_DRAW_TO_WINDOW, TRUE,
343 SK_WGL_DOUBLE_BUFFER, TRUE,
344 SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
345 SK_WGL_SUPPORT_OPENGL, TRUE,
346 SK_WGL_COLOR_BITS, 24,
347 SK_WGL_ALPHA_BITS, 8,
348 SK_WGL_STENCIL_BITS, 8,
349 0, 0
350 };
351
352 GLfloat fAttrs[] = {0, 0};
353
354 if (msaaSampleCount > 0 &&
355 extensions.hasExtension(dc, "WGL_ARB_multisample")) {
356 static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
357 GLint msaaIAttrs[kIAttrsCount + 6];
358 memcpy(msaaIAttrs, iAttrs, sizeof(GLint) * kIAttrsCount);
359 SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
360 0 == msaaIAttrs[kIAttrsCount - 1]);
361 msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
362 msaaIAttrs[kIAttrsCount - 1] = TRUE;
363 msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
364 msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
365 if (extensions.hasExtension(dc, "WGL_NV_multisample_coverage")) {
366 msaaIAttrs[kIAttrsCount + 2] = SK_WGL_COLOR_SAMPLES;
367 // We want the fewest number of color samples possible.
368 // Passing 0 gives only the formats where all samples are color
369 // samples.
370 msaaIAttrs[kIAttrsCount + 3] = 1;
371 msaaIAttrs[kIAttrsCount + 4] = 0;
372 msaaIAttrs[kIAttrsCount + 5] = 0;
373 } else {
374 msaaIAttrs[kIAttrsCount + 2] = 0;
375 msaaIAttrs[kIAttrsCount + 3] = 0;
376 }
377 GLuint num;
378 int formats[64];
379 extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
380 num = min(num,64);
381 int formatToTry = extensions.selectFormat(formats,
382 num,
383 dc,
384 msaaSampleCount);
385 DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd);
386 if (SetPixelFormat(dc, formatToTry, &pfd)) {
387 format = formatToTry;
388 }
389 }
390
391 if (0 == format) {
392 GLuint num;
393 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num);
394 DescribePixelFormat(dc, format, sizeof(pfd), &pfd);
395 BOOL set = SetPixelFormat(dc, format, &pfd);
396 SkASSERT(TRUE == set);
397 }
398
399 HGLRC glrc = NULL;
400 #if 0 // Change to 1 to attempt to create a core profile GL context of version 4 .3 or lower
401 if (extensions.hasExtension(dc, "WGL_ARB_create_context")) {
402 static const GLint kCoreGLVersions[] = {
403 4, 3,
404 4, 2,
405 4, 1,
406 4, 0,
407 3, 3,
408 3, 2,
409 };
410 GLint coreProfileAttribs[] = {
411 SK_WGL_CONTEXT_MAJOR_VERSION, -1,
412 SK_WGL_CONTEXT_MINOR_VERSION, -1,
413 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT,
414 0,
415 };
416 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) {
417 coreProfileAttribs[1] = kCoreGLVersions[2 * v];
418 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1];
419 glrc = extensions.createContextAttribs(dc, NULL, coreProfileAttribs) ;
420 if (NULL != glrc) {
421 break;
422 }
423 }
424 }
425 #endif
426
427 if (NULL == glrc) {
428 glrc = wglCreateContext(dc);
429 }
430 SkASSERT(glrc);
431
432 wglMakeCurrent(prevDC, prevGLRC);
433 return glrc;
434 }
435 326
436 bool SkOSWindow::attachGL(int msaaSampleCount) { 327 bool SkOSWindow::attachGL(int msaaSampleCount) {
328 HDC dc = GetDC((HWND)fHWND);
437 if (NULL == fHGLRC) { 329 if (NULL == fHGLRC) {
438 fHGLRC = create_gl((HWND)fHWND, msaaSampleCount); 330 fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, false);
439 if (NULL == fHGLRC) { 331 if (NULL == fHGLRC) {
440 return false; 332 return false;
441 } 333 }
442 glClearStencil(0); 334 glClearStencil(0);
443 glClearColor(0, 0, 0, 0); 335 glClearColor(0, 0, 0, 0);
444 glStencilMask(0xffffffff); 336 glStencilMask(0xffffffff);
445 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); 337 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
446 } 338 }
447 if (wglMakeCurrent(GetDC((HWND)fHWND), (HGLRC)fHGLRC)) { 339 if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) {
448 glViewport(0, 0, SkScalarRound(this->width()), 340 glViewport(0, 0, SkScalarRound(this->width()),
449 SkScalarRound(this->height())); 341 SkScalarRound(this->height()));
450 return true; 342 return true;
451 } 343 }
452 return false; 344 return false;
453 } 345 }
454 346
455 void SkOSWindow::detachGL() { 347 void SkOSWindow::detachGL() {
456 wglMakeCurrent(GetDC((HWND)fHWND), 0); 348 wglMakeCurrent(GetDC((HWND)fHWND), 0);
457 wglDeleteContext((HGLRC)fHGLRC); 349 wglDeleteContext((HGLRC)fHGLRC);
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 break; 579 break;
688 #endif // SK_ANGLE 580 #endif // SK_ANGLE
689 #endif // SK_SUPPORT_GPU 581 #endif // SK_SUPPORT_GPU
690 default: 582 default:
691 SkASSERT(false); 583 SkASSERT(false);
692 break; 584 break;
693 } 585 }
694 } 586 }
695 587
696 #endif 588 #endif
OLDNEW
« src/utils/win/SkWGL_win.cpp ('K') | « src/utils/win/SkWGL_win.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698