| OLD | NEW |
| 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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 238 GET_PROC(CreateContextAttribs, ARB); | 238 GET_PROC(CreateContextAttribs, ARB); |
| 239 | 239 |
| 240 wglMakeCurrent(dummyDC, NULL); | 240 wglMakeCurrent(dummyDC, NULL); |
| 241 wglDeleteContext(dummyGLRC); | 241 wglDeleteContext(dummyGLRC); |
| 242 destroy_dummy_window(dummyWND); | 242 destroy_dummy_window(dummyWND); |
| 243 } | 243 } |
| 244 | 244 |
| 245 wglMakeCurrent(prevDC, prevGLRC); | 245 wglMakeCurrent(prevDC, prevGLRC); |
| 246 } | 246 } |
| 247 | 247 |
| 248 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, bool preferCoreProfile) { | 248 HGLRC SkCreateWGLContext(HDC dc, int msaaSampleCount, SkWGLContextRequest contex
tType) { |
| 249 SkWGLExtensions extensions; | 249 SkWGLExtensions extensions; |
| 250 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) { | 250 if (!extensions.hasExtension(dc, "WGL_ARB_pixel_format")) { |
| 251 return NULL; | 251 return NULL; |
| 252 } | 252 } |
| 253 | 253 |
| 254 HDC prevDC = wglGetCurrentDC(); | 254 HDC prevDC = wglGetCurrentDC(); |
| 255 HGLRC prevGLRC = wglGetCurrentContext(); | 255 HGLRC prevGLRC = wglGetCurrentContext(); |
| 256 PIXELFORMATDESCRIPTOR pfd; | 256 PIXELFORMATDESCRIPTOR pfd; |
| 257 | 257 |
| 258 int format = 0; | 258 int format = 0; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 if (0 == format) { | 300 if (0 == format) { |
| 301 // Either MSAA wasn't requested or creation failed | 301 // Either MSAA wasn't requested or creation failed |
| 302 unsigned int num; | 302 unsigned int num; |
| 303 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num); | 303 extensions.choosePixelFormat(dc, iAttrs, fAttrs, 1, &format, &num); |
| 304 DescribePixelFormat(dc, format, sizeof(pfd), &pfd); | 304 DescribePixelFormat(dc, format, sizeof(pfd), &pfd); |
| 305 SkDEBUGCODE(BOOL set =) SetPixelFormat(dc, format, &pfd); | 305 SkDEBUGCODE(BOOL set =) SetPixelFormat(dc, format, &pfd); |
| 306 SkASSERT(TRUE == set); | 306 SkASSERT(TRUE == set); |
| 307 } | 307 } |
| 308 | 308 |
| 309 HGLRC glrc = NULL; | 309 HGLRC glrc = NULL; |
| 310 if (preferCoreProfile && extensions.hasExtension(dc, "WGL_ARB_create_context
")) { | 310 if (kGLES_SkWGLContextRequest == contextType) { |
| 311 static const int kCoreGLVersions[] = { | 311 if (!extensions.hasExtension(dc, "WGL_EXT_create_context_es2_profile"))
{ |
| 312 4, 3, | 312 return NULL; |
| 313 4, 2, | 313 } |
| 314 4, 1, | 314 static const int glesAttribs[] = { |
| 315 4, 0, | 315 SK_WGL_CONTEXT_MAJOR_VERSION, 3, |
| 316 3, 3, | 316 SK_WGL_CONTEXT_MINOR_VERSION, 0, |
| 317 3, 2, | 317 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_ES2_PROFILE_BIT, |
| 318 }; | |
| 319 int coreProfileAttribs[] = { | |
| 320 SK_WGL_CONTEXT_MAJOR_VERSION, -1, | |
| 321 SK_WGL_CONTEXT_MINOR_VERSION, -1, | |
| 322 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT, | |
| 323 0, | 318 0, |
| 324 }; | 319 }; |
| 325 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) { | 320 glrc = extensions.createContextAttribs(dc, NULL, glesAttribs); |
| 326 coreProfileAttribs[1] = kCoreGLVersions[2 * v]; | 321 if (NULL == glrc) { |
| 327 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1]; | 322 return NULL; |
| 328 glrc = extensions.createContextAttribs(dc, NULL, coreProfileAttribs)
; | 323 } |
| 329 if (NULL != glrc) { | 324 } else { |
| 330 break; | 325 if (kGLPreferCoreProfile_SkWGLContextRequest == contextType && |
| 326 extensions.hasExtension(dc, "WGL_ARB_create_context")) { |
| 327 static const int kCoreGLVersions[] = { |
| 328 4, 3, |
| 329 4, 2, |
| 330 4, 1, |
| 331 4, 0, |
| 332 3, 3, |
| 333 3, 2, |
| 334 }; |
| 335 int coreProfileAttribs[] = { |
| 336 SK_WGL_CONTEXT_MAJOR_VERSION, -1, |
| 337 SK_WGL_CONTEXT_MINOR_VERSION, -1, |
| 338 SK_WGL_CONTEXT_PROFILE_MASK, SK_WGL_CONTEXT_CORE_PROFILE_BIT, |
| 339 0, |
| 340 }; |
| 341 for (int v = 0; v < SK_ARRAY_COUNT(kCoreGLVersions) / 2; ++v) { |
| 342 coreProfileAttribs[1] = kCoreGLVersions[2 * v]; |
| 343 coreProfileAttribs[3] = kCoreGLVersions[2 * v + 1]; |
| 344 glrc = extensions.createContextAttribs(dc, NULL, coreProfileAttr
ibs); |
| 345 if (NULL != glrc) { |
| 346 break; |
| 347 } |
| 331 } | 348 } |
| 332 } | 349 } |
| 333 } | 350 } |
| 334 | 351 |
| 335 if (NULL == glrc) { | 352 if (NULL == glrc) { |
| 336 glrc = wglCreateContext(dc); | 353 glrc = wglCreateContext(dc); |
| 337 } | 354 } |
| 338 SkASSERT(glrc); | 355 SkASSERT(glrc); |
| 339 | 356 |
| 340 wglMakeCurrent(prevDC, prevGLRC); | 357 wglMakeCurrent(prevDC, prevGLRC); |
| 341 return glrc; | 358 return glrc; |
| 342 } | 359 } |
| OLD | NEW |