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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { | 141 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { |
142 static TextInputModeMapSingleton* singleton = | 142 static TextInputModeMapSingleton* singleton = |
143 TextInputModeMapSingleton::GetInstance(); | 143 TextInputModeMapSingleton::GetInstance(); |
144 TextInputModeMap::const_iterator it = | 144 TextInputModeMap::const_iterator it = |
145 singleton->map().find(input_mode.utf8()); | 145 singleton->map().find(input_mode.utf8()); |
146 if (it == singleton->map().end()) | 146 if (it == singleton->map().end()) |
147 return ui::TEXT_INPUT_MODE_DEFAULT; | 147 return ui::TEXT_INPUT_MODE_DEFAULT; |
148 return it->second; | 148 return it->second; |
149 } | 149 } |
150 | 150 |
151 bool IsThreadedCompositingEnabled() { | |
152 content::RenderThreadImpl* impl = content::RenderThreadImpl::current(); | |
153 return impl && !!impl->compositor_message_loop_proxy().get(); | |
154 } | |
155 | |
156 // TODO(brianderson): Replace the hard-coded threshold with a fraction of | 151 // TODO(brianderson): Replace the hard-coded threshold with a fraction of |
157 // the BeginMainFrame interval. | 152 // the BeginMainFrame interval. |
158 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to | 153 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to |
159 // be spent in input hanlders before input starts getting throttled. | 154 // be spent in input hanlders before input starts getting throttled. |
160 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; | 155 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
161 | 156 |
162 } // namespace | 157 } // namespace |
163 | 158 |
164 namespace content { | 159 namespace content { |
165 | 160 |
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 is_swapped_out_(swapped_out), | 381 is_swapped_out_(swapped_out), |
387 input_method_is_active_(false), | 382 input_method_is_active_(false), |
388 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 383 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
389 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), | 384 text_input_mode_(ui::TEXT_INPUT_MODE_DEFAULT), |
390 can_compose_inline_(true), | 385 can_compose_inline_(true), |
391 popup_type_(popup_type), | 386 popup_type_(popup_type), |
392 pending_window_rect_count_(0), | 387 pending_window_rect_count_(0), |
393 suppress_next_char_events_(false), | 388 suppress_next_char_events_(false), |
394 screen_info_(screen_info), | 389 screen_info_(screen_info), |
395 device_scale_factor_(screen_info_.deviceScaleFactor), | 390 device_scale_factor_(screen_info_.deviceScaleFactor), |
| 391 is_threaded_compositing_enabled_(false), |
396 current_event_latency_info_(NULL), | 392 current_event_latency_info_(NULL), |
397 next_output_surface_id_(0), | 393 next_output_surface_id_(0), |
398 #if defined(OS_ANDROID) | 394 #if defined(OS_ANDROID) |
399 text_field_is_dirty_(false), | 395 text_field_is_dirty_(false), |
400 outstanding_ime_acks_(0), | 396 outstanding_ime_acks_(0), |
401 body_background_color_(SK_ColorWHITE), | 397 body_background_color_(SK_ColorWHITE), |
402 #endif | 398 #endif |
403 popup_origin_scale_for_emulation_(0.f), | 399 popup_origin_scale_for_emulation_(0.f), |
404 resizing_mode_selector_(new ResizingModeSelector()), | 400 resizing_mode_selector_(new ResizingModeSelector()), |
405 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 401 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
406 if (!swapped_out) | 402 if (!swapped_out) |
407 RenderProcess::current()->AddRefProcess(); | 403 RenderProcess::current()->AddRefProcess(); |
408 DCHECK(RenderThread::Get()); | 404 DCHECK(RenderThread::Get()); |
| 405 is_threaded_compositing_enabled_ = |
| 406 CommandLine::ForCurrentProcess()->HasSwitch( |
| 407 switches::kEnableThreadedCompositing); |
409 } | 408 } |
410 | 409 |
411 RenderWidget::~RenderWidget() { | 410 RenderWidget::~RenderWidget() { |
412 DCHECK(!webwidget_) << "Leaking our WebWidget!"; | 411 DCHECK(!webwidget_) << "Leaking our WebWidget!"; |
413 | 412 |
414 // If we are swapped out, we have released already. | 413 // If we are swapped out, we have released already. |
415 if (!is_swapped_out_ && RenderProcess::current()) | 414 if (!is_swapped_out_ && RenderProcess::current()) |
416 RenderProcess::current()->ReleaseProcess(); | 415 RenderProcess::current()->ReleaseProcess(); |
417 } | 416 } |
418 | 417 |
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
827 context_provider = ContextProviderCommandBuffer::Create( | 826 context_provider = ContextProviderCommandBuffer::Create( |
828 CreateGraphicsContext3D(), "RenderCompositor"); | 827 CreateGraphicsContext3D(), "RenderCompositor"); |
829 if (!context_provider.get()) { | 828 if (!context_provider.get()) { |
830 // Cause the compositor to wait and try again. | 829 // Cause the compositor to wait and try again. |
831 return scoped_ptr<cc::OutputSurface>(); | 830 return scoped_ptr<cc::OutputSurface>(); |
832 } | 831 } |
833 } | 832 } |
834 | 833 |
835 uint32 output_surface_id = next_output_surface_id_++; | 834 uint32 output_surface_id = next_output_surface_id_++; |
836 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 835 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
837 DCHECK(IsThreadedCompositingEnabled()); | 836 DCHECK(is_threaded_compositing_enabled_); |
838 return scoped_ptr<cc::OutputSurface>( | 837 return scoped_ptr<cc::OutputSurface>( |
839 new DelegatedCompositorOutputSurface( | 838 new DelegatedCompositorOutputSurface( |
840 routing_id(), | 839 routing_id(), |
841 output_surface_id, | 840 output_surface_id, |
842 context_provider)); | 841 context_provider)); |
843 } | 842 } |
844 if (!context_provider.get()) { | 843 if (!context_provider.get()) { |
845 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 844 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
846 new CompositorSoftwareOutputDevice()); | 845 new CompositorSoftwareOutputDevice()); |
847 | 846 |
848 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 847 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
849 routing_id(), | 848 routing_id(), |
850 output_surface_id, | 849 output_surface_id, |
851 NULL, | 850 NULL, |
852 software_device.Pass(), | 851 software_device.Pass(), |
853 true)); | 852 true)); |
854 } | 853 } |
855 | 854 |
856 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 855 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
857 // Composite-to-mailbox is currently used for layout tests in order to cause | 856 // Composite-to-mailbox is currently used for layout tests in order to cause |
858 // them to draw inside in the renderer to do the readback there. This should | 857 // them to draw inside in the renderer to do the readback there. This should |
859 // no longer be the case when crbug.com/311404 is fixed. | 858 // no longer be the case when crbug.com/311404 is fixed. |
860 DCHECK(IsThreadedCompositingEnabled() || | 859 DCHECK(is_threaded_compositing_enabled_ || |
861 RenderThreadImpl::current()->layout_test_mode()); | 860 RenderThreadImpl::current()->layout_test_mode()); |
862 cc::ResourceFormat format = cc::RGBA_8888; | 861 cc::ResourceFormat format = cc::RGBA_8888; |
863 #if defined(OS_ANDROID) | 862 #if defined(OS_ANDROID) |
864 if (base::android::SysUtils::IsLowEndDevice()) | 863 if (base::android::SysUtils::IsLowEndDevice()) |
865 format = cc::RGB_565; | 864 format = cc::RGB_565; |
866 #endif | 865 #endif |
867 return scoped_ptr<cc::OutputSurface>( | 866 return scoped_ptr<cc::OutputSurface>( |
868 new MailboxOutputSurface( | 867 new MailboxOutputSurface( |
869 routing_id(), | 868 routing_id(), |
870 output_surface_id, | 869 output_surface_id, |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 } | 1160 } |
1162 | 1161 |
1163 void RenderWidget::AutoResizeCompositor() { | 1162 void RenderWidget::AutoResizeCompositor() { |
1164 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, | 1163 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, |
1165 device_scale_factor_)); | 1164 device_scale_factor_)); |
1166 if (compositor_) | 1165 if (compositor_) |
1167 compositor_->setViewportSize(size_, physical_backing_size_); | 1166 compositor_->setViewportSize(size_, physical_backing_size_); |
1168 } | 1167 } |
1169 | 1168 |
1170 void RenderWidget::initializeLayerTreeView() { | 1169 void RenderWidget::initializeLayerTreeView() { |
1171 compositor_ = | 1170 compositor_ = RenderWidgetCompositor::Create( |
1172 RenderWidgetCompositor::Create(this, IsThreadedCompositingEnabled()); | 1171 this, is_threaded_compositing_enabled_); |
1173 compositor_->setViewportSize(size_, physical_backing_size_); | 1172 compositor_->setViewportSize(size_, physical_backing_size_); |
1174 if (init_complete_) | 1173 if (init_complete_) |
1175 StartCompositor(); | 1174 StartCompositor(); |
1176 } | 1175 } |
1177 | 1176 |
1178 blink::WebLayerTreeView* RenderWidget::layerTreeView() { | 1177 blink::WebLayerTreeView* RenderWidget::layerTreeView() { |
1179 return compositor_.get(); | 1178 return compositor_.get(); |
1180 } | 1179 } |
1181 | 1180 |
1182 void RenderWidget::suppressCompositorScheduling(bool enable) { | 1181 void RenderWidget::suppressCompositorScheduling(bool enable) { |
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2071 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2070 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
2072 video_hole_frames_.AddObserver(frame); | 2071 video_hole_frames_.AddObserver(frame); |
2073 } | 2072 } |
2074 | 2073 |
2075 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2074 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
2076 video_hole_frames_.RemoveObserver(frame); | 2075 video_hole_frames_.RemoveObserver(frame); |
2077 } | 2076 } |
2078 #endif // defined(VIDEO_HOLE) | 2077 #endif // defined(VIDEO_HOLE) |
2079 | 2078 |
2080 } // namespace content | 2079 } // namespace content |
OLD | NEW |