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