Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 render_widget_host_->SetView(this); | 590 render_widget_host_->SetView(this); |
| 591 | 591 |
| 592 // Let the page-level input event router know about our surface ID | 592 // Let the page-level input event router know about our surface ID |
| 593 // namespace for surface-based hit testing. | 593 // namespace for surface-based hit testing. |
| 594 if (render_widget_host_->delegate() && | 594 if (render_widget_host_->delegate() && |
| 595 render_widget_host_->delegate()->GetInputEventRouter()) { | 595 render_widget_host_->delegate()->GetInputEventRouter()) { |
| 596 render_widget_host_->delegate() | 596 render_widget_host_->delegate() |
| 597 ->GetInputEventRouter() | 597 ->GetInputEventRouter() |
| 598 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); | 598 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); |
| 599 } | 599 } |
| 600 | |
| 601 if (!render_widget_host_->is_hidden()) | |
| 602 EnsureBrowserCompositorView(); | |
| 600 } | 603 } |
| 601 | 604 |
| 602 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 605 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 603 display::Screen::GetScreen()->RemoveObserver(this); | 606 display::Screen::GetScreen()->RemoveObserver(this); |
| 604 | 607 |
| 605 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 608 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 606 // pointer. | 609 // pointer. |
| 607 cocoa_view_ = nil; | 610 cocoa_view_ = nil; |
| 608 | 611 |
| 609 UnlockMouse(); | 612 UnlockMouse(); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 633 } | 636 } |
| 634 | 637 |
| 635 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { | 638 cc::SurfaceId RenderWidgetHostViewMac::SurfaceIdForTesting() const { |
| 636 return delegated_frame_host_->SurfaceIdForTesting(); | 639 return delegated_frame_host_->SurfaceIdForTesting(); |
| 637 } | 640 } |
| 638 | 641 |
| 639 /////////////////////////////////////////////////////////////////////////////// | 642 /////////////////////////////////////////////////////////////////////////////// |
| 640 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 643 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 641 | 644 |
| 642 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { | 645 void RenderWidgetHostViewMac::EnsureBrowserCompositorView() { |
| 646 DCHECK(!render_widget_host_->is_hidden()); | |
| 643 TRACE_EVENT0("browser", | 647 TRACE_EVENT0("browser", |
| 644 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); | 648 "RenderWidgetHostViewMac::EnsureBrowserCompositorView"); |
| 645 | 649 |
| 646 // Create the view, to transition from Destroyed -> Suspended. | 650 // Create the view, to transition from Destroyed -> Suspended. |
| 647 if (browser_compositor_state_ == BrowserCompositorDestroyed) { | 651 if (browser_compositor_state_ == BrowserCompositorDestroyed) { |
| 648 browser_compositor_ = BrowserCompositorMac::Create(); | 652 browser_compositor_ = BrowserCompositorMac::Create(); |
| 649 browser_compositor_->compositor()->SetRootLayer(root_layer_.get()); | 653 browser_compositor_->compositor()->SetRootLayer(root_layer_.get()); |
| 650 browser_compositor_->compositor()->SetHostHasTransparentBackground( | 654 browser_compositor_->compositor()->SetHostHasTransparentBackground( |
| 651 !GetBackgroundOpaque()); | 655 !GetBackgroundOpaque()); |
| 652 browser_compositor_->accelerated_widget_mac()->SetNSView(this); | 656 browser_compositor_->accelerated_widget_mac()->SetNSView(this); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 709 | 713 |
| 710 // If this view is in a window that is visible, keep around the suspended | 714 // If this view is in a window that is visible, keep around the suspended |
| 711 // BrowserCompositorView in case |cocoa_view_| is suddenly revealed (so that | 715 // BrowserCompositorView in case |cocoa_view_| is suddenly revealed (so that |
| 712 // we don't flash white). | 716 // we don't flash white). |
| 713 NSWindow* window = [cocoa_view_ window]; | 717 NSWindow* window = [cocoa_view_ window]; |
| 714 if (window) | 718 if (window) |
| 715 return; | 719 return; |
| 716 | 720 |
| 717 // This should only be reached if |render_widget_host_| is hidden, destroyed, | 721 // This should only be reached if |render_widget_host_| is hidden, destroyed, |
| 718 // or in the process of being destroyed. | 722 // or in the process of being destroyed. |
| 723 DCHECK(!render_widget_host_ || render_widget_host_->is_hidden()); | |
| 719 DestroyBrowserCompositorView(); | 724 DestroyBrowserCompositorView(); |
| 720 } | 725 } |
| 721 | 726 |
| 722 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { | 727 bool RenderWidgetHostViewMac::OnMessageReceived(const IPC::Message& message) { |
| 723 bool handled = true; | 728 bool handled = true; |
| 724 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) | 729 IPC_BEGIN_MESSAGE_MAP(RenderWidgetHostViewMac, message) |
| 725 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, | 730 IPC_MESSAGE_HANDLER(ViewMsg_GetRenderedTextCompleted, |
| 726 OnGetRenderedTextCompleted) | 731 OnGetRenderedTextCompleted) |
| 727 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, | 732 IPC_MESSAGE_HANDLER(ViewHostMsg_SetNeedsBeginFrames, |
| 728 OnSetNeedsBeginFrames) | 733 OnSetNeedsBeginFrames) |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 880 render_widget_host_->NotifyScreenInfoChanged(); | 885 render_widget_host_->NotifyScreenInfoChanged(); |
| 881 } | 886 } |
| 882 | 887 |
| 883 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 888 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
| 884 return render_widget_host_; | 889 return render_widget_host_; |
| 885 } | 890 } |
| 886 | 891 |
| 887 void RenderWidgetHostViewMac::Show() { | 892 void RenderWidgetHostViewMac::Show() { |
| 888 ScopedCAActionDisabler disabler; | 893 ScopedCAActionDisabler disabler; |
| 889 [cocoa_view_ setHidden:NO]; | 894 [cocoa_view_ setHidden:NO]; |
| 890 if (!render_widget_host_->is_hidden()) | 895 if (!render_widget_host_->is_hidden()) { |
| 896 DCHECK_EQ(browser_compositor_state_, BrowserCompositorActive); | |
| 891 return; | 897 return; |
| 898 } | |
| 899 | |
| 900 WasUnOccluded(); | |
| 892 | 901 |
| 893 // Re-create the browser compositor. If the DelegatedFrameHost has a cached | 902 // Re-create the browser compositor. If the DelegatedFrameHost has a cached |
| 894 // frame from the last time it was visible, then it will immediately be | 903 // frame from the last time it was visible, then it will immediately be |
| 895 // drawn. If not, then the compositor will remain locked until a new delegated | 904 // drawn. If not, then the compositor will remain locked until a new delegated |
| 896 // frame is swapped. | 905 // frame is swapped. |
| 897 EnsureBrowserCompositorView(); | 906 EnsureBrowserCompositorView(); |
| 898 | 907 |
| 899 WasUnOccluded(); | |
| 900 | |
| 901 // If there is not a frame being currently drawn, kick one, so that the below | 908 // If there is not a frame being currently drawn, kick one, so that the below |
| 902 // pause will have a frame to wait on. | 909 // pause will have a frame to wait on. |
| 903 render_widget_host_->ScheduleComposite(); | 910 render_widget_host_->ScheduleComposite(); |
| 904 PauseForPendingResizeOrRepaintsAndDraw(); | 911 PauseForPendingResizeOrRepaintsAndDraw(); |
| 905 } | 912 } |
| 906 | 913 |
| 907 void RenderWidgetHostViewMac::Hide() { | 914 void RenderWidgetHostViewMac::Hide() { |
| 908 ScopedCAActionDisabler disabler; | 915 ScopedCAActionDisabler disabler; |
| 909 [cocoa_view_ setHidden:YES]; | 916 [cocoa_view_ setHidden:YES]; |
| 910 if (!render_widget_host_->is_hidden()) { | 917 if (!render_widget_host_->is_hidden()) { |
| 911 // Note that the following call to WasHidden() can trigger thumbnail | 918 // Note that the following call to WasHidden() can trigger thumbnail |
| 912 // generation on behalf of the NTP, and that cannot succeed if the browser | 919 // generation on behalf of the NTP, and that cannot succeed if the browser |
| 913 // compositor view has been suspended. Therefore these two statements must | 920 // compositor view has been suspended. Therefore these two statements must |
| 914 // occur in this specific order. However, because thumbnail generation is | 921 // occur in this specific order. However, because thumbnail generation is |
| 915 // asychronous, that operation won't run before | 922 // asychronous, that operation won't run before |
| 916 // SuspendBrowserCompositorView() | 923 // SuspendBrowserCompositorView() |
| 917 // completes. As a result you won't get a thumbnail for the page unless you | 924 // completes. As a result you won't get a thumbnail for the page unless you |
| 918 // execute these two statements in this specific order. | 925 // execute these two statements in this specific order. |
| 919 render_widget_host_->WasHidden(); | 926 render_widget_host_->WasHidden(); |
| 927 // Re-check hidden flag, as the thumbnail generation could have called | |
|
enne (OOO)
2016/06/15 22:07:44
This was the cause of the white tabs. I added a b
| |
| 928 // WasUnOccluded and unhidden itself. | |
| 929 if (!render_widget_host_->is_hidden()) { | |
| 930 return; | |
| 931 } | |
| 920 SuspendBrowserCompositorView(); | 932 SuspendBrowserCompositorView(); |
| 921 } | 933 } |
| 922 DestroySuspendedBrowserCompositorViewIfNeeded(); | 934 DestroySuspendedBrowserCompositorViewIfNeeded(); |
| 923 } | 935 } |
| 924 | 936 |
| 925 void RenderWidgetHostViewMac::WasUnOccluded() { | 937 void RenderWidgetHostViewMac::WasUnOccluded() { |
| 926 if (!render_widget_host_->is_hidden()) | 938 if (!render_widget_host_->is_hidden()) |
| 927 return; | 939 return; |
| 928 | 940 |
| 929 ui::LatencyInfo renderer_latency_info; | 941 ui::LatencyInfo renderer_latency_info; |
| 930 renderer_latency_info.AddLatencyNumber( | 942 renderer_latency_info.AddLatencyNumber( |
| 931 ui::TAB_SHOW_COMPONENT, | 943 ui::TAB_SHOW_COMPONENT, |
| 932 render_widget_host_->GetLatencyComponentId(), | 944 render_widget_host_->GetLatencyComponentId(), |
| 933 0); | 945 0); |
| 934 render_widget_host_->WasShown(renderer_latency_info); | 946 render_widget_host_->WasShown(renderer_latency_info); |
| 947 EnsureBrowserCompositorView(); | |
| 935 } | 948 } |
| 936 | 949 |
| 937 void RenderWidgetHostViewMac::WasOccluded() { | 950 void RenderWidgetHostViewMac::WasOccluded() { |
| 938 if (render_widget_host_->is_hidden()) | 951 if (render_widget_host_->is_hidden()) |
| 939 return; | 952 return; |
| 940 | 953 |
| 941 // Ignore occlusion when in fullscreen low power mode, because the occlusion | 954 // Ignore occlusion when in fullscreen low power mode, because the occlusion |
| 942 // is likely coming from the fullscreen low power window. | 955 // is likely coming from the fullscreen low power window. |
| 943 if (browser_compositor_) { | 956 if (browser_compositor_) { |
| 944 if (browser_compositor_->accelerated_widget_mac() | 957 if (browser_compositor_->accelerated_widget_mac() |
| (...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1487 if (frame->delegated_frame_data) { | 1500 if (frame->delegated_frame_data) { |
| 1488 float scale_factor = frame->metadata.device_scale_factor; | 1501 float scale_factor = frame->metadata.device_scale_factor; |
| 1489 | 1502 |
| 1490 // Compute the frame size based on the root render pass rect size. | 1503 // Compute the frame size based on the root render pass rect size. |
| 1491 cc::RenderPass* root_pass = | 1504 cc::RenderPass* root_pass = |
| 1492 frame->delegated_frame_data->render_pass_list.back().get(); | 1505 frame->delegated_frame_data->render_pass_list.back().get(); |
| 1493 gfx::Size pixel_size = root_pass->output_rect.size(); | 1506 gfx::Size pixel_size = root_pass->output_rect.size(); |
| 1494 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); | 1507 gfx::Size dip_size = gfx::ConvertSizeToDIP(scale_factor, pixel_size); |
| 1495 | 1508 |
| 1496 root_layer_->SetBounds(gfx::Rect(dip_size)); | 1509 root_layer_->SetBounds(gfx::Rect(dip_size)); |
| 1497 if (!render_widget_host_->is_hidden()) { | 1510 if (browser_compositor_ && browser_compositor_->compositor()) { |
| 1498 EnsureBrowserCompositorView(); | |
| 1499 browser_compositor_->compositor()->SetScaleAndSize( | 1511 browser_compositor_->compositor()->SetScaleAndSize( |
| 1500 scale_factor, pixel_size); | 1512 scale_factor, pixel_size); |
| 1501 } | 1513 } |
| 1502 | 1514 |
| 1503 SendVSyncParametersToRenderer(); | 1515 SendVSyncParametersToRenderer(); |
| 1504 | 1516 |
| 1505 delegated_frame_host_->SwapDelegatedFrame(output_surface_id, | 1517 delegated_frame_host_->SwapDelegatedFrame(output_surface_id, |
| 1506 std::move(frame)); | 1518 std::move(frame)); |
| 1507 } else { | 1519 } else { |
| 1508 DLOG(ERROR) << "Received unexpected frame type."; | 1520 DLOG(ERROR) << "Received unexpected frame type."; |
| (...skipping 1933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3442 | 3454 |
| 3443 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3455 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3444 // regions that are not draggable. (See ControlRegionView in | 3456 // regions that are not draggable. (See ControlRegionView in |
| 3445 // native_app_window_cocoa.mm). This requires the render host view to be | 3457 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3446 // draggable by default. | 3458 // draggable by default. |
| 3447 - (BOOL)mouseDownCanMoveWindow { | 3459 - (BOOL)mouseDownCanMoveWindow { |
| 3448 return YES; | 3460 return YES; |
| 3449 } | 3461 } |
| 3450 | 3462 |
| 3451 @end | 3463 @end |
| OLD | NEW |