| 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_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 5 #ifndef CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ |
| 6 #define CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 6 #define CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ |
| 7 | 7 |
| 8 #include "cc/layers/delegated_frame_provider.h" | 8 #include "cc/layers/delegated_frame_provider.h" |
| 9 #include "cc/layers/delegated_frame_resource_collection.h" | 9 #include "cc/layers/delegated_frame_resource_collection.h" |
| 10 #include "cc/output/copy_output_result.h" | 10 #include "cc/output/copy_output_result.h" |
| 11 #include "cc/surfaces/surface_factory_client.h" | 11 #include "cc/surfaces/surface_factory_client.h" |
| 12 #include "content/browser/compositor/image_transport_factory.h" | 12 #include "content/browser/compositor/image_transport_factory.h" |
| 13 #include "content/browser/compositor/owned_mailbox.h" | 13 #include "content/browser/compositor/owned_mailbox.h" |
| 14 #include "content/browser/renderer_host/delegated_frame_evictor.h" | 14 #include "content/browser/renderer_host/delegated_frame_evictor.h" |
| 15 #include "content/browser/renderer_host/dip_util.h" | 15 #include "content/browser/renderer_host/dip_util.h" |
| 16 #include "content/browser/renderer_host/render_widget_host_impl.h" | 16 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 17 #include "content/browser/renderer_host/render_widget_host_view_base.h" | 17 #include "content/browser/renderer_host/render_widget_host_view_base.h" |
| 18 #include "content/public/browser/render_process_host.h" | 18 #include "content/public/browser/render_process_host.h" |
| 19 #include "ui/compositor/compositor.h" | 19 #include "ui/compositor/compositor.h" |
| 20 #include "ui/compositor/compositor_observer.h" | 20 #include "ui/compositor/compositor_observer.h" |
| 21 #include "ui/compositor/compositor_vsync_manager.h" | |
| 22 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/layer_owner_delegate.h" | 22 #include "ui/compositor/layer_owner_delegate.h" |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 23 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 | 24 |
| 26 namespace cc { | 25 namespace cc { |
| 27 class SurfaceFactory; | 26 class SurfaceFactory; |
| 28 enum class SurfaceDrawStatus; | 27 enum class SurfaceDrawStatus; |
| 28 struct BeginFrameArgs; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace media { | 31 namespace media { |
| 32 class VideoFrame; | 32 class VideoFrame; |
| 33 } | 33 } |
| 34 | 34 |
| 35 namespace content { | 35 namespace content { |
| 36 | 36 |
| 37 class DelegatedFrameHost; | 37 class DelegatedFrameHost; |
| 38 class ReadbackYUVInterface; | 38 class ReadbackYUVInterface; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 55 virtual void DelegatedFrameHostResizeLockWasReleased() = 0; | 55 virtual void DelegatedFrameHostResizeLockWasReleased() = 0; |
| 56 | 56 |
| 57 virtual void DelegatedFrameHostSendCompositorSwapAck( | 57 virtual void DelegatedFrameHostSendCompositorSwapAck( |
| 58 int output_surface_id, | 58 int output_surface_id, |
| 59 const cc::CompositorFrameAck& ack) = 0; | 59 const cc::CompositorFrameAck& ack) = 0; |
| 60 virtual void DelegatedFrameHostSendReclaimCompositorResources( | 60 virtual void DelegatedFrameHostSendReclaimCompositorResources( |
| 61 int output_surface_id, | 61 int output_surface_id, |
| 62 const cc::CompositorFrameAck& ack) = 0; | 62 const cc::CompositorFrameAck& ack) = 0; |
| 63 virtual void DelegatedFrameHostOnLostCompositorResources() = 0; | 63 virtual void DelegatedFrameHostOnLostCompositorResources() = 0; |
| 64 | 64 |
| 65 virtual void DelegatedFrameHostUpdateVSyncParameters( | 65 virtual void DelegatedFrameHostSendBeginFrame( |
| 66 const base::TimeTicks& timebase, | 66 const cc::BeginFrameArgs& args) = 0; |
| 67 const base::TimeDelta& interval) = 0; | |
| 68 }; | 67 }; |
| 69 | 68 |
| 70 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state | 69 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state |
| 71 // and functionality that is associated with delegated frames being sent from | 70 // and functionality that is associated with delegated frames being sent from |
| 72 // the RenderWidget. The DelegatedFrameHost will push these changes through to | 71 // the RenderWidget. The DelegatedFrameHost will push these changes through to |
| 73 // the ui::Compositor associated with its DelegatedFrameHostClient. | 72 // the ui::Compositor associated with its DelegatedFrameHostClient. |
| 74 class CONTENT_EXPORT DelegatedFrameHost | 73 class CONTENT_EXPORT DelegatedFrameHost |
| 75 : public ui::CompositorObserver, | 74 : public ui::CompositorObserver, |
| 76 public ui::CompositorVSyncManager::Observer, | 75 public ui::CompositorBeginFrameObserver, |
| 77 public ui::LayerOwnerDelegate, | 76 public ui::LayerOwnerDelegate, |
| 78 public ImageTransportFactoryObserver, | 77 public ImageTransportFactoryObserver, |
| 79 public DelegatedFrameEvictorClient, | 78 public DelegatedFrameEvictorClient, |
| 80 public cc::DelegatedFrameResourceCollectionClient, | 79 public cc::DelegatedFrameResourceCollectionClient, |
| 81 public cc::SurfaceFactoryClient, | 80 public cc::SurfaceFactoryClient, |
| 82 public base::SupportsWeakPtr<DelegatedFrameHost> { | 81 public base::SupportsWeakPtr<DelegatedFrameHost> { |
| 83 public: | 82 public: |
| 84 DelegatedFrameHost(DelegatedFrameHostClient* client); | 83 DelegatedFrameHost(DelegatedFrameHostClient* client, |
| 84 bool begin_frame_scheduling_enabled); |
| 85 ~DelegatedFrameHost() override; | 85 ~DelegatedFrameHost() override; |
| 86 | 86 |
| 87 bool CanCopyToBitmap() const; | 87 bool CanCopyToBitmap() const; |
| 88 | 88 |
| 89 // Public interface exposed to RenderWidgetHostView. | 89 // Public interface exposed to RenderWidgetHostView. |
| 90 void SwapDelegatedFrame( | 90 void SwapDelegatedFrame( |
| 91 uint32 output_surface_id, | 91 uint32 output_surface_id, |
| 92 scoped_ptr<cc::DelegatedFrameData> frame_data, | 92 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 93 float frame_device_scale_factor, | 93 float frame_device_scale_factor, |
| 94 const std::vector<ui::LatencyInfo>& latency_info); | 94 const std::vector<ui::LatencyInfo>& latency_info); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 void CopyFromCompositingSurfaceToVideoFrame( | 106 void CopyFromCompositingSurfaceToVideoFrame( |
| 107 const gfx::Rect& src_subrect, | 107 const gfx::Rect& src_subrect, |
| 108 const scoped_refptr<media::VideoFrame>& target, | 108 const scoped_refptr<media::VideoFrame>& target, |
| 109 const base::Callback<void(bool)>& callback); | 109 const base::Callback<void(bool)>& callback); |
| 110 bool CanCopyToVideoFrame() const; | 110 bool CanCopyToVideoFrame() const; |
| 111 bool CanSubscribeFrame() const; | 111 bool CanSubscribeFrame() const; |
| 112 void BeginFrameSubscription( | 112 void BeginFrameSubscription( |
| 113 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); | 113 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); |
| 114 void EndFrameSubscription(); | 114 void EndFrameSubscription(); |
| 115 bool HasFrameSubscriber() const { return frame_subscriber_; } | 115 bool HasFrameSubscriber() const { return frame_subscriber_; } |
| 116 void OnSetNeedsBeginFrames(bool needs_begin_frames); |
| 116 | 117 |
| 117 // Exposed for tests. | 118 // Exposed for tests. |
| 118 cc::DelegatedFrameProvider* FrameProviderForTesting() const { | 119 cc::DelegatedFrameProvider* FrameProviderForTesting() const { |
| 119 return frame_provider_.get(); | 120 return frame_provider_.get(); |
| 120 } | 121 } |
| 121 cc::SurfaceId SurfaceIdForTesting() const { return surface_id_; } | 122 cc::SurfaceId SurfaceIdForTesting() const { return surface_id_; } |
| 122 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { | 123 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { |
| 123 OnCompositingDidCommit(compositor); | 124 OnCompositingDidCommit(compositor); |
| 124 } | 125 } |
| 125 bool ReleasedFrontLockActiveForTesting() const { | 126 bool ReleasedFrontLockActiveForTesting() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 DestroyedAfterCopyRequest); | 141 DestroyedAfterCopyRequest); |
| 141 | 142 |
| 142 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { | 143 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { |
| 143 return frame_subscriber_.get(); | 144 return frame_subscriber_.get(); |
| 144 } | 145 } |
| 145 bool ShouldCreateResizeLock(); | 146 bool ShouldCreateResizeLock(); |
| 146 void LockResources(); | 147 void LockResources(); |
| 147 void UnlockResources(); | 148 void UnlockResources(); |
| 148 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | 149 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); |
| 149 | 150 |
| 151 void StartObservingBeginFrames(); |
| 152 void StopObservingBeginFrames(); |
| 153 |
| 150 // Overridden from ui::CompositorObserver: | 154 // Overridden from ui::CompositorObserver: |
| 151 void OnCompositingDidCommit(ui::Compositor* compositor) override; | 155 void OnCompositingDidCommit(ui::Compositor* compositor) override; |
| 152 void OnCompositingStarted(ui::Compositor* compositor, | 156 void OnCompositingStarted(ui::Compositor* compositor, |
| 153 base::TimeTicks start_time) override; | 157 base::TimeTicks start_time) override; |
| 154 void OnCompositingEnded(ui::Compositor* compositor) override; | 158 void OnCompositingEnded(ui::Compositor* compositor) override; |
| 155 void OnCompositingAborted(ui::Compositor* compositor) override; | 159 void OnCompositingAborted(ui::Compositor* compositor) override; |
| 156 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; | 160 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; |
| 157 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 161 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 158 | 162 |
| 159 // Overridden from ui::CompositorVSyncManager::Observer: | 163 // Overridden from ui::CompositorBeginFrameObserver: |
| 160 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 164 void OnSendBeginFrame(const cc::BeginFrameArgs& args) override; |
| 161 base::TimeDelta interval) override; | |
| 162 | 165 |
| 163 // Overridden from ui::LayerOwnerObserver: | 166 // Overridden from ui::LayerOwnerObserver: |
| 164 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; | 167 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; |
| 165 | 168 |
| 166 // Overridden from ImageTransportFactoryObserver: | 169 // Overridden from ImageTransportFactoryObserver: |
| 167 void OnLostResources() override; | 170 void OnLostResources() override; |
| 168 | 171 |
| 169 bool ShouldSkipFrame(gfx::Size size_in_dip) const; | 172 bool ShouldSkipFrame(gfx::Size size_in_dip) const; |
| 170 | 173 |
| 171 // Lazily grab a resize lock if the aura window size doesn't match the current | 174 // Lazily grab a resize lock if the aura window size doesn't match the current |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 | 235 |
| 233 DelegatedFrameHostClient* const client_; | 236 DelegatedFrameHostClient* const client_; |
| 234 ui::Compositor* compositor_; | 237 ui::Compositor* compositor_; |
| 235 | 238 |
| 236 // True if this renders into a Surface, false if it renders into a delegated | 239 // True if this renders into a Surface, false if it renders into a delegated |
| 237 // layer. | 240 // layer. |
| 238 bool use_surfaces_; | 241 bool use_surfaces_; |
| 239 | 242 |
| 240 std::vector<base::Closure> on_compositing_did_commit_callbacks_; | 243 std::vector<base::Closure> on_compositing_did_commit_callbacks_; |
| 241 | 244 |
| 242 // The vsync manager we are observing for changes, if any. | |
| 243 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; | |
| 244 | |
| 245 // The current VSync timebase and interval. These are zero until the first | 245 // The current VSync timebase and interval. These are zero until the first |
| 246 // call to OnUpdateVSyncParameters(). | 246 // call to OnUpdateVSyncParameters(). |
| 247 base::TimeTicks vsync_timebase_; | 247 base::TimeTicks vsync_timebase_; |
| 248 base::TimeDelta vsync_interval_; | 248 base::TimeDelta vsync_interval_; |
| 249 | 249 |
| 250 // With delegated renderer, this is the last output surface, used to | 250 // With delegated renderer, this is the last output surface, used to |
| 251 // disambiguate resources with the same id coming from different output | 251 // disambiguate resources with the same id coming from different output |
| 252 // surfaces. | 252 // surfaces. |
| 253 uint32 last_output_surface_id_; | 253 uint32 last_output_surface_id_; |
| 254 | 254 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 // Callback used to pass the output request to the layer or to a function | 311 // Callback used to pass the output request to the layer or to a function |
| 312 // specified by a test. | 312 // specified by a test. |
| 313 base::Callback<void(scoped_ptr<cc::CopyOutputRequest>)> | 313 base::Callback<void(scoped_ptr<cc::CopyOutputRequest>)> |
| 314 request_copy_of_output_callback_for_testing_; | 314 request_copy_of_output_callback_for_testing_; |
| 315 | 315 |
| 316 // YUV readback pipeline. | 316 // YUV readback pipeline. |
| 317 scoped_ptr<content::ReadbackYUVInterface> | 317 scoped_ptr<content::ReadbackYUVInterface> |
| 318 yuv_readback_pipeline_; | 318 yuv_readback_pipeline_; |
| 319 | 319 |
| 320 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; | 320 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; |
| 321 |
| 322 // True when unified BeginFrame scheduing is used. |
| 323 bool begin_frame_scheduling_enabled_; |
| 324 |
| 325 // True when RenderWidget needs a BeginFrame. |
| 326 bool needs_begin_frames_; |
| 327 |
| 328 // Pass |last_sent_begin_frame_args_| to compositor when |this| is added as a |
| 329 // CompositorBeginFrameObserver. With this, Compositor can determine whether |
| 330 // latest BeginFrameArgs can be used immediately or not. |
| 331 cc::BeginFrameArgs last_sent_begin_frame_args_; |
| 321 }; | 332 }; |
| 322 | 333 |
| 323 } // namespace content | 334 } // namespace content |
| 324 | 335 |
| 325 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 336 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ |
| OLD | NEW |