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 #include "SkTypes.h" | 8 #include "SkTypes.h" |
9 | 9 |
10 #if defined(SK_BUILD_FOR_WIN) | 10 #if defined(SK_BUILD_FOR_WIN) |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 | 326 |
327 bool SkOSWindow::attachGL(int msaaSampleCount) { | 327 bool SkOSWindow::attachGL(int msaaSampleCount, AttachmentInfo* info) { |
328 HDC dc = GetDC((HWND)fHWND); | 328 HDC dc = GetDC((HWND)fHWND); |
329 if (NULL == fHGLRC) { | 329 if (NULL == fHGLRC) { |
330 fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, false); | 330 fHGLRC = SkCreateWGLContext(dc, msaaSampleCount, false); |
331 if (NULL == fHGLRC) { | 331 if (NULL == fHGLRC) { |
332 return false; | 332 return false; |
333 } | 333 } |
334 glClearStencil(0); | 334 glClearStencil(0); |
335 glClearColor(0, 0, 0, 0); | 335 glClearColor(0, 0, 0, 0); |
336 glStencilMask(0xffffffff); | 336 glStencilMask(0xffffffff); |
337 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 337 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
338 } | 338 } |
339 if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) { | 339 if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) { |
340 glViewport(0, 0, SkScalarRound(this->width()), | 340 // use DescribePixelFormat to get the stencil bit depth. |
341 SkScalarRound(this->height())); | 341 int pixelFormat = GetPixelFormat(dc); |
| 342 PIXELFORMATDESCRIPTOR pfd; |
| 343 DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd); |
| 344 info->fStencilBits = pfd.cStencilBits; |
| 345 |
| 346 // Get sample count if the MSAA WGL extension is present |
| 347 SkWGLExtensions extensions; |
| 348 if (extensions.hasExtension(dc, "WGL_ARB_multisample")) { |
| 349 static const int kSampleCountAttr = SK_WGL_SAMPLES; |
| 350 extensions.getPixelFormatAttribiv(dc, |
| 351 pixelFormat, |
| 352 0, |
| 353 1, |
| 354 &kSampleCountAttr, |
| 355 &info->fSampleCount); |
| 356 } else { |
| 357 info->fSampleCount = 0; |
| 358 } |
| 359 |
| 360 glViewport(0, 0, SkScalarRound(this->width()), SkScalarRound(this->heigh
t())); |
342 return true; | 361 return true; |
343 } | 362 } |
344 return false; | 363 return false; |
345 } | 364 } |
346 | 365 |
347 void SkOSWindow::detachGL() { | 366 void SkOSWindow::detachGL() { |
348 wglMakeCurrent(GetDC((HWND)fHWND), 0); | 367 wglMakeCurrent(GetDC((HWND)fHWND), 0); |
349 wglDeleteContext((HGLRC)fHGLRC); | 368 wglDeleteContext((HGLRC)fHGLRC); |
350 fHGLRC = NULL; | 369 fHGLRC = NULL; |
351 } | 370 } |
352 | 371 |
353 void SkOSWindow::presentGL() { | 372 void SkOSWindow::presentGL() { |
354 glFlush(); | 373 glFlush(); |
355 SwapBuffers(GetDC((HWND)fHWND)); | 374 SwapBuffers(GetDC((HWND)fHWND)); |
356 } | 375 } |
357 | 376 |
358 #if SK_ANGLE | 377 #if SK_ANGLE |
359 bool create_ANGLE(EGLNativeWindowType hWnd, | 378 bool create_ANGLE(EGLNativeWindowType hWnd, |
360 int msaaSampleCount, | 379 int msaaSampleCount, |
361 EGLDisplay* eglDisplay, | 380 EGLDisplay* eglDisplay, |
362 EGLContext* eglContext, | 381 EGLContext* eglContext, |
363 EGLSurface* eglSurface) { | 382 EGLSurface* eglSurface, |
| 383 EGLConfig* eglConfig) { |
364 static const EGLint contextAttribs[] = { | 384 static const EGLint contextAttribs[] = { |
365 EGL_CONTEXT_CLIENT_VERSION, 2, | 385 EGL_CONTEXT_CLIENT_VERSION, 2, |
366 EGL_NONE, EGL_NONE | 386 EGL_NONE, EGL_NONE |
367 }; | 387 }; |
368 static const EGLint configAttribList[] = { | 388 static const EGLint configAttribList[] = { |
369 EGL_RED_SIZE, 8, | 389 EGL_RED_SIZE, 8, |
370 EGL_GREEN_SIZE, 8, | 390 EGL_GREEN_SIZE, 8, |
371 EGL_BLUE_SIZE, 8, | 391 EGL_BLUE_SIZE, 8, |
372 EGL_ALPHA_SIZE, 8, | 392 EGL_ALPHA_SIZE, 8, |
373 EGL_DEPTH_SIZE, 8, | 393 EGL_DEPTH_SIZE, 8, |
(...skipping 14 matching lines...) Expand all Loading... |
388 if (!eglInitialize(display, &majorVersion, &minorVersion)) { | 408 if (!eglInitialize(display, &majorVersion, &minorVersion)) { |
389 return false; | 409 return false; |
390 } | 410 } |
391 | 411 |
392 EGLint numConfigs; | 412 EGLint numConfigs; |
393 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { | 413 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { |
394 return false; | 414 return false; |
395 } | 415 } |
396 | 416 |
397 // Choose config | 417 // Choose config |
398 EGLConfig config; | |
399 bool foundConfig = false; | 418 bool foundConfig = false; |
400 if (msaaSampleCount) { | 419 if (msaaSampleCount) { |
401 static const int kConfigAttribListCnt = | 420 static const int kConfigAttribListCnt = |
402 SK_ARRAY_COUNT(configAttribList); | 421 SK_ARRAY_COUNT(configAttribList); |
403 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; | 422 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; |
404 memcpy(msaaConfigAttribList, | 423 memcpy(msaaConfigAttribList, |
405 configAttribList, | 424 configAttribList, |
406 sizeof(configAttribList)); | 425 sizeof(configAttribList)); |
407 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); | 426 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); |
408 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; | 427 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; |
409 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; | 428 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; |
410 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; | 429 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; |
411 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; | 430 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; |
412 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; | 431 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; |
413 if (eglChooseConfig(display, configAttribList, | 432 if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs
)) { |
414 &config, 1, &numConfigs)) { | |
415 SkASSERT(numConfigs > 0); | 433 SkASSERT(numConfigs > 0); |
416 foundConfig = true; | 434 foundConfig = true; |
417 } | 435 } |
418 } | 436 } |
419 if (!foundConfig) { | 437 if (!foundConfig) { |
420 if (!eglChooseConfig(display, configAttribList, | 438 if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfig
s)) { |
421 &config, 1, &numConfigs)) { | |
422 return false; | 439 return false; |
423 } | 440 } |
424 } | 441 } |
425 | 442 |
426 // Create a surface | 443 // Create a surface |
427 EGLSurface surface = eglCreateWindowSurface(display, config, | 444 EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, |
428 (EGLNativeWindowType)hWnd, | 445 (EGLNativeWindowType)hWnd, |
429 surfaceAttribList); | 446 surfaceAttribList); |
430 if (surface == EGL_NO_SURFACE) { | 447 if (surface == EGL_NO_SURFACE) { |
431 return false; | 448 return false; |
432 } | 449 } |
433 | 450 |
434 // Create a GL context | 451 // Create a GL context |
435 EGLContext context = eglCreateContext(display, config, | 452 EGLContext context = eglCreateContext(display, *eglConfig, |
436 EGL_NO_CONTEXT, | 453 EGL_NO_CONTEXT, |
437 contextAttribs ); | 454 contextAttribs ); |
438 if (context == EGL_NO_CONTEXT ) { | 455 if (context == EGL_NO_CONTEXT ) { |
439 return false; | 456 return false; |
440 } | 457 } |
441 | 458 |
442 // Make the context current | 459 // Make the context current |
443 if (!eglMakeCurrent(display, surface, surface, context)) { | 460 if (!eglMakeCurrent(display, surface, surface, context)) { |
444 return false; | 461 return false; |
445 } | 462 } |
446 | 463 |
447 *eglDisplay = display; | 464 *eglDisplay = display; |
448 *eglContext = context; | 465 *eglContext = context; |
449 *eglSurface = surface; | 466 *eglSurface = surface; |
450 return true; | 467 return true; |
451 } | 468 } |
452 | 469 |
453 bool SkOSWindow::attachANGLE(int msaaSampleCount) { | 470 bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) { |
454 if (EGL_NO_DISPLAY == fDisplay) { | 471 if (EGL_NO_DISPLAY == fDisplay) { |
455 bool bResult = create_ANGLE((HWND)fHWND, | 472 bool bResult = create_ANGLE((HWND)fHWND, |
456 msaaSampleCount, | 473 msaaSampleCount, |
457 &fDisplay, | 474 &fDisplay, |
458 &fContext, | 475 &fContext, |
459 &fSurface); | 476 &fSurface, |
| 477 &fConfig); |
460 if (false == bResult) { | 478 if (false == bResult) { |
461 return false; | 479 return false; |
462 } | 480 } |
463 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 481 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
464 | 482 |
465 if (intf) { | 483 if (intf) { |
466 ANGLE_GL_CALL(intf, ClearStencil(0)); | 484 ANGLE_GL_CALL(intf, ClearStencil(0)); |
467 ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); | 485 ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
468 ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); | 486 ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); |
469 ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT
)); | 487 ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT
)); |
470 } | 488 } |
471 } | 489 } |
472 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 490 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 491 eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilB
its); |
| 492 eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); |
| 493 |
473 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 494 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
474 | 495 |
475 if (intf ) { | 496 if (intf ) { |
476 ANGLE_GL_CALL(intf, Viewport(0, 0, SkScalarRound(this->width()), | 497 ANGLE_GL_CALL(intf, Viewport(0, 0, SkScalarRound(this->width()), |
477 SkScalarRound(this->height()))); | 498 SkScalarRound(this->height()))); |
478 } | 499 } |
479 return true; | 500 return true; |
480 } | 501 } |
481 return false; | 502 return false; |
482 } | 503 } |
(...skipping 17 matching lines...) Expand all Loading... |
500 if (intf) { | 521 if (intf) { |
501 ANGLE_GL_CALL(intf, Flush()); | 522 ANGLE_GL_CALL(intf, Flush()); |
502 } | 523 } |
503 | 524 |
504 eglSwapBuffers(fDisplay, fSurface); | 525 eglSwapBuffers(fDisplay, fSurface); |
505 } | 526 } |
506 #endif // SK_ANGLE | 527 #endif // SK_ANGLE |
507 #endif // SK_SUPPORT_GPU | 528 #endif // SK_SUPPORT_GPU |
508 | 529 |
509 // return true on success | 530 // return true on success |
510 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) { | 531 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { |
511 | 532 |
512 // attach doubles as "windowResize" so we need to allo | 533 // attach doubles as "windowResize" so we need to allo |
513 // already bound states to pass through again | 534 // already bound states to pass through again |
514 // TODO: split out the resize functionality | 535 // TODO: split out the resize functionality |
515 // SkASSERT(kNone_BackEndType == fAttached); | 536 // SkASSERT(kNone_BackEndType == fAttached); |
516 bool result = true; | 537 bool result = true; |
517 | 538 |
518 switch (attachType) { | 539 switch (attachType) { |
519 case kNone_BackEndType: | 540 case kNone_BackEndType: |
520 // nothing to do | 541 // nothing to do |
521 break; | 542 break; |
522 #if SK_SUPPORT_GPU | 543 #if SK_SUPPORT_GPU |
523 case kNativeGL_BackEndType: | 544 case kNativeGL_BackEndType: |
524 result = attachGL(msaaSampleCount); | 545 result = attachGL(msaaSampleCount, info); |
525 break; | 546 break; |
526 #if SK_ANGLE | 547 #if SK_ANGLE |
527 case kANGLE_BackEndType: | 548 case kANGLE_BackEndType: |
528 result = attachANGLE(msaaSampleCount); | 549 result = attachANGLE(msaaSampleCount, info); |
529 break; | 550 break; |
530 #endif // SK_ANGLE | 551 #endif // SK_ANGLE |
531 #endif // SK_SUPPORT_GPU | 552 #endif // SK_SUPPORT_GPU |
532 default: | 553 default: |
533 SkASSERT(false); | 554 SkASSERT(false); |
534 result = false; | 555 result = false; |
535 break; | 556 break; |
536 } | 557 } |
537 | 558 |
538 if (result) { | 559 if (result) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 break; | 600 break; |
580 #endif // SK_ANGLE | 601 #endif // SK_ANGLE |
581 #endif // SK_SUPPORT_GPU | 602 #endif // SK_SUPPORT_GPU |
582 default: | 603 default: |
583 SkASSERT(false); | 604 SkASSERT(false); |
584 break; | 605 break; |
585 } | 606 } |
586 } | 607 } |
587 | 608 |
588 #endif | 609 #endif |
OLD | NEW |