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 |
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 |
| 66 #if SK_COMMAND_BUFFER |
| 67 fCommandBuffer = nullptr; |
| 68 #endif // SK_COMMAND_BUFFER |
| 69 |
56 fHGLRC = NULL; | 70 fHGLRC = NULL; |
57 #endif | 71 #endif |
58 fAttached = kNone_BackEndType; | 72 fAttached = kNone_BackEndType; |
59 fFullscreen = false; | 73 fFullscreen = false; |
60 } | 74 } |
61 | 75 |
62 SkOSWindow::~SkOSWindow() { | 76 SkOSWindow::~SkOSWindow() { |
63 #if SK_SUPPORT_GPU | 77 #if SK_SUPPORT_GPU |
64 if (fHGLRC) { | 78 if (fHGLRC) { |
65 wglDeleteContext((HGLRC)fHGLRC); | 79 wglDeleteContext((HGLRC)fHGLRC); |
66 } | 80 } |
67 #if SK_ANGLE | 81 #if SK_ANGLE |
68 if (EGL_NO_CONTEXT != fContext) { | 82 if (EGL_NO_CONTEXT != fContext) { |
69 eglDestroyContext(fDisplay, fContext); | 83 eglDestroyContext(fDisplay, fContext); |
70 fContext = EGL_NO_CONTEXT; | 84 fContext = EGL_NO_CONTEXT; |
71 } | 85 } |
72 | 86 |
73 if (EGL_NO_SURFACE != fSurface) { | 87 if (EGL_NO_SURFACE != fSurface) { |
74 eglDestroySurface(fDisplay, fSurface); | 88 eglDestroySurface(fDisplay, fSurface); |
75 fSurface = EGL_NO_SURFACE; | 89 fSurface = EGL_NO_SURFACE; |
76 } | 90 } |
77 | 91 |
78 if (EGL_NO_DISPLAY != fDisplay) { | 92 if (EGL_NO_DISPLAY != fDisplay) { |
79 eglTerminate(fDisplay); | 93 eglTerminate(fDisplay); |
80 fDisplay = EGL_NO_DISPLAY; | 94 fDisplay = EGL_NO_DISPLAY; |
81 } | 95 } |
82 #endif // SK_ANGLE | 96 #endif // SK_ANGLE |
| 97 #if SK_COMMAND_BUFFER |
| 98 delete fCommandBuffer; |
| 99 #endif // SK_COMMAND_BUFFER |
| 100 |
83 #endif // SK_SUPPORT_GPU | 101 #endif // SK_SUPPORT_GPU |
84 this->closeWindow(); | 102 this->closeWindow(); |
85 } | 103 } |
86 | 104 |
87 static SkKey winToskKey(WPARAM vk) { | 105 static SkKey winToskKey(WPARAM vk) { |
88 static const struct { | 106 static const struct { |
89 WPARAM fVK; | 107 WPARAM fVK; |
90 SkKey fKey; | 108 SkKey fKey; |
91 } gPair[] = { | 109 } gPair[] = { |
92 { VK_BACK, kBack_SkKey }, | 110 { VK_BACK, kBack_SkKey }, |
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
523 void SkOSWindow::presentANGLE() { | 541 void SkOSWindow::presentANGLE() { |
524 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); | 542 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateANGLEInterface()); |
525 | 543 |
526 if (intf) { | 544 if (intf) { |
527 ANGLE_GL_CALL(intf, Flush()); | 545 ANGLE_GL_CALL(intf, Flush()); |
528 } | 546 } |
529 | 547 |
530 eglSwapBuffers(fDisplay, fSurface); | 548 eglSwapBuffers(fDisplay, fSurface); |
531 } | 549 } |
532 #endif // SK_ANGLE | 550 #endif // SK_ANGLE |
| 551 |
| 552 #if SK_COMMAND_BUFFER |
| 553 |
| 554 bool SkOSWindow::attachCommandBuffer(int msaaSampleCount, AttachmentInfo* info)
{ |
| 555 if (!fCommandBuffer) { |
| 556 fCommandBuffer = SkCommandBufferGLContext::Create((HWND)fHWND, msaaSampl
eCount); |
| 557 if (!fCommandBuffer) |
| 558 return false; |
| 559 |
| 560 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface(
)); |
| 561 if (intf) { |
| 562 COMMAND_BUFFER_GL_CALL(intf, ClearStencil(0)); |
| 563 COMMAND_BUFFER_GL_CALL(intf, ClearColor(0, 0, 0, 0)); |
| 564 COMMAND_BUFFER_GL_CALL(intf, StencilMask(0xffffffff)); |
| 565 COMMAND_BUFFER_GL_CALL(intf, Clear(GL_STENCIL_BUFFER_BIT |GL_COLOR_B
UFFER_BIT)); |
| 566 } |
| 567 } |
| 568 |
| 569 if (fCommandBuffer->makeCurrent()) { |
| 570 info->fStencilBits = fCommandBuffer->getStencilBits(); |
| 571 info->fSampleCount = fCommandBuffer->getSampleCount(); |
| 572 |
| 573 SkAutoTUnref<const GrGLInterface> intf(GrGLCreateCommandBufferInterface(
)); |
| 574 |
| 575 if (intf ) { |
| 576 COMMAND_BUFFER_GL_CALL(intf, Viewport(0, 0, |
| 577 SkScalarRoundToInt(this->width()), |
| 578 SkScalarRoundToInt(this->height()))); |
| 579 } |
| 580 return true; |
| 581 } |
| 582 return false; |
| 583 } |
| 584 |
| 585 void SkOSWindow::detachCommandBuffer() { |
| 586 delete fCommandBuffer; |
| 587 fCommandBuffer = nullptr; |
| 588 } |
| 589 |
| 590 void SkOSWindow::presentCommandBuffer() { |
| 591 fCommandBuffer->presentCommandBuffer(); |
| 592 } |
| 593 #endif // SK_COMMAND_BUFFER |
| 594 |
533 #endif // SK_SUPPORT_GPU | 595 #endif // SK_SUPPORT_GPU |
534 | 596 |
535 // return true on success | 597 // return true on success |
536 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { | 598 bool SkOSWindow::attach(SkBackEndTypes attachType, int msaaSampleCount, Attachme
ntInfo* info) { |
537 | 599 |
538 // attach doubles as "windowResize" so we need to allo | 600 // attach doubles as "windowResize" so we need to allo |
539 // already bound states to pass through again | 601 // already bound states to pass through again |
540 // TODO: split out the resize functionality | 602 // TODO: split out the resize functionality |
541 // SkASSERT(kNone_BackEndType == fAttached); | 603 // SkASSERT(kNone_BackEndType == fAttached); |
542 bool result = true; | 604 bool result = true; |
543 | 605 |
544 switch (attachType) { | 606 switch (attachType) { |
545 case kNone_BackEndType: | 607 case kNone_BackEndType: |
546 // nothing to do | 608 // nothing to do |
547 break; | 609 break; |
548 #if SK_SUPPORT_GPU | 610 #if SK_SUPPORT_GPU |
549 case kNativeGL_BackEndType: | 611 case kNativeGL_BackEndType: |
550 result = attachGL(msaaSampleCount, info); | 612 result = attachGL(msaaSampleCount, info); |
551 break; | 613 break; |
552 #if SK_ANGLE | 614 #if SK_ANGLE |
553 case kANGLE_BackEndType: | 615 case kANGLE_BackEndType: |
554 result = attachANGLE(msaaSampleCount, info); | 616 result = attachANGLE(msaaSampleCount, info); |
555 break; | 617 break; |
556 #endif // SK_ANGLE | 618 #endif // SK_ANGLE |
| 619 #if SK_COMMAND_BUFFER |
| 620 case kCommandBuffer_BackEndType: |
| 621 result = attachCommandBuffer(msaaSampleCount, info); |
| 622 break; |
| 623 #endif // SK_COMMAND_BUFFER |
557 #endif // SK_SUPPORT_GPU | 624 #endif // SK_SUPPORT_GPU |
558 default: | 625 default: |
559 SkASSERT(false); | 626 SkASSERT(false); |
560 result = false; | 627 result = false; |
561 break; | 628 break; |
562 } | 629 } |
563 | 630 |
564 if (result) { | 631 if (result) { |
565 fAttached = attachType; | 632 fAttached = attachType; |
566 } | 633 } |
567 | 634 |
568 return result; | 635 return result; |
569 } | 636 } |
570 | 637 |
571 void SkOSWindow::detach() { | 638 void SkOSWindow::detach() { |
572 switch (fAttached) { | 639 switch (fAttached) { |
573 case kNone_BackEndType: | 640 case kNone_BackEndType: |
574 // nothing to do | 641 // nothing to do |
575 break; | 642 break; |
576 #if SK_SUPPORT_GPU | 643 #if SK_SUPPORT_GPU |
577 case kNativeGL_BackEndType: | 644 case kNativeGL_BackEndType: |
578 detachGL(); | 645 detachGL(); |
579 break; | 646 break; |
580 #if SK_ANGLE | 647 #if SK_ANGLE |
581 case kANGLE_BackEndType: | 648 case kANGLE_BackEndType: |
582 detachANGLE(); | 649 detachANGLE(); |
583 break; | 650 break; |
584 #endif // SK_ANGLE | 651 #endif // SK_ANGLE |
| 652 #if SK_COMMAND_BUFFER |
| 653 case kCommandBuffer_BackEndType: |
| 654 detachCommandBuffer(); |
| 655 break; |
| 656 #endif // SK_COMMAND_BUFFER |
585 #endif // SK_SUPPORT_GPU | 657 #endif // SK_SUPPORT_GPU |
586 default: | 658 default: |
587 SkASSERT(false); | 659 SkASSERT(false); |
588 break; | 660 break; |
589 } | 661 } |
590 fAttached = kNone_BackEndType; | 662 fAttached = kNone_BackEndType; |
591 } | 663 } |
592 | 664 |
593 void SkOSWindow::present() { | 665 void SkOSWindow::present() { |
594 switch (fAttached) { | 666 switch (fAttached) { |
595 case kNone_BackEndType: | 667 case kNone_BackEndType: |
596 // nothing to do | 668 // nothing to do |
597 return; | 669 return; |
598 #if SK_SUPPORT_GPU | 670 #if SK_SUPPORT_GPU |
599 case kNativeGL_BackEndType: | 671 case kNativeGL_BackEndType: |
600 presentGL(); | 672 presentGL(); |
601 break; | 673 break; |
602 #if SK_ANGLE | 674 #if SK_ANGLE |
603 case kANGLE_BackEndType: | 675 case kANGLE_BackEndType: |
604 presentANGLE(); | 676 presentANGLE(); |
605 break; | 677 break; |
606 #endif // SK_ANGLE | 678 #endif // SK_ANGLE |
| 679 #if SK_COMMAND_BUFFER |
| 680 case kCommandBuffer_BackEndType: |
| 681 presentCommandBuffer(); |
| 682 break; |
| 683 #endif // SK_COMMAND_BUFFER |
607 #endif // SK_SUPPORT_GPU | 684 #endif // SK_SUPPORT_GPU |
608 default: | 685 default: |
609 SkASSERT(false); | 686 SkASSERT(false); |
610 break; | 687 break; |
611 } | 688 } |
612 } | 689 } |
613 | 690 |
614 bool SkOSWindow::makeFullscreen() { | 691 bool SkOSWindow::makeFullscreen() { |
615 if (fFullscreen) { | 692 if (fFullscreen) { |
616 return true; | 693 return true; |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
691 } | 768 } |
692 | 769 |
693 void SkOSWindow::closeWindow() { | 770 void SkOSWindow::closeWindow() { |
694 DestroyWindow((HWND)fHWND); | 771 DestroyWindow((HWND)fHWND); |
695 if (fFullscreen) { | 772 if (fFullscreen) { |
696 DestroyWindow((HWND)fSavedWindowState.fHWND); | 773 DestroyWindow((HWND)fSavedWindowState.fHWND); |
697 } | 774 } |
698 gHwndToOSWindowMap.remove(fHWND); | 775 gHwndToOSWindowMap.remove(fHWND); |
699 } | 776 } |
700 #endif | 777 #endif |
OLD | NEW |