Chromium Code Reviews| 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 12 matching lines...) Expand all Loading... | |
| 23 #if SK_ANGLE | 23 #if SK_ANGLE |
| 24 #include "gl/angle/SkANGLEGLContext.h" | 24 #include "gl/angle/SkANGLEGLContext.h" |
| 25 #include "gl/GrGLInterface.h" | 25 #include "gl/GrGLInterface.h" |
| 26 #include "GLES2/gl2.h" | 26 #include "GLES2/gl2.h" |
| 27 | 27 |
| 28 #define ANGLE_GL_CALL(IFACE, X) \ | 28 #define ANGLE_GL_CALL(IFACE, X) \ |
| 29 do { \ | 29 do { \ |
| 30 (IFACE)->fFunctions.f##X; \ | 30 (IFACE)->fFunctions.f##X; \ |
| 31 } while (false) | 31 } while (false) |
| 32 | 32 |
| 33 #endif | 33 #endif // SK_ANGLE |
| 34 | |
| 35 #if SK_COMMAND_BUFFER | |
| 36 #include "gl/command_buffer/SkCommandBufferGLContext.h" | |
| 37 | |
| 38 #define COMMAND_BUFFER_GL_CALL(IFACE, X) \ | |
| 39 do { \ | |
| 40 (IFACE)->fFunctions.f##X; \ | |
| 41 } while (false) | |
| 42 | |
| 43 #endif // SK_COMMAND_BUFFER | |
| 34 | 44 |
| 35 #define WM_EVENT_CALLBACK (WM_USER+0) | 45 #define WM_EVENT_CALLBACK (WM_USER+0) |
| 36 | 46 |
| 37 void post_skwinevent(HWND hwnd) | 47 void post_skwinevent(HWND hwnd) |
| 38 { | 48 { |
| 39 PostMessage(hwnd, WM_EVENT_CALLBACK, 0, 0); | 49 PostMessage(hwnd, WM_EVENT_CALLBACK, 0, 0); |
| 40 } | 50 } |
| 41 | 51 |
| 42 SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap; | 52 SkTHashMap<void*, SkOSWindow*> SkOSWindow::gHwndToOSWindowMap; |
| 43 | 53 |
| 44 SkOSWindow::SkOSWindow(const void* winInit) { | 54 SkOSWindow::SkOSWindow(const void* winInit) { |
| 45 fWinInit = *(const WindowInit*)winInit; | 55 fWinInit = *(const WindowInit*)winInit; |
| 46 | 56 |
| 47 fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW, | 57 fHWND = CreateWindow(fWinInit.fClass, NULL, WS_OVERLAPPEDWINDOW, |
| 48 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, fWinIni t.fInstance, NULL); | 58 CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, fWinIni t.fInstance, NULL); |
| 49 gHwndToOSWindowMap.set(fHWND, this); | 59 gHwndToOSWindowMap.set(fHWND, this); |
| 50 #if SK_SUPPORT_GPU | 60 #if SK_SUPPORT_GPU |
| 51 #if SK_ANGLE | 61 #if SK_ANGLE || SK_COMMAND_BUFFER |
| 52 fDisplay = EGL_NO_DISPLAY; | 62 fDisplay = EGL_NO_DISPLAY; |
| 53 fContext = EGL_NO_CONTEXT; | 63 fContext = EGL_NO_CONTEXT; |
| 54 fSurface = EGL_NO_SURFACE; | 64 fSurface = EGL_NO_SURFACE; |
| 55 #endif | 65 #endif |
| 56 fHGLRC = NULL; | 66 fHGLRC = NULL; |
| 57 #endif | 67 #endif |
| 58 fAttached = kNone_BackEndType; | 68 fAttached = kNone_BackEndType; |
| 59 fFullscreen = false; | 69 fFullscreen = false; |
| 60 } | 70 } |
| 61 | 71 |
| 62 SkOSWindow::~SkOSWindow() { | 72 SkOSWindow::~SkOSWindow() { |
| 63 #if SK_SUPPORT_GPU | 73 #if SK_SUPPORT_GPU |
| 64 if (fHGLRC) { | 74 if (fHGLRC) { |
| 65 wglDeleteContext((HGLRC)fHGLRC); | 75 wglDeleteContext((HGLRC)fHGLRC); |
| 66 } | 76 } |
| 67 #if SK_ANGLE | 77 #if SK_ANGLE || SK_COMMAND_BUFFER |
| 68 if (EGL_NO_CONTEXT != fContext) { | 78 if (EGL_NO_CONTEXT != fContext) { |
| 69 eglDestroyContext(fDisplay, fContext); | 79 eglDestroyContext(fDisplay, fContext); |
| 70 fContext = EGL_NO_CONTEXT; | 80 fContext = EGL_NO_CONTEXT; |
| 71 } | 81 } |
| 72 | 82 |
| 73 if (EGL_NO_SURFACE != fSurface) { | 83 if (EGL_NO_SURFACE != fSurface) { |
| 74 eglDestroySurface(fDisplay, fSurface); | 84 eglDestroySurface(fDisplay, fSurface); |
| 75 fSurface = EGL_NO_SURFACE; | 85 fSurface = EGL_NO_SURFACE; |
| 76 } | 86 } |
| 77 | 87 |
| 78 if (EGL_NO_DISPLAY != fDisplay) { | 88 if (EGL_NO_DISPLAY != fDisplay) { |
| 79 eglTerminate(fDisplay); | 89 eglTerminate(fDisplay); |
| 80 fDisplay = EGL_NO_DISPLAY; | 90 fDisplay = EGL_NO_DISPLAY; |
| 81 } | 91 } |
| 82 #endif // SK_ANGLE | 92 #endif // SK_ANGLE || SK_COMMAND_BUFFER |
| 83 #endif // SK_SUPPORT_GPU | 93 #endif // SK_SUPPORT_GPU |
| 84 this->closeWindow(); | 94 this->closeWindow(); |
| 85 } | 95 } |
| 86 | 96 |
| 87 static SkKey winToskKey(WPARAM vk) { | 97 static SkKey winToskKey(WPARAM vk) { |
| 88 static const struct { | 98 static const struct { |
| 89 WPARAM fVK; | 99 WPARAM fVK; |
| 90 SkKey fKey; | 100 SkKey fKey; |
| 91 } gPair[] = { | 101 } gPair[] = { |
| 92 { VK_BACK, kBack_SkKey }, | 102 { VK_BACK, kBack_SkKey }, |
| (...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 void SkOSWindow::presentANGLE() { | 533 void SkOSWindow::presentANGLE() { |
| 524 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 534 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
| 525 | 535 |
| 526 if (intf) { | 536 if (intf) { |
| 527 ANGLE_GL_CALL(intf, Flush()); | 537 ANGLE_GL_CALL(intf, Flush()); |
| 528 } | 538 } |
| 529 | 539 |
| 530 eglSwapBuffers(fDisplay, fSurface); | 540 eglSwapBuffers(fDisplay, fSurface); |
| 531 } | 541 } |
| 532 #endif // SK_ANGLE | 542 #endif // SK_ANGLE |
| 543 | |
| 544 #if SK_COMMAND_BUFFER | |
| 545 | |
| 546 bool create_CommandBuffer(EGLNativeWindowType hWnd, | |
|
bsalomon
2015/08/26 18:19:55
Can a lot of this be shared with the ANGLE functio
hendrikw
2015/08/27 01:28:35
All this code is bogus, I'm replacing it with the
| |
| 547 int msaaSampleCount, | |
| 548 EGLDisplay* eglDisplay, | |
| 549 EGLContext* eglContext, | |
| 550 EGLSurface* eglSurface, | |
| 551 EGLConfig* eglConfig) { | |
| 552 static const EGLint contextAttribs[] = { | |
| 553 EGL_CONTEXT_CLIENT_VERSION, 2, | |
| 554 EGL_NONE, EGL_NONE | |
| 555 }; | |
| 556 static const EGLint configAttribList[] = { | |
| 557 EGL_RED_SIZE, 8, | |
| 558 EGL_GREEN_SIZE, 8, | |
| 559 EGL_BLUE_SIZE, 8, | |
| 560 EGL_ALPHA_SIZE, 8, | |
| 561 EGL_DEPTH_SIZE, 8, | |
| 562 EGL_STENCIL_SIZE, 8, | |
| 563 EGL_NONE | |
| 564 }; | |
| 565 static const EGLint surfaceAttribList[] = { | |
| 566 EGL_NONE, EGL_NONE | |
| 567 }; | |
| 568 | |
| 569 EGLDisplay display = SkANGLEGLContext::GetD3DEGLDisplay(GetDC(hWnd)); | |
|
bsalomon
2015/08/26 18:19:55
Seems a bit weird to use angle here to get the dis
hendrikw
2015/08/27 01:28:35
All of this code is gone, yay.
| |
| 570 | |
| 571 if (EGL_NO_DISPLAY == display) { | |
| 572 SkDebugf("Could not create Command Buffer egl display!\n"); | |
| 573 return false; | |
| 574 } | |
| 575 | |
| 576 // Initialize EGL | |
| 577 EGLint majorVersion, minorVersion; | |
| 578 if (!eglInitialize(display, &majorVersion, &minorVersion)) { | |
| 579 return false; | |
| 580 } | |
| 581 | |
| 582 EGLint numConfigs; | |
| 583 if (!eglGetConfigs(display, NULL, 0, &numConfigs)) { | |
| 584 return false; | |
| 585 } | |
| 586 | |
| 587 // Choose config | |
| 588 bool foundConfig = false; | |
| 589 if (msaaSampleCount) { | |
| 590 static const int kConfigAttribListCnt = | |
| 591 SK_ARRAY_COUNT(configAttribList); | |
| 592 EGLint msaaConfigAttribList[kConfigAttribListCnt + 4]; | |
| 593 memcpy(msaaConfigAttribList, | |
| 594 configAttribList, | |
| 595 sizeof(configAttribList)); | |
| 596 SkASSERT(EGL_NONE == msaaConfigAttribList[kConfigAttribListCnt - 1]); | |
| 597 msaaConfigAttribList[kConfigAttribListCnt - 1] = EGL_SAMPLE_BUFFERS; | |
| 598 msaaConfigAttribList[kConfigAttribListCnt + 0] = 1; | |
| 599 msaaConfigAttribList[kConfigAttribListCnt + 1] = EGL_SAMPLES; | |
| 600 msaaConfigAttribList[kConfigAttribListCnt + 2] = msaaSampleCount; | |
| 601 msaaConfigAttribList[kConfigAttribListCnt + 3] = EGL_NONE; | |
| 602 if (eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfigs )) { | |
| 603 SkASSERT(numConfigs > 0); | |
| 604 foundConfig = true; | |
| 605 } | |
| 606 } | |
| 607 if (!foundConfig) { | |
| 608 if (!eglChooseConfig(display, configAttribList, eglConfig, 1, &numConfig s)) { | |
| 609 return false; | |
| 610 } | |
| 611 } | |
| 612 | |
| 613 // Create a surface | |
| 614 EGLSurface surface = eglCreateWindowSurface(display, *eglConfig, | |
| 615 (EGLNativeWindowType)hWnd, | |
| 616 surfaceAttribList); | |
| 617 if (surface == EGL_NO_SURFACE) { | |
| 618 return false; | |
| 619 } | |
| 620 | |
| 621 // Create a GL context | |
| 622 EGLContext context = eglCreateContext(display, *eglConfig, | |
| 623 EGL_NO_CONTEXT, | |
| 624 contextAttribs ); | |
| 625 if (context == EGL_NO_CONTEXT ) { | |
| 626 return false; | |
| 627 } | |
| 628 | |
| 629 // Make the context current | |
| 630 if (!eglMakeCurrent(display, surface, surface, context)) { | |
| 631 return false; | |
| 632 } | |
| 633 | |
| 634 *eglDisplay = display; | |
| 635 *eglContext = context; | |
| 636 *eglSurface = surface; | |
| 637 return true; | |
| 638 } | |
| 639 | |
| 640 bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info) { | |
| 641 if (EGL_NO_DISPLAY == fDisplay) { | |
| 642 bool bResult = create_CommandBuffer((HWND)fHWND, | |
| 643 msaaSampleCount, | |
| 644 &fDisplay, | |
| 645 &fContext, | |
| 646 &fSurface, | |
| 647 &fConfig); | |
| 648 if (false == bResult) { | |
| 649 return false; | |
| 650 } | |
| 651 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | |
| 652 | |
| 653 if (intf) { | |
| 654 COMMAND_BUFFER_GL_CALL(intf, ClearStencil(0)); | |
| 655 COMMAND_BUFFER_GL_CALL(intf, ClearColor(0, 0, 0, 0)); | |
| 656 COMMAND_BUFFER_GL_CALL(intf, StencilMask(0xffffffff)); | |
| 657 COMMAND_BUFFER_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_B UFFER_BIT)); | |
| 658 } | |
| 659 } | |
| 660 if (eglMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | |
| 661 eglGetConfigAttrib(fDisplay, fConfig, EGL_STENCIL_SIZE, &info->fStencilB its); | |
| 662 eglGetConfigAttrib(fDisplay, fConfig, EGL_SAMPLES, &info->fSampleCount); | |
| 663 | |
| 664 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | |
| 665 | |
| 666 if (intf ) { | |
| 667 COMMAND_BUFFER_GL_CALL(intf, Viewport(0, 0, | |
| 668 SkScalarRoundToInt(this->width()), | |
| 669 SkScalarRoundToInt(this->height()))); | |
| 670 } | |
| 671 return true; | |
| 672 } | |
| 673 return false; | |
| 674 } | |
| 675 | |
| 676 void SkOSWindow::detachCommandBuffer() { | |
| 677 eglMakeCurrent(fDisplay, EGL_NO_SURFACE , EGL_NO_SURFACE , EGL_NO_CONTEXT); | |
| 678 | |
| 679 eglDestroyContext(fDisplay, fContext); | |
| 680 fContext = EGL_NO_CONTEXT; | |
| 681 | |
| 682 eglDestroySurface(fDisplay, fSurface); | |
| 683 fSurface = EGL_NO_SURFACE; | |
| 684 | |
| 685 eglTerminate(fDisplay); | |
| 686 fDisplay = EGL_NO_DISPLAY; | |
| 687 } | |
| 688 | |
| 689 void SkOSWindow::presentCommandBuffer() { | |
| 690 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | |
| 691 | |
| 692 if (intf) { | |
| 693 COMMAND_BUFFER_GL_CALL(intf, Flush()); | |
| 694 } | |
| 695 | |
| 696 eglSwapBuffers(fDisplay, fSurface); | |
| 697 } | |
| 698 #endif // SK_COMMAND_BUFFER | |
| 699 | |
| 533 #endif // SK_SUPPORT_GPU | 700 #endif // SK_SUPPORT_GPU |
| 534 | 701 |
| 535 // return true on success | 702 // return true on success |
| 536 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme ntInfo* info) { | 703 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme ntInfo* info) { |
| 537 | 704 |
| 538 // attach doubles as "windowResize" so we need to allo | 705 // attach doubles as "windowResize" so we need to allo |
| 539 // already bound states to pass through again | 706 // already bound states to pass through again |
| 540 // TODO: split out the resize functionality | 707 // TODO: split out the resize functionality |
| 541 // SkASSERT(kNone_BackEndType == fAttached); | 708 // SkASSERT(kNone_BackEndType == fAttached); |
| 542 bool result = true; | 709 bool result = true; |
| 543 | 710 |
| 544 switch (attachType) { | 711 switch (attachType) { |
| 545 case kNone_BackEndType: | 712 case kNone_BackEndType: |
| 546 // nothing to do | 713 // nothing to do |
| 547 break; | 714 break; |
| 548 #if SK_SUPPORT_GPU | 715 #if SK_SUPPORT_GPU |
| 549 case kNativeGL_BackEndType: | 716 case kNativeGL_BackEndType: |
| 550 result = attachGL(msaaSampleCount, info); | 717 result = attachGL(msaaSampleCount, info); |
| 551 break; | 718 break; |
| 552 #if SK_ANGLE | 719 #if SK_ANGLE |
| 553 case kANGLE_BackEndType: | 720 case kANGLE_BackEndType: |
| 554 result = attachANGLE(msaaSampleCount, info); | 721 result = attachANGLE(msaaSampleCount, info); |
| 555 break; | 722 break; |
| 556 #endif // SK_ANGLE | 723 #endif // SK_ANGLE |
| 724 #if SK_COMMAND_BUFFER | |
| 725 case kCommandBuffer_BackEndType: | |
| 726 result = attachCommandBuffer(msaaSampleCount, info); | |
| 727 break; | |
| 728 #endif // SK_COMMAND_BUFFER | |
| 557 #endif // SK_SUPPORT_GPU | 729 #endif // SK_SUPPORT_GPU |
| 558 default: | 730 default: |
| 559 SkASSERT(false); | 731 SkASSERT(false); |
| 560 result = false; | 732 result = false; |
| 561 break; | 733 break; |
| 562 } | 734 } |
| 563 | 735 |
| 564 if (result) { | 736 if (result) { |
| 565 fAttached = attachType; | 737 fAttached = attachType; |
| 566 } | 738 } |
| 567 | 739 |
| 568 return result; | 740 return result; |
| 569 } | 741 } |
| 570 | 742 |
| 571 void SkOSWindow::detach() { | 743 void SkOSWindow::detach() { |
| 572 switch (fAttached) { | 744 switch (fAttached) { |
| 573 case kNone_BackEndType: | 745 case kNone_BackEndType: |
| 574 // nothing to do | 746 // nothing to do |
| 575 break; | 747 break; |
| 576 #if SK_SUPPORT_GPU | 748 #if SK_SUPPORT_GPU |
| 577 case kNativeGL_BackEndType: | 749 case kNativeGL_BackEndType: |
| 578 detachGL(); | 750 detachGL(); |
| 579 break; | 751 break; |
| 580 #if SK_ANGLE | 752 #if SK_ANGLE |
| 581 case kANGLE_BackEndType: | 753 case kANGLE_BackEndType: |
| 582 detachANGLE(); | 754 detachANGLE(); |
| 583 break; | 755 break; |
| 584 #endif // SK_ANGLE | 756 #endif // SK_ANGLE |
| 757 #if SK_COMMAND_BUFFER | |
| 758 case kCommandBuffer_BackEndType: | |
| 759 detachCommandBuffer(); | |
| 760 break; | |
| 761 #endif // SK_COMMAND_BUFFER | |
| 585 #endif // SK_SUPPORT_GPU | 762 #endif // SK_SUPPORT_GPU |
| 586 default: | 763 default: |
| 587 SkASSERT(false); | 764 SkASSERT(false); |
| 588 break; | 765 break; |
| 589 } | 766 } |
| 590 fAttached = kNone_BackEndType; | 767 fAttached = kNone_BackEndType; |
| 591 } | 768 } |
| 592 | 769 |
| 593 void SkOSWindow::present() { | 770 void SkOSWindow::present() { |
| 594 switch (fAttached) { | 771 switch (fAttached) { |
| 595 case kNone_BackEndType: | 772 case kNone_BackEndType: |
| 596 // nothing to do | 773 // nothing to do |
| 597 return; | 774 return; |
| 598 #if SK_SUPPORT_GPU | 775 #if SK_SUPPORT_GPU |
| 599 case kNativeGL_BackEndType: | 776 case kNativeGL_BackEndType: |
| 600 presentGL(); | 777 presentGL(); |
| 601 break; | 778 break; |
| 602 #if SK_ANGLE | 779 #if SK_ANGLE |
| 603 case kANGLE_BackEndType: | 780 case kANGLE_BackEndType: |
| 604 presentANGLE(); | 781 presentANGLE(); |
| 605 break; | 782 break; |
| 606 #endif // SK_ANGLE | 783 #endif // SK_ANGLE |
| 784 #if SK_COMMAND_BUFFER | |
| 785 case kCommandBuffer_BackEndType: | |
| 786 presentCommandBuffer(); | |
| 787 break; | |
| 788 #endif // SK_COMMAND_BUFFER | |
| 607 #endif // SK_SUPPORT_GPU | 789 #endif // SK_SUPPORT_GPU |
| 608 default: | 790 default: |
| 609 SkASSERT(false); | 791 SkASSERT(false); |
| 610 break; | 792 break; |
| 611 } | 793 } |
| 612 } | 794 } |
| 613 | 795 |
| 614 bool SkOSWindow::makeFullscreen() { | 796 bool SkOSWindow::makeFullscreen() { |
| 615 if (fFullscreen) { | 797 if (fFullscreen) { |
| 616 return true; | 798 return true; |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 691 } | 873 } |
| 692 | 874 |
| 693 void SkOSWindow::closeWindow() { | 875 void SkOSWindow::closeWindow() { |
| 694 DestroyWindow((HWND)fHWND); | 876 DestroyWindow((HWND)fHWND); |
| 695 if (fFullscreen) { | 877 if (fFullscreen) { |
| 696 DestroyWindow((HWND)fSavedWindowState.fHWND); | 878 DestroyWindow((HWND)fSavedWindowState.fHWND); |
| 697 } | 879 } |
| 698 gHwndToOSWindowMap.remove(fHWND); | 880 gHwndToOSWindowMap.remove(fHWND); |
| 699 } | 881 } |
| 700 #endif | 882 #endif |
| OLD | NEW |