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/bind.h" | 7 #include "base/bind.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
10 #include "base/debug/trace_event_synthetic_delay.h" | 10 #include "base/debug/trace_event_synthetic_delay.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "content/common/input_messages.h" | 29 #include "content/common/input_messages.h" |
30 #include "content/common/swapped_out_messages.h" | 30 #include "content/common/swapped_out_messages.h" |
31 #include "content/common/view_messages.h" | 31 #include "content/common/view_messages.h" |
32 #include "content/public/common/content_switches.h" | 32 #include "content/public/common/content_switches.h" |
33 #include "content/public/common/context_menu_params.h" | 33 #include "content/public/common/context_menu_params.h" |
34 #include "content/renderer/cursor_utils.h" | 34 #include "content/renderer/cursor_utils.h" |
35 #include "content/renderer/external_popup_menu.h" | 35 #include "content/renderer/external_popup_menu.h" |
36 #include "content/renderer/gpu/compositor_output_surface.h" | 36 #include "content/renderer/gpu/compositor_output_surface.h" |
37 #include "content/renderer/gpu/compositor_software_output_device.h" | 37 #include "content/renderer/gpu/compositor_software_output_device.h" |
38 #include "content/renderer/gpu/delegated_compositor_output_surface.h" | 38 #include "content/renderer/gpu/delegated_compositor_output_surface.h" |
| 39 #include "content/renderer/gpu/frame_swap_message_queue.h" |
39 #include "content/renderer/gpu/mailbox_output_surface.h" | 40 #include "content/renderer/gpu/mailbox_output_surface.h" |
40 #include "content/renderer/gpu/render_widget_compositor.h" | 41 #include "content/renderer/gpu/render_widget_compositor.h" |
41 #include "content/renderer/ime_event_guard.h" | 42 #include "content/renderer/ime_event_guard.h" |
42 #include "content/renderer/input/input_handler_manager.h" | 43 #include "content/renderer/input/input_handler_manager.h" |
43 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 44 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
44 #include "content/renderer/render_frame_impl.h" | 45 #include "content/renderer/render_frame_impl.h" |
45 #include "content/renderer/render_process.h" | 46 #include "content/renderer/render_process.h" |
46 #include "content/renderer/render_thread_impl.h" | 47 #include "content/renderer/render_thread_impl.h" |
47 #include "content/renderer/renderer_webkitplatformsupport_impl.h" | 48 #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
48 #include "content/renderer/resizing_mode_selector.h" | 49 #include "content/renderer/resizing_mode_selector.h" |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 return ui::TEXT_INPUT_MODE_DEFAULT; | 147 return ui::TEXT_INPUT_MODE_DEFAULT; |
147 return it->second; | 148 return it->second; |
148 } | 149 } |
149 | 150 |
150 // TODO(brianderson): Replace the hard-coded threshold with a fraction of | 151 // TODO(brianderson): Replace the hard-coded threshold with a fraction of |
151 // the BeginMainFrame interval. | 152 // the BeginMainFrame interval. |
152 // 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 |
153 // be spent in input hanlders before input starts getting throttled. | 154 // be spent in input hanlders before input starts getting throttled. |
154 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; | 155 const int kInputHandlingTimeThrottlingThresholdMicroseconds = 4166; |
155 | 156 |
| 157 class QueueMessageSwapPromise : public cc::SwapPromise { |
| 158 public: |
| 159 QueueMessageSwapPromise( |
| 160 scoped_refptr<IPC::SyncMessageFilter> message_sender, |
| 161 scoped_refptr<content::FrameSwapMessageQueue> message_queue, |
| 162 IPC::Message* msg) |
| 163 : message_sender_(message_sender), |
| 164 message_queue_(message_queue), |
| 165 msg_(msg) { |
| 166 DCHECK(message_sender_.get()); |
| 167 DCHECK(message_queue_.get()); |
| 168 DCHECK(msg); |
| 169 } |
| 170 |
| 171 virtual ~QueueMessageSwapPromise() { |
| 172 // The promise should have either been kept or broken before it's deleted. |
| 173 DCHECK(!msg_); |
| 174 } |
| 175 |
| 176 virtual void DidSwap(cc::CompositorFrameMetadata* metadata) OVERRIDE { |
| 177 message_queue_->QueueMessage(msg_); |
| 178 msg_ = NULL; |
| 179 } |
| 180 |
| 181 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { |
| 182 message_sender_->Send(msg_); |
| 183 msg_ = NULL; |
| 184 } |
| 185 |
| 186 private: |
| 187 scoped_refptr<IPC::SyncMessageFilter> message_sender_; |
| 188 scoped_refptr<content::FrameSwapMessageQueue> message_queue_; |
| 189 IPC::Message* msg_; |
| 190 }; |
| 191 |
156 } // namespace | 192 } // namespace |
157 | 193 |
158 namespace content { | 194 namespace content { |
159 | 195 |
160 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- | 196 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- |
161 | 197 |
162 class RenderWidget::ScreenMetricsEmulator { | 198 class RenderWidget::ScreenMetricsEmulator { |
163 public: | 199 public: |
164 ScreenMetricsEmulator( | 200 ScreenMetricsEmulator( |
165 RenderWidget* widget, | 201 RenderWidget* widget, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 #if defined(OS_ANDROID) | 426 #if defined(OS_ANDROID) |
391 text_field_is_dirty_(false), | 427 text_field_is_dirty_(false), |
392 outstanding_ime_acks_(0), | 428 outstanding_ime_acks_(0), |
393 body_background_color_(SK_ColorWHITE), | 429 body_background_color_(SK_ColorWHITE), |
394 #endif | 430 #endif |
395 #if defined(OS_MACOSX) | 431 #if defined(OS_MACOSX) |
396 cached_has_main_frame_horizontal_scrollbar_(false), | 432 cached_has_main_frame_horizontal_scrollbar_(false), |
397 cached_has_main_frame_vertical_scrollbar_(false), | 433 cached_has_main_frame_vertical_scrollbar_(false), |
398 #endif | 434 #endif |
399 popup_origin_scale_for_emulation_(0.f), | 435 popup_origin_scale_for_emulation_(0.f), |
| 436 frame_swap_message_queue_(new FrameSwapMessageQueue()), |
400 resizing_mode_selector_(new ResizingModeSelector()), | 437 resizing_mode_selector_(new ResizingModeSelector()), |
401 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 438 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
402 if (!swapped_out) | 439 if (!swapped_out) |
403 RenderProcess::current()->AddRefProcess(); | 440 RenderProcess::current()->AddRefProcess(); |
404 DCHECK(RenderThread::Get()); | 441 DCHECK(RenderThread::Get()); |
405 is_threaded_compositing_enabled_ = | 442 is_threaded_compositing_enabled_ = |
406 CommandLine::ForCurrentProcess()->HasSwitch( | 443 CommandLine::ForCurrentProcess()->HasSwitch( |
407 switches::kEnableThreadedCompositing); | 444 switches::kEnableThreadedCompositing); |
408 } | 445 } |
409 | 446 |
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 } | 844 } |
808 | 845 |
809 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 846 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
810 // For widgets that are never visible, we don't start the compositor, so we | 847 // For widgets that are never visible, we don't start the compositor, so we |
811 // never get a request for a cc::OutputSurface. | 848 // never get a request for a cc::OutputSurface. |
812 DCHECK(!never_visible_); | 849 DCHECK(!never_visible_); |
813 | 850 |
814 #if defined(OS_ANDROID) | 851 #if defined(OS_ANDROID) |
815 if (SynchronousCompositorFactory* factory = | 852 if (SynchronousCompositorFactory* factory = |
816 SynchronousCompositorFactory::GetInstance()) { | 853 SynchronousCompositorFactory::GetInstance()) { |
817 return factory->CreateOutputSurface(routing_id()); | 854 return factory->CreateOutputSurface(routing_id(), |
| 855 frame_swap_message_queue_); |
818 } | 856 } |
819 #endif | 857 #endif |
820 | 858 |
821 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 859 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
822 bool use_software = fallback; | 860 bool use_software = fallback; |
823 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 861 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
824 use_software = true; | 862 use_software = true; |
825 | 863 |
826 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 864 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
827 if (!use_software) { | 865 if (!use_software) { |
828 context_provider = ContextProviderCommandBuffer::Create( | 866 context_provider = ContextProviderCommandBuffer::Create( |
829 CreateGraphicsContext3D(), "RenderCompositor"); | 867 CreateGraphicsContext3D(), "RenderCompositor"); |
830 if (!context_provider.get()) { | 868 if (!context_provider.get()) { |
831 // Cause the compositor to wait and try again. | 869 // Cause the compositor to wait and try again. |
832 return scoped_ptr<cc::OutputSurface>(); | 870 return scoped_ptr<cc::OutputSurface>(); |
833 } | 871 } |
834 } | 872 } |
835 | 873 |
836 uint32 output_surface_id = next_output_surface_id_++; | 874 uint32 output_surface_id = next_output_surface_id_++; |
837 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 875 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
838 DCHECK(is_threaded_compositing_enabled_); | 876 DCHECK(is_threaded_compositing_enabled_); |
839 return scoped_ptr<cc::OutputSurface>( | 877 return scoped_ptr<cc::OutputSurface>( |
840 new DelegatedCompositorOutputSurface( | 878 new DelegatedCompositorOutputSurface(routing_id(), |
841 routing_id(), | 879 output_surface_id, |
842 output_surface_id, | 880 context_provider, |
843 context_provider)); | 881 frame_swap_message_queue_)); |
844 } | 882 } |
845 if (!context_provider.get()) { | 883 if (!context_provider.get()) { |
846 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 884 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
847 new CompositorSoftwareOutputDevice()); | 885 new CompositorSoftwareOutputDevice()); |
848 | 886 |
849 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 887 return scoped_ptr<cc::OutputSurface>( |
850 routing_id(), | 888 new CompositorOutputSurface(routing_id(), |
851 output_surface_id, | 889 output_surface_id, |
852 NULL, | 890 NULL, |
853 software_device.Pass(), | 891 software_device.Pass(), |
854 true)); | 892 frame_swap_message_queue_, |
| 893 true)); |
855 } | 894 } |
856 | 895 |
857 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 896 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
858 // Composite-to-mailbox is currently used for layout tests in order to cause | 897 // Composite-to-mailbox is currently used for layout tests in order to cause |
859 // them to draw inside in the renderer to do the readback there. This should | 898 // them to draw inside in the renderer to do the readback there. This should |
860 // no longer be the case when crbug.com/311404 is fixed. | 899 // no longer be the case when crbug.com/311404 is fixed. |
861 DCHECK(is_threaded_compositing_enabled_ || | 900 DCHECK(is_threaded_compositing_enabled_ || |
862 RenderThreadImpl::current()->layout_test_mode()); | 901 RenderThreadImpl::current()->layout_test_mode()); |
863 cc::ResourceFormat format = cc::RGBA_8888; | 902 cc::ResourceFormat format = cc::RGBA_8888; |
864 #if defined(OS_ANDROID) | 903 #if defined(OS_ANDROID) |
865 if (base::android::SysUtils::IsLowEndDevice()) | 904 if (base::android::SysUtils::IsLowEndDevice()) |
866 format = cc::RGB_565; | 905 format = cc::RGB_565; |
867 #endif | 906 #endif |
868 return scoped_ptr<cc::OutputSurface>( | 907 return scoped_ptr<cc::OutputSurface>( |
869 new MailboxOutputSurface( | 908 new MailboxOutputSurface(routing_id(), |
870 routing_id(), | 909 output_surface_id, |
871 output_surface_id, | 910 context_provider, |
872 context_provider, | 911 scoped_ptr<cc::SoftwareOutputDevice>(), |
873 scoped_ptr<cc::SoftwareOutputDevice>(), | 912 frame_swap_message_queue_, |
874 format)); | 913 format)); |
875 } | 914 } |
876 bool use_swap_compositor_frame_message = false; | 915 bool use_swap_compositor_frame_message = false; |
877 return scoped_ptr<cc::OutputSurface>( | 916 return scoped_ptr<cc::OutputSurface>( |
878 new CompositorOutputSurface( | 917 new CompositorOutputSurface(routing_id(), |
879 routing_id(), | 918 output_surface_id, |
880 output_surface_id, | 919 context_provider, |
881 context_provider, | 920 scoped_ptr<cc::SoftwareOutputDevice>(), |
882 scoped_ptr<cc::SoftwareOutputDevice>(), | 921 frame_swap_message_queue_, |
883 use_swap_compositor_frame_message)); | 922 use_swap_compositor_frame_message)); |
884 } | 923 } |
885 | 924 |
886 void RenderWidget::OnSwapBuffersAborted() { | 925 void RenderWidget::OnSwapBuffersAborted() { |
887 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 926 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
888 // Schedule another frame so the compositor learns about it. | 927 // Schedule another frame so the compositor learns about it. |
889 scheduleComposite(); | 928 scheduleComposite(); |
890 } | 929 } |
891 | 930 |
892 void RenderWidget::OnSwapBuffersPosted() { | 931 void RenderWidget::OnSwapBuffersPosted() { |
893 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); | 932 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); |
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1201 void RenderWidget::didBecomeReadyForAdditionalInput() { | 1240 void RenderWidget::didBecomeReadyForAdditionalInput() { |
1202 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); | 1241 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); |
1203 FlushPendingInputEventAck(); | 1242 FlushPendingInputEventAck(); |
1204 } | 1243 } |
1205 | 1244 |
1206 void RenderWidget::DidCommitCompositorFrame() { | 1245 void RenderWidget::DidCommitCompositorFrame() { |
1207 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_, | 1246 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_, |
1208 DidCommitCompositorFrame()); | 1247 DidCommitCompositorFrame()); |
1209 } | 1248 } |
1210 | 1249 |
| 1250 namespace {} // namespace |
| 1251 |
| 1252 void RenderWidget::QueueMessage(IPC::Message* msg, |
| 1253 MessageDeliveryPolicy policy) { |
| 1254 if (!compositor_) { |
| 1255 Send(msg); |
| 1256 return; |
| 1257 } |
| 1258 |
| 1259 if (policy == MESSAGE_DELIVERY_POLICY_WITH_NEXT_SWAP) { |
| 1260 frame_swap_message_queue_->QueueMessage(msg); |
| 1261 return; |
| 1262 } |
| 1263 |
| 1264 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE && |
| 1265 !compositor_->commitRequested()) { |
| 1266 scoped_ptr<FrameSwapMessageQueue::SendMessageScope> send_message_scope = |
| 1267 frame_swap_message_queue_->AcquireSendMessageScope(); |
| 1268 Send(msg); |
| 1269 return; |
| 1270 } |
| 1271 |
| 1272 DCHECK(policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE || |
| 1273 policy == MESSAGE_DELIVERY_POLICY_WITH_NEXT_COMMIT); |
| 1274 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise( |
| 1275 RenderThreadImpl::current()->sync_message_filter(), |
| 1276 frame_swap_message_queue_, |
| 1277 msg)); |
| 1278 compositor_->QueueSwapPromise(promise.Pass()); |
| 1279 } |
| 1280 |
1211 void RenderWidget::didCommitAndDrawCompositorFrame() { | 1281 void RenderWidget::didCommitAndDrawCompositorFrame() { |
1212 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); | 1282 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
1213 // Accelerated FPS tick for performance tests. See | 1283 // Accelerated FPS tick for performance tests. See |
1214 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is | 1284 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is |
1215 // renamed or moved. | 1285 // renamed or moved. |
1216 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU", | 1286 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU", |
1217 TRACE_EVENT_SCOPE_THREAD); | 1287 TRACE_EVENT_SCOPE_THREAD); |
1218 // Notify subclasses that we initiated the paint operation. | 1288 // Notify subclasses that we initiated the paint operation. |
1219 DidInitiatePaint(); | 1289 DidInitiatePaint(); |
1220 } | 1290 } |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 | 2144 |
2075 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2145 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2076 swapped_out_frames_.AddObserver(frame); | 2146 swapped_out_frames_.AddObserver(frame); |
2077 } | 2147 } |
2078 | 2148 |
2079 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2149 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2080 swapped_out_frames_.RemoveObserver(frame); | 2150 swapped_out_frames_.RemoveObserver(frame); |
2081 } | 2151 } |
2082 | 2152 |
2083 } // namespace content | 2153 } // namespace content |
OLD | NEW |