From 66239a2c717c25fde08075660acd47d1871f723d Mon Sep 17 00:00:00 2001 From: "jbauman@chromium.org" Date: Wed, 5 Jun 2013 03:38:26 +0000 Subject: [PATCH] Plumb LatencyInfo through aura. This will allow the tracking of latency through the browser compositor. BUG=155367 Review URL: https://chromiumcodereview.appspot.com/15842013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204147 0039d316-1c4b-4281-b951-d872f2087c98 --- content/browser/gpu/gpu_process_host_ui_shim.cc | 1 + .../renderer_host/image_transport_factory.cc | 23 +++++++++++++++ .../renderer_host/render_widget_host_impl.cc | 22 +++++++++++++++ .../renderer_host/render_widget_host_impl.h | 2 ++ .../renderer_host/render_widget_host_view_aura.cc | 33 +++++++++++++++------- .../renderer_host/render_widget_host_view_aura.h | 7 +++-- content/common/cc_messages.h | 1 + ui/compositor/compositor.cc | 4 +++ ui/compositor/compositor.h | 3 ++ 9 files changed, 84 insertions(+), 12 deletions(-) diff --git a/content/browser/gpu/gpu_process_host_ui_shim.cc b/content/browser/gpu/gpu_process_host_ui_shim.cc index 959831105604..488a979e9eac 100644 --- a/content/browser/gpu/gpu_process_host_ui_shim.cc +++ b/content/browser/gpu/gpu_process_host_ui_shim.cc @@ -344,6 +344,7 @@ void GpuProcessHostUIShim::OnAcceleratedSurfaceBuffersSwapped( } void GpuProcessHostUIShim::OnFrameDrawn(const ui::LatencyInfo& latency_info) { + RenderWidgetHostImpl::CompositorFrameDrawn(latency_info); } void GpuProcessHostUIShim::OnAcceleratedSurfacePostSubBuffer( diff --git a/content/browser/renderer_host/image_transport_factory.cc b/content/browser/renderer_host/image_transport_factory.cc index 1e566ac2f1e7..eecbf3feb32a 100644 --- a/content/browser/renderer_host/image_transport_factory.cc +++ b/content/browser/renderer_host/image_transport_factory.cc @@ -353,6 +353,29 @@ class BrowserCompositorOutputSurface compositor_, timebase, interval)); } + virtual void SwapBuffers(const ui::LatencyInfo& latency_info) OVERRIDE { + WebGraphicsContext3DCommandBufferImpl* command_buffer = + static_cast(context3d()); + CommandBufferProxyImpl* command_buffer_proxy = + command_buffer->GetCommandBufferProxy(); + DCHECK(command_buffer_proxy); + context3d()->shallowFlushCHROMIUM(); + command_buffer_proxy->SetLatencyInfo(latency_info); + OutputSurface::SwapBuffers(latency_info); + } + + virtual void PostSubBuffer(gfx::Rect rect, + const ui::LatencyInfo& latency_info) OVERRIDE { + WebGraphicsContext3DCommandBufferImpl* command_buffer = + static_cast(context3d()); + CommandBufferProxyImpl* command_buffer_proxy = + command_buffer->GetCommandBufferProxy(); + DCHECK(command_buffer_proxy); + context3d()->shallowFlushCHROMIUM(); + command_buffer_proxy->SetLatencyInfo(latency_info); + OutputSurface::PostSubBuffer(rect, latency_info); + } + private: int surface_id_; scoped_refptr output_surface_proxy_; diff --git a/content/browser/renderer_host/render_widget_host_impl.cc b/content/browser/renderer_host/render_widget_host_impl.cc index 0fab1323f8ae..994f69198c25 100644 --- a/content/browser/renderer_host/render_widget_host_impl.cc +++ b/content/browser/renderer_host/render_widget_host_impl.cc @@ -2523,4 +2523,26 @@ void RenderWidgetHostImpl::FrameSwapped(const ui::LatencyInfo& latency_info) { Send(new ViewMsg_SetBrowserRenderingStats(routing_id_, rendering_stats_)); } +// static +void RenderWidgetHostImpl::CompositorFrameDrawn( + const ui::LatencyInfo& latency_info) { + for (ui::LatencyInfo::LatencyMap::const_iterator b = + latency_info.latency_components.begin(); + b != latency_info.latency_components.end(); + ++b) { + if (b->first.first != ui::INPUT_EVENT_LATENCY_COMPONENT) + continue; + // Matches with GetLatencyComponentId + int routing_id = b->first.second & 0xffffffff; + int process_id = (b->first.second >> 32) & 0xffffffff; + RenderProcessHost* host = RenderProcessHost::FromID(process_id); + if (!host) + continue; + RenderWidgetHost* rwh = host->GetRenderWidgetHostByID(routing_id); + if (!rwh) + continue; + RenderWidgetHostImpl::From(rwh)->FrameSwapped(latency_info); + } +} + } // namespace content diff --git a/content/browser/renderer_host/render_widget_host_impl.h b/content/browser/renderer_host/render_widget_host_impl.h index 4df4ab3cc3d1..d74c97fb94a1 100644 --- a/content/browser/renderer_host/render_widget_host_impl.h +++ b/content/browser/renderer_host/render_widget_host_impl.h @@ -486,6 +486,8 @@ class CONTENT_EXPORT RenderWidgetHostImpl : virtual public RenderWidgetHost, // subsystem. int64 GetLatencyComponentId(); + static void CompositorFrameDrawn(const ui::LatencyInfo& latency_info); + protected: virtual RenderWidgetHostImpl* AsRenderWidgetHostImpl() OVERRIDE; diff --git a/content/browser/renderer_host/render_widget_host_view_aura.cc b/content/browser/renderer_host/render_widget_host_view_aura.cc index dccc948633be..4f7f93c9e2fd 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.cc +++ b/content/browser/renderer_host/render_widget_host_view_aura.cc @@ -1466,14 +1466,17 @@ void RenderWidgetHostViewAura::AcceleratedSurfaceBuffersSwapped( params_in_pixel.route_id, gpu_host_id, params_in_pixel.mailbox_name); - BuffersSwapped( - params_in_pixel.size, params_in_pixel.scale_factor, - params_in_pixel.mailbox_name, ack_callback); + BuffersSwapped(params_in_pixel.size, + params_in_pixel.scale_factor, + params_in_pixel.mailbox_name, + params_in_pixel.latency_info, + ack_callback); } void RenderWidgetHostViewAura::SwapDelegatedFrame( scoped_ptr frame_data, - float frame_device_scale_factor) { + float frame_device_scale_factor, + const ui::LatencyInfo& latency_info) { gfx::Size frame_size_in_dip; if (!frame_data->render_pass_list.empty()) { frame_size_in_dip = gfx::ToFlooredSize(gfx::ScaleSize( @@ -1499,6 +1502,7 @@ void RenderWidgetHostViewAura::SwapDelegatedFrame( if (!compositor) { SendDelegatedFrameAck(); } else { + compositor->SetLatencyInfo(latency_info); AddOnCommitCallbackAndDisableLocks( base::Bind(&RenderWidgetHostViewAura::SendDelegatedFrameAck, AsWeakPtr())); @@ -1514,7 +1518,8 @@ void RenderWidgetHostViewAura::SendDelegatedFrameAck() { void RenderWidgetHostViewAura::SwapSoftwareFrame( scoped_ptr frame_data, - float frame_device_scale_factor) { + float frame_device_scale_factor, + const ui::LatencyInfo& latency_info) { const gfx::Size& frame_size = frame_data->size; const gfx::Rect& damage_rect = frame_data->damage_rect; const TransportDIB::Id& dib_id = frame_data->dib_id; @@ -1561,6 +1566,7 @@ void RenderWidgetHostViewAura::SwapSoftwareFrame( window_->SetExternalTexture(NULL); window_->SchedulePaintInRect( ConvertRectToDIP(frame_device_scale_factor, damage_rect)); + compositor->SetLatencyInfo(latency_info); if (paint_observer_) paint_observer_->OnUpdateCompositorContent(); @@ -1578,13 +1584,15 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame( scoped_ptr frame) { if (frame->delegated_frame_data) { SwapDelegatedFrame(frame->delegated_frame_data.Pass(), - frame->metadata.device_scale_factor); + frame->metadata.device_scale_factor, + frame->metadata.latency_info); return; } if (frame->software_frame_data) { SwapSoftwareFrame(frame->software_frame_data.Pass(), - frame->metadata.device_scale_factor); + frame->metadata.device_scale_factor, + frame->metadata.latency_info); return; } @@ -1608,9 +1616,11 @@ void RenderWidgetHostViewAura::OnSwapCompositorFrame( std::string mailbox_name( reinterpret_cast(frame->gl_frame_data->mailbox.name), sizeof(frame->gl_frame_data->mailbox.name)); - BuffersSwapped( - frame->gl_frame_data->size, frame->metadata.device_scale_factor, - mailbox_name, ack_callback); + BuffersSwapped(frame->gl_frame_data->size, + frame->metadata.device_scale_factor, + mailbox_name, + frame->metadata.latency_info, + ack_callback); } #if defined(OS_WIN) @@ -1627,6 +1637,7 @@ void RenderWidgetHostViewAura::BuffersSwapped( const gfx::Size& size, float surface_scale_factor, const std::string& mailbox_name, + const ui::LatencyInfo& latency_info, const BufferPresentedCallback& ack_callback) { scoped_refptr texture_to_return(current_surface_); const gfx::Rect surface_rect = gfx::Rect(size); @@ -1642,6 +1653,7 @@ void RenderWidgetHostViewAura::BuffersSwapped( if (compositor) { gfx::Size surface_size = ConvertSizeToDIP(surface_scale_factor, size); window_->SchedulePaintInRect(gfx::Rect(surface_size)); + compositor->SetLatencyInfo(latency_info); } if (paint_observer_) @@ -1716,6 +1728,7 @@ void RenderWidgetHostViewAura::AcceleratedSurfacePostSubBuffer( if (paint_observer_) paint_observer_->OnUpdateCompositorContent(); window_->SchedulePaintInRect(rect_to_paint); + compositor->SetLatencyInfo(params_in_pixel.latency_info); } SwapBuffersCompleted(ack_callback, previous_texture); diff --git a/content/browser/renderer_host/render_widget_host_view_aura.h b/content/browser/renderer_host/render_widget_host_view_aura.h index 95fcdbb70e52..0ed95a0ed0c0 100644 --- a/content/browser/renderer_host/render_widget_host_view_aura.h +++ b/content/browser/renderer_host/render_widget_host_view_aura.h @@ -461,6 +461,7 @@ class RenderWidgetHostViewAura void BuffersSwapped(const gfx::Size& size, float surface_scale_factor, const std::string& mailbox_name, + const ui::LatencyInfo& latency_info, const BufferPresentedCallback& ack_callback); bool SwapBuffersPrepare(const gfx::Rect& surface_rect, @@ -475,12 +476,14 @@ class RenderWidgetHostViewAura void SwapDelegatedFrame( scoped_ptr frame_data, - float frame_device_scale_factor); + float frame_device_scale_factor, + const ui::LatencyInfo& latency_info); void SendDelegatedFrameAck(); void SwapSoftwareFrame( scoped_ptr frame_data, - float frame_device_scale_factor); + float frame_device_scale_factor, + const ui::LatencyInfo& latency_info); void SendSoftwareFrameAck(const TransportDIB::Id& id); BrowserAccessibilityManager* GetOrCreateBrowserAccessibilityManager(); diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index 5c78b32fb574..fcc1db87dd57 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -222,6 +222,7 @@ IPC_STRUCT_TRAITS_BEGIN(cc::CompositorFrameMetadata) IPC_STRUCT_TRAITS_MEMBER(location_bar_offset) IPC_STRUCT_TRAITS_MEMBER(location_bar_content_translation) IPC_STRUCT_TRAITS_MEMBER(overdraw_bottom_height) + IPC_STRUCT_TRAITS_MEMBER(latency_info) IPC_STRUCT_TRAITS_END() IPC_STRUCT_TRAITS_BEGIN(cc::GLFrameData) diff --git a/ui/compositor/compositor.cc b/ui/compositor/compositor.cc index fb7395253749..ee996b81d13b 100644 --- a/ui/compositor/compositor.cc +++ b/ui/compositor/compositor.cc @@ -623,6 +623,10 @@ void Compositor::ScheduleRedrawRect(const gfx::Rect& damage_rect) { host_->SetNeedsRedrawRect(damage_rect); } +void Compositor::SetLatencyInfo(const ui::LatencyInfo& latency_info) { + host_->SetLatencyInfo(latency_info); +} + bool Compositor::ReadPixels(SkBitmap* bitmap, const gfx::Rect& bounds_in_pixel) { if (bounds_in_pixel.right() > size().width() || diff --git a/ui/compositor/compositor.h b/ui/compositor/compositor.h index 8eb32eb44563..ef7ce6b1522a 100644 --- a/ui/compositor/compositor.h +++ b/ui/compositor/compositor.h @@ -55,6 +55,7 @@ class CompositorObserver; class ContextProviderFromContextFactory; class Layer; class PostedSwapQueue; +struct LatencyInfo; // This class abstracts the creation of the 3D context for the compositor. It is // a global object. @@ -297,6 +298,8 @@ class COMPOSITOR_EXPORT Compositor // from changes to layer properties. void ScheduleRedrawRect(const gfx::Rect& damage_rect); + void SetLatencyInfo(const ui::LatencyInfo& latency_info); + // Reads the region |bounds_in_pixel| of the contents of the last rendered // frame into the given bitmap. // Returns false if the pixels could not be read. -- 2.11.4.GIT