| 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" |
| 33 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" | 34 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h" |
| 34 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" | 35 #include "content/browser/renderer_host/compositing_iosurface_layer_mac.h" |
| 35 #include "content/browser/renderer_host/compositing_iosurface_mac.h" | 36 #include "content/browser/renderer_host/compositing_iosurface_mac.h" |
| 37 #include "content/browser/renderer_host/render_widget_helper.h" |
| 36 #include "content/browser/renderer_host/render_view_host_impl.h" | 38 #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" | 39 #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" | 40 #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" | 41 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 40 #include "content/common/accessibility_messages.h" | 42 #include "content/common/accessibility_messages.h" |
| 41 #include "content/common/edit_command.h" | 43 #include "content/common/edit_command.h" |
| 42 #include "content/common/gpu/gpu_messages.h" | 44 #include "content/common/gpu/gpu_messages.h" |
| 43 #include "content/common/input_messages.h" | 45 #include "content/common/input_messages.h" |
| 44 #include "content/common/view_messages.h" | 46 #include "content/common/view_messages.h" |
| 45 #include "content/common/webplugin_geometry.h" | 47 #include "content/common/webplugin_geometry.h" |
| 46 #include "content/public/browser/browser_thread.h" | 48 #include "content/public/browser/browser_thread.h" |
| 47 #include "content/public/browser/native_web_keyboard_event.h" | 49 #include "content/public/browser/native_web_keyboard_event.h" |
| 48 #include "content/public/browser/notification_service.h" | 50 #include "content/public/browser/notification_service.h" |
| 49 #include "content/public/browser/notification_types.h" | 51 #include "content/public/browser/notification_types.h" |
| 50 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 52 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 51 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 53 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
| 52 #include "content/public/browser/user_metrics.h" | 54 #include "content/public/browser/user_metrics.h" |
| 53 #include "content/public/browser/web_contents.h" | 55 #include "content/public/browser/web_contents.h" |
| 54 #include "skia/ext/platform_canvas.h" | 56 #include "skia/ext/platform_canvas.h" |
| 55 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 57 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 56 #include "third_party/WebKit/public/web/WebInputEvent.h" | 58 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 57 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" | 59 #include "third_party/WebKit/public/web/mac/WebInputEventFactory.h" |
| 58 #import "third_party/mozilla/ComplexTextInputPanel.h" | 60 #import "third_party/mozilla/ComplexTextInputPanel.h" |
| 59 #include "ui/base/cocoa/animation_utils.h" | 61 #include "ui/base/cocoa/animation_utils.h" |
| 60 #import "ui/base/cocoa/fullscreen_window_manager.h" | 62 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 61 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 63 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 62 #include "ui/events/keycodes/keyboard_codes.h" | 64 #include "ui/events/keycodes/keyboard_codes.h" |
| 63 #include "ui/base/layout.h" | 65 #include "ui/base/layout.h" |
| 66 #include "ui/compositor/compositor.h" |
| 67 #include "ui/compositor/layer.h" |
| 64 #include "ui/gfx/display.h" | 68 #include "ui/gfx/display.h" |
| 65 #include "ui/gfx/point.h" | 69 #include "ui/gfx/point.h" |
| 66 #include "ui/gfx/rect_conversions.h" | 70 #include "ui/gfx/rect_conversions.h" |
| 67 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 71 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 68 #include "ui/gfx/screen.h" | 72 #include "ui/gfx/screen.h" |
| 69 #include "ui/gfx/size_conversions.h" | 73 #include "ui/gfx/size_conversions.h" |
| 70 #include "ui/gl/gl_switches.h" | 74 #include "ui/gl/gl_switches.h" |
| 71 #include "ui/gl/io_surface_support_mac.h" | 75 #include "ui/gl/io_surface_support_mac.h" |
| 72 | 76 |
| 73 using content::BrowserAccessibility; | 77 using content::BrowserAccessibility; |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 base::scoped_nsobject<CompositingIOSurfaceLayer> layer) { | 403 base::scoped_nsobject<CompositingIOSurfaceLayer> layer) { |
| 400 // Disable the fade-out animation as the layer is removed. | 404 // Disable the fade-out animation as the layer is removed. |
| 401 ScopedCAActionDisabler disabler; | 405 ScopedCAActionDisabler disabler; |
| 402 [layer removeFromSuperlayer]; | 406 [layer removeFromSuperlayer]; |
| 403 } | 407 } |
| 404 | 408 |
| 405 } // namespace | 409 } // namespace |
| 406 | 410 |
| 407 namespace content { | 411 namespace content { |
| 408 | 412 |
| 413 //////////////////////////////////////////////////////////////////////////////// |
| 414 // DelegatedFrameHost, public: |
| 415 |
| 416 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { |
| 417 return compositor_.get(); |
| 418 } |
| 419 |
| 420 ui::Layer* RenderWidgetHostViewMac::GetLayer() { |
| 421 return root_layer_.get(); |
| 422 } |
| 423 |
| 424 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { |
| 425 return render_widget_host_; |
| 426 } |
| 427 |
| 428 void RenderWidgetHostViewMac::SchedulePaintInRect( |
| 429 const gfx::Rect& damage_rect_in_dip) { |
| 430 compositor_->ScheduleFullRedraw(); |
| 431 } |
| 432 |
| 433 bool RenderWidgetHostViewMac::IsVisible() { |
| 434 return !render_widget_host_->is_hidden(); |
| 435 } |
| 436 |
| 437 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { |
| 438 return GetViewBounds().size(); |
| 439 } |
| 440 |
| 441 float RenderWidgetHostViewMac::CurrentDeviceScaleFactor() { |
| 442 return ViewScaleFactor(); |
| 443 } |
| 444 |
| 445 gfx::Size RenderWidgetHostViewMac::ConvertViewSizeToPixel( |
| 446 const gfx::Size& size) { |
| 447 return gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(size), |
| 448 ViewScaleFactor())).size(); |
| 449 } |
| 450 |
| 451 scoped_ptr<ResizeLock> RenderWidgetHostViewMac::CreateResizeLock( |
| 452 bool defer_compositor_lock) { |
| 453 NOTREACHED(); |
| 454 ResizeLock* lock = NULL; |
| 455 return scoped_ptr<ResizeLock>(lock); |
| 456 } |
| 457 |
| 458 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { |
| 459 return delegated_frame_host_.get(); |
| 460 } |
| 461 |
| 409 /////////////////////////////////////////////////////////////////////////////// | 462 /////////////////////////////////////////////////////////////////////////////// |
| 410 // RenderWidgetHostViewBase, public: | 463 // RenderWidgetHostViewBase, public: |
| 411 | 464 |
| 412 // static | 465 // static |
| 413 void RenderWidgetHostViewBase::GetDefaultScreenInfo( | 466 void RenderWidgetHostViewBase::GetDefaultScreenInfo( |
| 414 blink::WebScreenInfo* results) { | 467 blink::WebScreenInfo* results) { |
| 415 *results = GetWebScreenInfo(NULL); | 468 *results = GetWebScreenInfo(NULL); |
| 416 } | 469 } |
| 417 | 470 |
| 418 /////////////////////////////////////////////////////////////////////////////// | 471 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 } | 508 } |
| 456 | 509 |
| 457 render_widget_host_->SetView(this); | 510 render_widget_host_->SetView(this); |
| 458 } | 511 } |
| 459 | 512 |
| 460 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 513 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 461 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 514 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 462 // pointer. | 515 // pointer. |
| 463 cocoa_view_ = nil; | 516 cocoa_view_ = nil; |
| 464 | 517 |
| 518 // Delete the delegated frame state. |
| 519 delegated_frame_host_.reset(); |
| 520 compositor_.reset(); |
| 521 root_layer_.reset(); |
| 522 |
| 465 UnlockMouse(); | 523 UnlockMouse(); |
| 466 | 524 |
| 467 // Make sure that the layer doesn't reach into the now-invalid object. | 525 // Make sure that the layer doesn't reach into the now-invalid object. |
| 468 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | 526 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); |
| 469 DestroySoftwareLayer(); | 527 DestroySoftwareLayer(); |
| 470 | 528 |
| 471 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 529 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the |
| 472 // RenderWidgetHost does we need to tell it not to hold a stale pointer to | 530 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
| 473 // us. | 531 // us. |
| 474 if (render_widget_host_) | 532 if (render_widget_host_) |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 860 } |
| 803 | 861 |
| 804 void RenderWidgetHostViewMac::WasShown() { | 862 void RenderWidgetHostViewMac::WasShown() { |
| 805 if (!render_widget_host_->is_hidden()) | 863 if (!render_widget_host_->is_hidden()) |
| 806 return; | 864 return; |
| 807 | 865 |
| 808 if (web_contents_switch_paint_time_.is_null()) | 866 if (web_contents_switch_paint_time_.is_null()) |
| 809 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 867 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
| 810 render_widget_host_->WasShown(); | 868 render_widget_host_->WasShown(); |
| 811 software_frame_manager_->SetVisibility(true); | 869 software_frame_manager_->SetVisibility(true); |
| 870 if (delegated_frame_host_) |
| 871 delegated_frame_host_->WasShown(); |
| 812 | 872 |
| 813 // Call setNeedsDisplay before pausing for new frames to come in -- if any | 873 // Call setNeedsDisplay before pausing for new frames to come in -- if any |
| 814 // do, and are drawn, then the needsDisplay bit will be cleared. | 874 // do, and are drawn, then the needsDisplay bit will be cleared. |
| 815 [software_layer_ setNeedsDisplay]; | 875 [software_layer_ setNeedsDisplay]; |
| 816 [compositing_iosurface_layer_ setNeedsDisplay]; | 876 [compositing_iosurface_layer_ setNeedsDisplay]; |
| 817 PauseForPendingResizeOrRepaintsAndDraw(); | 877 PauseForPendingResizeOrRepaintsAndDraw(); |
| 818 | 878 |
| 819 // We're messing with the window, so do this to ensure no flashes. | 879 // We're messing with the window, so do this to ensure no flashes. |
| 820 if (!use_core_animation_) | 880 if (!use_core_animation_) |
| 821 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 881 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 822 } | 882 } |
| 823 | 883 |
| 824 void RenderWidgetHostViewMac::WasHidden() { | 884 void RenderWidgetHostViewMac::WasHidden() { |
| 825 if (render_widget_host_->is_hidden()) | 885 if (render_widget_host_->is_hidden()) |
| 826 return; | 886 return; |
| 827 | 887 |
| 828 // Any pending frames will not be displayed until this is shown again. Ack | 888 // Any pending frames will not be displayed until this is shown again. Ack |
| 829 // them now. | 889 // them now. |
| 830 SendPendingSwapAck(); | 890 SendPendingSwapAck(); |
| 831 | 891 |
| 832 // If we have a renderer, then inform it that we are being hidden so it can | 892 // If we have a renderer, then inform it that we are being hidden so it can |
| 833 // reduce its resource utilization. | 893 // reduce its resource utilization. |
| 834 render_widget_host_->WasHidden(); | 894 render_widget_host_->WasHidden(); |
| 835 software_frame_manager_->SetVisibility(false); | 895 software_frame_manager_->SetVisibility(false); |
| 896 if (delegated_frame_host_) |
| 897 delegated_frame_host_->WasHidden(); |
| 836 | 898 |
| 837 // There can be a transparent flash as this view is removed and the next is | 899 // There can be a transparent flash as this view is removed and the next is |
| 838 // added, because of OSX windowing races between displaying the contents of | 900 // added, because of OSX windowing races between displaying the contents of |
| 839 // the NSView and its corresponding OpenGL context. | 901 // the NSView and its corresponding OpenGL context. |
| 840 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding | 902 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding |
| 841 // screen updates until the next tab draws. | 903 // screen updates until the next tab draws. |
| 842 if (!use_core_animation_) | 904 if (!use_core_animation_) |
| 843 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 905 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
| 844 | 906 |
| 845 web_contents_switch_paint_time_ = base::TimeTicks(); | 907 web_contents_switch_paint_time_ = base::TimeTicks(); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 927 void RenderWidgetHostViewMac::Blur() { | 989 void RenderWidgetHostViewMac::Blur() { |
| 928 UnlockMouse(); | 990 UnlockMouse(); |
| 929 [[cocoa_view_ window] makeFirstResponder:nil]; | 991 [[cocoa_view_ window] makeFirstResponder:nil]; |
| 930 } | 992 } |
| 931 | 993 |
| 932 bool RenderWidgetHostViewMac::HasFocus() const { | 994 bool RenderWidgetHostViewMac::HasFocus() const { |
| 933 return [[cocoa_view_ window] firstResponder] == cocoa_view_; | 995 return [[cocoa_view_ window] firstResponder] == cocoa_view_; |
| 934 } | 996 } |
| 935 | 997 |
| 936 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { | 998 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { |
| 999 if (delegated_frame_host_) |
| 1000 return delegated_frame_host_->CanCopyToBitmap(); |
| 1001 |
| 937 return software_frame_manager_->HasCurrentFrame() || | 1002 return software_frame_manager_->HasCurrentFrame() || |
| 938 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); | 1003 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); |
| 939 } | 1004 } |
| 940 | 1005 |
| 941 void RenderWidgetHostViewMac::Show() { | 1006 void RenderWidgetHostViewMac::Show() { |
| 942 [cocoa_view_ setHidden:NO]; | 1007 [cocoa_view_ setHidden:NO]; |
| 943 | 1008 |
| 944 WasShown(); | 1009 WasShown(); |
| 945 } | 1010 } |
| 946 | 1011 |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1167 | 1232 |
| 1168 bool RenderWidgetHostViewMac::IsPopup() const { | 1233 bool RenderWidgetHostViewMac::IsPopup() const { |
| 1169 return popup_type_ != blink::WebPopupTypeNone; | 1234 return popup_type_ != blink::WebPopupTypeNone; |
| 1170 } | 1235 } |
| 1171 | 1236 |
| 1172 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 1237 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
| 1173 const gfx::Rect& src_subrect, | 1238 const gfx::Rect& src_subrect, |
| 1174 const gfx::Size& dst_size, | 1239 const gfx::Size& dst_size, |
| 1175 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1240 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 1176 const SkBitmap::Config config) { | 1241 const SkBitmap::Config config) { |
| 1242 if (delegated_frame_host_) { |
| 1243 delegated_frame_host_->CopyFromCompositingSurface( |
| 1244 src_subrect, dst_size, callback, config); |
| 1245 return; |
| 1246 } |
| 1247 |
| 1177 if (config != SkBitmap::kARGB_8888_Config) { | 1248 if (config != SkBitmap::kARGB_8888_Config) { |
| 1178 NOTIMPLEMENTED(); | 1249 NOTIMPLEMENTED(); |
| 1179 callback.Run(false, SkBitmap()); | 1250 callback.Run(false, SkBitmap()); |
| 1180 } | 1251 } |
| 1181 base::ScopedClosureRunner scoped_callback_runner( | 1252 base::ScopedClosureRunner scoped_callback_runner( |
| 1182 base::Bind(callback, false, SkBitmap())); | 1253 base::Bind(callback, false, SkBitmap())); |
| 1183 float scale = ScaleFactorForView(cocoa_view_); | 1254 float scale = ScaleFactorForView(cocoa_view_); |
| 1184 gfx::Size dst_pixel_size = gfx::ToFlooredSize( | 1255 gfx::Size dst_pixel_size = gfx::ToFlooredSize( |
| 1185 gfx::ScaleSize(dst_size, scale)); | 1256 gfx::ScaleSize(dst_size, scale)); |
| 1186 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { | 1257 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1224 | 1295 |
| 1225 ignore_result(scoped_callback_runner.Release()); | 1296 ignore_result(scoped_callback_runner.Release()); |
| 1226 callback.Run(true, target_bitmap); | 1297 callback.Run(true, target_bitmap); |
| 1227 } | 1298 } |
| 1228 } | 1299 } |
| 1229 | 1300 |
| 1230 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( | 1301 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( |
| 1231 const gfx::Rect& src_subrect, | 1302 const gfx::Rect& src_subrect, |
| 1232 const scoped_refptr<media::VideoFrame>& target, | 1303 const scoped_refptr<media::VideoFrame>& target, |
| 1233 const base::Callback<void(bool)>& callback) { | 1304 const base::Callback<void(bool)>& callback) { |
| 1305 if (delegated_frame_host_) { |
| 1306 delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame( |
| 1307 src_subrect, target, callback); |
| 1308 return; |
| 1309 } |
| 1310 |
| 1234 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 1311 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
| 1235 if (!render_widget_host_->is_accelerated_compositing_active() || | 1312 if (!render_widget_host_->is_accelerated_compositing_active() || |
| 1236 !compositing_iosurface_ || | 1313 !compositing_iosurface_ || |
| 1237 !compositing_iosurface_->HasIOSurface()) | 1314 !compositing_iosurface_->HasIOSurface()) |
| 1238 return; | 1315 return; |
| 1239 | 1316 |
| 1240 if (!target.get()) { | 1317 if (!target.get()) { |
| 1241 NOTREACHED(); | 1318 NOTREACHED(); |
| 1242 return; | 1319 return; |
| 1243 } | 1320 } |
| 1244 | 1321 |
| 1245 if (target->format() != media::VideoFrame::YV12 && | 1322 if (target->format() != media::VideoFrame::YV12 && |
| 1246 target->format() != media::VideoFrame::I420) { | 1323 target->format() != media::VideoFrame::I420) { |
| 1247 NOTREACHED(); | 1324 NOTREACHED(); |
| 1248 return; | 1325 return; |
| 1249 } | 1326 } |
| 1250 | 1327 |
| 1251 if (src_subrect.IsEmpty()) | 1328 if (src_subrect.IsEmpty()) |
| 1252 return; | 1329 return; |
| 1253 | 1330 |
| 1254 ignore_result(scoped_callback_runner.Release()); | 1331 ignore_result(scoped_callback_runner.Release()); |
| 1255 compositing_iosurface_->CopyToVideoFrame( | 1332 compositing_iosurface_->CopyToVideoFrame( |
| 1256 GetScaledOpenGLPixelRect(src_subrect), | 1333 GetScaledOpenGLPixelRect(src_subrect), |
| 1257 target, | 1334 target, |
| 1258 callback); | 1335 callback); |
| 1259 } | 1336 } |
| 1260 | 1337 |
| 1261 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { | 1338 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { |
| 1339 if (delegated_frame_host_) |
| 1340 return delegated_frame_host_->CanCopyToVideoFrame(); |
| 1341 |
| 1262 return (!software_frame_manager_->HasCurrentFrame() && | 1342 return (!software_frame_manager_->HasCurrentFrame() && |
| 1263 render_widget_host_->is_accelerated_compositing_active() && | 1343 render_widget_host_->is_accelerated_compositing_active() && |
| 1264 compositing_iosurface_ && | 1344 compositing_iosurface_ && |
| 1265 compositing_iosurface_->HasIOSurface()); | 1345 compositing_iosurface_->HasIOSurface()); |
| 1266 } | 1346 } |
| 1267 | 1347 |
| 1268 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { | 1348 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { |
| 1349 if (delegated_frame_host_) |
| 1350 return delegated_frame_host_->CanSubscribeFrame(); |
| 1351 |
| 1269 return !software_frame_manager_->HasCurrentFrame(); | 1352 return !software_frame_manager_->HasCurrentFrame(); |
| 1270 } | 1353 } |
| 1271 | 1354 |
| 1272 void RenderWidgetHostViewMac::BeginFrameSubscription( | 1355 void RenderWidgetHostViewMac::BeginFrameSubscription( |
| 1273 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1356 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
| 1357 if (delegated_frame_host_) { |
| 1358 delegated_frame_host_->BeginFrameSubscription(subscriber.Pass()); |
| 1359 return; |
| 1360 } |
| 1274 frame_subscriber_ = subscriber.Pass(); | 1361 frame_subscriber_ = subscriber.Pass(); |
| 1275 } | 1362 } |
| 1276 | 1363 |
| 1277 void RenderWidgetHostViewMac::EndFrameSubscription() { | 1364 void RenderWidgetHostViewMac::EndFrameSubscription() { |
| 1365 if (delegated_frame_host_) { |
| 1366 delegated_frame_host_->EndFrameSubscription(); |
| 1367 return; |
| 1368 } |
| 1369 |
| 1278 frame_subscriber_.reset(); | 1370 frame_subscriber_.reset(); |
| 1279 } | 1371 } |
| 1280 | 1372 |
| 1281 // Sets whether or not to accept first responder status. | 1373 // Sets whether or not to accept first responder status. |
| 1282 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { | 1374 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { |
| 1283 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; | 1375 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; |
| 1284 } | 1376 } |
| 1285 | 1377 |
| 1286 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { | 1378 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { |
| 1287 if (render_widget_host_) | 1379 if (render_widget_host_) |
| (...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1799 return (software_frame_manager_->HasCurrentFrame() && | 1891 return (software_frame_manager_->HasCurrentFrame() && |
| 1800 (desired_size.IsEmpty() || | 1892 (desired_size.IsEmpty() || |
| 1801 software_frame_manager_->GetCurrentFrameSizeInDIP() == | 1893 software_frame_manager_->GetCurrentFrameSizeInDIP() == |
| 1802 desired_size)); | 1894 desired_size)); |
| 1803 } | 1895 } |
| 1804 return false; | 1896 return false; |
| 1805 } | 1897 } |
| 1806 | 1898 |
| 1807 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1899 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
| 1808 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1900 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
| 1809 // Only software compositor frames are accepted. | 1901 if (frame->delegated_frame_data) { |
| 1810 if (!frame->software_frame_data) { | 1902 if (!compositor_) { |
| 1903 compositor_.reset(new ui::Compositor(cocoa_view_)); |
| 1904 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); |
| 1905 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
| 1906 } |
| 1907 |
| 1908 // TODO(ccameron): Having the root layer set while swapping the frame will |
| 1909 // result in frames not appearing. Fix this. |
| 1910 compositor_->SetRootLayer(NULL); |
| 1911 delegated_frame_host_->SwapDelegatedFrame( |
| 1912 output_surface_id, |
| 1913 frame->delegated_frame_data.Pass(), |
| 1914 frame->metadata.device_scale_factor, |
| 1915 frame->metadata.latency_info); |
| 1916 gfx::Size size = ToCeiledSize(frame->metadata.viewport_size); |
| 1917 float scale_factor = frame->metadata.device_scale_factor; |
| 1918 if (compositor_->size() != size || |
| 1919 compositor_->device_scale_factor() != scale_factor) { |
| 1920 // TODO(ccameron): The scale factor here does not result in the |
| 1921 // composited frame that is received having the right scale factor. Fix |
| 1922 // this. |
| 1923 compositor_->SetScaleAndSize(scale_factor, size); |
| 1924 root_layer_->SetBounds(gfx::Rect(size)); |
| 1925 } |
| 1926 compositor_->SetRootLayer(root_layer_.get()); |
| 1927 } else if (frame->software_frame_data) { |
| 1928 if (!software_frame_manager_->SwapToNewFrame( |
| 1929 output_surface_id, |
| 1930 frame->software_frame_data.get(), |
| 1931 frame->metadata.device_scale_factor, |
| 1932 render_widget_host_->GetProcess()->GetHandle())) { |
| 1933 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
| 1934 return; |
| 1935 } |
| 1936 |
| 1937 // Add latency info to report when the frame finishes drawing. |
| 1938 AddPendingLatencyInfo(frame->metadata.latency_info); |
| 1939 GotSoftwareFrame(); |
| 1940 |
| 1941 cc::CompositorFrameAck ack; |
| 1942 RenderWidgetHostImpl::SendSwapCompositorFrameAck( |
| 1943 render_widget_host_->GetRoutingID(), |
| 1944 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), |
| 1945 render_widget_host_->GetProcess()->GetID(), |
| 1946 ack); |
| 1947 software_frame_manager_->SwapToNewFrameComplete( |
| 1948 !render_widget_host_->is_hidden()); |
| 1949 |
| 1950 // Notify observers, tab capture observers in particular, that a new |
| 1951 // software frame has come in. |
| 1952 NotificationService::current()->Notify( |
| 1953 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, |
| 1954 Source<RenderWidgetHost>(render_widget_host_), |
| 1955 NotificationService::NoDetails()); |
| 1956 } else { |
| 1811 DLOG(ERROR) << "Received unexpected frame type."; | 1957 DLOG(ERROR) << "Received unexpected frame type."; |
| 1812 RecordAction( | 1958 RecordAction( |
| 1813 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); | 1959 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); |
| 1814 render_widget_host_->GetProcess()->ReceivedBadMessage(); | 1960 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
| 1815 return; | |
| 1816 } | 1961 } |
| 1817 | |
| 1818 if (!software_frame_manager_->SwapToNewFrame( | |
| 1819 output_surface_id, | |
| 1820 frame->software_frame_data.get(), | |
| 1821 frame->metadata.device_scale_factor, | |
| 1822 render_widget_host_->GetProcess()->GetHandle())) { | |
| 1823 render_widget_host_->GetProcess()->ReceivedBadMessage(); | |
| 1824 return; | |
| 1825 } | |
| 1826 | |
| 1827 // Add latency info to report when the frame finishes drawing. | |
| 1828 AddPendingLatencyInfo(frame->metadata.latency_info); | |
| 1829 GotSoftwareFrame(); | |
| 1830 | |
| 1831 cc::CompositorFrameAck ack; | |
| 1832 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
| 1833 render_widget_host_->GetRoutingID(), | |
| 1834 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), | |
| 1835 render_widget_host_->GetProcess()->GetID(), | |
| 1836 ack); | |
| 1837 software_frame_manager_->SwapToNewFrameComplete( | |
| 1838 !render_widget_host_->is_hidden()); | |
| 1839 | |
| 1840 // Notify observers, tab capture observers in particular, that a new software | |
| 1841 // frame has come in. | |
| 1842 NotificationService::current()->Notify( | |
| 1843 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | |
| 1844 Source<RenderWidgetHost>(render_widget_host_), | |
| 1845 NotificationService::NoDetails()); | |
| 1846 } | 1962 } |
| 1847 | 1963 |
| 1848 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { | 1964 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { |
| 1849 } | 1965 } |
| 1850 | 1966 |
| 1851 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, | 1967 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, |
| 1852 int route_id) { | 1968 int route_id) { |
| 1853 } | 1969 } |
| 1854 | 1970 |
| 1855 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { | 1971 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { |
| (...skipping 1279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3135 if (!renderWidgetHostView_->render_widget_host_) | 3251 if (!renderWidgetHostView_->render_widget_host_) |
| 3136 return; | 3252 return; |
| 3137 | 3253 |
| 3138 // Move the CALayers to their positions in the new view size. Note that | 3254 // Move the CALayers to their positions in the new view size. Note that |
| 3139 // this will not draw anything because the non-background layers' sizes | 3255 // this will not draw anything because the non-background layers' sizes |
| 3140 // didn't actually change. | 3256 // didn't actually change. |
| 3141 renderWidgetHostView_->LayoutLayers(); | 3257 renderWidgetHostView_->LayoutLayers(); |
| 3142 | 3258 |
| 3143 renderWidgetHostView_->render_widget_host_->SendScreenRects(); | 3259 renderWidgetHostView_->render_widget_host_->SendScreenRects(); |
| 3144 renderWidgetHostView_->render_widget_host_->WasResized(); | 3260 renderWidgetHostView_->render_widget_host_->WasResized(); |
| 3261 if (renderWidgetHostView_->delegated_frame_host_) |
| 3262 renderWidgetHostView_->delegated_frame_host_->WasResized(); |
| 3145 | 3263 |
| 3146 // Wait for the frame that WasResize might have requested. If the view is | 3264 // Wait for the frame that WasResize might have requested. If the view is |
| 3147 // being made visible at a new size, then this call will have no effect | 3265 // being made visible at a new size, then this call will have no effect |
| 3148 // because the view widget is still hidden, and the pause call in WasShown | 3266 // because the view widget is still hidden, and the pause call in WasShown |
| 3149 // will have this effect for us. | 3267 // will have this effect for us. |
| 3150 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); | 3268 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); |
| 3151 } | 3269 } |
| 3152 | 3270 |
| 3153 // Fills with white the parts of the area to the right and bottom for |rect| | 3271 // Fills with white the parts of the area to the right and bottom for |rect| |
| 3154 // that intersect |damagedRect|. | 3272 // that intersect |damagedRect|. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3194 height = -height; | 3312 height = -height; |
| 3195 } | 3313 } |
| 3196 | 3314 |
| 3197 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 3315 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
| 3198 CGContextSetFillColorWithColor(context, | 3316 CGContextSetFillColorWithColor(context, |
| 3199 CGColorGetConstantColor(kCGColorWhite)); | 3317 CGColorGetConstantColor(kCGColorWhite)); |
| 3200 CGContextFillRect(context, NSRectToCGRect(r)); | 3318 CGContextFillRect(context, NSRectToCGRect(r)); |
| 3201 } | 3319 } |
| 3202 } | 3320 } |
| 3203 | 3321 |
| 3322 - (void)onNativeSurfaceBuffersSwappedWithParams: |
| 3323 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { |
| 3324 |
| 3325 renderWidgetHostView_->CompositorSwapBuffers( |
| 3326 params.surface_handle, |
| 3327 params.size, |
| 3328 params.scale_factor, |
| 3329 params.latency_info); |
| 3330 } |
| 3331 |
| 3204 - (void)drawRect:(NSRect)dirtyRect { | 3332 - (void)drawRect:(NSRect)dirtyRect { |
| 3205 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); | 3333 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
| 3206 DCHECK(!renderWidgetHostView_->use_core_animation_); | 3334 DCHECK(!renderWidgetHostView_->use_core_animation_); |
| 3207 | 3335 |
| 3208 if (!renderWidgetHostView_->render_widget_host_) { | 3336 if (!renderWidgetHostView_->render_widget_host_) { |
| 3209 // When using CoreAnimation, this path is used to paint the contents area | 3337 // When using CoreAnimation, this path is used to paint the contents area |
| 3210 // white before any frames come in. When layers to draw frames exist, this | 3338 // white before any frames come in. When layers to draw frames exist, this |
| 3211 // is not hit. | 3339 // is not hit. |
| 3212 [[NSColor whiteColor] set]; | 3340 [[NSColor whiteColor] set]; |
| 3213 NSRectFill(dirtyRect); | 3341 NSRectFill(dirtyRect); |
| (...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4307 } | 4435 } |
| 4308 | 4436 |
| 4309 - (void)disableRendering { | 4437 - (void)disableRendering { |
| 4310 // Disable the fade-out animation as the layer is removed. | 4438 // Disable the fade-out animation as the layer is removed. |
| 4311 ScopedCAActionDisabler disabler; | 4439 ScopedCAActionDisabler disabler; |
| 4312 [self removeFromSuperlayer]; | 4440 [self removeFromSuperlayer]; |
| 4313 renderWidgetHostView_ = nil; | 4441 renderWidgetHostView_ = nil; |
| 4314 } | 4442 } |
| 4315 | 4443 |
| 4316 @end // implementation SoftwareLayer | 4444 @end // implementation SoftwareLayer |
| OLD | NEW |