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/port/browser/render_widget_host_view_frame_subscriber.h" | 48 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
47 #include "content/public/browser/browser_thread.h" | 49 #include "content/public/browser/browser_thread.h" |
48 #include "content/public/browser/native_web_keyboard_event.h" | 50 #include "content/public/browser/native_web_keyboard_event.h" |
49 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
50 #include "content/public/browser/notification_types.h" | 52 #include "content/public/browser/notification_types.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 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 base::scoped_nsobject<CompositingIOSurfaceLayer> layer) { | 389 base::scoped_nsobject<CompositingIOSurfaceLayer> layer) { |
386 // Disable the fade-out animation as the layer is removed. | 390 // Disable the fade-out animation as the layer is removed. |
387 ScopedCAActionDisabler disabler; | 391 ScopedCAActionDisabler disabler; |
388 [layer removeFromSuperlayer]; | 392 [layer removeFromSuperlayer]; |
389 } | 393 } |
390 | 394 |
391 } // namespace | 395 } // namespace |
392 | 396 |
393 namespace content { | 397 namespace content { |
394 | 398 |
399 //////////////////////////////////////////////////////////////////////////////// | |
400 // DelegatedFrameHost, public: | |
401 | |
402 ui::Compositor* RenderWidgetHostViewMac::GetCompositor() const { | |
403 return compositor_.get(); | |
404 } | |
405 | |
406 ui::Layer* RenderWidgetHostViewMac::GetLayer() { | |
407 return root_layer_.get(); | |
408 } | |
409 | |
410 RenderWidgetHostImpl* RenderWidgetHostViewMac::GetHost() { | |
411 return render_widget_host_; | |
412 } | |
413 | |
414 void RenderWidgetHostViewMac::SchedulePaintInRect( | |
415 const gfx::Rect& damage_rect_in_dip) { | |
416 compositor_->ScheduleFullRedraw(); | |
417 } | |
418 | |
419 bool RenderWidgetHostViewMac::IsVisible() { | |
420 return !render_widget_host_->is_hidden(); | |
421 } | |
422 | |
423 gfx::Size RenderWidgetHostViewMac::DesiredFrameSize() { | |
424 return GetViewBounds().size(); | |
425 } | |
426 | |
427 float RenderWidgetHostViewMac::CurrentDeviceScaleFactor() { | |
428 return ViewScaleFactor(); | |
429 } | |
430 | |
431 gfx::Size RenderWidgetHostViewMac::ConvertViewSizeToPixel( | |
432 const gfx::Size& size) { | |
433 return gfx::ToEnclosingRect(gfx::ScaleRect(gfx::Rect(size), | |
434 ViewScaleFactor())).size(); | |
435 } | |
436 | |
437 scoped_ptr<ResizeLock> RenderWidgetHostViewMac::CreateResizeLock( | |
438 bool defer_compositor_lock) { | |
439 NOTREACHED(); | |
440 ResizeLock* lock = NULL; | |
441 return scoped_ptr<ResizeLock>(lock); | |
442 } | |
443 | |
444 DelegatedFrameHost* RenderWidgetHostViewMac::GetDelegatedFrameHost() const { | |
445 return delegated_frame_host_.get(); | |
446 } | |
447 | |
395 /////////////////////////////////////////////////////////////////////////////// | 448 /////////////////////////////////////////////////////////////////////////////// |
396 // RenderWidgetHostViewBase, public: | 449 // RenderWidgetHostViewBase, public: |
397 | 450 |
398 // static | 451 // static |
399 void RenderWidgetHostViewBase::GetDefaultScreenInfo( | 452 void RenderWidgetHostViewBase::GetDefaultScreenInfo( |
400 blink::WebScreenInfo* results) { | 453 blink::WebScreenInfo* results) { |
401 *results = GetWebScreenInfo(NULL); | 454 *results = GetWebScreenInfo(NULL); |
402 } | 455 } |
403 | 456 |
404 /////////////////////////////////////////////////////////////////////////////// | 457 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
441 } | 494 } |
442 | 495 |
443 render_widget_host_->SetView(this); | 496 render_widget_host_->SetView(this); |
444 } | 497 } |
445 | 498 |
446 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 499 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
447 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 500 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
448 // pointer. | 501 // pointer. |
449 cocoa_view_ = nil; | 502 cocoa_view_ = nil; |
450 | 503 |
504 // Delete the delegated frame state. | |
505 delegated_frame_host_.reset(); | |
506 compositor_.reset(); | |
507 root_layer_.reset(); | |
508 | |
451 UnlockMouse(); | 509 UnlockMouse(); |
452 | 510 |
453 // Make sure that the layer doesn't reach into the now-invalid object. | 511 // Make sure that the layer doesn't reach into the now-invalid object. |
454 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); | 512 DestroyCompositedIOSurfaceAndLayer(kDestroyContext); |
455 DestroySoftwareLayer(); | 513 DestroySoftwareLayer(); |
456 | 514 |
457 // We are owned by RenderWidgetHostViewCocoa, so if we go away before the | 515 // 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 | 516 // RenderWidgetHost does we need to tell it not to hold a stale pointer to |
459 // us. | 517 // us. |
460 if (render_widget_host_) | 518 if (render_widget_host_) |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
788 } | 846 } |
789 | 847 |
790 void RenderWidgetHostViewMac::WasShown() { | 848 void RenderWidgetHostViewMac::WasShown() { |
791 if (!render_widget_host_->is_hidden()) | 849 if (!render_widget_host_->is_hidden()) |
792 return; | 850 return; |
793 | 851 |
794 if (web_contents_switch_paint_time_.is_null()) | 852 if (web_contents_switch_paint_time_.is_null()) |
795 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 853 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
796 render_widget_host_->WasShown(); | 854 render_widget_host_->WasShown(); |
797 software_frame_manager_->SetVisibility(true); | 855 software_frame_manager_->SetVisibility(true); |
856 if (delegated_frame_host_) | |
857 delegated_frame_host_->WasShown(); | |
798 | 858 |
799 // Call setNeedsDisplay before pausing for new frames to come in -- if any | 859 // Call setNeedsDisplay before pausing for new frames to come in -- if any |
800 // do, and are drawn, then the needsDisplay bit will be cleared. | 860 // do, and are drawn, then the needsDisplay bit will be cleared. |
801 [software_layer_ setNeedsDisplay]; | 861 [software_layer_ setNeedsDisplay]; |
802 [compositing_iosurface_layer_ setNeedsDisplay]; | 862 [compositing_iosurface_layer_ setNeedsDisplay]; |
803 PauseForPendingResizeOrRepaintsAndDraw(); | 863 PauseForPendingResizeOrRepaintsAndDraw(); |
804 | 864 |
805 // We're messing with the window, so do this to ensure no flashes. | 865 // We're messing with the window, so do this to ensure no flashes. |
806 if (!use_core_animation_) | 866 if (!use_core_animation_) |
807 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 867 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
808 } | 868 } |
809 | 869 |
810 void RenderWidgetHostViewMac::WasHidden() { | 870 void RenderWidgetHostViewMac::WasHidden() { |
811 if (render_widget_host_->is_hidden()) | 871 if (render_widget_host_->is_hidden()) |
812 return; | 872 return; |
813 | 873 |
814 // Any pending frames will not be displayed until this is shown again. Ack | 874 // Any pending frames will not be displayed until this is shown again. Ack |
815 // them now. | 875 // them now. |
816 SendPendingSwapAck(); | 876 SendPendingSwapAck(); |
817 | 877 |
818 // If we have a renderer, then inform it that we are being hidden so it can | 878 // If we have a renderer, then inform it that we are being hidden so it can |
819 // reduce its resource utilization. | 879 // reduce its resource utilization. |
820 render_widget_host_->WasHidden(); | 880 render_widget_host_->WasHidden(); |
821 software_frame_manager_->SetVisibility(false); | 881 software_frame_manager_->SetVisibility(false); |
882 if (delegated_frame_host_) | |
883 delegated_frame_host_->WasHidden(); | |
822 | 884 |
823 // There can be a transparent flash as this view is removed and the next is | 885 // 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 | 886 // added, because of OSX windowing races between displaying the contents of |
825 // the NSView and its corresponding OpenGL context. | 887 // the NSView and its corresponding OpenGL context. |
826 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding | 888 // disableScreenUpdatesUntilFlush prevents the transparent flash by avoiding |
827 // screen updates until the next tab draws. | 889 // screen updates until the next tab draws. |
828 if (!use_core_animation_) | 890 if (!use_core_animation_) |
829 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 891 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
830 | 892 |
831 web_contents_switch_paint_time_ = base::TimeTicks(); | 893 web_contents_switch_paint_time_ = base::TimeTicks(); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
913 void RenderWidgetHostViewMac::Blur() { | 975 void RenderWidgetHostViewMac::Blur() { |
914 UnlockMouse(); | 976 UnlockMouse(); |
915 [[cocoa_view_ window] makeFirstResponder:nil]; | 977 [[cocoa_view_ window] makeFirstResponder:nil]; |
916 } | 978 } |
917 | 979 |
918 bool RenderWidgetHostViewMac::HasFocus() const { | 980 bool RenderWidgetHostViewMac::HasFocus() const { |
919 return [[cocoa_view_ window] firstResponder] == cocoa_view_; | 981 return [[cocoa_view_ window] firstResponder] == cocoa_view_; |
920 } | 982 } |
921 | 983 |
922 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { | 984 bool RenderWidgetHostViewMac::IsSurfaceAvailableForCopy() const { |
985 if (delegated_frame_host_) | |
986 return delegated_frame_host_->CanCopyToBitmap(); | |
987 | |
923 return software_frame_manager_->HasCurrentFrame() || | 988 return software_frame_manager_->HasCurrentFrame() || |
924 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); | 989 (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()); |
925 } | 990 } |
926 | 991 |
927 void RenderWidgetHostViewMac::Show() { | 992 void RenderWidgetHostViewMac::Show() { |
928 [cocoa_view_ setHidden:NO]; | 993 [cocoa_view_ setHidden:NO]; |
929 | 994 |
930 WasShown(); | 995 WasShown(); |
931 } | 996 } |
932 | 997 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1153 | 1218 |
1154 bool RenderWidgetHostViewMac::IsPopup() const { | 1219 bool RenderWidgetHostViewMac::IsPopup() const { |
1155 return popup_type_ != blink::WebPopupTypeNone; | 1220 return popup_type_ != blink::WebPopupTypeNone; |
1156 } | 1221 } |
1157 | 1222 |
1158 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 1223 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
1159 const gfx::Rect& src_subrect, | 1224 const gfx::Rect& src_subrect, |
1160 const gfx::Size& dst_size, | 1225 const gfx::Size& dst_size, |
1161 const base::Callback<void(bool, const SkBitmap&)>& callback, | 1226 const base::Callback<void(bool, const SkBitmap&)>& callback, |
1162 const SkBitmap::Config config) { | 1227 const SkBitmap::Config config) { |
1228 if (delegated_frame_host_) { | |
1229 delegated_frame_host_->CopyFromCompositingSurface( | |
1230 src_subrect, dst_size, callback, config); | |
1231 return; | |
1232 } | |
1233 | |
1163 if (config != SkBitmap::kARGB_8888_Config) { | 1234 if (config != SkBitmap::kARGB_8888_Config) { |
1164 NOTIMPLEMENTED(); | 1235 NOTIMPLEMENTED(); |
1165 callback.Run(false, SkBitmap()); | 1236 callback.Run(false, SkBitmap()); |
1166 } | 1237 } |
1167 base::ScopedClosureRunner scoped_callback_runner( | 1238 base::ScopedClosureRunner scoped_callback_runner( |
1168 base::Bind(callback, false, SkBitmap())); | 1239 base::Bind(callback, false, SkBitmap())); |
1169 float scale = ScaleFactorForView(cocoa_view_); | 1240 float scale = ScaleFactorForView(cocoa_view_); |
1170 gfx::Size dst_pixel_size = gfx::ToFlooredSize( | 1241 gfx::Size dst_pixel_size = gfx::ToFlooredSize( |
1171 gfx::ScaleSize(dst_size, scale)); | 1242 gfx::ScaleSize(dst_size, scale)); |
1172 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { | 1243 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1210 | 1281 |
1211 ignore_result(scoped_callback_runner.Release()); | 1282 ignore_result(scoped_callback_runner.Release()); |
1212 callback.Run(true, target_bitmap); | 1283 callback.Run(true, target_bitmap); |
1213 } | 1284 } |
1214 } | 1285 } |
1215 | 1286 |
1216 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( | 1287 void RenderWidgetHostViewMac::CopyFromCompositingSurfaceToVideoFrame( |
1217 const gfx::Rect& src_subrect, | 1288 const gfx::Rect& src_subrect, |
1218 const scoped_refptr<media::VideoFrame>& target, | 1289 const scoped_refptr<media::VideoFrame>& target, |
1219 const base::Callback<void(bool)>& callback) { | 1290 const base::Callback<void(bool)>& callback) { |
1291 if (delegated_frame_host_) { | |
1292 delegated_frame_host_->CopyFromCompositingSurfaceToVideoFrame( | |
1293 src_subrect, target, callback); | |
1294 return; | |
1295 } | |
1296 | |
1220 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 1297 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
1221 if (!render_widget_host_->is_accelerated_compositing_active() || | 1298 if (!render_widget_host_->is_accelerated_compositing_active() || |
1222 !compositing_iosurface_ || | 1299 !compositing_iosurface_ || |
1223 !compositing_iosurface_->HasIOSurface()) | 1300 !compositing_iosurface_->HasIOSurface()) |
1224 return; | 1301 return; |
1225 | 1302 |
1226 if (!target.get()) { | 1303 if (!target.get()) { |
1227 NOTREACHED(); | 1304 NOTREACHED(); |
1228 return; | 1305 return; |
1229 } | 1306 } |
1230 | 1307 |
1231 if (target->format() != media::VideoFrame::YV12 && | 1308 if (target->format() != media::VideoFrame::YV12 && |
1232 target->format() != media::VideoFrame::I420) { | 1309 target->format() != media::VideoFrame::I420) { |
1233 NOTREACHED(); | 1310 NOTREACHED(); |
1234 return; | 1311 return; |
1235 } | 1312 } |
1236 | 1313 |
1237 if (src_subrect.IsEmpty()) | 1314 if (src_subrect.IsEmpty()) |
1238 return; | 1315 return; |
1239 | 1316 |
1240 ignore_result(scoped_callback_runner.Release()); | 1317 ignore_result(scoped_callback_runner.Release()); |
1241 compositing_iosurface_->CopyToVideoFrame( | 1318 compositing_iosurface_->CopyToVideoFrame( |
1242 GetScaledOpenGLPixelRect(src_subrect), | 1319 GetScaledOpenGLPixelRect(src_subrect), |
1243 target, | 1320 target, |
1244 callback); | 1321 callback); |
1245 } | 1322 } |
1246 | 1323 |
1247 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { | 1324 bool RenderWidgetHostViewMac::CanCopyToVideoFrame() const { |
1325 if (delegated_frame_host_) | |
1326 return delegated_frame_host_->CanCopyToVideoFrame(); | |
1327 | |
1248 return (!software_frame_manager_->HasCurrentFrame() && | 1328 return (!software_frame_manager_->HasCurrentFrame() && |
1249 render_widget_host_->is_accelerated_compositing_active() && | 1329 render_widget_host_->is_accelerated_compositing_active() && |
1250 compositing_iosurface_ && | 1330 compositing_iosurface_ && |
1251 compositing_iosurface_->HasIOSurface()); | 1331 compositing_iosurface_->HasIOSurface()); |
1252 } | 1332 } |
1253 | 1333 |
1254 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { | 1334 bool RenderWidgetHostViewMac::CanSubscribeFrame() const { |
1335 if (delegated_frame_host_) | |
1336 return delegated_frame_host_->CanSubscribeFrame(); | |
1337 | |
1255 return !software_frame_manager_->HasCurrentFrame(); | 1338 return !software_frame_manager_->HasCurrentFrame(); |
1256 } | 1339 } |
1257 | 1340 |
1258 void RenderWidgetHostViewMac::BeginFrameSubscription( | 1341 void RenderWidgetHostViewMac::BeginFrameSubscription( |
1259 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { | 1342 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) { |
1343 if (delegated_frame_host_) { | |
1344 delegated_frame_host_->BeginFrameSubscription(subscriber.Pass()); | |
1345 return; | |
1346 } | |
1260 frame_subscriber_ = subscriber.Pass(); | 1347 frame_subscriber_ = subscriber.Pass(); |
1261 } | 1348 } |
1262 | 1349 |
1263 void RenderWidgetHostViewMac::EndFrameSubscription() { | 1350 void RenderWidgetHostViewMac::EndFrameSubscription() { |
1351 if (delegated_frame_host_) { | |
1352 delegated_frame_host_->EndFrameSubscription(); | |
1353 return; | |
1354 } | |
1355 | |
1264 frame_subscriber_.reset(); | 1356 frame_subscriber_.reset(); |
1265 } | 1357 } |
1266 | 1358 |
1267 // Sets whether or not to accept first responder status. | 1359 // Sets whether or not to accept first responder status. |
1268 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { | 1360 void RenderWidgetHostViewMac::SetTakesFocusOnlyOnMouseDown(bool flag) { |
1269 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; | 1361 [cocoa_view_ setTakesFocusOnlyOnMouseDown:flag]; |
1270 } | 1362 } |
1271 | 1363 |
1272 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { | 1364 void RenderWidgetHostViewMac::ForwardMouseEvent(const WebMouseEvent& event) { |
1273 if (render_widget_host_) | 1365 if (render_widget_host_) |
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1771 return (software_frame_manager_->HasCurrentFrame() && | 1863 return (software_frame_manager_->HasCurrentFrame() && |
1772 (desired_size.IsEmpty() || | 1864 (desired_size.IsEmpty() || |
1773 software_frame_manager_->GetCurrentFrameSizeInDIP() == | 1865 software_frame_manager_->GetCurrentFrameSizeInDIP() == |
1774 desired_size)); | 1866 desired_size)); |
1775 } | 1867 } |
1776 return false; | 1868 return false; |
1777 } | 1869 } |
1778 | 1870 |
1779 void RenderWidgetHostViewMac::OnSwapCompositorFrame( | 1871 void RenderWidgetHostViewMac::OnSwapCompositorFrame( |
1780 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { | 1872 uint32 output_surface_id, scoped_ptr<cc::CompositorFrame> frame) { |
1781 // Only software compositor frames are accepted. | 1873 if (frame->delegated_frame_data) { |
1782 if (!frame->software_frame_data) { | 1874 if (!compositor_) { |
1875 compositor_.reset(new ui::Compositor(cocoa_view_)); | |
1876 root_layer_.reset(new ui::Layer(ui::LAYER_TEXTURED)); | |
1877 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | |
1878 } | |
1879 | |
1880 // TODO(ccameron): Having the root layer set while swapping the frame will | |
1881 // result in frames not appearing. Fix this. | |
1882 compositor_->SetRootLayer(nil); | |
piman
2014/05/07 00:32:55
nit: nil? NULL?
ccameron
2014/05/07 00:37:48
Changed to NULL (oops - nil is for Objective C ids
| |
1883 delegated_frame_host_->SwapDelegatedFrame( | |
1884 output_surface_id, | |
1885 frame->delegated_frame_data.Pass(), | |
1886 frame->metadata.device_scale_factor, | |
1887 frame->metadata.latency_info); | |
1888 gfx::Size size = ToCeiledSize(frame->metadata.viewport_size); | |
1889 float scale_factor = frame->metadata.device_scale_factor; | |
1890 if (compositor_->size() != size || | |
1891 compositor_->device_scale_factor() != scale_factor) { | |
1892 // TODO(ccameron): The scale factor here does not result in the | |
1893 // composited frame that is recieved having the right scale factor. Fix | |
piman
2014/05/07 00:32:55
nit: received
ccameron
2014/05/07 00:37:48
Done.
| |
1894 // this. | |
1895 compositor_->SetScaleAndSize(scale_factor, size); | |
1896 root_layer_->SetBounds(gfx::Rect(size)); | |
1897 } | |
1898 compositor_->SetRootLayer(root_layer_.get()); | |
1899 } else if (frame->software_frame_data) { | |
1900 if (!software_frame_manager_->SwapToNewFrame( | |
1901 output_surface_id, | |
1902 frame->software_frame_data.get(), | |
1903 frame->metadata.device_scale_factor, | |
1904 render_widget_host_->GetProcess()->GetHandle())) { | |
1905 render_widget_host_->GetProcess()->ReceivedBadMessage(); | |
1906 return; | |
1907 } | |
1908 | |
1909 // Add latency info to report when the frame finishes drawing. | |
1910 AddPendingLatencyInfo(frame->metadata.latency_info); | |
1911 GotSoftwareFrame(); | |
1912 | |
1913 cc::CompositorFrameAck ack; | |
1914 RenderWidgetHostImpl::SendSwapCompositorFrameAck( | |
1915 render_widget_host_->GetRoutingID(), | |
1916 software_frame_manager_->GetCurrentFrameOutputSurfaceId(), | |
1917 render_widget_host_->GetProcess()->GetID(), | |
1918 ack); | |
1919 software_frame_manager_->SwapToNewFrameComplete( | |
1920 !render_widget_host_->is_hidden()); | |
1921 | |
1922 // Notify observers, tab capture observers in particular, that a new | |
1923 // software frame has come in. | |
1924 NotificationService::current()->Notify( | |
1925 NOTIFICATION_RENDER_WIDGET_HOST_DID_UPDATE_BACKING_STORE, | |
1926 Source<RenderWidgetHost>(render_widget_host_), | |
1927 NotificationService::NoDetails()); | |
1928 } else { | |
1783 DLOG(ERROR) << "Received unexpected frame type."; | 1929 DLOG(ERROR) << "Received unexpected frame type."; |
1784 RecordAction( | 1930 RecordAction( |
1785 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); | 1931 base::UserMetricsAction("BadMessageTerminate_UnexpectedFrameType")); |
1786 render_widget_host_->GetProcess()->ReceivedBadMessage(); | 1932 render_widget_host_->GetProcess()->ReceivedBadMessage(); |
1787 return; | |
1788 } | 1933 } |
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 } | 1934 } |
1819 | 1935 |
1820 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { | 1936 void RenderWidgetHostViewMac::OnAcceleratedCompositingStateChange() { |
1821 } | 1937 } |
1822 | 1938 |
1823 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, | 1939 void RenderWidgetHostViewMac::AcceleratedSurfaceInitialized(int host_id, |
1824 int route_id) { | 1940 int route_id) { |
1825 } | 1941 } |
1826 | 1942 |
1827 void RenderWidgetHostViewMac::GetScreenInfo(blink::WebScreenInfo* results) { | 1943 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_) | 3223 if (!renderWidgetHostView_->render_widget_host_) |
3108 return; | 3224 return; |
3109 | 3225 |
3110 // Move the CALayers to their positions in the new view size. Note that | 3226 // 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 | 3227 // this will not draw anything because the non-background layers' sizes |
3112 // didn't actually change. | 3228 // didn't actually change. |
3113 renderWidgetHostView_->LayoutLayers(); | 3229 renderWidgetHostView_->LayoutLayers(); |
3114 | 3230 |
3115 renderWidgetHostView_->render_widget_host_->SendScreenRects(); | 3231 renderWidgetHostView_->render_widget_host_->SendScreenRects(); |
3116 renderWidgetHostView_->render_widget_host_->WasResized(); | 3232 renderWidgetHostView_->render_widget_host_->WasResized(); |
3233 if (renderWidgetHostView_->delegated_frame_host_) | |
3234 renderWidgetHostView_->delegated_frame_host_->WasResized(); | |
3117 | 3235 |
3118 // Wait for the frame that WasResize might have requested. If the view is | 3236 // 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 | 3237 // 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 | 3238 // because the view widget is still hidden, and the pause call in WasShown |
3121 // will have this effect for us. | 3239 // will have this effect for us. |
3122 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); | 3240 renderWidgetHostView_->PauseForPendingResizeOrRepaintsAndDraw(); |
3123 } | 3241 } |
3124 | 3242 |
3125 // Fills with white the parts of the area to the right and bottom for |rect| | 3243 // Fills with white the parts of the area to the right and bottom for |rect| |
3126 // that intersect |damagedRect|. | 3244 // that intersect |damagedRect|. |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3166 height = -height; | 3284 height = -height; |
3167 } | 3285 } |
3168 | 3286 |
3169 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; | 3287 NSRect r = [self flipRectToNSRect:gfx::Rect(x, y, width, height)]; |
3170 CGContextSetFillColorWithColor(context, | 3288 CGContextSetFillColorWithColor(context, |
3171 CGColorGetConstantColor(kCGColorWhite)); | 3289 CGColorGetConstantColor(kCGColorWhite)); |
3172 CGContextFillRect(context, NSRectToCGRect(r)); | 3290 CGContextFillRect(context, NSRectToCGRect(r)); |
3173 } | 3291 } |
3174 } | 3292 } |
3175 | 3293 |
3294 - (void)onNativeSurfaceBuffersSwappedWithParams: | |
3295 (GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params)params { | |
3296 | |
3297 renderWidgetHostView_->CompositorSwapBuffers( | |
3298 params.surface_handle, | |
3299 params.size, | |
3300 params.scale_factor, | |
3301 params.latency_info); | |
3302 } | |
3303 | |
3176 - (void)drawRect:(NSRect)dirtyRect { | 3304 - (void)drawRect:(NSRect)dirtyRect { |
3177 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); | 3305 TRACE_EVENT0("browser", "RenderWidgetHostViewCocoa::drawRect"); |
3178 DCHECK(!renderWidgetHostView_->use_core_animation_); | 3306 DCHECK(!renderWidgetHostView_->use_core_animation_); |
3179 | 3307 |
3180 if (!renderWidgetHostView_->render_widget_host_) { | 3308 if (!renderWidgetHostView_->render_widget_host_) { |
3181 // When using CoreAnimation, this path is used to paint the contents area | 3309 // 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 | 3310 // white before any frames come in. When layers to draw frames exist, this |
3183 // is not hit. | 3311 // is not hit. |
3184 [[NSColor whiteColor] set]; | 3312 [[NSColor whiteColor] set]; |
3185 NSRectFill(dirtyRect); | 3313 NSRectFill(dirtyRect); |
(...skipping 1093 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4279 } | 4407 } |
4280 | 4408 |
4281 - (void)disableRendering { | 4409 - (void)disableRendering { |
4282 // Disable the fade-out animation as the layer is removed. | 4410 // Disable the fade-out animation as the layer is removed. |
4283 ScopedCAActionDisabler disabler; | 4411 ScopedCAActionDisabler disabler; |
4284 [self removeFromSuperlayer]; | 4412 [self removeFromSuperlayer]; |
4285 renderWidgetHostView_ = nil; | 4413 renderWidgetHostView_ = nil; |
4286 } | 4414 } |
4287 | 4415 |
4288 @end // implementation SoftwareLayer | 4416 @end // implementation SoftwareLayer |
OLD | NEW |