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 SendMessageOnSwapPromise : public cc::SwapPromise { | |
158 public: | |
159 SendMessageOnSwapPromise( | |
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 ~SendMessageOnSwapPromise() { | |
172 // The promise should be either fulfilled or broken before it's deleted. | |
173 DCHECK(!msg_); | |
174 } | |
175 | |
176 virtual void DidSwap(cc::CompositorFrameMetadata* metadata) OVERRIDE { | |
177 if (!message_queue_->TryQueueMessage(metadata->source_frame_number, msg_)) { | |
178 message_sender_->Send(msg_); | |
179 } | |
180 msg_ = NULL; | |
181 } | |
182 | |
183 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE { | |
184 message_sender_->Send(msg_); | |
185 msg_ = NULL; | |
186 } | |
187 | |
188 private: | |
189 scoped_refptr<IPC::SyncMessageFilter> message_sender_; | |
190 scoped_refptr<content::FrameSwapMessageQueue> message_queue_; | |
191 IPC::Message* msg_; | |
192 }; | |
193 | |
156 } // namespace | 194 } // namespace |
157 | 195 |
158 namespace content { | 196 namespace content { |
159 | 197 |
160 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- | 198 // RenderWidget::ScreenMetricsEmulator ---------------------------------------- |
161 | 199 |
162 class RenderWidget::ScreenMetricsEmulator { | 200 class RenderWidget::ScreenMetricsEmulator { |
163 public: | 201 public: |
164 ScreenMetricsEmulator( | 202 ScreenMetricsEmulator( |
165 RenderWidget* widget, | 203 RenderWidget* widget, |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
390 #if defined(OS_ANDROID) | 428 #if defined(OS_ANDROID) |
391 text_field_is_dirty_(false), | 429 text_field_is_dirty_(false), |
392 outstanding_ime_acks_(0), | 430 outstanding_ime_acks_(0), |
393 body_background_color_(SK_ColorWHITE), | 431 body_background_color_(SK_ColorWHITE), |
394 #endif | 432 #endif |
395 #if defined(OS_MACOSX) | 433 #if defined(OS_MACOSX) |
396 cached_has_main_frame_horizontal_scrollbar_(false), | 434 cached_has_main_frame_horizontal_scrollbar_(false), |
397 cached_has_main_frame_vertical_scrollbar_(false), | 435 cached_has_main_frame_vertical_scrollbar_(false), |
398 #endif | 436 #endif |
399 popup_origin_scale_for_emulation_(0.f), | 437 popup_origin_scale_for_emulation_(0.f), |
438 frame_swap_message_queue_(new FrameSwapMessageQueue()), | |
400 resizing_mode_selector_(new ResizingModeSelector()), | 439 resizing_mode_selector_(new ResizingModeSelector()), |
401 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { | 440 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { |
402 if (!swapped_out) | 441 if (!swapped_out) |
403 RenderProcess::current()->AddRefProcess(); | 442 RenderProcess::current()->AddRefProcess(); |
404 DCHECK(RenderThread::Get()); | 443 DCHECK(RenderThread::Get()); |
405 is_threaded_compositing_enabled_ = | 444 is_threaded_compositing_enabled_ = |
406 CommandLine::ForCurrentProcess()->HasSwitch( | 445 CommandLine::ForCurrentProcess()->HasSwitch( |
407 switches::kEnableThreadedCompositing); | 446 switches::kEnableThreadedCompositing); |
408 } | 447 } |
409 | 448 |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
804 | 843 |
805 bool RenderWidget::ForceCompositingModeEnabled() { | 844 bool RenderWidget::ForceCompositingModeEnabled() { |
806 return false; | 845 return false; |
807 } | 846 } |
808 | 847 |
809 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { | 848 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { |
810 // For widgets that are never visible, we don't start the compositor, so we | 849 // For widgets that are never visible, we don't start the compositor, so we |
811 // never get a request for a cc::OutputSurface. | 850 // never get a request for a cc::OutputSurface. |
812 DCHECK(!never_visible_); | 851 DCHECK(!never_visible_); |
813 | 852 |
853 | |
814 #if defined(OS_ANDROID) | 854 #if defined(OS_ANDROID) |
815 if (SynchronousCompositorFactory* factory = | 855 if (SynchronousCompositorFactory* factory = |
816 SynchronousCompositorFactory::GetInstance()) { | 856 SynchronousCompositorFactory::GetInstance()) { |
817 return factory->CreateOutputSurface(routing_id()); | 857 return factory->CreateOutputSurface(routing_id(), |
858 frame_swap_message_queue_); | |
818 } | 859 } |
819 #endif | 860 #endif |
820 | 861 |
821 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 862 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
822 bool use_software = fallback; | 863 bool use_software = fallback; |
823 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) | 864 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) |
824 use_software = true; | 865 use_software = true; |
825 | 866 |
826 scoped_refptr<ContextProviderCommandBuffer> context_provider; | 867 scoped_refptr<ContextProviderCommandBuffer> context_provider; |
827 if (!use_software) { | 868 if (!use_software) { |
828 context_provider = ContextProviderCommandBuffer::Create( | 869 context_provider = ContextProviderCommandBuffer::Create( |
829 CreateGraphicsContext3D(), "RenderCompositor"); | 870 CreateGraphicsContext3D(), "RenderCompositor"); |
830 if (!context_provider.get()) { | 871 if (!context_provider.get()) { |
831 // Cause the compositor to wait and try again. | 872 // Cause the compositor to wait and try again. |
832 return scoped_ptr<cc::OutputSurface>(); | 873 return scoped_ptr<cc::OutputSurface>(); |
833 } | 874 } |
834 } | 875 } |
835 | 876 |
877 | |
836 uint32 output_surface_id = next_output_surface_id_++; | 878 uint32 output_surface_id = next_output_surface_id_++; |
837 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { | 879 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { |
838 DCHECK(is_threaded_compositing_enabled_); | 880 DCHECK(is_threaded_compositing_enabled_); |
839 return scoped_ptr<cc::OutputSurface>( | 881 return scoped_ptr<cc::OutputSurface>( |
840 new DelegatedCompositorOutputSurface( | 882 new DelegatedCompositorOutputSurface( |
841 routing_id(), | 883 routing_id(), |
842 output_surface_id, | 884 output_surface_id, |
843 context_provider)); | 885 context_provider, |
886 frame_swap_message_queue_)); | |
844 } | 887 } |
845 if (!context_provider.get()) { | 888 if (!context_provider.get()) { |
846 scoped_ptr<cc::SoftwareOutputDevice> software_device( | 889 scoped_ptr<cc::SoftwareOutputDevice> software_device( |
847 new CompositorSoftwareOutputDevice()); | 890 new CompositorSoftwareOutputDevice()); |
848 | 891 |
849 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( | 892 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( |
850 routing_id(), | 893 routing_id(), |
851 output_surface_id, | 894 output_surface_id, |
852 NULL, | 895 NULL, |
853 software_device.Pass(), | 896 software_device.Pass(), |
897 frame_swap_message_queue_, | |
854 true)); | 898 true)); |
855 } | 899 } |
856 | 900 |
857 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { | 901 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { |
858 // Composite-to-mailbox is currently used for layout tests in order to cause | 902 // 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 | 903 // 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. | 904 // no longer be the case when crbug.com/311404 is fixed. |
861 DCHECK(is_threaded_compositing_enabled_ || | 905 DCHECK(is_threaded_compositing_enabled_ || |
862 RenderThreadImpl::current()->layout_test_mode()); | 906 RenderThreadImpl::current()->layout_test_mode()); |
863 cc::ResourceFormat format = cc::RGBA_8888; | 907 cc::ResourceFormat format = cc::RGBA_8888; |
864 #if defined(OS_ANDROID) | 908 #if defined(OS_ANDROID) |
865 if (base::android::SysUtils::IsLowEndDevice()) | 909 if (base::android::SysUtils::IsLowEndDevice()) |
866 format = cc::RGB_565; | 910 format = cc::RGB_565; |
867 #endif | 911 #endif |
868 return scoped_ptr<cc::OutputSurface>( | 912 return scoped_ptr<cc::OutputSurface>( |
869 new MailboxOutputSurface( | 913 new MailboxOutputSurface( |
870 routing_id(), | 914 routing_id(), |
871 output_surface_id, | 915 output_surface_id, |
872 context_provider, | 916 context_provider, |
873 scoped_ptr<cc::SoftwareOutputDevice>(), | 917 scoped_ptr<cc::SoftwareOutputDevice>(), |
918 frame_swap_message_queue_, | |
874 format)); | 919 format)); |
875 } | 920 } |
876 bool use_swap_compositor_frame_message = false; | 921 bool use_swap_compositor_frame_message = false; |
877 return scoped_ptr<cc::OutputSurface>( | 922 return scoped_ptr<cc::OutputSurface>( |
878 new CompositorOutputSurface( | 923 new CompositorOutputSurface( |
879 routing_id(), | 924 routing_id(), |
880 output_surface_id, | 925 output_surface_id, |
881 context_provider, | 926 context_provider, |
882 scoped_ptr<cc::SoftwareOutputDevice>(), | 927 scoped_ptr<cc::SoftwareOutputDevice>(), |
928 frame_swap_message_queue_, | |
883 use_swap_compositor_frame_message)); | 929 use_swap_compositor_frame_message)); |
884 } | 930 } |
885 | 931 |
886 void RenderWidget::OnSwapBuffersAborted() { | 932 void RenderWidget::OnSwapBuffersAborted() { |
887 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); | 933 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); |
888 // Schedule another frame so the compositor learns about it. | 934 // Schedule another frame so the compositor learns about it. |
889 scheduleComposite(); | 935 scheduleComposite(); |
890 } | 936 } |
891 | 937 |
892 void RenderWidget::OnSwapBuffersPosted() { | 938 void RenderWidget::OnSwapBuffersPosted() { |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1201 void RenderWidget::didBecomeReadyForAdditionalInput() { | 1247 void RenderWidget::didBecomeReadyForAdditionalInput() { |
1202 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); | 1248 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); |
1203 FlushPendingInputEventAck(); | 1249 FlushPendingInputEventAck(); |
1204 } | 1250 } |
1205 | 1251 |
1206 void RenderWidget::DidCommitCompositorFrame() { | 1252 void RenderWidget::DidCommitCompositorFrame() { |
1207 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_, | 1253 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_, |
1208 DidCommitCompositorFrame()); | 1254 DidCommitCompositorFrame()); |
1209 } | 1255 } |
1210 | 1256 |
1257 namespace { | |
1258 | |
1259 } // namespace | |
1260 | |
1261 void RenderWidget::QueueMessage(IPC::Message* msg) { | |
1262 if (!compositor_ || !compositor_->commitRequested()) { | |
piman
2014/05/20 19:54:05
I think I would move the commitRequested() logic t
mkosiba (inactive)
2014/05/22 17:40:24
Originally I was thinking of having an enum specif
| |
1263 Send(msg); | |
1264 } else { | |
1265 scoped_ptr<cc::SwapPromise> promise(new SendMessageOnSwapPromise( | |
1266 RenderThreadImpl::current()->sync_message_filter(), | |
1267 frame_swap_message_queue_, | |
1268 msg)); | |
1269 compositor_->QueueSwapPromise(promise.Pass()); | |
piman
2014/05/20 19:54:05
I still have concerns about the arbitrary limit in
mkosiba (inactive)
2014/05/22 17:40:24
ok, I removed the limit. I can add miletus@ to the
| |
1270 } | |
1271 } | |
1272 | |
1211 void RenderWidget::didCommitAndDrawCompositorFrame() { | 1273 void RenderWidget::didCommitAndDrawCompositorFrame() { |
1212 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); | 1274 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); |
1213 // Accelerated FPS tick for performance tests. See | 1275 // Accelerated FPS tick for performance tests. See |
1214 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is | 1276 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is |
1215 // renamed or moved. | 1277 // renamed or moved. |
1216 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU", | 1278 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU", |
1217 TRACE_EVENT_SCOPE_THREAD); | 1279 TRACE_EVENT_SCOPE_THREAD); |
1218 // Notify subclasses that we initiated the paint operation. | 1280 // Notify subclasses that we initiated the paint operation. |
1219 DidInitiatePaint(); | 1281 DidInitiatePaint(); |
1220 } | 1282 } |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2074 | 2136 |
2075 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2137 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2076 swapped_out_frames_.AddObserver(frame); | 2138 swapped_out_frames_.AddObserver(frame); |
2077 } | 2139 } |
2078 | 2140 |
2079 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { | 2141 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { |
2080 swapped_out_frames_.RemoveObserver(frame); | 2142 swapped_out_frames_.RemoveObserver(frame); |
2081 } | 2143 } |
2082 | 2144 |
2083 } // namespace content | 2145 } // namespace content |
OLD | NEW |