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

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: don't use metadata to stash IPC messages Created 6 years, 7 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/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
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 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 #if defined(OS_ANDROID) 394 #if defined(OS_ANDROID)
394 text_field_is_dirty_(false), 395 text_field_is_dirty_(false),
395 outstanding_ime_acks_(0), 396 outstanding_ime_acks_(0),
396 body_background_color_(SK_ColorWHITE), 397 body_background_color_(SK_ColorWHITE),
397 #endif 398 #endif
398 #if defined(OS_MACOSX) 399 #if defined(OS_MACOSX)
399 cached_has_main_frame_horizontal_scrollbar_(false), 400 cached_has_main_frame_horizontal_scrollbar_(false),
400 cached_has_main_frame_vertical_scrollbar_(false), 401 cached_has_main_frame_vertical_scrollbar_(false),
401 #endif 402 #endif
402 popup_origin_scale_for_emulation_(0.f), 403 popup_origin_scale_for_emulation_(0.f),
404 frame_swap_message_queue_(new FrameSwapMessageQueue()),
403 resizing_mode_selector_(new ResizingModeSelector()), 405 resizing_mode_selector_(new ResizingModeSelector()),
404 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) { 406 context_menu_source_type_(ui::MENU_SOURCE_MOUSE) {
405 if (!swapped_out) 407 if (!swapped_out)
406 RenderProcess::current()->AddRefProcess(); 408 RenderProcess::current()->AddRefProcess();
407 DCHECK(RenderThread::Get()); 409 DCHECK(RenderThread::Get());
408 is_threaded_compositing_enabled_ = 410 is_threaded_compositing_enabled_ =
409 CommandLine::ForCurrentProcess()->HasSwitch( 411 CommandLine::ForCurrentProcess()->HasSwitch(
410 switches::kEnableThreadedCompositing); 412 switches::kEnableThreadedCompositing);
411 } 413 }
412 414
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
813 815
814 bool RenderWidget::ForceCompositingModeEnabled() { 816 bool RenderWidget::ForceCompositingModeEnabled() {
815 return false; 817 return false;
816 } 818 }
817 819
818 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) { 820 scoped_ptr<cc::OutputSurface> RenderWidget::CreateOutputSurface(bool fallback) {
819 // For widgets that are never visible, we don't start the compositor, so we 821 // For widgets that are never visible, we don't start the compositor, so we
820 // never get a request for a cc::OutputSurface. 822 // never get a request for a cc::OutputSurface.
821 DCHECK(!never_visible_); 823 DCHECK(!never_visible_);
822 824
825
823 #if defined(OS_ANDROID) 826 #if defined(OS_ANDROID)
824 if (SynchronousCompositorFactory* factory = 827 if (SynchronousCompositorFactory* factory =
825 SynchronousCompositorFactory::GetInstance()) { 828 SynchronousCompositorFactory::GetInstance()) {
826 return factory->CreateOutputSurface(routing_id()); 829 return factory->CreateOutputSurface(routing_id());
827 } 830 }
828 #endif 831 #endif
829 832
830 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 833 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
831 bool use_software = fallback; 834 bool use_software = fallback;
832 if (command_line.HasSwitch(switches::kDisableGpuCompositing)) 835 if (command_line.HasSwitch(switches::kDisableGpuCompositing))
833 use_software = true; 836 use_software = true;
834 837
835 scoped_refptr<ContextProviderCommandBuffer> context_provider; 838 scoped_refptr<ContextProviderCommandBuffer> context_provider;
836 if (!use_software) { 839 if (!use_software) {
837 context_provider = ContextProviderCommandBuffer::Create( 840 context_provider = ContextProviderCommandBuffer::Create(
838 CreateGraphicsContext3D(), "RenderCompositor"); 841 CreateGraphicsContext3D(), "RenderCompositor");
839 if (!context_provider.get()) { 842 if (!context_provider.get()) {
840 // Cause the compositor to wait and try again. 843 // Cause the compositor to wait and try again.
841 return scoped_ptr<cc::OutputSurface>(); 844 return scoped_ptr<cc::OutputSurface>();
842 } 845 }
843 } 846 }
844 847
848
845 uint32 output_surface_id = next_output_surface_id_++; 849 uint32 output_surface_id = next_output_surface_id_++;
846 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) { 850 if (command_line.HasSwitch(switches::kEnableDelegatedRenderer)) {
847 DCHECK(is_threaded_compositing_enabled_); 851 DCHECK(is_threaded_compositing_enabled_);
848 return scoped_ptr<cc::OutputSurface>( 852 return scoped_ptr<cc::OutputSurface>(
849 new DelegatedCompositorOutputSurface( 853 new DelegatedCompositorOutputSurface(
850 routing_id(), 854 routing_id(),
851 output_surface_id, 855 output_surface_id,
852 context_provider)); 856 context_provider,
857 frame_swap_message_queue_));
853 } 858 }
854 if (!context_provider.get()) { 859 if (!context_provider.get()) {
855 scoped_ptr<cc::SoftwareOutputDevice> software_device( 860 scoped_ptr<cc::SoftwareOutputDevice> software_device(
856 new CompositorSoftwareOutputDevice()); 861 new CompositorSoftwareOutputDevice());
857 862
858 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface( 863 return scoped_ptr<cc::OutputSurface>(new CompositorOutputSurface(
859 routing_id(), 864 routing_id(),
860 output_surface_id, 865 output_surface_id,
861 NULL, 866 NULL,
862 software_device.Pass(), 867 software_device.Pass(),
868 frame_swap_message_queue_,
863 true)); 869 true));
864 } 870 }
865 871
866 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) { 872 if (command_line.HasSwitch(cc::switches::kCompositeToMailbox)) {
867 // Composite-to-mailbox is currently used for layout tests in order to cause 873 // Composite-to-mailbox is currently used for layout tests in order to cause
868 // them to draw inside in the renderer to do the readback there. This should 874 // them to draw inside in the renderer to do the readback there. This should
869 // no longer be the case when crbug.com/311404 is fixed. 875 // no longer be the case when crbug.com/311404 is fixed.
870 DCHECK(is_threaded_compositing_enabled_ || 876 DCHECK(is_threaded_compositing_enabled_ ||
871 RenderThreadImpl::current()->layout_test_mode()); 877 RenderThreadImpl::current()->layout_test_mode());
872 cc::ResourceFormat format = cc::RGBA_8888; 878 cc::ResourceFormat format = cc::RGBA_8888;
873 #if defined(OS_ANDROID) 879 #if defined(OS_ANDROID)
874 if (base::android::SysUtils::IsLowEndDevice()) 880 if (base::android::SysUtils::IsLowEndDevice())
875 format = cc::RGB_565; 881 format = cc::RGB_565;
876 #endif 882 #endif
877 return scoped_ptr<cc::OutputSurface>( 883 return scoped_ptr<cc::OutputSurface>(
878 new MailboxOutputSurface( 884 new MailboxOutputSurface(
879 routing_id(), 885 routing_id(),
880 output_surface_id, 886 output_surface_id,
881 context_provider, 887 context_provider,
882 scoped_ptr<cc::SoftwareOutputDevice>(), 888 scoped_ptr<cc::SoftwareOutputDevice>(),
889 frame_swap_message_queue_,
883 format)); 890 format));
884 } 891 }
885 bool use_swap_compositor_frame_message = false; 892 bool use_swap_compositor_frame_message = false;
886 return scoped_ptr<cc::OutputSurface>( 893 return scoped_ptr<cc::OutputSurface>(
887 new CompositorOutputSurface( 894 new CompositorOutputSurface(
888 routing_id(), 895 routing_id(),
889 output_surface_id, 896 output_surface_id,
890 context_provider, 897 context_provider,
891 scoped_ptr<cc::SoftwareOutputDevice>(), 898 scoped_ptr<cc::SoftwareOutputDevice>(),
899 frame_swap_message_queue_,
892 use_swap_compositor_frame_message)); 900 use_swap_compositor_frame_message));
893 } 901 }
894 902
895 void RenderWidget::OnSwapBuffersAborted() { 903 void RenderWidget::OnSwapBuffersAborted() {
896 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted"); 904 TRACE_EVENT0("renderer", "RenderWidget::OnSwapBuffersAborted");
897 // Schedule another frame so the compositor learns about it. 905 // Schedule another frame so the compositor learns about it.
898 scheduleComposite(); 906 scheduleComposite();
899 } 907 }
900 908
901 void RenderWidget::OnSwapBuffersPosted() { 909 void RenderWidget::OnSwapBuffersPosted() {
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 void RenderWidget::didBecomeReadyForAdditionalInput() { 1234 void RenderWidget::didBecomeReadyForAdditionalInput() {
1227 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput"); 1235 TRACE_EVENT0("renderer", "RenderWidget::didBecomeReadyForAdditionalInput");
1228 FlushPendingInputEventAck(); 1236 FlushPendingInputEventAck();
1229 } 1237 }
1230 1238
1231 void RenderWidget::DidCommitCompositorFrame() { 1239 void RenderWidget::DidCommitCompositorFrame() {
1232 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_, 1240 FOR_EACH_OBSERVER(RenderFrameImpl, swapped_out_frames_,
1233 DidCommitCompositorFrame()); 1241 DidCommitCompositorFrame());
1234 } 1242 }
1235 1243
1244 namespace {
1245
1246 // TODO(mkosiba): move most of this to RenderWidgetCompositor, although
mkosiba (inactive) 2014/05/13 19:15:26 ..although it might be best to have this as a sepa
1247 class RWSwapPromise : public cc::SwapPromise {
1248 public:
1249 RWSwapPromise(scoped_refptr<IPC::SyncMessageFilter> message_sender,
1250 scoped_refptr<FrameSwapMessageQueue> message_queue,
1251 IPC::Message* msg)
1252 : message_sender_(message_sender),
1253 message_queue_(message_queue),
1254 msg_(msg) {
1255 DCHECK(message_sender_.get());
1256 DCHECK(message_queue_.get());
1257 DCHECK(msg);
1258 }
1259
1260 virtual ~RWSwapPromise() {
1261 // The promise should be either fulfilled or broken before it's deleted.
1262 DCHECK(!msg_);
1263 }
1264
1265 virtual void DidSwap(cc::CompositorFrameMetadata* metadata) OVERRIDE {
1266 if (!message_queue_->TryQueueMessage(metadata->source_frame_number, msg_)) {
mkosiba (inactive) 2014/05/14 10:08:08 the interesting case is how to handle messages tha
mkosiba (inactive) 2014/05/15 17:11:49 Simpler option: acquire lock on FrameSwapMessageQu
1267 message_sender_->Send(msg_);
1268 }
1269 msg_ = NULL;
1270 }
1271
1272 virtual void DidNotSwap(DidNotSwapReason reason) OVERRIDE {
1273 message_sender_->Send(msg_);
1274 msg_ = NULL;
1275 }
1276
1277 private:
1278 scoped_refptr<IPC::SyncMessageFilter> message_sender_;
1279 scoped_refptr<FrameSwapMessageQueue> message_queue_;
1280 IPC::Message* msg_;
1281 };
1282
1283 } // namespace
1284
1285 void RenderWidget::QueueMessage(IPC::Message* msg) {
1286 if (!compositor_ || !compositor_->commitRequested()) {
1287 Send(msg);
1288 } else {
1289 scoped_ptr<cc::SwapPromise> promise(
1290 new RWSwapPromise(RenderThreadImpl::current()->sync_message_filter(),
1291 frame_swap_message_queue_,
1292 msg));
1293 compositor_->QueueSwapPromise(promise.Pass());
1294 }
1295 }
1296
1236 void RenderWidget::didCommitAndDrawCompositorFrame() { 1297 void RenderWidget::didCommitAndDrawCompositorFrame() {
1237 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); 1298 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
1238 // Accelerated FPS tick for performance tests. See 1299 // Accelerated FPS tick for performance tests. See
1239 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is 1300 // tab_capture_performancetest.cc. NOTE: Tests may break if this event is
1240 // renamed or moved. 1301 // renamed or moved.
1241 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU", 1302 UNSHIPPED_TRACE_EVENT_INSTANT0("test_fps", "TestFrameTickGPU",
1242 TRACE_EVENT_SCOPE_THREAD); 1303 TRACE_EVENT_SCOPE_THREAD);
1243 // Notify subclasses that we initiated the paint operation. 1304 // Notify subclasses that we initiated the paint operation.
1244 DidInitiatePaint(); 1305 DidInitiatePaint();
1245 } 1306 }
(...skipping 862 matching lines...) Expand 10 before | Expand all | Expand 10 after
2108 2169
2109 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) { 2170 void RenderWidget::RegisterSwappedOutChildFrame(RenderFrameImpl* frame) {
2110 swapped_out_frames_.AddObserver(frame); 2171 swapped_out_frames_.AddObserver(frame);
2111 } 2172 }
2112 2173
2113 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) { 2174 void RenderWidget::UnregisterSwappedOutChildFrame(RenderFrameImpl* frame) {
2114 swapped_out_frames_.RemoveObserver(frame); 2175 swapped_out_frames_.RemoveObserver(frame);
2115 } 2176 }
2116 2177
2117 } // namespace content 2178 } // namespace content
OLDNEW
« content/renderer/gpu/render_widget_compositor.cc ('K') | « content/renderer/render_widget.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698