| 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 17 matching lines...) Expand all Loading... |
| 28 #include "content/common/gpu/gpu_process_launch_causes.h" | 28 #include "content/common/gpu/gpu_process_launch_causes.h" |
| 29 #include "content/common/input/synthetic_gesture_packet.h" | 29 #include "content/common/input/synthetic_gesture_packet.h" |
| 30 #include "content/common/input/web_input_event_traits.h" | 30 #include "content/common/input/web_input_event_traits.h" |
| 31 #include "content/common/input_messages.h" | 31 #include "content/common/input_messages.h" |
| 32 #include "content/common/swapped_out_messages.h" | 32 #include "content/common/swapped_out_messages.h" |
| 33 #include "content/common/view_messages.h" | 33 #include "content/common/view_messages.h" |
| 34 #include "content/public/common/content_switches.h" | 34 #include "content/public/common/content_switches.h" |
| 35 #include "content/public/common/context_menu_params.h" | 35 #include "content/public/common/context_menu_params.h" |
| 36 #include "content/renderer/cursor_utils.h" | 36 #include "content/renderer/cursor_utils.h" |
| 37 #include "content/renderer/external_popup_menu.h" | 37 #include "content/renderer/external_popup_menu.h" |
| 38 #include "content/renderer/gpu/compositor_dependencies_impl.h" |
| 38 #include "content/renderer/gpu/compositor_output_surface.h" | 39 #include "content/renderer/gpu/compositor_output_surface.h" |
| 39 #include "content/renderer/gpu/compositor_software_output_device.h" | 40 #include "content/renderer/gpu/compositor_software_output_device.h" |
| 40 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 41 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
| 41 #include "content/renderer/gpu/frame_swap_message_queue.h" | 42 #include "content/renderer/gpu/frame_swap_message_queue.h" |
| 42 #include "content/renderer/gpu/mailbox_output_surface.h" | 43 #include "content/renderer/gpu/mailbox_output_surface.h" |
| 43 #include "content/renderer/gpu/queue_message_swap_promise.h" | 44 #include "content/renderer/gpu/queue_message_swap_promise.h" |
| 44 #include "content/renderer/gpu/render_widget_compositor.h" | 45 #include "content/renderer/gpu/render_widget_compositor.h" |
| 45 #include "content/renderer/ime_event_guard.h" | 46 #include "content/renderer/ime_event_guard.h" |
| 46 #include "content/renderer/input/input_handler_manager.h" | 47 #include "content/renderer/input/input_handler_manager.h" |
| 47 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 48 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { | 147 ui::TextInputMode ConvertInputMode(const blink::WebString& input_mode) { |
| 147 static TextInputModeMapSingleton* singleton = | 148 static TextInputModeMapSingleton* singleton = |
| 148 TextInputModeMapSingleton::GetInstance(); | 149 TextInputModeMapSingleton::GetInstance(); |
| 149 TextInputModeMap::const_iterator it = | 150 TextInputModeMap::const_iterator it = |
| 150 singleton->map().find(input_mode.utf8()); | 151 singleton->map().find(input_mode.utf8()); |
| 151 if (it == singleton->map().end()) | 152 if (it == singleton->map().end()) |
| 152 return ui::TEXT_INPUT_MODE_DEFAULT; | 153 return ui::TEXT_INPUT_MODE_DEFAULT; |
| 153 return it->second; | 154 return it->second; |
| 154 } | 155 } |
| 155 | 156 |
| 156 bool IsThreadedCompositingEnabled() { | |
| 157 content::RenderThreadImpl* impl = content::RenderThreadImpl::current(); | |
| 158 return impl && !!impl->compositor_message_loop_proxy().get(); | |
| 159 } | |
| 160 | |
| 161 // TODO(brianderson): Replace the hard-coded threshold with a fraction of | 157 // TODO(brianderson): Replace the hard-coded threshold with a fraction of |
| 162 // the BeginMainFrame interval. | 158 // the BeginMainFrame interval. |
| 163 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to | 159 // 4166us will allow 1/4 of a 60Hz interval or 1/2 of a 120Hz interval to |
| 164 // be spent in input hanlders before input starts getting throttled. | 160 // be spent in input hanlders before input starts getting throttled. |
| 165 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; | 161 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
| 166 | 162 |
| 167 int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) { | 163 int64 GetEventLatencyMicros(const WebInputEvent& event, base::TimeTicks now) { |
| 168 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds)) | 164 return (now - base::TimeDelta::FromSecondsD(event.timeStampSeconds)) |
| 169 .ToInternalValue(); | 165 .ToInternalValue(); |
| 170 } | 166 } |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 956 context_provider = ContextProviderCommandBuffer::Create( | 952 context_provider = ContextProviderCommandBuffer::Create( |
| 957 CreateGraphicsContext3D(), "RenderCompositor"); | 953 CreateGraphicsContext3D(), "RenderCompositor"); |
| 958 if (!context_provider.get()) { | 954 if (!context_provider.get()) { |
| 959 // Cause the compositor to wait and try again. | 955 // Cause the compositor to wait and try again. |
| 960 return scoped_ptr<cc::OutputSurface>(); | 956 return scoped_ptr<cc::OutputSurface>(); |
| 961 } | 957 } |
| 962 } | 958 } |
| 963 | 959 |
| 964 uint32 output_surface_id = next_output_surface_id_++; | 960 uint32 output_surface_id = next_output_surface_id_++; |
| 965 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 961 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
| 966 DCHECK(IsThreadedCompositingEnabled()); | 962 DCHECK(compositor_deps_->GetCompositorImplThreadTaskRunner()); |
| 967 return scoped_ptr<cc::OutputSurface>( | 963 return scoped_ptr<cc::OutputSurface>( |
| 968 new DelegatedCompositorOutputSurface(routing_id(), | 964 new DelegatedCompositorOutputSurface(routing_id(), |
| 969 output_surface_id, | 965 output_surface_id, |
| 970 context_provider, | 966 context_provider, |
| 971 frame_swap_message_queue_)); | 967 frame_swap_message_queue_)); |
| 972 } | 968 } |
| 973 if (!context_provider.get()) { | 969 if (!context_provider.get()) { |
| 974 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 970 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
| 975 new CompositorSoftwareOutputDevice()); | 971 new CompositorSoftwareOutputDevice()); |
| 976 | 972 |
| 977 return scoped_ptr<cc::OutputSurface>( | 973 return scoped_ptr<cc::OutputSurface>( |
| 978 new CompositorOutputSurface(routing_id(), | 974 new CompositorOutputSurface(routing_id(), |
| 979 output_surface_id, | 975 output_surface_id, |
| 980 NULL, | 976 NULL, |
| 981 software_device.Pass(), | 977 software_device.Pass(), |
| 982 frame_swap_message_queue_, | 978 frame_swap_message_queue_, |
| 983 true)); | 979 true)); |
| 984 } | 980 } |
| 985 | 981 |
| 986 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 982 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
| 987 // Composite-to-mailbox is currently used for layout tests in order to cause | 983 // Composite-to-mailbox is currently used for layout tests in order to cause |
| 988 // them to draw inside in the renderer to do the readback there. This should | 984 // them to draw inside in the renderer to do the readback there. This should |
| 989 // no longer be the case when crbug.com/311404 is fixed. | 985 // no longer be the case when crbug.com/311404 is fixed. |
| 990 DCHECK(IsThreadedCompositingEnabled() || | 986 DCHECK(RenderThreadImpl::current()->layout_test_mode()); |
| 991 RenderThreadImpl::current()->layout_test_mode()); | |
| 992 cc::ResourceFormat format = cc::RGBA_8888; | 987 cc::ResourceFormat format = cc::RGBA_8888; |
| 993 if (base::SysInfo::IsLowEndDevice()) | 988 if (base::SysInfo::IsLowEndDevice()) |
| 994 format = cc::RGB_565; | 989 format = cc::RGB_565; |
| 995 return scoped_ptr<cc::OutputSurface>( | 990 return scoped_ptr<cc::OutputSurface>( |
| 996 new MailboxOutputSurface(routing_id(), | 991 new MailboxOutputSurface(routing_id(), |
| 997 output_surface_id, | 992 output_surface_id, |
| 998 context_provider, | 993 context_provider, |
| 999 scoped_ptr<cc::SoftwareOutputDevice>(), | 994 scoped_ptr<cc::SoftwareOutputDevice>(), |
| 1000 frame_swap_message_queue_, | 995 frame_swap_message_queue_, |
| 1001 format)); | 996 format)); |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 void RenderWidget::AutoResizeCompositor() { | 1281 void RenderWidget::AutoResizeCompositor() { |
| 1287 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, | 1282 physical_backing_size_ = gfx::ToCeiledSize(gfx::ScaleSize(size_, |
| 1288 device_scale_factor_)); | 1283 device_scale_factor_)); |
| 1289 if (compositor_) | 1284 if (compositor_) |
| 1290 compositor_->setViewportSize(size_, physical_backing_size_); | 1285 compositor_->setViewportSize(size_, physical_backing_size_); |
| 1291 } | 1286 } |
| 1292 | 1287 |
| 1293 void RenderWidget::initializeLayerTreeView() { | 1288 void RenderWidget::initializeLayerTreeView() { |
| 1294 DCHECK(!host_closing_); | 1289 DCHECK(!host_closing_); |
| 1295 | 1290 |
| 1296 compositor_ = | 1291 RenderThreadImpl* render_thread = RenderThreadImpl::current(); |
| 1297 RenderWidgetCompositor::Create(this, IsThreadedCompositingEnabled()); | 1292 // RenderThreadImpl can be null in tests, but is not null for tests that use |
| 1293 // a compositor. For future tests that end up wanting to use a compositor but |
| 1294 // have a null RenderThreadImpl, they should inject a custom |
| 1295 // CompositorDependencies instead of using the default implementation here. |
| 1296 DCHECK(render_thread); |
| 1297 |
| 1298 compositor_deps_ = |
| 1299 make_scoped_ptr(new CompositorDependenciesImpl(render_thread)); |
| 1300 compositor_ = RenderWidgetCompositor::Create(this, compositor_deps_.get()); |
| 1298 compositor_->setViewportSize(size_, physical_backing_size_); | 1301 compositor_->setViewportSize(size_, physical_backing_size_); |
| 1299 if (init_complete_) | 1302 if (init_complete_) |
| 1300 StartCompositor(); | 1303 StartCompositor(); |
| 1301 } | 1304 } |
| 1302 | 1305 |
| 1303 void RenderWidget::WillCloseLayerTreeView() { | 1306 void RenderWidget::WillCloseLayerTreeView() { |
| 1304 if (host_closing_) | 1307 if (host_closing_) |
| 1305 return; | 1308 return; |
| 1306 | 1309 |
| 1307 // Prevent new compositors or output surfaces from being created. | 1310 // Prevent new compositors or output surfaces from being created. |
| (...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2145 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); | 2148 UpdateTextInputState(SHOW_IME_IF_NEEDED, FROM_NON_IME); |
| 2146 } | 2149 } |
| 2147 #endif | 2150 #endif |
| 2148 } | 2151 } |
| 2149 | 2152 |
| 2150 void RenderWidget::StartCompositor() { | 2153 void RenderWidget::StartCompositor() { |
| 2151 // For widgets that are never visible, we don't need the compositor to run | 2154 // For widgets that are never visible, we don't need the compositor to run |
| 2152 // at all. | 2155 // at all. |
| 2153 if (never_visible_) | 2156 if (never_visible_) |
| 2154 return; | 2157 return; |
| 2158 // In tests without a RenderThreadImpl, don't set ready as this kicks |
| 2159 // off creating output surfaces that the test can't create. |
| 2160 if (!RenderThreadImpl::current()) |
| 2161 return; |
| 2155 compositor_->setSurfaceReady(); | 2162 compositor_->setSurfaceReady(); |
| 2156 } | 2163 } |
| 2157 | 2164 |
| 2158 void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { | 2165 void RenderWidget::SchedulePluginMove(const WebPluginGeometry& move) { |
| 2159 size_t i = 0; | 2166 size_t i = 0; |
| 2160 for (; i < plugin_window_moves_.size(); ++i) { | 2167 for (; i < plugin_window_moves_.size(); ++i) { |
| 2161 if (plugin_window_moves_[i].window == move.window) { | 2168 if (plugin_window_moves_[i].window == move.window) { |
| 2162 if (move.rects_valid) { | 2169 if (move.rects_valid) { |
| 2163 plugin_window_moves_[i] = move; | 2170 plugin_window_moves_[i] = move; |
| 2164 } else { | 2171 } else { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2329 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { | 2336 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2330 video_hole_frames_.AddObserver(frame); | 2337 video_hole_frames_.AddObserver(frame); |
| 2331 } | 2338 } |
| 2332 | 2339 |
| 2333 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { | 2340 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { |
| 2334 video_hole_frames_.RemoveObserver(frame); | 2341 video_hole_frames_.RemoveObserver(frame); |
| 2335 } | 2342 } |
| 2336 #endif // defined(VIDEO_HOLE) | 2343 #endif // defined(VIDEO_HOLE) |
| 2337 | 2344 |
| 2338 } // namespace content | 2345 } // namespace content |
| OLD | NEW |