| 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/renderer/render_widget.h" | 5 #include "content/renderer/render_widget.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { | 145 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { |
| 146 static TextInputModeMapSingleton* singleton = | 146 static TextInputModeMapSingleton* singleton = |
| 147 TextInputModeMapSingleton::GetInstance(); | 147 TextInputModeMapSingleton::GetInstance(); |
| 148 TextInputModeMap::const_iterator it = | 148 TextInputModeMap::const_iterator it = |
| 149 singleton->map().find(input_mode.utf8()); | 149 singleton->map().find(input_mode.utf8()); |
| 150 if (it == singleton->map().end()) | 150 if (it == singleton->map().end()) |
| 151 return ui::TEXT_INPUT_MODE_DEFAULT; | 151 return ui::TEXT_INPUT_MODE_DEFAULT; |
| 152 return it->second; | 152 return it->second; |
| 153 } | 153 } |
| 154 | 154 |
| 155 bool IsThreadedCompositingEnabled() { | |
| 156 content::RenderThreadImpl* impl = content::RenderThreadImpl::current(); | |
| 157 return impl && !!impl->compositor_message_loop_proxy().get(); | |
| 158 } | |
| 159 | |
| 160 // TODO(brianderson): Replace the hard-coded threshold with a fraction of | 155 // TODO(brianderson): Replace the hard-coded threshold with a fraction of |
| 161 // the BeginMainFrame interval. | 156 // the BeginMainFrame interval. |
| 162 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to | 157 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to |
| 163 // be spent in input hanlders before input starts getting throttled. | 158 // be spent in input hanlders before input starts getting throttled. |
| 164 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; | 159 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
| 165 | 160 |
| 166 int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) { | 161 int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) { |
| 167 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds)) | 162 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds)) |
| 168 .ToInternalValue(); | 163 .ToInternalValue(); |
| 169 } | 164 } |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 | 450 |
| 456 // RenderWidget --------------------------------------------------------------- | 451 // RenderWidget --------------------------------------------------------------- |
| 457 | 452 |
| 458 RenderWidget::RenderWidget(blink::WebPopupType popup_type, | 453 RenderWidget::RenderWidget(blink::WebPopupType popup_type, |
| 459 const blink::WebScreenInfo& screen_info, | 454 const blink::WebScreenInfo& screen_info, |
| 460 bool swapped_out, | 455 bool swapped_out, |
| 461 bool hidden, | 456 bool hidden, |
| 462 bool never_visible) | 457 bool never_visible) |
| 463 : routing_id_(MSG_ROUTING_NONE), | 458 : routing_id_(MSG_ROUTING_NONE), |
| 464 surface_id_(0), | 459 surface_id_(0), |
| 465 webwidget_(NULL), | 460 compositor_deps_(nullptr), |
| 461 webwidget_(nullptr), |
| 466 opener_id_(MSG_ROUTING_NONE), | 462 opener_id_(MSG_ROUTING_NONE), |
| 467 init_complete_(false), | 463 init_complete_(false), |
| 468 top_controls_shrink_blink_size_(false), | 464 top_controls_shrink_blink_size_(false), |
| 469 top_controls_height_(0.f), | 465 top_controls_height_(0.f), |
| 470 next_paint_flags_(0), | 466 next_paint_flags_(0), |
| 471 auto_resize_mode_(false), | 467 auto_resize_mode_(false), |
| 472 need_update_rect_for_auto_resize_(false), | 468 need_update_rect_for_auto_resize_(false), |
| 473 did_show_(false), | 469 did_show_(false), |
| 474 is_hidden_(hidden), | 470 is_hidden_(hidden), |
| 475 never_visible_(never_visible), | 471 never_visible_(never_visible), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 RenderWidget::~RenderWidget() { | 509 RenderWidget::~RenderWidget() { |
| 514 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 510 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
| 515 | 511 |
| 516 // If we are swapped out, we have released already. | 512 // If we are swapped out, we have released already. |
| 517 if (!is_swapped_out_ && RenderProcess::current()) | 513 if (!is_swapped_out_ && RenderProcess::current()) |
| 518 RenderProcess::current()->ReleaseProcess(); | 514 RenderProcess::current()->ReleaseProcess(); |
| 519 } | 515 } |
| 520 | 516 |
| 521 // static | 517 // static |
| 522 RenderWidget* RenderWidget::Create(int32 opener_id, | 518 RenderWidget* RenderWidget::Create(int32 opener_id, |
| 519 CompositorDependencies* compositor_deps, |
| 523 blink::WebPopupType popup_type, | 520 blink::WebPopupType popup_type, |
| 524 const blink::WebScreenInfo& screen_info) { | 521 const blink::WebScreenInfo& screen_info) { |
| 525 DCHECK(opener_id != MSG_ROUTING_NONE); | 522 DCHECK(opener_id != MSG_ROUTING_NONE); |
| 526 scoped_refptr<RenderWidget> widget( | 523 scoped_refptr<RenderWidget> widget( |
| 527 new RenderWidget(popup_type, screen_info, false, false, false)); | 524 new RenderWidget(popup_type, screen_info, false, false, false)); |
| 528 if (widget->Init(opener_id)) { // adds reference on success. | 525 if (widget->Init(opener_id, compositor_deps)) { // adds reference on success. |
| 529 return widget.get(); | 526 return widget.get(); |
| 530 } | 527 } |
| 531 return NULL; | 528 return NULL; |
| 532 } | 529 } |
| 533 | 530 |
| 534 // static | 531 // static |
| 535 WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { | 532 WebWidget* RenderWidget::CreateWebWidget(RenderWidget* render_widget) { |
| 536 switch (render_widget->popup_type_) { | 533 switch (render_widget->popup_type_) { |
| 537 case blink::WebPopupTypeNone: // Nothing to create. | 534 case blink::WebPopupTypeNone: // Nothing to create. |
| 538 break; | 535 break; |
| 539 case blink::WebPopupTypeSelect: | 536 case blink::WebPopupTypeSelect: |
| 540 case blink::WebPopupTypeSuggestion: | 537 case blink::WebPopupTypeSuggestion: |
| 541 return WebPopupMenu::create(render_widget); | 538 return WebPopupMenu::create(render_widget); |
| 542 case blink::WebPopupTypePage: | 539 case blink::WebPopupTypePage: |
| 543 return WebPagePopup::create(render_widget); | 540 return WebPagePopup::create(render_widget); |
| 544 default: | 541 default: |
| 545 NOTREACHED(); | 542 NOTREACHED(); |
| 546 } | 543 } |
| 547 return NULL; | 544 return NULL; |
| 548 } | 545 } |
| 549 | 546 |
| 550 bool RenderWidget::Init(int32 opener_id) { | 547 bool RenderWidget::Init(int32 opener_id, |
| 551 return DoInit(opener_id, | 548 CompositorDependencies* compositor_deps) { |
| 552 RenderWidget::CreateWebWidget(this), | 549 return DoInit(opener_id, compositor_deps, RenderWidget::CreateWebWidget(this), |
| 553 new ViewHostMsg_CreateWidget(opener_id, popup_type_, | 550 new ViewHostMsg_CreateWidget(opener_id, popup_type_, |
| 554 &routing_id_, &surface_id_)); | 551 &routing_id_, &surface_id_)); |
| 555 } | 552 } |
| 556 | 553 |
| 557 bool RenderWidget::DoInit(int32 opener_id, | 554 bool RenderWidget::DoInit(int32 opener_id, |
| 555 CompositorDependencies* compositor_deps, |
| 558 WebWidget* web_widget, | 556 WebWidget* web_widget, |
| 559 IPC::SyncMessage* create_widget_message) { | 557 IPC::SyncMessage* create_widget_message) { |
| 560 DCHECK(!webwidget_); | 558 DCHECK(!webwidget_); |
| 561 | 559 |
| 562 if (opener_id != MSG_ROUTING_NONE) | 560 if (opener_id != MSG_ROUTING_NONE) |
| 563 opener_id_ = opener_id; | 561 opener_id_ = opener_id; |
| 564 | 562 |
| 563 compositor_deps_ = compositor_deps; |
| 565 webwidget_ = web_widget; | 564 webwidget_ = web_widget; |
| 566 | 565 |
| 567 bool result = RenderThread::Get()->Send(create_widget_message); | 566 bool result = RenderThread::Get()->Send(create_widget_message); |
| 568 if (result) { | 567 if (result) { |
| 569 RenderThread::Get()->AddRoute(routing_id_, this); | 568 RenderThread::Get()->AddRoute(routing_id_, this); |
| 570 // Take a reference on behalf of the RenderThread. This will be balanced | 569 // Take a reference on behalf of the RenderThread. This will be balanced |
| 571 // when we receive ViewMsg_Close. | 570 // when we receive ViewMsg_Close. |
| 572 AddRef(); | 571 AddRef(); |
| 573 if (RenderThreadImpl::current()) { | 572 if (RenderThreadImpl::current()) { |
| 574 RenderThreadImpl::current()->WidgetCreated(); | 573 RenderThreadImpl::current()->WidgetCreated(); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 955 context_provider = ContextProviderCommandBuffer::Create( | 954 context_provider = ContextProviderCommandBuffer::Create( |
| 956 CreateGraphicsContext3D(), "RenderCompositor"); | 955 CreateGraphicsContext3D(), "RenderCompositor"); |
| 957 if (!context_provider.get()) { | 956 if (!context_provider.get()) { |
| 958 // Cause the compositor to wait and try again. | 957 // Cause the compositor to wait and try again. |
| 959 return scoped_ptr<cc::OutputSurface>(); | 958 return scoped_ptr<cc::OutputSurface>(); |
| 960 } | 959 } |
| 961 } | 960 } |
| 962 | 961 |
| 963 uint32 output_surface_id = next_output_surface_id_++; | 962 uint32 output_surface_id = next_output_surface_id_++; |
| 964 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 963 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
| 965 DCHECK(IsThreadedCompositingEnabled()); | 964 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); |
| 966 return scoped_ptr<cc::OutputSurface>( | 965 return scoped_ptr<cc::OutputSurface>( |
| 967 new DelegatedCompositorOutputSurface(routing_id(), | 966 new DelegatedCompositorOutputSurface(routing_id(), |
| 968 output_surface_id, | 967 output_surface_id, |
| 969 context_provider, | 968 context_provider, |
| 970 frame_swap_message_queue_)); | 969 frame_swap_message_queue_)); |
| 971 } | 970 } |
| 972 if (!context_provider.get()) { | 971 if (!context_provider.get()) { |
| 973 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 972 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| 974 new CompositorSoftwareOutputDevice()); | 973 new CompositorSoftwareOutputDevice()); |
| 975 | 974 |
| 976 return scoped_ptr<cc::OutputSurface>( | 975 return scoped_ptr<cc::OutputSurface>( |
| 977 new CompositorOutputSurface(routing_id(), | 976 new CompositorOutputSurface(routing_id(), |
| 978 output_surface_id, | 977 output_surface_id, |
| 979 NULL, | 978 NULL, |
| 980 software_device.Pass(), | 979 software_device.Pass(), |
| 981 frame_swap_message_queue_, | 980 frame_swap_message_queue_, |
| 982 true)); | 981 true)); |
| 983 } | 982 } |
| 984 | 983 |
| 985 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 984 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
| 986 // Composite-to-mailbox is currently used for layout tests in order to cause | 985 // Composite-to-mailbox is currently used for layout tests in order to cause |
| 987 // them to draw inside in the renderer to do the readback there. This should | 986 // them to draw inside in the renderer to do the readback there. This should |
| 988 // no longer be the case when crbug.com/311404 is fixed. | 987 // no longer be the case when crbug.com/311404 is fixed. |
| 989 DCHECK(IsThreadedCompositingEnabled() || | 988 DCHECK(RenderThreadImpl::current()->layout_test_mode()); |
| 990 RenderThreadImpl::current()->layout_test_mode()); | |
| 991 cc::ResourceFormat format = cc::RGBA_8888; | 989 cc::ResourceFormat format = cc::RGBA_8888; |
| 992 if (base::SysInfo::IsLowEndDevice()) | 990 if (base::SysInfo::IsLowEndDevice()) |
| 993 format = cc::RGB_565; | 991 format = cc::RGB_565; |
| 994 return scoped_ptr<cc::OutputSurface>( | 992 return scoped_ptr<cc::OutputSurface>( |
| 995 new MailboxOutputSurface(routing_id(), | 993 new MailboxOutputSurface(routing_id(), |
| 996 output_surface_id, | 994 output_surface_id, |
| 997 context_provider, | 995 context_provider, |
| 998 scoped_ptr<cc::SoftwareOutputDevice>(), | 996 scoped_ptr<cc::SoftwareOutputDevice>(), |
| 999 frame_swap_message_queue_, | 997 frame_swap_message_queue_, |
| 1000 format)); | 998 format)); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1285 void RenderWidget::AutoResizeCompositor() { | 1283 void RenderWidget::AutoResizeCompositor() { |
| 1286 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, | 1284 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, |
| 1287 device_scale_factor_)); | 1285 device_scale_factor_)); |
| 1288 if (compositor_) | 1286 if (compositor_) |
| 1289 compositor_->setViewportSize(size_, physical_backing_size_); | 1287 compositor_->setViewportSize(size_, physical_backing_size_); |
| 1290 } | 1288 } |
| 1291 | 1289 |
| 1292 void RenderWidget::initializeLayerTreeView() { | 1290 void RenderWidget::initializeLayerTreeView() { |
| 1293 DCHECK(!host_closing_); | 1291 DCHECK(!host_closing_); |
| 1294 | 1292 |
| 1295 compositor_ = | 1293 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_); |
| 1296 RenderWidgetCompositor::Create(this, IsThreadedCompositingEnabled()); | |
| 1297 compositor_->setViewportSize(size_, physical_backing_size_); | 1294 compositor_->setViewportSize(size_, physical_backing_size_); |
| 1298 if (init_complete_) | 1295 if (init_complete_) |
| 1299 StartCompositor(); | 1296 StartCompositor(); |
| 1300 } | 1297 } |
| 1301 | 1298 |
| 1302 void RenderWidget::WillCloseLayerTreeView() { | 1299 void RenderWidget::WillCloseLayerTreeView() { |
| 1303 if (host_closing_) | 1300 if (host_closing_) |
| 1304 return; | 1301 return; |
| 1305 | 1302 |
| 1306 // Prevent new compositors or output surfaces from being created. | 1303 // Prevent new compositors or output surfaces from being created. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1420 params.view_size = size_; | 1417 params.view_size = size_; |
| 1421 params.plugin_window_moves.swap(plugin_window_moves_); | 1418 params.plugin_window_moves.swap(plugin_window_moves_); |
| 1422 params.flags = next_paint_flags_; | 1419 params.flags = next_paint_flags_; |
| 1423 | 1420 |
| 1424 Send(new ViewHostMsg_UpdateRect(routing_id_, params)); | 1421 Send(new ViewHostMsg_UpdateRect(routing_id_, params)); |
| 1425 next_paint_flags_ = 0; | 1422 next_paint_flags_ = 0; |
| 1426 need_update_rect_for_auto_resize_ = false; | 1423 need_update_rect_for_auto_resize_ = false; |
| 1427 } | 1424 } |
| 1428 | 1425 |
| 1429 void RenderWidget::scheduleComposite() { | 1426 void RenderWidget::scheduleComposite() { |
| 1430 RenderThreadImpl* render_thread = RenderThreadImpl::current(); | 1427 if (compositor_ && |
| 1431 // render_thread may be NULL in tests. | 1428 compositor_deps_->GetCompositorImplThreadTaskRunner().get()) { |
| 1432 if (render_thread && render_thread->compositor_message_loop_proxy().get() && | |
| 1433 compositor_) { | |
| 1434 compositor_->setNeedsAnimate(); | 1429 compositor_->setNeedsAnimate(); |
| 1435 } | 1430 } |
| 1436 } | 1431 } |
| 1437 | 1432 |
| 1438 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { | 1433 void RenderWidget::didChangeCursor(const WebCursorInfo& cursor_info) { |
| 1439 // TODO(darin): Eliminate this temporary. | 1434 // TODO(darin): Eliminate this temporary. |
| 1440 WebCursor cursor; | 1435 WebCursor cursor; |
| 1441 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info); | 1436 InitializeCursorFromWebKitCursorInfo(&cursor, cursor_info); |
| 1442 // Only send a SetCursor message if we need to make a change. | 1437 // Only send a SetCursor message if we need to make a change. |
| 1443 if (!current_cursor_.IsEqual(cursor)) { | 1438 if (!current_cursor_.IsEqual(cursor)) { |
| (...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2142 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 2137 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
| 2143 } | 2138 } |
| 2144 #endif | 2139 #endif |
| 2145 } | 2140 } |
| 2146 | 2141 |
| 2147 void RenderWidget::StartCompositor() { | 2142 void RenderWidget::StartCompositor() { |
| 2148 // For widgets that are never visible, we don't need the compositor to run | 2143 // For widgets that are never visible, we don't need the compositor to run |
| 2149 // at all. | 2144 // at all. |
| 2150 if (never_visible_) | 2145 if (never_visible_) |
| 2151 return; | 2146 return; |
| 2147 // In tests without a RenderThreadImpl, don't set ready as this kicks |
| 2148 // off creating output surfaces that the test can't create. |
| 2149 if (!RenderThreadImpl::current()) |
| 2150 return; |
| 2152 compositor_->setSurfaceReady(); | 2151 compositor_->setSurfaceReady(); |
| 2153 } | 2152 } |
| 2154 | 2153 |
| 2155 void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { | 2154 void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { |
| 2156 size_t i = 0; | 2155 size_t i = 0; |
| 2157 for (; i < plugin_window_moves_.size(); ++i) { | 2156 for (; i < plugin_window_moves_.size(); ++i) { |
| 2158 if (plugin_window_moves_[i].window == move.window) { | 2157 if (plugin_window_moves_[i].window == move.window) { |
| 2159 if (move.rects_valid) { | 2158 if (move.rects_valid) { |
| 2160 plugin_window_moves_[i] = move; | 2159 plugin_window_moves_[i] = move; |
| 2161 } else { | 2160 } else { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2326 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2325 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2327 video_hole_frames_.AddObserver(frame); | 2326 video_hole_frames_.AddObserver(frame); |
| 2328 } | 2327 } |
| 2329 | 2328 |
| 2330 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2329 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2331 video_hole_frames_.RemoveObserver(frame); | 2330 video_hole_frames_.RemoveObserver(frame); |
| 2332 } | 2331 } |
| 2333 #endif // defined(VIDEO_HOLE) | 2332 #endif // defined(VIDEO_HOLE) |
| 2334 | 2333 |
| 2335 } // namespace content | 2334 } // namespace content |
| OLD | NEW |