| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #ifndef CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ |
| 6 #define CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "cc/output/copy_output_result.h" | 13 #include "cc/output/copy_output_result.h" |
| 14 #include "cc/surfaces/surface_factory_client.h" | 14 #include "cc/scheduler/begin_frame_source.h" |
| 15 #include "cc/surfaces/compositor_frame_sink_support_client.h" |
| 15 #include "content/browser/compositor/image_transport_factory.h" | 16 #include "content/browser/compositor/image_transport_factory.h" |
| 16 #include "content/browser/compositor/owned_mailbox.h" | 17 #include "content/browser/compositor/owned_mailbox.h" |
| 17 #include "content/browser/renderer_host/delegated_frame_evictor.h" | 18 #include "content/browser/renderer_host/delegated_frame_evictor.h" |
| 18 #include "content/browser/renderer_host/dip_util.h" | 19 #include "content/browser/renderer_host/dip_util.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 20 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 20 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 21 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
| 22 #include "ui/compositor/compositor.h" | 23 #include "ui/compositor/compositor.h" |
| 23 #include "ui/compositor/compositor_observer.h" | 24 #include "ui/compositor/compositor_observer.h" |
| 24 #include "ui/compositor/compositor_vsync_manager.h" | 25 #include "ui/compositor/compositor_vsync_manager.h" |
| 25 #include "ui/compositor/layer.h" | 26 #include "ui/compositor/layer.h" |
| 26 #include "ui/events/event.h" | 27 #include "ui/events/event.h" |
| 27 #include "ui/gfx/geometry/rect_conversions.h" | 28 #include "ui/gfx/geometry/rect_conversions.h" |
| 28 | 29 |
| 29 namespace base { | 30 namespace base { |
| 30 class TickClock; | 31 class TickClock; |
| 31 } | 32 } |
| 32 | 33 |
| 33 namespace cc { | 34 namespace cc { |
| 34 class SurfaceFactory; | 35 class CompositorFrameSinkSupport; |
| 35 } | 36 } |
| 36 | 37 |
| 37 namespace media { | 38 namespace media { |
| 38 class VideoFrame; | 39 class VideoFrame; |
| 39 } | 40 } |
| 40 | 41 |
| 41 namespace display_compositor { | 42 namespace display_compositor { |
| 42 class ReadbackYUVInterface; | 43 class ReadbackYUVInterface; |
| 43 } | 44 } |
| 44 | 45 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 80 |
| 80 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state | 81 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state |
| 81 // and functionality that is associated with delegated frames being sent from | 82 // and functionality that is associated with delegated frames being sent from |
| 82 // the RenderWidget. The DelegatedFrameHost will push these changes through to | 83 // the RenderWidget. The DelegatedFrameHost will push these changes through to |
| 83 // the ui::Compositor associated with its DelegatedFrameHostClient. | 84 // the ui::Compositor associated with its DelegatedFrameHostClient. |
| 84 class CONTENT_EXPORT DelegatedFrameHost | 85 class CONTENT_EXPORT DelegatedFrameHost |
| 85 : public ui::CompositorObserver, | 86 : public ui::CompositorObserver, |
| 86 public ui::CompositorVSyncManager::Observer, | 87 public ui::CompositorVSyncManager::Observer, |
| 87 public ui::ContextFactoryObserver, | 88 public ui::ContextFactoryObserver, |
| 88 public DelegatedFrameEvictorClient, | 89 public DelegatedFrameEvictorClient, |
| 89 public cc::SurfaceFactoryClient, | 90 public NON_EXPORTED_BASE(cc::CompositorFrameSinkSupportClient), |
| 91 public cc::ExternalBeginFrameSourceClient, |
| 90 public base::SupportsWeakPtr<DelegatedFrameHost> { | 92 public base::SupportsWeakPtr<DelegatedFrameHost> { |
| 91 public: | 93 public: |
| 92 DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id, | 94 DelegatedFrameHost(const cc::FrameSinkId& frame_sink_id, |
| 93 DelegatedFrameHostClient* client); | 95 DelegatedFrameHostClient* client); |
| 94 ~DelegatedFrameHost() override; | 96 ~DelegatedFrameHost() override; |
| 95 | 97 |
| 96 // ui::CompositorObserver implementation. | 98 // ui::CompositorObserver implementation. |
| 97 void OnCompositingDidCommit(ui::Compositor* compositor) override; | 99 void OnCompositingDidCommit(ui::Compositor* compositor) override; |
| 98 void OnCompositingStarted(ui::Compositor* compositor, | 100 void OnCompositingStarted(ui::Compositor* compositor, |
| 99 base::TimeTicks start_time) override; | 101 base::TimeTicks start_time) override; |
| 100 void OnCompositingEnded(ui::Compositor* compositor) override; | 102 void OnCompositingEnded(ui::Compositor* compositor) override; |
| 101 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; | 103 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; |
| 102 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 104 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 103 | 105 |
| 104 // ui::CompositorVSyncManager::Observer implementation. | 106 // ui::CompositorVSyncManager::Observer implementation. |
| 105 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 107 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 106 base::TimeDelta interval) override; | 108 base::TimeDelta interval) override; |
| 107 | 109 |
| 108 // ImageTransportFactoryObserver implementation. | 110 // ImageTransportFactoryObserver implementation. |
| 109 void OnLostResources() override; | 111 void OnLostResources() override; |
| 110 | 112 |
| 111 // DelegatedFrameEvictorClient implementation. | 113 // DelegatedFrameEvictorClient implementation. |
| 112 void EvictDelegatedFrame() override; | 114 void EvictDelegatedFrame() override; |
| 113 | 115 |
| 114 // cc::SurfaceFactoryClient implementation. | 116 // cc::CompositorFrameSinkSupportClient implementation. |
| 115 void ReturnResources(const cc::ReturnedResourceArray& resources) override; | 117 void DidReceiveCompositorFrameAck() override; |
| 118 void OnBeginFrame(const cc::BeginFrameArgs& args) override; |
| 119 void ReclaimResources(const cc::ReturnedResourceArray& resources) override; |
| 116 void WillDrawSurface(const cc::LocalSurfaceId& id, | 120 void WillDrawSurface(const cc::LocalSurfaceId& id, |
| 117 const gfx::Rect& damage_rect) override; | 121 const gfx::Rect& damage_rect) override; |
| 118 void SetBeginFrameSource(cc::BeginFrameSource* begin_frame_source) override; | |
| 119 | 122 |
| 120 bool CanCopyToBitmap() const; | 123 bool CanCopyToBitmap() const; |
| 121 | 124 |
| 122 // Public interface exposed to RenderWidgetHostView. | 125 // Public interface exposed to RenderWidgetHostView. |
| 123 | 126 |
| 124 void SwapDelegatedFrame(uint32_t compositor_frame_sink_id, | 127 void SwapDelegatedFrame(uint32_t compositor_frame_sink_id, |
| 125 cc::CompositorFrame frame); | 128 cc::CompositorFrame frame); |
| 126 void ClearDelegatedFrame(); | 129 void ClearDelegatedFrame(); |
| 127 void WasHidden(); | 130 void WasHidden(); |
| 128 void WasShown(const ui::LatencyInfo& latency_info); | 131 void WasShown(const ui::LatencyInfo& latency_info); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 base::WeakPtr<DelegatedFrameHost> rwhva, | 238 base::WeakPtr<DelegatedFrameHost> rwhva, |
| 236 const base::Callback<void(bool)>& callback, | 239 const base::Callback<void(bool)>& callback, |
| 237 scoped_refptr<OwnedMailbox> subscriber_texture, | 240 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 238 std::unique_ptr<cc::SingleReleaseCallback> release_callback, | 241 std::unique_ptr<cc::SingleReleaseCallback> release_callback, |
| 239 bool result); | 242 bool result); |
| 240 static void ReturnSubscriberTexture( | 243 static void ReturnSubscriberTexture( |
| 241 base::WeakPtr<DelegatedFrameHost> rwhva, | 244 base::WeakPtr<DelegatedFrameHost> rwhva, |
| 242 scoped_refptr<OwnedMailbox> subscriber_texture, | 245 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 243 const gpu::SyncToken& sync_token); | 246 const gpu::SyncToken& sync_token); |
| 244 | 247 |
| 245 void SendReclaimCompositorResources(uint32_t compositor_frame_sink_id, | |
| 246 bool is_swap_ack); | |
| 247 void SurfaceDrawn(uint32_t compositor_frame_sink_id); | |
| 248 | |
| 249 // Called to consult the current |frame_subscriber_|, to determine and maybe | 248 // Called to consult the current |frame_subscriber_|, to determine and maybe |
| 250 // initiate a copy-into-video-frame request. | 249 // initiate a copy-into-video-frame request. |
| 251 void AttemptFrameSubscriberCapture(const gfx::Rect& damage_rect); | 250 void AttemptFrameSubscriberCapture(const gfx::Rect& damage_rect); |
| 252 | 251 |
| 252 // cc::ExternalBeginFrameSource implementation. |
| 253 void OnNeedsBeginFrames(bool needs_begin_frames) override; |
| 254 void OnDidFinishFrame(const cc::BeginFrameAck& ack) override; |
| 255 |
| 253 const cc::FrameSinkId frame_sink_id_; | 256 const cc::FrameSinkId frame_sink_id_; |
| 254 cc::LocalSurfaceId local_surface_id_; | 257 cc::LocalSurfaceId local_surface_id_; |
| 255 DelegatedFrameHostClient* const client_; | 258 DelegatedFrameHostClient* const client_; |
| 256 ui::Compositor* compositor_; | 259 ui::Compositor* compositor_; |
| 257 | 260 |
| 258 // The vsync manager we are observing for changes, if any. | 261 // The vsync manager we are observing for changes, if any. |
| 259 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; | 262 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; |
| 260 | 263 |
| 261 // The current VSync timebase and interval. These are zero until the first | 264 // The current VSync timebase and interval. These are zero until the first |
| 262 // call to SetVSyncParameters(). | 265 // call to SetVSyncParameters(). |
| 263 base::TimeTicks vsync_timebase_; | 266 base::TimeTicks vsync_timebase_; |
| 264 base::TimeDelta vsync_interval_; | 267 base::TimeDelta vsync_interval_; |
| 265 | 268 |
| 266 // Overridable tick clock used for testing functions using current time. | 269 // Overridable tick clock used for testing functions using current time. |
| 267 std::unique_ptr<base::TickClock> tick_clock_; | 270 std::unique_ptr<base::TickClock> tick_clock_; |
| 268 | 271 |
| 269 // With delegated renderer, this is the last output surface, used to | 272 // With delegated renderer, this is the last output surface, used to |
| 270 // disambiguate resources with the same id coming from different output | 273 // disambiguate resources with the same id coming from different output |
| 271 // surfaces. | 274 // surfaces. |
| 272 uint32_t last_compositor_frame_sink_id_; | 275 uint32_t last_compositor_frame_sink_id_; |
| 273 | 276 |
| 274 // The number of delegated frame acks that are pending, to delay resource | |
| 275 // returns until the acks are sent. | |
| 276 int pending_delegated_ack_count_; | |
| 277 | |
| 278 // True after a delegated frame has been skipped, until a frame is not | 277 // True after a delegated frame has been skipped, until a frame is not |
| 279 // skipped. | 278 // skipped. |
| 280 bool skipped_frames_; | 279 bool skipped_frames_; |
| 281 std::vector<ui::LatencyInfo> skipped_latency_info_list_; | 280 std::vector<ui::LatencyInfo> skipped_latency_info_list_; |
| 282 | 281 |
| 283 std::unique_ptr<ui::Layer> right_gutter_; | 282 std::unique_ptr<ui::Layer> right_gutter_; |
| 284 std::unique_ptr<ui::Layer> bottom_gutter_; | 283 std::unique_ptr<ui::Layer> bottom_gutter_; |
| 285 | 284 |
| 286 // This is the last root background color from a swapped frame. | 285 // This is the last root background color from a swapped frame. |
| 287 SkColor background_color_; | 286 SkColor background_color_; |
| 288 | 287 |
| 289 // State for rendering into a Surface. | 288 // State for rendering into a Surface. |
| 290 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; | 289 std::unique_ptr<cc::SurfaceIdAllocator> id_allocator_; |
| 291 std::unique_ptr<cc::SurfaceFactory> surface_factory_; | 290 std::unique_ptr<cc::CompositorFrameSinkSupport> support_; |
| 292 gfx::Size current_surface_size_; | 291 gfx::Size current_surface_size_; |
| 293 float current_scale_factor_; | 292 float current_scale_factor_; |
| 294 cc::ReturnedResourceArray surface_returned_resources_; | 293 cc::ReturnedResourceArray surface_returned_resources_; |
| 295 | 294 |
| 296 // This lock is the one waiting for a frame of the right size to come back | 295 // This lock is the one waiting for a frame of the right size to come back |
| 297 // from the renderer/GPU process. It is set from the moment the aura window | 296 // from the renderer/GPU process. It is set from the moment the aura window |
| 298 // got resized, to the moment we committed the renderer frame of the same | 297 // got resized, to the moment we committed the renderer frame of the same |
| 299 // size. It keeps track of the size we expect from the renderer, and locks the | 298 // size. It keeps track of the size we expect from the renderer, and locks the |
| 300 // compositor, as well as the UI for a short time to give a chance to the | 299 // compositor, as well as the UI for a short time to give a chance to the |
| 301 // renderer of producing a frame of the right size. | 300 // renderer of producing a frame of the right size. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 326 | 325 |
| 327 // Callback used to pass the output request to the layer or to a function | 326 // Callback used to pass the output request to the layer or to a function |
| 328 // specified by a test. | 327 // specified by a test. |
| 329 base::Callback<void(std::unique_ptr<cc::CopyOutputRequest>)> | 328 base::Callback<void(std::unique_ptr<cc::CopyOutputRequest>)> |
| 330 request_copy_of_output_callback_for_testing_; | 329 request_copy_of_output_callback_for_testing_; |
| 331 | 330 |
| 332 // YUV readback pipeline. | 331 // YUV readback pipeline. |
| 333 std::unique_ptr<display_compositor::ReadbackYUVInterface> | 332 std::unique_ptr<display_compositor::ReadbackYUVInterface> |
| 334 yuv_readback_pipeline_; | 333 yuv_readback_pipeline_; |
| 335 | 334 |
| 335 std::unique_ptr<cc::ExternalBeginFrameSource> begin_frame_source_; |
| 336 |
| 337 bool needs_begin_frame_ = false; |
| 338 |
| 336 std::unique_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; | 339 std::unique_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; |
| 337 }; | 340 }; |
| 338 | 341 |
| 339 } // namespace content | 342 } // namespace content |
| 340 | 343 |
| 341 #endif // CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ | 344 #endif // CONTENT_BROWSER_RENDERER_HOST_DELEGATED_FRAME_HOST_H_ |
| OLD | NEW |