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 <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/resize_lock.h" | |
| 30 #include "content/browser/frame_host/frame_tree.h" | 31 #include "content/browser/frame_host/frame_tree.h" |
| 31 #include "content/browser/frame_host/frame_tree_node.h" | 32 #include "content/browser/frame_host/frame_tree_node.h" |
| 32 #include "content/browser/frame_host/render_frame_host_impl.h" | 33 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 34 #include "content/browser/gpu/gpu_process_host.h" | |
| 35 #include "content/browser/gpu/gpu_surface_tracker.h" | |
| 33 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 36 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
| 34 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | 37 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
| 35 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 38 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
| 39 #include "content/browser/renderer_host/render_widget_helper.h" | |
| 36 #include "content/browser/renderer_host/render_view_host_impl.h" | 40 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 37 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h" | 41 #import "content/browser/renderer_host/render_widget_host_view_mac_dictionary_he lper.h" |
| 38 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" | 42 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h elper.h" |
| 39 #import "content/browser/renderer_host/text_input_client_mac.h" | 43 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 40 #include "content/common/accessibility_messages.h" | 44 #include "content/common/accessibility_messages.h" |
| 41 #include "content/common/edit_command.h" | 45 #include "content/common/edit_command.h" |
| 42 #include "content/common/gpu/gpu_messages.h" | 46 #include "content/common/gpu/gpu_messages.h" |
| 43 #include "content/common/input_messages.h" | 47 #include "content/common/input_messages.h" |
| 44 #include "content/common/view_messages.h" | 48 #include "content/common/view_messages.h" |
| 45 #include "content/common/webplugin_geometry.h" | 49 #include "content/common/webplugin_geometry.h" |
| 46 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 50 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
| 47 #include "content/public/browser/browser_thread.h" | 51 #include "content/public/browser/browser_thread.h" |
| 48 #include "content/public/browser/native_web_keyboard_event.h" | 52 #include "content/public/browser/native_web_keyboard_event.h" |
| 49 #include "content/public/browser/notification_service.h" | 53 #include "content/public/browser/notification_service.h" |
| 50 #include "content/public/browser/notification_types.h" | 54 #include "content/public/browser/notification_types.h" |
| 51 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 55 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
| 52 #include "content/public/browser/user_metrics.h" | 56 #include "content/public/browser/user_metrics.h" |
| 53 #include "content/public/browser/web_contents.h" | 57 #include "content/public/browser/web_contents.h" |
| 54 #include "skia/ext/platform_canvas.h" | 58 #include "skia/ext/platform_canvas.h" |
| 55 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 59 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 56 #include "third_party/WebKit/public/web/WebInputEvent.h" | 60 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 57 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" | 61 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" |
| 58 #import "third_party/mozilla/ComplexTextInputPanel.h" | 62 #import "third_party/mozilla/ComplexTextInputPanel.h" |
| 59 #include "ui/base/cocoa/animation_utils.h" | 63 #include "ui/base/cocoa/animation_utils.h" |
| 60 #import "ui/base/cocoa/fullscreen_window_manager.h" | 64 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 61 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 65 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 62 #include "ui/events/keycodes/keyboard_codes.h" | 66 #include "ui/events/keycodes/keyboard_codes.h" |
| 63 #include "ui/base/layout.h" | 67 #include "ui/base/layout.h" |
| 68 #include "ui/compositor/compositor.h" | |
| 69 #include "ui/compositor/layer.h" | |
| 64 #include "ui/gfx/display.h" | 70 #include "ui/gfx/display.h" |
| 65 #include "ui/gfx/point.h" | 71 #include "ui/gfx/point.h" |
| 66 #include "ui/gfx/rect_conversions.h" | 72 #include "ui/gfx/rect_conversions.h" |
| 67 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 73 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 68 #include "ui/gfx/screen.h" | 74 #include "ui/gfx/screen.h" |
| 69 #include "ui/gfx/size_conversions.h" | 75 #include "ui/gfx/size_conversions.h" |
| 70 #include "ui/gl/gl_switches.h" | 76 #include "ui/gl/gl_switches.h" |
| 71 #include "ui/gl/io_surface_support_mac.h" | 77 #include "ui/gl/io_surface_support_mac.h" |
| 72 | 78 |
| 73 using content::BrowserAccessibility; | 79 using content::BrowserAccessibility; |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 101 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 107 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 102 @interface NSView (NSOpenGLSurfaceResolutionLionAPI) | 108 @interface NSView (NSOpenGLSurfaceResolutionLionAPI) |
| 103 - (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag; | 109 - (void)setWantsBestResolutionOpenGLSurface:(BOOL)flag; |
| 104 @end | 110 @end |
| 105 | 111 |
| 106 static NSString* const NSWindowDidChangeBackingPropertiesNotification = | 112 static NSString* const NSWindowDidChangeBackingPropertiesNotification = |
| 107 @"NSWindowDidChangeBackingPropertiesNotification"; | 113 @"NSWindowDidChangeBackingPropertiesNotification"; |
| 108 | 114 |
| 109 #endif // 10.7 | 115 #endif // 10.7 |
| 110 | 116 |
| 117 // Declare methods used to present swaps to this view. | |
| 118 @interface NSView (ContentCompositingView) | |
| 119 - (void)onNativeSurfaceBuffersSwappedWithParams: | |
| 120 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params; | |
| 121 @end | |
| 122 | |
| 123 @implementation NSView (ContentCompositingView) | |
| 124 - (void)onNativeSurfaceBuffersSwappedWithParams: | |
| 125 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { | |
| 126 } | |
| 127 @end | |
| 128 | |
| 111 // This method will return YES for OS X versions 10.7.3 and later, and NO | 129 // This method will return YES for OS X versions 10.7.3 and later, and NO |
| 112 // otherwise. | 130 // otherwise. |
| 113 // Used to prevent a crash when building with the 10.7 SDK and accessing the | 131 // Used to prevent a crash when building with the 10.7 SDK and accessing the |
| 114 // notification below. See: http://crbug.com/260595. | 132 // notification below. See: http://crbug.com/260595. |
| 115 static BOOL SupportsBackingPropertiesChangedNotification() { | 133 static BOOL SupportsBackingPropertiesChangedNotification() { |
| 116 // windowDidChangeBackingProperties: method has been added to the | 134 // windowDidChangeBackingProperties: method has been added to the |
| 117 // NSWindowDelegate protocol in 10.7.3, at the same time as the | 135 // NSWindowDelegate protocol in 10.7.3, at the same time as the |
| 118 // NSWindowDidChangeBackingPropertiesNotification notification was added. | 136 // NSWindowDidChangeBackingPropertiesNotification notification was added. |
| 119 // If the protocol contains this method description, the notification should | 137 // If the protocol contains this method description, the notification should |
| 120 // be supported as well. | 138 // be supported as well. |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 // Disable the fade-out animation as the layer is removed. | 404 // Disable the fade-out animation as the layer is removed. |
| 387 ScopedCAActionDisabler disabler; | 405 ScopedCAActionDisabler disabler; |
| 388 [layer removeFromSuperlayer]; | 406 [layer removeFromSuperlayer]; |
| 389 } | 407 } |
| 390 | 408 |
| 391 } // namespace | 409 } // namespace |
| 392 | 410 |
| 393 namespace content { | 411 namespace content { |
| 394 | 412 |
| 395 /////////////////////////////////////////////////////////////////////////////// | 413 /////////////////////////////////////////////////////////////////////////////// |
| 414 // RenderWidgetHelper, public: | |
| 415 | |
| 416 void RenderWidgetHelper::OnNativeSurfaceBuffersSwapped( | |
| 417 GpuProcessHost* gpu_process_host, | |
| 418 const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params) { | |
| 419 if (BrowserThread::CurrentlyOn(BrowserThread::IO)) { | |
| 420 // Immediately acknowledge this frame on the IO thread instead of the UI | |
| 421 // thread. The UI thread will wait on the GPU process. If the UI thread | |
| 422 // were to be responsible for acking swaps, then there would be a cycle | |
| 423 // and a potential deadlock. | |
| 424 // TODO(ccameron): This immediate ack circumvents GPU back-pressure that | |
| 425 // is necessary to throttle renderers. Fix that. | |
| 426 // TODO(ccameron): It is possible that the IOSurface will be deleted or | |
| 427 // reused soon as it is acked. Take out a reference to the IOSurface here, | |
| 428 // to ensure the IOSurface does not disappear before routing to the UI | |
| 429 // thread. | |
| 430 AcceleratedSurfaceMsg_BufferPresented_Params ack_params; | |
| 431 ack_params.sync_point = 0; | |
| 432 ack_params.renderer_id = 0; | |
| 433 gpu_process_host->Send(new AcceleratedSurfaceMsg_BufferPresented( | |
| 434 params.route_id, ack_params)); | |
| 435 | |
| 436 gpu_process_host = NULL; | |
| 437 BrowserThread::PostTask( | |
| 438 BrowserThread::UI, | |
| 439 FROM_HERE, | |
| 440 base::Bind(&OnNativeSurfaceBuffersSwapped, gpu_process_host, params)); | |
|
piman
2014/05/06 20:02:54
It kinda calls for having a different function for
ccameron
2014/05/06 20:39:00
Done.
| |
| 441 return; | |
| 442 } | |
| 443 | |
| 444 gfx::AcceleratedWidget native_widget = | |
| 445 GpuSurfaceTracker::Get()->AcquireNativeWidget(params.surface_id); | |
| 446 [native_widget onNativeSurfaceBuffersSwappedWithParams:params]; | |
| 447 } | |
| 448 | |
| 449 //////////////////////////////////////////////////////////////////////////////// | |
| 450 // DelegatedFrameHost, public: | |
| 451 | |
| 452 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { | |
| 453 return compositor_.get(); | |
| 454 } | |
| 455 | |
| 456 ui::Layer* RenderWidgetHostViewMac::GetLayer() { | |
| 457 return root_layer_.get(); | |
| 458 } | |
| 459 | |
| 460 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { | |
| 461 return render_widget_host_; | |
| 462 } | |
| 463 | |
| 464 void RenderWidgetHostViewMac::SchedulePaintInRect( | |
| 465 const gfx::Rect& damage_rect_in_dip) { | |
| 466 compositor_->ScheduleFullRedraw(); | |
| 467 } | |
| 468 | |
| 469 bool RenderWidgetHostViewMac::IsVisible() { | |
| 470 return !render_widget_host_->is_hidden(); | |
| 471 } | |
| 472 | |
| 473 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { | |
| 474 return GetViewBounds().size(); | |
| 475 } | |
| 476 | |
| 477 float RenderWidgetHostViewMac::CurrentDeviceScaleFactor() { | |
| 478 return ViewScaleFactor(); | |
| 479 } | |
| 480 | |
| 481 gfx::Size RenderWidgetHostViewMac::ConvertViewSizeToPixel( | |
| 482 const gfx::Size& size) { | |
| 483 return gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(size), | |
| 484 ViewScaleFactor())).size(); | |
| 485 } | |
| 486 | |
| 487 scoped_ptr<ResizeLock> RenderWidgetHostViewMac::CreateResizeLock( | |
| 488 bool defer_compositor_lock) { | |
| 489 NOTREACHED(); | |
| 490 ResizeLock* lock = NULL; | |
| 491 return scoped_ptr<ResizeLock>(lock); | |
| 492 } | |
| 493 | |
| 494 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { | |
| 495 return delegated_frame_host_.get(); | |
| 496 } | |
| 497 | |
| 498 /////////////////////////////////////////////////////////////////////////////// | |
| 396 // RenderWidgetHostViewBase, public: | 499 // RenderWidgetHostViewBase, public: |
| 397 | 500 |
| 398 // static | 501 // static |
| 399 void RenderWidgetHostViewBase::GetDefaultScreenInfo( | 502 void RenderWidgetHostViewBase::GetDefaultScreenInfo( |
| 400 blink::WebScreenInfo* results) { | 503 blink::WebScreenInfo* results) { |
| 401 *results = GetWebScreenInfo(NULL); | 504 *results = GetWebScreenInfo(NULL); |
| 402 } | 505 } |
| 403 | 506 |
| 404 /////////////////////////////////////////////////////////////////////////////// | 507 /////////////////////////////////////////////////////////////////////////////// |
| 405 // RenderWidgetHostViewMac, public: | 508 // RenderWidgetHostViewMac, public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 441 } | 544 } |
| 442 | 545 |
| 443 render_widget_host_->SetView(this); | 546 render_widget_host_->SetView(this); |
| 444 } | 547 } |
| 445 | 548 |
| 446 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 549 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 447 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 550 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 448 // pointer. | 551 // pointer. |
| 449 cocoa_view_ = nil; | 552 cocoa_view_ = nil; |
| 450 | 553 |
| 554 // Delete the delegated frame state. | |
| 555 delegated_frame_host_.reset(); | |
| 556 compositor_.reset(); | |
| 557 root_layer_.reset(); | |
| 558 | |
| 451 UnlockMouse(); | 559 UnlockMouse(); |
| 452 | 560 |
| 453 // Make sure that the layer doesn't reach into the now-invalid object. | 561 // Make sure that the layer doesn't reach into the now-invalid object. |
| 454 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | 562 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); |
| 455 DestroySoftwareLayer(); | 563 DestroySoftwareLayer(); |
| 456 | 564 |
| 457 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 565 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 458 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 566 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| 459 // us. | 567 // us. |
| 460 if (render_widget_host_) | 568 if (render_widget_host_) |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 788 } | 896 } |
| 789 | 897 |
| 790 void RenderWidgetHostViewMac::WasShown() { | 898 void RenderWidgetHostViewMac::WasShown() { |
| 791 if (!render_widget_host_->is_hidden()) | 899 if (!render_widget_host_->is_hidden()) |
| 792 return; | 900 return; |
| 793 | 901 |
| 794 if (web_contents_switch_paint_time_.is_null()) | 902 if (web_contents_switch_paint_time_.is_null()) |
| 795 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 903 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
| 796 render_widget_host_->WasShown(); | 904 render_widget_host_->WasShown(); |
| 797 software_frame_manager_->SetVisibility(true); | 905 software_frame_manager_->SetVisibility(true); |
| 906 if (delegated_frame_host_) | |
| 907 delegated_frame_host_->WasShown(); | |
| 798 | 908 |
| 799 // Call setNeedsDisplay before pausing for new frames to come in -- if any | 909 // Call setNeedsDisplay before pausing for new frames to come in -- if any |
| 800 // do, and are drawn, then the needsDisplay bit will be cleared. | 910 // do, and are drawn, then the needsDisplay bit will be cleared. |
| 801 [software_layer_ setNeedsDisplay]; | 911 [software_layer_ setNeedsDisplay]; |
| 802 [compositing_iosurface_layer_ setNeedsDisplay]; | 912 [compositing_iosurface_layer_ setNeedsDisplay]; |
| 803 PauseForPendingResizeOrRepaintsAndDraw(); | 913 PauseForPendingResizeOrRepaintsAndDraw(); |
| 804 | 914 |
| 805 // We're messing with the window, so do this to ensure no flashes. | 915 // We're messing with the window, so do this to ensure no flashes. |
| 806 if (!use_core_animation_) | 916 if (!use_core_animation_) |
| 807 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 917 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 808 } | 918 } |
| 809 | 919 |
| 810 void RenderWidgetHostViewMac::WasHidden() { | 920 void RenderWidgetHostViewMac::WasHidden() { |
| 811 if (render_widget_host_->is_hidden()) | 921 if (render_widget_host_->is_hidden()) |
| 812 return; | 922 return; |
| 813 | 923 |
| 814 // Any pending frames will not be displayed until this is shown again. Ack | 924 // Any pending frames will not be displayed until this is shown again. Ack |
| 815 // them now. | 925 // them now. |
| 816 SendPendingSwapAck(); | 926 SendPendingSwapAck(); |
| 817 | 927 |
| 818 // If we have a renderer, then inform it that we are being hidden so it can | 928 // If we have a renderer, then inform it that we are being hidden so it can |
| 819 // reduce its resource utilization. | 929 // reduce its resource utilization. |
| 820 render_widget_host_->WasHidden(); | 930 render_widget_host_->WasHidden(); |
| 821 software_frame_manager_->SetVisibility(false); | 931 software_frame_manager_->SetVisibility(false); |
| 932 if (delegated_frame_host_) | |
| 933 delegated_frame_host_->WasHidden(); | |
| 822 | 934 |
| 823 // There can be a transparent flash as this view is removed and the next is | 935 // There can be a transparent flash as this view is removed and the next is |
| 824 // added, because of OSX windowing races between displaying the contents of | 936 // added, because of OSX windowing races between displaying the contents of |
| 825 // the NSView and its corresponding OpenGL context. | 937 // the NSView and its corresponding OpenGL context. |
| 826 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding | 938 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding |
| 827 // screen updates until the next tab draws. | 939 // screen updates until the next tab draws. |
| 828 if (!use_core_animation_) | 940 if (!use_core_animation_) |
| 829 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 941 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 830 | 942 |
| 831 web_contents_switch_paint_time_ = base::TimeTicks(); | 943 web_contents_switch_paint_time_ = base::TimeTicks(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 913 void RenderWidgetHostViewMac::Blur() { | 1025 void RenderWidgetHostViewMac::Blur() { |
| 914 UnlockMouse(); | 1026 UnlockMouse(); |
| 915 [[cocoa_view_ window] makeFirstResponder:nil]; | 1027 [[cocoa_view_ window] makeFirstResponder:nil]; |
| 916 } | 1028 } |
| 917 | 1029 |
| 918 bool RenderWidgetHostViewMac::HasFocus() const { | 1030 bool RenderWidgetHostViewMac::HasFocus() const { |
| 919 return [[cocoa_view_ window] firstResponder] == cocoa_view_; | 1031 return [[cocoa_view_ window] firstResponder] == cocoa_view_; |
| 920 } | 1032 } |
| 921 | 1033 |
| 922 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { | 1034 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { |
| 1035 if (delegated_frame_host_) | |
| 1036 return delegated_frame_host_->CanCopyToBitmap(); | |
| 1037 | |
| 923 return software_frame_manager_->HasCurrentFrame() || | 1038 return software_frame_manager_->HasCurrentFrame() || |
| 924 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); | 1039 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); |
| 925 } | 1040 } |
| 926 | 1041 |
| 927 void RenderWidgetHostViewMac::Show() { | 1042 void RenderWidgetHostViewMac::Show() { |
| 928 [cocoa_view_ setHidden:NO]; | 1043 [cocoa_view_ setHidden:NO]; |
| 929 | 1044 |
| 930 WasShown(); | 1045 WasShown(); |
| 931 } | 1046 } |
| 932 | 1047 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1153 | 1268 |
| 1154 bool RenderWidgetHostViewMac::IsPopup() const { | 1269 bool RenderWidgetHostViewMac::IsPopup() const { |
| 1155 return popup_type_ != blink::WebPopupTypeNone; | 1270 return popup_type_ != blink::WebPopupTypeNone; |
| 1156 } | 1271 } |
| 1157 | 1272 |
| 1158 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 1273 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
| 1159 const gfx::Rect& src_subrect, | 1274 const gfx::Rect& src_subrect, |
| 1160 const gfx::Size& dst_size, | 1275 const gfx::Size& dst_size, |
| 1161 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1276 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1162 const SkBitmap::Config config) { | 1277 const SkBitmap::Config config) { |
| 1278 if (delegated_frame_host_) { | |
| 1279 delegated_frame_host_->CopyFromCompositingSurface( | |
| 1280 src_subrect, dst_size, callback, config); | |
| 1281 return; | |
| 1282 } | |
| 1283 | |
| 1163 if (config != SkBitmap::kARGB_8888_Config) { | 1284 if (config != SkBitmap::kARGB_8888_Config) { |
| 1164 NOTIMPLEMENTED(); | 1285 NOTIMPLEMENTED(); |
| 1165 callback.Run(false, SkBitmap()); | 1286 callback.Run(false, SkBitmap()); |
| 1166 } | 1287 } |
| 1167 base::ScopedClosureRunner scoped_callback_runner( | 1288 base::ScopedClosureRunner scoped_callback_runner( |
| 1168 base::Bind(callback, false, SkBitmap())); | 1289 base::Bind(callback, false, SkBitmap())); |
| 1169 float scale = ScaleFactorForView(cocoa_view_); | 1290 float scale = ScaleFactorForView(cocoa_view_); |
| 1170 gfx::Size dst_pixel_size = gfx::ToFlooredSize( | 1291 gfx::Size dst_pixel_size = gfx::ToFlooredSize( |
| 1171 gfx::ScaleSize(dst_size, scale)); | 1292 gfx::ScaleSize(dst_size, scale)); |
| 1172 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { | 1293 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1210 | 1331 |
| 1211 ignore_result(scoped_callback_runner.Release()); | 1332 ignore_result(scoped_callback_runner.Release()); |
| 1212 callback.Run(true, target_bitmap); | 1333 callback.Run(true, target_bitmap); |
| 1213 } | 1334 } |
| 1214 } | 1335 } |
| 1215 | 1336 |
| 1216 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( | 1337 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( |
| 1217 const gfx::Rect& src_subrect, | 1338 const gfx::Rect& src_subrect, |
| 1218 const scoped_refptr<media::VideoFrame>& target, | 1339 const scoped_refptr<media::VideoFrame>& target, |
| 1219 const base::Callback<void(bool)>& callback) { | 1340 const base::Callback<void(bool)>& callback) { |
| 1341 if (delegated_frame_host_) { | |
| 1342 delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame( | |
| 1343 src_subrect, target, callback); | |
| 1344 return; | |
| 1345 } | |
| 1346 | |
| 1220 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 1347 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
| 1221 if (!render_widget_host_->is_accelerated_compositing_active() || | 1348 if (!render_widget_host_->is_accelerated_compositing_active() || |
| 1222 !compositing_iosurface_ || | 1349 !compositing_iosurface_ || |
| 1223 !compositing_iosurface_->HasIOSurface()) | 1350 !compositing_iosurface_->HasIOSurface()) |
| 1224 return; | 1351 return; |
| 1225 | 1352 |
| 1226 if (!target.get()) { | 1353 if (!target.get()) { |
| 1227 NOTREACHED(); | 1354 NOTREACHED(); |
| 1228 return; | 1355 return; |
| 1229 } | 1356 } |
| 1230 | 1357 |
| 1231 if (target->format() != media::VideoFrame::YV12 && | 1358 if (target->format() != media::VideoFrame::YV12 && |
| 1232 target->format() != media::VideoFrame::I420) { | 1359 target->format() != media::VideoFrame::I420) { |
| 1233 NOTREACHED(); | 1360 NOTREACHED(); |
| 1234 return; | 1361 return; |
| 1235 } | 1362 } |
| 1236 | 1363 |
| 1237 if (src_subrect.IsEmpty()) | 1364 if (src_subrect.IsEmpty()) |
| 1238 return; | 1365 return; |
| 1239 | 1366 |
| 1240 ignore_result(scoped_callback_runner.Release()); | 1367 ignore_result(scoped_callback_runner.Release()); |
| 1241 compositing_iosurface_->CopyToVideoFrame( | 1368 compositing_iosurface_->CopyToVideoFrame( |
| 1242 GetScaledOpenGLPixelRect(src_subrect), | 1369 GetScaledOpenGLPixelRect(src_subrect), |
| 1243 target, | 1370 target, |
| 1244 callback); | 1371 callback); |
| 1245 } | 1372 } |
| 1246 | 1373 |
| 1247 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { | 1374 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { |
| 1375 if (delegated_frame_host_) | |
| 1376 return delegated_frame_host_->CanCopyToVideoFrame(); | |
| 1377 | |
| 1248 return (!software_frame_manager_->HasCurrentFrame() && | 1378 return (!software_frame_manager_->HasCurrentFrame() && |
| 1249 render_widget_host_->is_accelerated_compositing_active() && | 1379 render_widget_host_->is_accelerated_compositing_active() && |
| 1250 compositing_iosurface_ && | 1380 compositing_iosurface_ && |
| 1251 compositing_iosurface_->HasIOSurface()); | 1381 compositing_iosurface_->HasIOSurface()); |
| 1252 } | 1382 } |
| 1253 | 1383 |
| 1254 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { | 1384 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { |
| 1385 if (delegated_frame_host_) | |
| 1386 return delegated_frame_host_->CanSubscribeFrame(); | |
| 1387 | |
| 1255 return !software_frame_manager_->HasCurrentFrame(); | 1388 return !software_frame_manager_->HasCurrentFrame(); |
| 1256 } | 1389 } |
| 1257 | 1390 |
| 1258 void RenderWidgetHostViewMac::BeginFrameSubscription( | 1391 void RenderWidgetHostViewMac::BeginFrameSubscription( |
| 1259 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1392 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
| 1393 if (delegated_frame_host_) { | |
| 1394 delegated_frame_host_->BeginFrameSubscription(subscriber.Pass()); | |
| 1395 return; | |
| 1396 } | |
| 1260 frame_subscriber_ = subscriber.Pass(); | 1397 frame_subscriber_ = subscriber.Pass(); |
| 1261 } | 1398 } |
| 1262 | 1399 |
| 1263 void RenderWidgetHostViewMac::EndFrameSubscription() { | 1400 void RenderWidgetHostViewMac::EndFrameSubscription() { |
| 1401 if (delegated_frame_host_) { | |
| 1402 delegated_frame_host_->EndFrameSubscription(); | |
| 1403 return; | |
| 1404 } | |
| 1405 | |
| 1264 frame_subscriber_.reset(); | 1406 frame_subscriber_.reset(); |
| 1265 } | 1407 } |
| 1266 | 1408 |
| 1267 // Sets whether or not to accept first responder status. | 1409 // Sets whether or not to accept first responder status. |
| 1268 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { | 1410 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { |
| 1269 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; | 1411 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; |
| 1270 } | 1412 } |
| 1271 | 1413 |
| 1272 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { | 1414 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { |
| 1273 if (render_widget_host_) | 1415 if (render_widget_host_) |
| (...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1771 return (software_frame_manager_->HasCurrentFrame() && | 1913 return (software_frame_manager_->HasCurrentFrame() && |
| 1772 (desired_size.IsEmpty() || | 1914 (desired_size.IsEmpty() || |
| 1773 software_frame_manager_->GetCurrentFrameSizeInDIP() == | 1915 software_frame_manager_->GetCurrentFrameSizeInDIP() == |
| 1774 desired_size)); | 1916 desired_size)); |
| 1775 } | 1917 } |
| 1776 return false; | 1918 return false; |
| 1777 } | 1919 } |
| 1778 | 1920 |
| 1779 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1921 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
| 1780 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1922 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
| 1781 // Only software compositor frames are accepted. | 1923 if (frame->delegated_frame_data) { |
| 1782 if (!frame->software_frame_data) { | 1924 if (!compositor_) { |
| 1925 compositor_.reset(new ui::Compositor(cocoa_view_)); | |
| 1926 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | |
| 1927 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | |
| 1928 } | |
| 1929 | |
| 1930 delegated_frame_host_->SwapDelegatedFrame( | |
| 1931 output_surface_id, | |
| 1932 frame->delegated_frame_data.Pass(), | |
| 1933 frame->metadata.device_scale_factor, | |
| 1934 frame->metadata.latency_info); | |
| 1935 | |
| 1936 gfx::Size size = ToCeiledSize(frame->metadata.viewport_size); | |
| 1937 float scale_factor = frame->metadata.page_scale_factor; | |
| 1938 if (compositor_->size() != size || | |
| 1939 compositor_->device_scale_factor() != scale_factor) { | |
| 1940 compositor_->SetScaleAndSize(scale_factor, size); | |
| 1941 root_layer_->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); | |
| 1942 } | |
| 1943 if (compositor_->root_layer() != root_layer_) | |
| 1944 compositor_->SetRootLayer(root_layer_.get()); | |
| 1945 } else if (frame->software_frame_data) { | |
| 1946 if (!software_frame_manager_->SwapToNewFrame( | |
| 1947 output_surface_id, | |
| 1948 frame->software_frame_data.get(), | |
| 1949 frame->metadata.device_scale_factor, | |
| 1950 render_widget_host_->GetProcess()->GetHandle())) { | |
| 1951 render_widget_host_->GetProcess()->ReceivedBadMessage(); | |
| 1952 return; | |
| 1953 } | |
| 1954 | |
| 1955 // Add latency info to report when the frame finishes drawing. | |
| 1956 AddPendingLatencyInfo(frame->metadata.latency_info); | |
| 1957 GotSoftwareFrame(); | |
| 1958 | |
| 1959 cc::CompositorFrameAck ack; | |
| 1960 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
| 1961 render_widget_host_->GetRoutingID(), | |
| 1962 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), | |
| 1963 render_widget_host_->GetProcess()->GetID(), | |
| 1964 ack); | |
| 1965 software_frame_manager_->SwapToNewFrameComplete( | |
| 1966 !render_widget_host_->is_hidden()); | |
| 1967 | |
| 1968 // Notify observers, tab capture observers in particular, that a new | |
| 1969 // software frame has come in. | |
| 1970 NotificationService::current()->Notify( | |
| 1971 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | |
| 1972 Source<RenderWidgetHost>(render_widget_host_), | |
| 1973 NotificationService::NoDetails()); | |
| 1974 } else { | |
| 1783 DLOG(ERROR) << "Received unexpected frame type."; | 1975 DLOG(ERROR) << "Received unexpected frame type."; |
| 1784 RecordAction( | 1976 RecordAction( |
| 1785 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); | 1977 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); |
| 1786 render_widget_host_->GetProcess()->ReceivedBadMessage(); | 1978 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
| 1787 return; | |
| 1788 } | 1979 } |
| 1789 | |
| 1790 if (!software_frame_manager_->SwapToNewFrame( | |
| 1791 output_surface_id, | |
| 1792 frame->software_frame_data.get(), | |
| 1793 frame->metadata.device_scale_factor, | |
| 1794 render_widget_host_->GetProcess()->GetHandle())) { | |
| 1795 render_widget_host_->GetProcess()->ReceivedBadMessage(); | |
| 1796 return; | |
| 1797 } | |
| 1798 | |
| 1799 // Add latency info to report when the frame finishes drawing. | |
| 1800 AddPendingLatencyInfo(frame->metadata.latency_info); | |
| 1801 GotSoftwareFrame(); | |
| 1802 | |
| 1803 cc::CompositorFrameAck ack; | |
| 1804 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
| 1805 render_widget_host_->GetRoutingID(), | |
| 1806 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), | |
| 1807 render_widget_host_->GetProcess()->GetID(), | |
| 1808 ack); | |
| 1809 software_frame_manager_->SwapToNewFrameComplete( | |
| 1810 !render_widget_host_->is_hidden()); | |
| 1811 | |
| 1812 // Notify observers, tab capture observers in particular, that a new software | |
| 1813 // frame has come in. | |
| 1814 NotificationService::current()->Notify( | |
| 1815 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | |
| 1816 Source<RenderWidgetHost>(render_widget_host_), | |
| 1817 NotificationService::NoDetails()); | |
| 1818 } | 1980 } |
| 1819 | 1981 |
| 1820 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { | 1982 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { |
| 1821 } | 1983 } |
| 1822 | 1984 |
| 1823 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, | 1985 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, |
| 1824 int route_id) { | 1986 int route_id) { |
| 1825 } | 1987 } |
| 1826 | 1988 |
| 1827 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { | 1989 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3107 if (!renderWidgetHostView_->render_widget_host_) | 3269 if (!renderWidgetHostView_->render_widget_host_) |
| 3108 return; | 3270 return; |
| 3109 | 3271 |
| 3110 // Move the CALayers to their positions in the new view size. Note that | 3272 // Move the CALayers to their positions in the new view size. Note that |
| 3111 // this will not draw anything because the non-background layers' sizes | 3273 // this will not draw anything because the non-background layers' sizes |
| 3112 // didn't actually change. | 3274 // didn't actually change. |
| 3113 renderWidgetHostView_->LayoutLayers(); | 3275 renderWidgetHostView_->LayoutLayers(); |
| 3114 | 3276 |
| 3115 renderWidgetHostView_->render_widget_host_->SendScreenRects(); | 3277 renderWidgetHostView_->render_widget_host_->SendScreenRects(); |
| 3116 renderWidgetHostView_->render_widget_host_->WasResized(); | 3278 renderWidgetHostView_->render_widget_host_->WasResized(); |
| 3279 if (renderWidgetHostView_->delegated_frame_host_) | |
| 3280 renderWidgetHostView_->delegated_frame_host_->WasResized(); | |
| 3117 | 3281 |
| 3118 // Wait for the frame that WasResize might have requested. If the view is | 3282 // Wait for the frame that WasResize might have requested. If the view is |
| 3119 // being made visible at a new size, then this call will have no effect | 3283 // being made visible at a new size, then this call will have no effect |
| 3120 // because the view widget is still hidden, and the pause call in WasShown | 3284 // because the view widget is still hidden, and the pause call in WasShown |
| 3121 // will have this effect for us. | 3285 // will have this effect for us. |
| 3122 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); | 3286 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); |
| 3123 } | 3287 } |
| 3124 | 3288 |
| 3125 // Fills with white the parts of the area to the right and bottom for |rect| | 3289 // Fills with white the parts of the area to the right and bottom for |rect| |
| 3126 // that intersect |damagedRect|. | 3290 // that intersect |damagedRect|. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3166 height = -height; | 3330 height = -height; |
| 3167 } | 3331 } |
| 3168 | 3332 |
| 3169 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 3333 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
| 3170 CGContextSetFillColorWithColor(context, | 3334 CGContextSetFillColorWithColor(context, |
| 3171 CGColorGetConstantColor(kCGColorWhite)); | 3335 CGColorGetConstantColor(kCGColorWhite)); |
| 3172 CGContextFillRect(context, NSRectToCGRect(r)); | 3336 CGContextFillRect(context, NSRectToCGRect(r)); |
| 3173 } | 3337 } |
| 3174 } | 3338 } |
| 3175 | 3339 |
| 3340 - (void)onNativeSurfaceBuffersSwappedWithParams: | |
| 3341 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { | |
| 3342 | |
| 3343 renderWidgetHostView_->CompositorSwapBuffers( | |
| 3344 params.surface_handle, | |
| 3345 params.size, | |
| 3346 params.scale_factor, | |
| 3347 params.latency_info); | |
| 3348 } | |
| 3349 | |
| 3176 - (void)drawRect:(NSRect)dirtyRect { | 3350 - (void)drawRect:(NSRect)dirtyRect { |
| 3177 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); | 3351 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
| 3178 DCHECK(!renderWidgetHostView_->use_core_animation_); | 3352 DCHECK(!renderWidgetHostView_->use_core_animation_); |
| 3179 | 3353 |
| 3180 if (!renderWidgetHostView_->render_widget_host_) { | 3354 if (!renderWidgetHostView_->render_widget_host_) { |
| 3181 // When using CoreAnimation, this path is used to paint the contents area | 3355 // When using CoreAnimation, this path is used to paint the contents area |
| 3182 // white before any frames come in. When layers to draw frames exist, this | 3356 // white before any frames come in. When layers to draw frames exist, this |
| 3183 // is not hit. | 3357 // is not hit. |
| 3184 [[NSColor whiteColor] set]; | 3358 [[NSColor whiteColor] set]; |
| 3185 NSRectFill(dirtyRect); | 3359 NSRectFill(dirtyRect); |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4279 } | 4453 } |
| 4280 | 4454 |
| 4281 - (void)disableRendering { | 4455 - (void)disableRendering { |
| 4282 // Disable the fade-out animation as the layer is removed. | 4456 // Disable the fade-out animation as the layer is removed. |
| 4283 ScopedCAActionDisabler disabler; | 4457 ScopedCAActionDisabler disabler; |
| 4284 [self removeFromSuperlayer]; | 4458 [self removeFromSuperlayer]; |
| 4285 renderWidgetHostView_ = nil; | 4459 renderWidgetHostView_ = nil; |
| 4286 } | 4460 } |
| 4287 | 4461 |
| 4288 @end // implementation SoftwareLayer | 4462 @end // implementation SoftwareLayer |
| OLD | NEW |