Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(854)

Side by Side Diff: content/renderer/render_widget.cc

Issue 240163005: Deliver IPC messages together with SwapCompositorFrame (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unique policy, clean tests up a bit Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 19 matching lines...) Expand all
30 #include "content/common/input_messages.h" 30 #include "content/common/input_messages.h"
31 #include "content/common/swapped_out_messages.h" 31 #include "content/common/swapped_out_messages.h"
32 #include "content/common/view_messages.h" 32 #include "content/common/view_messages.h"
33 #include "content/public/common/content_switches.h" 33 #include "content/public/common/content_switches.h"
34 #include "content/public/common/context_menu_params.h" 34 #include "content/public/common/context_menu_params.h"
35 #include "content/renderer/cursor_utils.h" 35 #include "content/renderer/cursor_utils.h"
36 #include "content/renderer/external_popup_menu.h" 36 #include "content/renderer/external_popup_menu.h"
37 #include "content/renderer/gpu/compositor_output_surface.h" 37 #include "content/renderer/gpu/compositor_output_surface.h"
38 #include "content/renderer/gpu/compositor_software_output_device.h" 38 #include "content/renderer/gpu/compositor_software_output_device.h"
39 #include "content/renderer/gpu/delegated_compositor_output_surface.h" 39 #include "content/renderer/gpu/delegated_compositor_output_surface.h"
40 #include "content/renderer/gpu/frame_swap_message_queue.h"
40 #include "content/renderer/gpu/mailbox_output_surface.h" 41 #include "content/renderer/gpu/mailbox_output_surface.h"
42 #include "content/renderer/gpu/queue_message_swap_promise.h"
41 #include "content/renderer/gpu/render_widget_compositor.h" 43 #include "content/renderer/gpu/render_widget_compositor.h"
42 #include "content/renderer/ime_event_guard.h" 44 #include "content/renderer/ime_event_guard.h"
43 #include "content/renderer/input/input_handler_manager.h" 45 #include "content/renderer/input/input_handler_manager.h"
44 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 46 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
45 #include "content/renderer/render_frame_impl.h" 47 #include "content/renderer/render_frame_impl.h"
46 #include "content/renderer/render_frame_proxy.h" 48 #include "content/renderer/render_frame_proxy.h"
47 #include "content/renderer/render_process.h" 49 #include "content/renderer/render_process.h"
48 #include "content/renderer/render_thread_impl.h" 50 #include "content/renderer/render_thread_impl.h"
49 #include "content/renderer/renderer_webkitplatformsupport_impl.h" 51 #include "content/renderer/renderer_webkitplatformsupport_impl.h"
50 #include "content/renderer/resizing_mode_selector.h" 52 #include "content/renderer/resizing_mode_selector.h"
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 device_scale_factor_(screen_info_.deviceScaleFactor), 391 device_scale_factor_(screen_info_.deviceScaleFactor),
390 is_threaded_compositing_enabled_(false), 392 is_threaded_compositing_enabled_(false),
391 current_event_latency_info_(NULL), 393 current_event_latency_info_(NULL),
392 next_output_surface_id_(0), 394 next_output_surface_id_(0),
393 #if defined(OS_ANDROID) 395 #if defined(OS_ANDROID)
394 text_field_is_dirty_(false), 396 text_field_is_dirty_(false),
395 outstanding_ime_acks_(0), 397 outstanding_ime_acks_(0),
396 body_background_color_(SK_ColorWHITE), 398 body_background_color_(SK_ColorWHITE),
397 #endif 399 #endif
398 popup_origin_scale_for_emulation_(0.f), 400 popup_origin_scale_for_emulation_(0.f),
401 frame_swap_message_queue_(new FrameSwapMessageQueue()),
399 resizing_mode_selector_(new ResizingModeSelector()), 402 resizing_mode_selector_(new ResizingModeSelector()),
400 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { 403 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
401 if (!swapped_out) 404 if (!swapped_out)
402 RenderProcess::current()->AddRefProcess(); 405 RenderProcess::current()->AddRefProcess();
403 DCHECK(RenderThread::Get()); 406 DCHECK(RenderThread::Get());
404 is_threaded_compositing_enabled_ = 407 is_threaded_compositing_enabled_ =
405 CommandLine::ForCurrentProcess()->HasSwitch( 408 CommandLine::ForCurrentProcess()->HasSwitch(
406 switches::kEnableThreadedCompositing); 409 switches::kEnableThreadedCompositing);
407 } 410 }
408 411
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 } 807 }
805 808
806 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { 809 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
807 // For widgets that are never visible, we don't start the compositor, so we 810 // For widgets that are never visible, we don't start the compositor, so we
808 // never get a request for a cc::OutputSurface. 811 // never get a request for a cc::OutputSurface.
809 DCHECK(!never_visible_); 812 DCHECK(!never_visible_);
810 813
811 #if defined(OS_ANDROID) 814 #if defined(OS_ANDROID)
812 if (SynchronousCompositorFactory* factory = 815 if (SynchronousCompositorFactory* factory =
813 SynchronousCompositorFactory::GetInstance()) { 816 SynchronousCompositorFactory::GetInstance()) {
814 return factory->CreateOutputSurface(routing_id()); 817 return factory->CreateOutputSurface(routing_id(),
818 frame_swap_message_queue_);
815 } 819 }
816 #endif 820 #endif
817 821
818 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 822 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
819 bool use_software = fallback; 823 bool use_software = fallback;
820 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) 824 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
821 use_software = true; 825 use_software = true;
822 826
823 scoped_refptr<ContextProviderCommandBuffer> context_provider; 827 scoped_refptr<ContextProviderCommandBuffer> context_provider;
824 if (!use_software) { 828 if (!use_software) {
825 context_provider = ContextProviderCommandBuffer::Create( 829 context_provider = ContextProviderCommandBuffer::Create(
826 CreateGraphicsContext3D(), "RenderCompositor"); 830 CreateGraphicsContext3D(), "RenderCompositor");
827 if (!context_provider.get()) { 831 if (!context_provider.get()) {
828 // Cause the compositor to wait and try again. 832 // Cause the compositor to wait and try again.
829 return scoped_ptr<cc::OutputSurface>(); 833 return scoped_ptr<cc::OutputSurface>();
830 } 834 }
831 } 835 }
832 836
833 uint32 output_surface_id = next_output_surface_id_++; 837 uint32 output_surface_id = next_output_surface_id_++;
834 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { 838 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
835 DCHECK(is_threaded_compositing_enabled_); 839 DCHECK(is_threaded_compositing_enabled_);
836 return scoped_ptr<cc::OutputSurface>( 840 return scoped_ptr<cc::OutputSurface>(
837 new DelegatedCompositorOutputSurface( 841 new DelegatedCompositorOutputSurface(routing_id(),
838 routing_id(), 842 output_surface_id,
839 output_surface_id, 843 context_provider,
840 context_provider)); 844 frame_swap_message_queue_));
841 } 845 }
842 if (!context_provider.get()) { 846 if (!context_provider.get()) {
843 scoped_ptr<cc::SoftwareOutputDevice> software_device( 847 scoped_ptr<cc::SoftwareOutputDevice> software_device(
844 new CompositorSoftwareOutputDevice()); 848 new CompositorSoftwareOutputDevice());
845 849
846 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( 850 return scoped_ptr<cc::OutputSurface>(
847 routing_id(), 851 new CompositorOutputSurface(routing_id(),
848 output_surface_id, 852 output_surface_id,
849 NULL, 853 NULL,
850 software_device.Pass(), 854 software_device.Pass(),
851 true)); 855 frame_swap_message_queue_,
856 true));
852 } 857 }
853 858
854 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { 859 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
855 // Composite-to-mailbox is currently used for layout tests in order to cause 860 // Composite-to-mailbox is currently used for layout tests in order to cause
856 // them to draw inside in the renderer to do the readback there. This should 861 // them to draw inside in the renderer to do the readback there. This should
857 // no longer be the case when crbug.com/311404 is fixed. 862 // no longer be the case when crbug.com/311404 is fixed.
858 DCHECK(is_threaded_compositing_enabled_ || 863 DCHECK(is_threaded_compositing_enabled_ ||
859 RenderThreadImpl::current()->layout_test_mode()); 864 RenderThreadImpl::current()->layout_test_mode());
860 cc::ResourceFormat format = cc::RGBA_8888; 865 cc::ResourceFormat format = cc::RGBA_8888;
861 #if defined(OS_ANDROID) 866 #if defined(OS_ANDROID)
862 if (base::android::SysUtils::IsLowEndDevice()) 867 if (base::android::SysUtils::IsLowEndDevice())
863 format = cc::RGB_565; 868 format = cc::RGB_565;
864 #endif 869 #endif
865 return scoped_ptr<cc::OutputSurface>( 870 return scoped_ptr<cc::OutputSurface>(
866 new MailboxOutputSurface( 871 new MailboxOutputSurface(routing_id(),
867 routing_id(), 872 output_surface_id,
868 output_surface_id, 873 context_provider,
869 context_provider, 874 scoped_ptr<cc::SoftwareOutputDevice>(),
870 scoped_ptr<cc::SoftwareOutputDevice>(), 875 frame_swap_message_queue_,
871 format)); 876 format));
872 } 877 }
873 bool use_swap_compositor_frame_message = false; 878 bool use_swap_compositor_frame_message = false;
874 return scoped_ptr<cc::OutputSurface>( 879 return scoped_ptr<cc::OutputSurface>(
875 new CompositorOutputSurface( 880 new CompositorOutputSurface(routing_id(),
876 routing_id(), 881 output_surface_id,
877 output_surface_id, 882 context_provider,
878 context_provider, 883 scoped_ptr<cc::SoftwareOutputDevice>(),
879 scoped_ptr<cc::SoftwareOutputDevice>(), 884 frame_swap_message_queue_,
880 use_swap_compositor_frame_message)); 885 use_swap_compositor_frame_message));
881 } 886 }
882 887
883 void RenderWidget::OnSwapBuffersAborted() { 888 void RenderWidget::OnSwapBuffersAborted() {
884 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); 889 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
885 // Schedule another frame so the compositor learns about it. 890 // Schedule another frame so the compositor learns about it.
886 scheduleComposite(); 891 scheduleComposite();
887 } 892 }
888 893
889 void RenderWidget::OnSwapBuffersPosted() { 894 void RenderWidget::OnSwapBuffersPosted() {
890 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted"); 895 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersPosted");
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 1206
1202 void RenderWidget::DidCommitCompositorFrame() { 1207 void RenderWidget::DidCommitCompositorFrame() {
1203 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_, 1208 FOR_EACH_OBSERVER(RenderFrameProxy, render_frame_proxies_,
1204 DidCommitCompositorFrame()); 1209 DidCommitCompositorFrame());
1205 #if defined(VIDEO_HOLE) 1210 #if defined(VIDEO_HOLE)
1206 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_, 1211 FOR_EACH_OBSERVER(RenderFrameImpl, video_hole_frames_,
1207 DidCommitCompositorFrame()); 1212 DidCommitCompositorFrame());
1208 #endif // defined(VIDEO_HOLE) 1213 #endif // defined(VIDEO_HOLE)
1209 } 1214 }
1210 1215
1216 // static
1217 scoped_ptr<cc::SwapPromise> RenderWidget::QueueMessageImpl(
1218 IPC::Message* msg,
1219 MessageDeliveryPolicy policy,
1220 FrameSwapMessageQueue* frame_swap_message_queue,
1221 scoped_refptr<IPC::SyncMessageFilter> sync_message_filter,
1222 bool commit_requested,
1223 int source_frame_number) {
1224 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1225 // No need for lock: this gets changed only on this thread.
1226 !commit_requested &&
1227 // No need for lock: Messages are only enqueued from this thread, if we
1228 // don't have any now, no other thread will add any.
1229 frame_swap_message_queue->Empty()) {
1230 sync_message_filter->Send(msg);
1231 return scoped_ptr<cc::SwapPromise>();
1232 }
1233
1234 bool first_message_for_frame = false;
1235 frame_swap_message_queue->QueueMessageForFrame(policy,
1236 source_frame_number,
1237 make_scoped_ptr(msg),
1238 &first_message_for_frame);
1239 if (first_message_for_frame) {
1240 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1241 sync_message_filter, frame_swap_message_queue, source_frame_number));
1242 return promise.PassAs<cc::SwapPromise>();
1243 }
1244 return scoped_ptr<cc::SwapPromise>();
1245 }
1246
1247 void RenderWidget::QueueMessage(IPC::Message* msg,
1248 MessageDeliveryPolicy policy) {
1249 if (!compositor_) {
1250 Send(msg);
1251 return;
1252 }
1253
1254 scoped_ptr<cc::SwapPromise> swap_promise =
1255 QueueMessageImpl(msg,
1256 policy,
1257 frame_swap_message_queue_,
1258 RenderThreadImpl::current()->sync_message_filter(),
1259 compositor_->commitRequested(),
1260 compositor_->GetSourceFrameNumber());
1261
1262 if (swap_promise) {
1263 compositor_->QueueSwapPromise(swap_promise.Pass());
1264 compositor_->SetNeedsCommit();
1265 }
1266 }
1267
1211 void RenderWidget::didCommitAndDrawCompositorFrame() { 1268 void RenderWidget::didCommitAndDrawCompositorFrame() {
1212 // NOTE: Tests may break if this event is renamed or moved. See 1269 // NOTE: Tests may break if this event is renamed or moved. See
1213 // tab_capture_performancetest.cc. 1270 // tab_capture_performancetest.cc.
1214 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); 1271 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
1215 // Notify subclasses that we initiated the paint operation. 1272 // Notify subclasses that we initiated the paint operation.
1216 DidInitiatePaint(); 1273 DidInitiatePaint();
1217 } 1274 }
1218 1275
1219 void RenderWidget::didCompleteSwapBuffers() { 1276 void RenderWidget::didCompleteSwapBuffers() {
1220 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); 1277 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2117 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2061 video_hole_frames_.AddObserver(frame); 2118 video_hole_frames_.AddObserver(frame);
2062 } 2119 }
2063 2120
2064 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2121 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2065 video_hole_frames_.RemoveObserver(frame); 2122 video_hole_frames_.RemoveObserver(frame);
2066 } 2123 }
2067 #endif // defined(VIDEO_HOLE) 2124 #endif // defined(VIDEO_HOLE)
2068 2125
2069 } // namespace content 2126 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698