Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(223)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 316103004: Mac ÜC: Enable GPU back-pressure from the browser to the renderer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@dip
Patch Set: Simplify Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/callback_helpers.h" 12 #include "base/callback_helpers.h"
13 #include "base/command_line.h" 13 #include "base/command_line.h"
14 #include "base/debug/crash_logging.h" 14 #include "base/debug/crash_logging.h"
15 #include "base/debug/trace_event.h" 15 #include "base/debug/trace_event.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/mac/mac_util.h" 17 #include "base/mac/mac_util.h"
18 #include "base/mac/scoped_cftyperef.h" 18 #include "base/mac/scoped_cftyperef.h"
19 #import "base/mac/scoped_nsobject.h" 19 #import "base/mac/scoped_nsobject.h"
20 #include "base/mac/sdk_forward_declarations.h" 20 #include "base/mac/sdk_forward_declarations.h"
21 #include "base/message_loop/message_loop.h" 21 #include "base/message_loop/message_loop.h"
22 #include "base/metrics/histogram.h" 22 #include "base/metrics/histogram.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/sys_string_conversions.h" 25 #include "base/strings/sys_string_conversions.h"
26 #include "base/strings/utf_string_conversions.h" 26 #include "base/strings/utf_string_conversions.h"
27 #include "base/sys_info.h" 27 #include "base/sys_info.h"
28 #import "content/browser/accessibility/browser_accessibility_cocoa.h" 28 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
29 #include "content/browser/accessibility/browser_accessibility_manager_mac.h" 29 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
30 #include "content/browser/compositor/browser_compositor_view_mac.h"
31 #include "content/browser/compositor/resize_lock.h" 30 #include "content/browser/compositor/resize_lock.h"
32 #include "content/browser/frame_host/frame_tree.h" 31 #include "content/browser/frame_host/frame_tree.h"
33 #include "content/browser/frame_host/frame_tree_node.h" 32 #include "content/browser/frame_host/frame_tree_node.h"
34 #include "content/browser/frame_host/render_frame_host_impl.h" 33 #include "content/browser/frame_host/render_frame_host_impl.h"
35 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" 34 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
36 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" 35 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h"
37 #include "content/browser/renderer_host/compositing_iosurface_mac.h" 36 #include "content/browser/renderer_host/compositing_iosurface_mac.h"
38 #include "content/browser/renderer_host/render_widget_helper.h" 37 #include "content/browser/renderer_host/render_widget_helper.h"
39 #include "content/browser/renderer_host/render_view_host_impl.h" 38 #include "content/browser/renderer_host/render_view_host_impl.h"
40 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h" 39 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h"
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 ui::Layer* RenderWidgetHostViewMac::GetLayer() { 416 ui::Layer* RenderWidgetHostViewMac::GetLayer() {
418 return root_layer_.get(); 417 return root_layer_.get();
419 } 418 }
420 419
421 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { 420 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() {
422 return render_widget_host_; 421 return render_widget_host_;
423 } 422 }
424 423
425 void RenderWidgetHostViewMac::SchedulePaintInRect( 424 void RenderWidgetHostViewMac::SchedulePaintInRect(
426 const gfx::Rect& damage_rect_in_dip) { 425 const gfx::Rect& damage_rect_in_dip) {
427 [browser_compositor_view_ compositor]->Draw(); 426 if (browser_compositor_lock_)
427 browser_compositor_damaged_during_lock_ = true;
428 else
429 [browser_compositor_view_ compositor]->ScheduleFullRedraw();
430 }
431
432 void RenderWidgetHostViewMac::DelegatedCompositorDidSwapBuffers() {
433 // If this view is not visible then do not lock the compositor, because the
434 // wait for the surface to be drawn will time out.
435 NSWindow* window = [cocoa_view_ window];
436 if (!window)
437 return;
438 if (window && [window respondsToSelector:@selector(occlusionState)]) {
439 bool window_is_occluded =
440 !([window occlusionState] & NSWindowOcclusionStateVisible);
441 if (window_is_occluded)
442 return;
443 }
444 browser_compositor_lock_ =
445 [browser_compositor_view_ compositor]->GetCompositorLock();
446 }
447
448 void RenderWidgetHostViewMac::DelegatedCompositorAbortedSwapBuffers() {
449 PostReleaseBrowserCompositorLock();
428 } 450 }
429 451
430 bool RenderWidgetHostViewMac::IsVisible() { 452 bool RenderWidgetHostViewMac::IsVisible() {
431 return !render_widget_host_->is_hidden(); 453 return !render_widget_host_->is_hidden();
432 } 454 }
433 455
434 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { 456 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() {
435 return GetViewBounds().size(); 457 return GetViewBounds().size();
436 } 458 }
437 459
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 } 524 }
503 525
504 render_widget_host_->SetView(this); 526 render_widget_host_->SetView(this);
505 } 527 }
506 528
507 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { 529 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() {
508 // This is being called from |cocoa_view_|'s destructor, so invalidate the 530 // This is being called from |cocoa_view_|'s destructor, so invalidate the
509 // pointer. 531 // pointer.
510 cocoa_view_ = nil; 532 cocoa_view_ = nil;
511 533
512 // Delete the delegated frame state.
513 delegated_frame_host_.reset();
514 root_layer_.reset();
515
516 UnlockMouse(); 534 UnlockMouse();
517 535
518 // Make sure that the layer doesn't reach into the now-invalid object. 536 // Make sure that the layer doesn't reach into the now-invalid object.
519 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); 537 DestroyCompositedIOSurfaceAndLayer(kDestroyContext);
520 DestroySoftwareLayer(); 538 DestroySoftwareLayer();
521 539
522 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the 540 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the
523 // RenderWidgetHost does we need to tell it not to hold a stale pointer to 541 // RenderWidgetHost does we need to tell it not to hold a stale pointer to
524 // us. 542 // us.
525 if (render_widget_host_) 543 if (render_widget_host_)
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 CGDirectDisplayID display_id = [screen_number unsignedIntValue]; 835 CGDirectDisplayID display_id = [screen_number unsignedIntValue];
818 836
819 display_link_ = DisplayLinkMac::GetForDisplay(display_id); 837 display_link_ = DisplayLinkMac::GetForDisplay(display_id);
820 if (!display_link_) { 838 if (!display_link_) {
821 // Note that on some headless systems, the display link will fail to be 839 // Note that on some headless systems, the display link will fail to be
822 // created, so this should not be a fatal error. 840 // created, so this should not be a fatal error.
823 LOG(ERROR) << "Failed to create display link."; 841 LOG(ERROR) << "Failed to create display link.";
824 } 842 }
825 } 843 }
826 844
845 void RenderWidgetHostViewMac::PostReleaseBrowserCompositorLock() {
846 base::MessageLoop::current()->PostTask(FROM_HERE,
847 base::Bind(&RenderWidgetHostViewMac::ReleaseBrowserCompositorLock,
848 weak_factory_.GetWeakPtr()));
849 }
850
851 void RenderWidgetHostViewMac::ReleaseBrowserCompositorLock() {
852 if (!browser_compositor_view_)
853 return;
854
855 browser_compositor_lock_ = NULL;
856 if (browser_compositor_damaged_during_lock_) {
857 browser_compositor_damaged_during_lock_ = false;
858 [browser_compositor_view_ compositor]->ScheduleFullRedraw();
859 }
860 }
861
827 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() { 862 void RenderWidgetHostViewMac::SendVSyncParametersToRenderer() {
828 if (!render_widget_host_ || !display_link_) 863 if (!render_widget_host_ || !display_link_)
829 return; 864 return;
830 865
831 base::TimeTicks timebase; 866 base::TimeTicks timebase;
832 base::TimeDelta interval; 867 base::TimeDelta interval;
833 if (!display_link_->GetVSyncParameters(&timebase, &interval)) 868 if (!display_link_->GetVSyncParameters(&timebase, &interval))
834 return; 869 return;
835 870
836 render_widget_host_->UpdateVSyncParameters(timebase, interval); 871 render_widget_host_->UpdateVSyncParameters(timebase, interval);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; 908 [[cocoa_view_ window] disableScreenUpdatesUntilFlush];
874 } 909 }
875 910
876 void RenderWidgetHostViewMac::WasHidden() { 911 void RenderWidgetHostViewMac::WasHidden() {
877 if (render_widget_host_->is_hidden()) 912 if (render_widget_host_->is_hidden())
878 return; 913 return;
879 914
880 // Any pending frames will not be displayed until this is shown again. Ack 915 // Any pending frames will not be displayed until this is shown again. Ack
881 // them now. 916 // them now.
882 SendPendingSwapAck(); 917 SendPendingSwapAck();
918 PostReleaseBrowserCompositorLock();
883 919
884 // If we have a renderer, then inform it that we are being hidden so it can 920 // If we have a renderer, then inform it that we are being hidden so it can
885 // reduce its resource utilization. 921 // reduce its resource utilization.
886 render_widget_host_->WasHidden(); 922 render_widget_host_->WasHidden();
887 software_frame_manager_->SetVisibility(false); 923 software_frame_manager_->SetVisibility(false);
888 if (delegated_frame_host_) 924 if (delegated_frame_host_)
889 delegated_frame_host_->WasHidden(); 925 delegated_frame_host_->WasHidden();
890 926
891 // There can be a transparent flash as this view is removed and the next is 927 // There can be a transparent flash as this view is removed and the next is
892 // added, because of OSX windowing races between displaying the contents of 928 // added, because of OSX windowing races between displaying the contents of
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
1097 1133
1098 [fullscreen_window_manager_ exitFullscreenMode]; 1134 [fullscreen_window_manager_ exitFullscreenMode];
1099 fullscreen_window_manager_.reset(); 1135 fullscreen_window_manager_.reset();
1100 [pepper_fullscreen_window_ close]; 1136 [pepper_fullscreen_window_ close];
1101 1137
1102 // This can be called as part of processing the window's responder 1138 // This can be called as part of processing the window's responder
1103 // chain, for instance |-performKeyEquivalent:|. In that case the 1139 // chain, for instance |-performKeyEquivalent:|. In that case the
1104 // object needs to survive until the stack unwinds. 1140 // object needs to survive until the stack unwinds.
1105 pepper_fullscreen_window_.autorelease(); 1141 pepper_fullscreen_window_.autorelease();
1106 1142
1143 // Delete the delegated frame state, which will reach back into
1144 // render_widget_host_.
1145 browser_compositor_lock_ = NULL;
1146 [browser_compositor_view_ resetClient];
1147 delegated_frame_host_.reset();
1148 root_layer_.reset();
1149
1107 // We get this call just before |render_widget_host_| deletes 1150 // We get this call just before |render_widget_host_| deletes
1108 // itself. But we are owned by |cocoa_view_|, which may be retained 1151 // itself. But we are owned by |cocoa_view_|, which may be retained
1109 // by some other code. Examples are WebContentsViewMac's 1152 // by some other code. Examples are WebContentsViewMac's
1110 // |latent_focus_view_| and TabWindowController's 1153 // |latent_focus_view_| and TabWindowController's
1111 // |cachedContentView_|. 1154 // |cachedContentView_|.
1112 render_widget_host_ = NULL; 1155 render_widget_host_ = NULL;
1113 } 1156 }
1114 1157
1115 // Called from the renderer to tell us what the tooltip text should be. It 1158 // Called from the renderer to tell us what the tooltip text should be. It
1116 // calls us frequently so we need to cache the value to prevent doing a lot 1159 // calls us frequently so we need to cache the value to prevent doing a lot
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 } 1928 }
1886 return false; 1929 return false;
1887 } 1930 }
1888 1931
1889 void RenderWidgetHostViewMac::OnSwapCompositorFrame( 1932 void RenderWidgetHostViewMac::OnSwapCompositorFrame(
1890 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { 1933 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) {
1891 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame"); 1934 TRACE_EVENT0("browser", "RenderWidgetHostViewMac::OnSwapCompositorFrame");
1892 1935
1893 if (frame->delegated_frame_data) { 1936 if (frame->delegated_frame_data) {
1894 if (!browser_compositor_view_) { 1937 if (!browser_compositor_view_) {
1895 browser_compositor_view_.reset( 1938 browser_compositor_view_.reset([[BrowserCompositorViewMac alloc]
1896 [[BrowserCompositorViewMac alloc] initWithSuperview:cocoa_view_]); 1939 initWithSuperview:cocoa_view_ withClient:this]);
1897 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); 1940 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED));
1898 delegated_frame_host_.reset(new DelegatedFrameHost(this)); 1941 delegated_frame_host_.reset(new DelegatedFrameHost(this));
1899 [browser_compositor_view_ compositor]->SetRootLayer(root_layer_.get()); 1942 [browser_compositor_view_ compositor]->SetRootLayer(root_layer_.get());
1900 } 1943 }
1901 1944
1902 float scale_factor = frame->metadata.device_scale_factor; 1945 float scale_factor = frame->metadata.device_scale_factor;
1903 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size); 1946 gfx::Size dip_size = ToCeiledSize(frame->metadata.viewport_size);
1904 gfx::Size pixel_size = ConvertSizeToPixel( 1947 gfx::Size pixel_size = ConvertSizeToPixel(
1905 scale_factor, dip_size); 1948 scale_factor, dip_size);
1906 [browser_compositor_view_ compositor]->SetScaleAndSize( 1949 [browser_compositor_view_ compositor]->SetScaleAndSize(
(...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after
2464 [software_layer_ setFrame:new_background_frame]; 2507 [software_layer_ setFrame:new_background_frame];
2465 } 2508 }
2466 } 2509 }
2467 } 2510 }
2468 2511
2469 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() { 2512 SkBitmap::Config RenderWidgetHostViewMac::PreferredReadbackFormat() {
2470 return SkBitmap::kARGB_8888_Config; 2513 return SkBitmap::kARGB_8888_Config;
2471 } 2514 }
2472 2515
2473 //////////////////////////////////////////////////////////////////////////////// 2516 ////////////////////////////////////////////////////////////////////////////////
2517 // BrowserCompositorViewMacClient, public:
2518
2519 void RenderWidgetHostViewMac::BrowserCompositorDidDrawFrame() {
2520 PostReleaseBrowserCompositorLock();
2521 }
2522
2523 ////////////////////////////////////////////////////////////////////////////////
2474 // CompositingIOSurfaceLayerClient, public: 2524 // CompositingIOSurfaceLayerClient, public:
2475 2525
2476 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) { 2526 void RenderWidgetHostViewMac::AcceleratedLayerDidDrawFrame(bool succeeded) {
2477 SendPendingLatencyInfoToHost(); 2527 SendPendingLatencyInfoToHost();
2478 SendPendingSwapAck(); 2528 SendPendingSwapAck();
2479 if (!succeeded) 2529 if (!succeeded)
2480 GotAcceleratedCompositingError(); 2530 GotAcceleratedCompositingError();
2481 } 2531 }
2482 2532
2483 } // namespace content 2533 } // namespace content
(...skipping 1890 matching lines...) Expand 10 before | Expand all | Expand 10 after
4374 4424
4375 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 4425 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
4376 // regions that are not draggable. (See ControlRegionView in 4426 // regions that are not draggable. (See ControlRegionView in
4377 // native_app_window_cocoa.mm). This requires the render host view to be 4427 // native_app_window_cocoa.mm). This requires the render host view to be
4378 // draggable by default. 4428 // draggable by default.
4379 - (BOOL)mouseDownCanMoveWindow { 4429 - (BOOL)mouseDownCanMoveWindow {
4380 return YES; 4430 return YES;
4381 } 4431 }
4382 4432
4383 @end 4433 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698