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 <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 ui::Layer* RenderWidgetHostViewMac::GetLayer() { | 414 ui::Layer* RenderWidgetHostViewMac::GetLayer() { |
415 return root_layer_.get(); | 415 return root_layer_.get(); |
416 } | 416 } |
417 | 417 |
418 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { | 418 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { |
419 return render_widget_host_; | 419 return render_widget_host_; |
420 } | 420 } |
421 | 421 |
422 void RenderWidgetHostViewMac::SchedulePaintInRect( | 422 void RenderWidgetHostViewMac::SchedulePaintInRect( |
423 const gfx::Rect& damage_rect_in_dip) { | 423 const gfx::Rect& damage_rect_in_dip) { |
424 if (browser_compositor_lock_) | 424 [browser_compositor_view_ compositor]->ScheduleFullRedraw(); |
425 browser_compositor_damaged_during_lock_ = true; | |
426 else | |
427 [browser_compositor_view_ compositor]->ScheduleFullRedraw(); | |
428 } | |
429 | |
430 void RenderWidgetHostViewMac::DelegatedCompositorDidSwapBuffers() { | |
431 // If this view is not visible then do not lock the compositor, because the | |
432 // wait for the surface to be drawn will time out. | |
433 NSWindow* window = [cocoa_view_ window]; | |
434 if (!window) | |
435 return; | |
436 if (window && [window respondsToSelector:@selector(occlusionState)]) { | |
437 bool window_is_occluded = | |
438 !([window occlusionState] & NSWindowOcclusionStateVisible); | |
439 if (window_is_occluded) | |
440 return; | |
441 } | |
442 browser_compositor_lock_ = | |
443 [browser_compositor_view_ compositor]->GetCompositorLock(); | |
444 } | |
445 | |
446 void RenderWidgetHostViewMac::DelegatedCompositorAbortedSwapBuffers() { | |
447 PostReleaseBrowserCompositorLock(); | |
448 } | 425 } |
449 | 426 |
450 bool RenderWidgetHostViewMac::IsVisible() { | 427 bool RenderWidgetHostViewMac::IsVisible() { |
451 return !render_widget_host_->is_hidden(); | 428 return !render_widget_host_->is_hidden(); |
452 } | 429 } |
453 | 430 |
454 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { | 431 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { |
455 return GetViewBounds().size(); | 432 return GetViewBounds().size(); |
456 } | 433 } |
457 | 434 |
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
793 CGDirectDisplayID display_id = [screen_number unsignedIntValue]; | 770 CGDirectDisplayID display_id = [screen_number unsignedIntValue]; |
794 | 771 |
795 display_link_ = DisplayLinkMac::GetForDisplay(display_id); | 772 display_link_ = DisplayLinkMac::GetForDisplay(display_id); |
796 if (!display_link_) { | 773 if (!display_link_) { |
797 // Note that on some headless systems, the display link will fail to be | 774 // Note that on some headless systems, the display link will fail to be |
798 // created, so this should not be a fatal error. | 775 // created, so this should not be a fatal error. |
799 LOG(ERROR) << "Failed to create display link."; | 776 LOG(ERROR) << "Failed to create display link."; |
800 } | 777 } |
801 } | 778 } |
802 | 779 |
803 void RenderWidgetHostViewMac::PostReleaseBrowserCompositorLock() { | |
804 base::MessageLoop::current()->PostTask(FROM_HERE, | |
805 base::Bind(&RenderWidgetHostViewMac::ReleaseBrowserCompositorLock, | |
806 weak_factory_.GetWeakPtr())); | |
807 } | |
808 | |
809 void RenderWidgetHostViewMac::ReleaseBrowserCompositorLock() { | |
810 if (!browser_compositor_view_) | |
811 return; | |
812 | |
813 browser_compositor_lock_ = NULL; | |
814 if (browser_compositor_damaged_during_lock_) { | |
815 browser_compositor_damaged_during_lock_ = false; | |
816 [browser_compositor_view_ compositor]->ScheduleFullRedraw(); | |
817 } | |
818 } | |
819 | |
820 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { | 780 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { |
821 if (!render_widget_host_ || !display_link_) | 781 if (!render_widget_host_ || !display_link_) |
822 return; | 782 return; |
823 | 783 |
824 base::TimeTicks timebase; | 784 base::TimeTicks timebase; |
825 base::TimeDelta interval; | 785 base::TimeDelta interval; |
826 if (!display_link_->GetVSyncParameters(&timebase, &interval)) | 786 if (!display_link_->GetVSyncParameters(&timebase, &interval)) |
827 return; | 787 return; |
828 | 788 |
829 render_widget_host_->UpdateVSyncParameters(timebase, interval); | 789 render_widget_host_->UpdateVSyncParameters(timebase, interval); |
(...skipping 30 matching lines...) Expand all Loading... |
860 PauseForPendingResizeOrRepaintsAndDraw(); | 820 PauseForPendingResizeOrRepaintsAndDraw(); |
861 } | 821 } |
862 | 822 |
863 void RenderWidgetHostViewMac::WasHidden() { | 823 void RenderWidgetHostViewMac::WasHidden() { |
864 if (render_widget_host_->is_hidden()) | 824 if (render_widget_host_->is_hidden()) |
865 return; | 825 return; |
866 | 826 |
867 // Any pending frames will not be displayed until this is shown again. Ack | 827 // Any pending frames will not be displayed until this is shown again. Ack |
868 // them now. | 828 // them now. |
869 SendPendingSwapAck(); | 829 SendPendingSwapAck(); |
870 PostReleaseBrowserCompositorLock(); | |
871 | 830 |
872 // If we have a renderer, then inform it that we are being hidden so it can | 831 // If we have a renderer, then inform it that we are being hidden so it can |
873 // reduce its resource utilization. | 832 // reduce its resource utilization. |
874 render_widget_host_->WasHidden(); | 833 render_widget_host_->WasHidden(); |
875 software_frame_manager_->SetVisibility(false); | 834 software_frame_manager_->SetVisibility(false); |
876 if (delegated_frame_host_) | 835 if (delegated_frame_host_) |
877 delegated_frame_host_->WasHidden(); | 836 delegated_frame_host_->WasHidden(); |
878 } | 837 } |
879 | 838 |
880 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { | 839 void RenderWidgetHostViewMac::SetSize(const gfx::Size& size) { |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1073 fullscreen_window_manager_.reset(); | 1032 fullscreen_window_manager_.reset(); |
1074 [pepper_fullscreen_window_ close]; | 1033 [pepper_fullscreen_window_ close]; |
1075 | 1034 |
1076 // This can be called as part of processing the window's responder | 1035 // This can be called as part of processing the window's responder |
1077 // chain, for instance |-performKeyEquivalent:|. In that case the | 1036 // chain, for instance |-performKeyEquivalent:|. In that case the |
1078 // object needs to survive until the stack unwinds. | 1037 // object needs to survive until the stack unwinds. |
1079 pepper_fullscreen_window_.autorelease(); | 1038 pepper_fullscreen_window_.autorelease(); |
1080 | 1039 |
1081 // Delete the delegated frame state, which will reach back into | 1040 // Delete the delegated frame state, which will reach back into |
1082 // render_widget_host_. | 1041 // render_widget_host_. |
1083 browser_compositor_lock_ = NULL; | |
1084 [browser_compositor_view_ resetClient]; | 1042 [browser_compositor_view_ resetClient]; |
1085 delegated_frame_host_.reset(); | 1043 delegated_frame_host_.reset(); |
1086 root_layer_.reset(); | 1044 root_layer_.reset(); |
1087 | 1045 |
1088 // We get this call just before |render_widget_host_| deletes | 1046 // We get this call just before |render_widget_host_| deletes |
1089 // itself. But we are owned by |cocoa_view_|, which may be retained | 1047 // itself. But we are owned by |cocoa_view_|, which may be retained |
1090 // by some other code. Examples are WebContentsViewMac's | 1048 // by some other code. Examples are WebContentsViewMac's |
1091 // |latent_focus_view_| and TabWindowController's | 1049 // |latent_focus_view_| and TabWindowController's |
1092 // |cachedContentView_|. | 1050 // |cachedContentView_|. |
1093 render_widget_host_ = NULL; | 1051 render_widget_host_ = NULL; |
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1776 } | 1734 } |
1777 return false; | 1735 return false; |
1778 } | 1736 } |
1779 | 1737 |
1780 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1738 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
1781 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1739 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
1782 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); | 1740 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); |
1783 | 1741 |
1784 if (frame->delegated_frame_data) { | 1742 if (frame->delegated_frame_data) { |
1785 if (!browser_compositor_view_) { | 1743 if (!browser_compositor_view_) { |
1786 browser_compositor_view_.reset([[BrowserCompositorViewMac alloc] | 1744 browser_compositor_view_.reset( |
1787 initWithSuperview:cocoa_view_ withClient:this]); | 1745 [[BrowserCompositorViewMac alloc] initWithSuperview:cocoa_view_]); |
1788 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | 1746 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
1789 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 1747 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
1790 [browser_compositor_view_ compositor]->SetRootLayer(root_layer_.get()); | 1748 [browser_compositor_view_ compositor]->SetRootLayer(root_layer_.get()); |
1791 } | 1749 } |
1792 | 1750 |
1793 float scale_factor = frame->metadata.device_scale_factor; | 1751 float scale_factor = frame->metadata.device_scale_factor; |
1794 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size); | 1752 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size); |
1795 gfx::Size pixel_size = ConvertSizeToPixel( | 1753 gfx::Size pixel_size = ConvertSizeToPixel( |
1796 scale_factor, dip_size); | 1754 scale_factor, dip_size); |
1797 [browser_compositor_view_ compositor]->SetScaleAndSize( | 1755 [browser_compositor_view_ compositor]->SetScaleAndSize( |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2306 [software_layer_ setFrame:new_background_frame]; | 2264 [software_layer_ setFrame:new_background_frame]; |
2307 } | 2265 } |
2308 } | 2266 } |
2309 } | 2267 } |
2310 | 2268 |
2311 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { | 2269 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { |
2312 return SkBitmap::kARGB_8888_Config; | 2270 return SkBitmap::kARGB_8888_Config; |
2313 } | 2271 } |
2314 | 2272 |
2315 //////////////////////////////////////////////////////////////////////////////// | 2273 //////////////////////////////////////////////////////////////////////////////// |
2316 // BrowserCompositorViewMacClient, public: | |
2317 | |
2318 void RenderWidgetHostViewMac::BrowserCompositorDidDrawFrame() { | |
2319 PostReleaseBrowserCompositorLock(); | |
2320 } | |
2321 | |
2322 //////////////////////////////////////////////////////////////////////////////// | |
2323 // CompositingIOSurfaceLayerClient, public: | 2274 // CompositingIOSurfaceLayerClient, public: |
2324 | 2275 |
2325 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { | 2276 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { |
2326 SendPendingLatencyInfoToHost(); | 2277 SendPendingLatencyInfoToHost(); |
2327 SendPendingSwapAck(); | 2278 SendPendingSwapAck(); |
2328 if (!succeeded) | 2279 if (!succeeded) |
2329 GotAcceleratedCompositingError(); | 2280 GotAcceleratedCompositingError(); |
2330 } | 2281 } |
2331 | 2282 |
2332 } // namespace content | 2283 } // namespace content |
(...skipping 1687 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4020 | 3971 |
4021 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3972 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
4022 // regions that are not draggable. (See ControlRegionView in | 3973 // regions that are not draggable. (See ControlRegionView in |
4023 // native_app_window_cocoa.mm). This requires the render host view to be | 3974 // native_app_window_cocoa.mm). This requires the render host view to be |
4024 // draggable by default. | 3975 // draggable by default. |
4025 - (BOOL)mouseDownCanMoveWindow { | 3976 - (BOOL)mouseDownCanMoveWindow { |
4026 return YES; | 3977 return YES; |
4027 } | 3978 } |
4028 | 3979 |
4029 @end | 3980 @end |
OLD | NEW |