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

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: feedback + add more testing 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"
41 #include "content/renderer/gpu/render_widget_compositor.h" 42 #include "content/renderer/gpu/render_widget_compositor.h"
42 #include "content/renderer/ime_event_guard.h" 43 #include "content/renderer/ime_event_guard.h"
43 #include "content/renderer/input/input_handler_manager.h" 44 #include "content/renderer/input/input_handler_manager.h"
44 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" 45 #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
46 #include "content/renderer/queue_message_swap_promise.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"
51 #include "ipc/ipc_sync_message.h" 53 #include "ipc/ipc_sync_message.h"
52 #include "skia/ext/platform_canvas.h" 54 #include "skia/ext/platform_canvas.h"
53 #include "third_party/WebKit/public/platform/WebCursorInfo.h" 55 #include "third_party/WebKit/public/platform/WebCursorInfo.h"
54 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h" 56 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
(...skipping 334 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_NEXT_SWAP) {
1225 frame_swap_message_queue->QueueMessage(make_scoped_ptr(msg));
1226 // TODO: do we want to SetNeedsRedraw here?
mkosiba (inactive) 2014/06/24 18:29:54 do we?
piman 2014/06/24 19:35:53 It's hard to tell with no caller yet. Maybe it's b
mkosiba (inactive) 2014/06/25 18:40:38 ack.
1227 return scoped_ptr<cc::SwapPromise>();
1228 }
1229
1230 if (policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE &&
1231 // No need for lock: this gets changed only on this thread.
1232 !commit_requested &&
1233 // No need for lock: Messages are only enqueued from this thread, if we
1234 // don't have any now, no other thread will add any.
1235 frame_swap_message_queue->Empty()) {
1236 sync_message_filter->Send(msg);
1237 return scoped_ptr<cc::SwapPromise>();
1238 }
1239
1240 DCHECK(policy == MESSAGE_DELIVERY_POLICY_WITH_VISUAL_STATE ||
1241 policy == MESSAGE_DELIVERY_POLICY_WITH_NEXT_COMMIT);
1242 bool first_message_for_frame = false;
1243 frame_swap_message_queue->QueueMessageForFrame(
1244 source_frame_number, make_scoped_ptr(msg), &first_message_for_frame);
1245 if (first_message_for_frame) {
1246 scoped_ptr<cc::SwapPromise> promise(new QueueMessageSwapPromise(
1247 sync_message_filter,
1248 frame_swap_message_queue,
1249 source_frame_number));
1250 return promise.PassAs<cc::SwapPromise>();
1251 }
1252 return scoped_ptr<cc::SwapPromise>();
1253 }
1254
1255 void RenderWidget::QueueMessage(IPC::Message* msg,
1256 MessageDeliveryPolicy policy) {
1257 if (!compositor_) {
1258 Send(msg);
1259 return;
1260 }
1261
1262 scoped_ptr<cc::SwapPromise> swap_promise =
1263 QueueMessageImpl(msg,
1264 policy,
1265 frame_swap_message_queue_,
1266 RenderThreadImpl::current()->sync_message_filter(),
1267 !compositor_->commitRequested(),
piman 2014/06/24 19:35:53 no ! I think?
mkosiba (inactive) 2014/06/25 18:40:38 right, copy-paste is the most evil thing ever.
1268 compositor_->GetSourceFrameNumber());
1269
1270 if (swap_promise) {
1271 compositor_->QueueSwapPromise(swap_promise.Pass());
1272 compositor_->setNeedsCommit();
1273 }
1274 }
1275
1211 void RenderWidget::didCommitAndDrawCompositorFrame() { 1276 void RenderWidget::didCommitAndDrawCompositorFrame() {
1212 // NOTE: Tests may break if this event is renamed or moved. See 1277 // NOTE: Tests may break if this event is renamed or moved. See
1213 // tab_capture_performancetest.cc. 1278 // tab_capture_performancetest.cc.
1214 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame"); 1279 TRACE_EVENT0("gpu", "RenderWidget::didCommitAndDrawCompositorFrame");
1215 // Notify subclasses that we initiated the paint operation. 1280 // Notify subclasses that we initiated the paint operation.
1216 DidInitiatePaint(); 1281 DidInitiatePaint();
1217 } 1282 }
1218 1283
1219 void RenderWidget::didCompleteSwapBuffers() { 1284 void RenderWidget::didCompleteSwapBuffers() {
1220 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers"); 1285 TRACE_EVENT0("renderer", "RenderWidget::didCompleteSwapBuffers");
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
2060 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) { 2125 void RenderWidget::RegisterVideoHoleFrame(RenderFrameImpl* frame) {
2061 video_hole_frames_.AddObserver(frame); 2126 video_hole_frames_.AddObserver(frame);
2062 } 2127 }
2063 2128
2064 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) { 2129 void RenderWidget::UnregisterVideoHoleFrame(RenderFrameImpl* frame) {
2065 video_hole_frames_.RemoveObserver(frame); 2130 video_hole_frames_.RemoveObserver(frame);
2066 } 2131 }
2067 #endif // defined(VIDEO_HOLE) 2132 #endif // defined(VIDEO_HOLE)
2068 2133
2069 } // namespace content 2134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698