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

Unified 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, 10 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/win/SkWGL_win.cpp
===================================================================
--- src/utils/win/SkWGL_win.cpp (revision 7977)
+++ src/utils/win/SkWGL_win.cpp (working copy)
@@ -263,3 +263,108 @@
wglMakeCurrent(prevDC, prevGLRC);
}
+
+HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile) {
+ SkWGLExtensions extensions;
+ if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) {
+ return NULL;
+ }
+
+ HDC prevDC = wglGetCurrentDC();
+ HGLRC prevGLRC = wglGetCurrentContext();
+ PIXELFORMATDESCRIPTOR pfd;
+
+ int format = 0;
+
+ static const int iAttrs[] = {
+ SK_WGL_DRAW_TO_WINDOW, TRUE,
+ SK_WGL_DOUBLE_BUFFER, TRUE,
+ SK_WGL_ACCELERATION, SK_WGL_FULL_ACCELERATION,
+ SK_WGL_SUPPORT_OPENGL, TRUE,
+ SK_WGL_COLOR_BITS, 24,
+ SK_WGL_ALPHA_BITS, 8,
+ SK_WGL_STENCIL_BITS, 8,
+ 0, 0
+ };
+
+ float fAttrs[] = {0, 0};
+
+ if (msaaSampleCount > 0 &&
+ extensions.hasExtension(dc, "WGL_ARB_multisample")) {
+ static const int kIAttrsCount = SK_ARRAY_COUNT(iAttrs);
+ int msaaIAttrs[kIAttrsCount + 6];
+ memcpy(msaaIAttrs, iAttrs, sizeof(int) * kIAttrsCount);
+ SkASSERT(0 == msaaIAttrs[kIAttrsCount - 2] &&
+ 0 == msaaIAttrs[kIAttrsCount - 1]);
+ msaaIAttrs[kIAttrsCount - 2] = SK_WGL_SAMPLE_BUFFERS;
+ msaaIAttrs[kIAttrsCount - 1] = TRUE;
+ msaaIAttrs[kIAttrsCount + 0] = SK_WGL_SAMPLES;
+ msaaIAttrs[kIAttrsCount + 1] = msaaSampleCount;
+ if (extensions.hasExtension(dc, "WGL_NV_multisample_coverage")) {
+ msaaIAttrs[kIAttrsCount + 2] = SK_WGL_COLOR_SAMPLES;
+ // We want the fewest number of color samples possible.
+ // Passing 0 gives only the formats where all samples are color
+ // samples.
+ msaaIAttrs[kIAttrsCount + 3] = 1;
+ msaaIAttrs[kIAttrsCount + 4] = 0;
+ msaaIAttrs[kIAttrsCount + 5] = 0;
+ } else {
+ msaaIAttrs[kIAttrsCount + 2] = 0;
+ msaaIAttrs[kIAttrsCount + 3] = 0;
+ }
+ unsigned int num;
+ int formats[64];
+ extensions.choosePixelFormat(dc, msaaIAttrs, fAttrs, 64, formats, &num);
+ num = min(num,64);
+ int formatToTry = extensions.selectFormat(formats,
+ num,
+ dc,
+ msaaSampleCount);
+ DescribePixelFormat(dc, formatToTry, sizeof(pfd), &pfd);
+ if (SetPixelFormat(dc, formatToTry, &pfd)) {
+ format = formatToTry;
+ }
+ }
+
+ 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.
+ unsigned int num;
+ extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num);
+ DescribePixelFormat(dc, format, sizeof(pfd), &pfd);
+ BOOL set = SetPixelFormat(dc, format, &pfd);
+ SkASSERT(TRUE == set);
+ }
+
+ HGLRC glrc = NULL;
+ if (preferCoreProfile && extensions.hasExtension(dc, "WGL_ARB_create_context")) {
+ static const int kCoreGLVersions[] = {
+ 4, 3,
+ 4, 2,
+ 4, 1,
+ 4, 0,
+ 3, 3,
+ 3, 2,
+ };
+ int coreProfileAttribs[] = {
+ SK_WGL_CONTEXT_MAJOR_VERSION, -1,
+ SK_WGL_CONTEXT_MINOR_VERSION, -1,
+ SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT,
+ 0,
+ };
+ for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) {
+ coreProfileAttribs[1] = kCoreGLVersions[2 * v];
+ coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1];
+ glrc = extensions.createContextAttribs(dc, NULL, coreProfileAttribs);
+ if (NULL != glrc) {
+ break;
+ }
+ }
+ }
+
+ if (NULL == glrc) {
+ glrc = wglCreateContext(dc);
+ }
+ SkASSERT(glrc);
+
+ wglMakeCurrent(prevDC, prevGLRC);
+ return glrc;
+}
« 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