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 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 | 426 |
427 if (NULL == glrc) { | 427 if (NULL == glrc) { |
428 glrc = wglCreateContext(dc); | 428 glrc = wglCreateContext(dc); |
429 } | 429 } |
430 SkASSERT(glrc); | 430 SkASSERT(glrc); |
431 | 431 |
432 wglMakeCurrent(prevDC, prevGLRC); | 432 wglMakeCurrent(prevDC, prevGLRC); |
433 return glrc; | 433 return glrc; |
434 } | 434 } |
435 | 435 |
436 bool SkOSWindow::attachGL(int msaaSampleCount) { | 436 bool SkOSWindow::attachGL(int msaaSampleCount, AttachmentInfo* info) { |
437 if (NULL == fHGLRC) { | 437 if (NULL == fHGLRC) { |
438 fHGLRC = create_gl((HWND)fHWND, msaaSampleCount); | 438 fHGLRC = create_gl((HWND)fHWND, msaaSampleCount); |
439 if (NULL == fHGLRC) { | 439 if (NULL == fHGLRC) { |
440 return false; | 440 return false; |
441 } | 441 } |
442 glClearStencil(0); | 442 glClearStencil(0); |
443 glClearColor(0, 0, 0, 0); | 443 glClearColor(0, 0, 0, 0); |
444 glStencilMask(0xffffffff); | 444 glStencilMask(0xffffffff); |
445 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); | 445 glClear(GL_STENCIL_BUFFER_BIT | GL_COLOR_BUFFER_BIT); |
446 } | 446 } |
447 if (wglMakeCurrent(GetDC((HWND)fHWND), (HGLRC)fHGLRC)) { | 447 HDC dc = GetDC((HWND)fHWND); |
448 glViewport(0, 0, SkScalarRound(this->width()), | 448 if (wglMakeCurrent(dc, (HGLRC)fHGLRC)) { |
449 SkScalarRound(this->height())); | 449 // use DescribePixelFormat to get the stencil bit depth. |
| 450 int pixelFormat = GetPixelFormat(dc); |
| 451 PIXELFORMATDESCRIPTOR pfd; |
| 452 DescribePixelFormat(dc, pixelFormat, sizeof(pfd), &pfd); |
| 453 info->fStencilBits = pfd.cStencilBits; |
| 454 |
| 455 // Get sample count if the the MSAA WGL extension is present |
| 456 SkWGLExtensions extensions; |
| 457 if (extensions.hasExtension(dc, "WGL_ARB_multisample")) { |
| 458 static const int kSampleCountAttr = SK_WGL_SAMPLES; |
| 459 extensions.getPixelFormatAttribiv(dc, |
| 460 pixelFormat, |
| 461 0, |
| 462 1, |
| 463 &kSampleCountAttr, |
| 464 &info->fSampleCount); |
| 465 } else { |
| 466 info->fSampleCount = 0; |
| 467 } |
| 468 |
| 469 glViewport(0, 0, SkScalarRound(this->width()), SkScalarRound(this->heigh
t())); |
450 return true; | 470 return true; |
451 } | 471 } |
452 return false; | 472 return false; |
453 } | 473 } |
454 | 474 |
455 void SkOSWindow::detachGL() { | 475 void SkOSWindow::detachGL() { |
456 wglMakeCurrent(GetDC((HWND)fHWND), 0); | 476 wglMakeCurrent(GetDC((HWND)fHWND), 0); |
457 wglDeleteContext((HGLRC)fHGLRC); | 477 wglDeleteContext((HGLRC)fHGLRC); |
458 fHGLRC = NULL; | 478 fHGLRC = NULL; |
459 } | 479 } |
460 | 480 |
461 void SkOSWindow::presentGL() { | 481 void SkOSWindow::presentGL() { |
462 glFlush(); | 482 glFlush(); |
463 SwapBuffers(GetDC((HWND)fHWND)); | 483 SwapBuffers(GetDC((HWND)fHWND)); |
464 } | 484 } |
465 | 485 |
466 #if SK_ANGLE | 486 #if SK_ANGLE |
467 bool create_ANGLE(EGLNativeWindowType hWnd, | 487 bool create_ANGLE(EGLNativeWindowType hWnd, |
468 int msaaSampleCount, | 488 int msaaSampleCount, |
469 EGLDisplay* eglDisplay, | 489 EGLDisplay* eglDisplay, |
470 EGLContext* eglContext, | 490 EGLContext* eglContext, |
471 EGLSurface* eglSurface) { | 491 EGLSurface* eglSurface, |
| 492 EGLConfig* eglConfig) { |
472 static const EGLint contextAttribs[] = { | 493 static const EGLint contextAttribs[] = { |
473 EGL_CONTEXT_CLIENT_VERSION, 2, | 494 EGL_CONTEXT_CLIENT_VERSION, 2, |
474 EGL_NONE, EGL_NONE | 495 EGL_NONE, EGL_NONE |
475 }; | 496 }; |
476 static const EGLint configAttribList[] = { | 497 static const EGLint configAttribList[] = { |
477 EGL_RED_SIZE, 8, | 498 EGL_RED_SIZE, 8, |
478 EGL_GREEN_SIZE, 8, | 499 EGL_GREEN_SIZE, 8, |
479 EGL_BLUE_SIZE, 8, | 500 EGL_BLUE_SIZE, 8, |
480 EGL_ALPHA_SIZE, 8, | 501 EGL_ALPHA_SIZE, 8, |
481 EGL_DEPTH_SIZE, 8, | 502 EGL_DEPTH_SIZE, 8, |
(...skipping 14 matching lines...) Expand all Loading... |
496 if (!eglInitialize(display, &majorVersion, &minorVersion)) { | 517 if (!eglInitialize(display, &majorVersion, &minorVersion)) { |
497 return false; | 518 return false; |
498 } | 519 } |
499 | 520 |
500 EGLint numConfigs; | 521 EGLint numConfigs; |
501 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { | 522 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { |
502 return false; | 523 return false; |
503 } | 524 } |
504 | 525 |
505 // Choose config | 526 // Choose config |
506 EGLConfig config; | |
507 bool foundConfig = false; | 527 bool foundConfig = false; |
508 if (msaaSampleCount) { | 528 if (msaaSampleCount) { |
509 static const int kConfigAttribListCnt = | 529 static const int kConfigAttribListCnt = |
510 SK_ARRAY_COUNT(configAttribList); | 530 SK_ARRAY_COUNT(configAttribList); |
511 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; | 531 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; |
512 memcpy(msaaConfigAttribList, | 532 memcpy(msaaConfigAttribList, |
513 configAttribList, | 533 configAttribList, |
514 sizeof(configAttribList)); | 534 sizeof(configAttribList)); |
515 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); | 535 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); |
516 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; | 536 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; |
517 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; | 537 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; |
518 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; | 538 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; |
519 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; | 539 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; |
520 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; | 540 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; |
521 if (eglChooseConfig(display, configAttribList, | 541 if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs
)) { |
522 &config, 1, &numConfigs)) { | |
523 SkASSERT(numConfigs > 0); | 542 SkASSERT(numConfigs > 0); |
524 foundConfig = true; | 543 foundConfig = true; |
525 } | 544 } |
526 } | 545 } |
527 if (!foundConfig) { | 546 if (!foundConfig) { |
528 if (!eglChooseConfig(display, configAttribList, | 547 if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfig
s)) { |
529 &config, 1, &numConfigs)) { | |
530 return false; | 548 return false; |
531 } | 549 } |
532 } | 550 } |
533 | 551 |
534 // Create a surface | 552 // Create a surface |
535 EGLSurface surface = eglCreateWindowSurface(display, config, | 553 EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, |
536 (EGLNativeWindowType)hWnd, | 554 (EGLNativeWindowType)hWnd, |
537 surfaceAttribList); | 555 surfaceAttribList); |
538 if (surface == EGL_NO_SURFACE) { | 556 if (surface == EGL_NO_SURFACE) { |
539 return false; | 557 return false; |
540 } | 558 } |
541 | 559 |
542 // Create a GL context | 560 // Create a GL context |
543 EGLContext context = eglCreateContext(display, config, | 561 EGLContext context = eglCreateContext(display, *eglConfig, |
544 EGL_NO_CONTEXT, | 562 EGL_NO_CONTEXT, |
545 contextAttribs ); | 563 contextAttribs ); |
546 if (context == EGL_NO_CONTEXT ) { | 564 if (context == EGL_NO_CONTEXT ) { |
547 return false; | 565 return false; |
548 } | 566 } |
549 | 567 |
550 // Make the context current | 568 // Make the context current |
551 if (!eglMakeCurrent(display, surface, surface, context)) { | 569 if (!eglMakeCurrent(display, surface, surface, context)) { |
552 return false; | 570 return false; |
553 } | 571 } |
554 | 572 |
555 *eglDisplay = display; | 573 *eglDisplay = display; |
556 *eglContext = context; | 574 *eglContext = context; |
557 *eglSurface = surface; | 575 *eglSurface = surface; |
558 return true; | 576 return true; |
559 } | 577 } |
560 | 578 |
561 bool SkOSWindow::attachANGLE(int msaaSampleCount) { | 579 bool SkOSWindow::attachANGLE(int msaaSampleCount, AttachmentInfo* info) { |
562 if (EGL_NO_DISPLAY == fDisplay) { | 580 if (EGL_NO_DISPLAY == fDisplay) { |
563 bool bResult = create_ANGLE((HWND)fHWND, | 581 bool bResult = create_ANGLE((HWND)fHWND, |
564 msaaSampleCount, | 582 msaaSampleCount, |
565 &fDisplay, | 583 &fDisplay, |
566 &fContext, | 584 &fContext, |
567 &fSurface); | 585 &fSurface, |
| 586 &fConfig); |
568 if (false == bResult) { | 587 if (false == bResult) { |
569 return false; | 588 return false; |
570 } | 589 } |
571 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 590 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
572 | 591 |
573 if (intf) { | 592 if (intf) { |
574 ANGLE_GL_CALL(intf, ClearStencil(0)); | 593 ANGLE_GL_CALL(intf, ClearStencil(0)); |
575 ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); | 594 ANGLE_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
576 ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); | 595 ANGLE_GL_CALL(intf, StencilMask(0xffffffff)); |
577 ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT
)); | 596 ANGLE_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_BUFFER_BIT
)); |
578 } | 597 } |
579 } | 598 } |
580 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 599 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
| 600 eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilB
its); |
| 601 eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); |
| 602 |
581 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 603 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
582 | 604 |
583 if (intf ) { | 605 if (intf ) { |
584 ANGLE_GL_CALL(intf, Viewport(0, 0, SkScalarRound(this->width()), | 606 ANGLE_GL_CALL(intf, Viewport(0, 0, SkScalarRound(this->width()), |
585 SkScalarRound(this->height()))); | 607 SkScalarRound(this->height()))); |
586 } | 608 } |
587 return true; | 609 return true; |
588 } | 610 } |
589 return false; | 611 return false; |
590 } | 612 } |
(...skipping 17 matching lines...) Expand all Loading... |
608 if (intf) { | 630 if (intf) { |
609 ANGLE_GL_CALL(intf, Flush()); | 631 ANGLE_GL_CALL(intf, Flush()); |
610 } | 632 } |
611 | 633 |
612 eglSwapBuffers(fDisplay, fSurface); | 634 eglSwapBuffers(fDisplay, fSurface); |
613 } | 635 } |
614 #endif // SK_ANGLE | 636 #endif // SK_ANGLE |
615 #endif // SK_SUPPORT_GPU | 637 #endif // SK_SUPPORT_GPU |
616 | 638 |
617 // return true on success | 639 // return true on success |
618 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount) { | 640 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { |
619 | 641 |
620 // attach doubles as "windowResize" so we need to allo | 642 // attach doubles as "windowResize" so we need to allo |
621 // already bound states to pass through again | 643 // already bound states to pass through again |
622 // TODO: split out the resize functionality | 644 // TODO: split out the resize functionality |
623 // SkASSERT(kNone_BackEndType == fAttached); | 645 // SkASSERT(kNone_BackEndType == fAttached); |
624 bool result = true; | 646 bool result = true; |
625 | 647 |
626 switch (attachType) { | 648 switch (attachType) { |
627 case kNone_BackEndType: | 649 case kNone_BackEndType: |
628 // nothing to do | 650 // nothing to do |
629 break; | 651 break; |
630 #if SK_SUPPORT_GPU | 652 #if SK_SUPPORT_GPU |
631 case kNativeGL_BackEndType: | 653 case kNativeGL_BackEndType: |
632 result = attachGL(msaaSampleCount); | 654 result = attachGL(msaaSampleCount, info); |
633 break; | 655 break; |
634 #if SK_ANGLE | 656 #if SK_ANGLE |
635 case kANGLE_BackEndType: | 657 case kANGLE_BackEndType: |
636 result = attachANGLE(msaaSampleCount); | 658 result = attachANGLE(msaaSampleCount, info); |
637 break; | 659 break; |
638 #endif // SK_ANGLE | 660 #endif // SK_ANGLE |
639 #endif // SK_SUPPORT_GPU | 661 #endif // SK_SUPPORT_GPU |
640 default: | 662 default: |
641 SkASSERT(false); | 663 SkASSERT(false); |
642 result = false; | 664 result = false; |
643 break; | 665 break; |
644 } | 666 } |
645 | 667 |
646 if (result) { | 668 if (result) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 break; | 709 break; |
688 #endif // SK_ANGLE | 710 #endif // SK_ANGLE |
689 #endif // SK_SUPPORT_GPU | 711 #endif // SK_SUPPORT_GPU |
690 default: | 712 default: |
691 SkASSERT(false); | 713 SkASSERT(false); |
692 break; | 714 break; |
693 } | 715 } |
694 } | 716 } |
695 | 717 |
696 #endif | 718 #endif |
OLD | NEW |