| 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" | 21 #include "ui/compositor/compositor_vsync_manager.h" |
| 22 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 23 #include "ui/compositor/layer_owner_delegate.h" | 23 #include "ui/compositor/layer_owner_delegate.h" |
| 24 #include "ui/gfx/geometry/rect_conversions.h" | 24 #include "ui/gfx/geometry/rect_conversions.h" |
| 25 | 25 |
| 26 namespace cc { | 26 namespace cc { |
| 27 class SurfaceFactory; | 27 class SurfaceFactory; |
| 28 enum class SurfaceDrawStatus; | 28 enum class SurfaceDrawStatus; |
| 29 struct BeginFrameArgs; |
| 29 } | 30 } |
| 30 | 31 |
| 31 namespace media { | 32 namespace media { |
| 32 class VideoFrame; | 33 class VideoFrame; |
| 33 } | 34 } |
| 34 | 35 |
| 35 namespace content { | 36 namespace content { |
| 36 | 37 |
| 37 class DelegatedFrameHost; | 38 class DelegatedFrameHost; |
| 38 class ReadbackYUVInterface; | 39 class ReadbackYUVInterface; |
| 39 class RenderWidgetHostViewFrameSubscriber; | 40 class RenderWidgetHostViewFrameSubscriber; |
| 40 class RenderWidgetHostImpl; | 41 class RenderWidgetHostImpl; |
| 41 class ResizeLock; | 42 class ResizeLock; |
| 42 | 43 |
| 43 // The DelegatedFrameHostClient is the interface from the DelegatedFrameHost, | 44 // The DelegatedFrameHostClient is the interface from the DelegatedFrameHost, |
| 44 // which manages delegated frames, and the ui::Compositor being used to | 45 // which manages delegated frames, and the ui::Compositor being used to |
| 45 // display them. | 46 // display them. |
| 46 class CONTENT_EXPORT DelegatedFrameHostClient { | 47 class CONTENT_EXPORT DelegatedFrameHostClient { |
| 47 public: | 48 public: |
| 49 virtual ~DelegatedFrameHostClient() {} |
| 50 |
| 48 virtual ui::Layer* DelegatedFrameHostGetLayer() const = 0; | 51 virtual ui::Layer* DelegatedFrameHostGetLayer() const = 0; |
| 49 virtual bool DelegatedFrameHostIsVisible() const = 0; | 52 virtual bool DelegatedFrameHostIsVisible() const = 0; |
| 50 virtual gfx::Size DelegatedFrameHostDesiredSizeInDIP() const = 0; | 53 virtual gfx::Size DelegatedFrameHostDesiredSizeInDIP() const = 0; |
| 51 | 54 |
| 52 virtual bool DelegatedFrameCanCreateResizeLock() const = 0; | 55 virtual bool DelegatedFrameCanCreateResizeLock() const = 0; |
| 53 virtual scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( | 56 virtual scoped_ptr<ResizeLock> DelegatedFrameHostCreateResizeLock( |
| 54 bool defer_compositor_lock) = 0; | 57 bool defer_compositor_lock) = 0; |
| 55 virtual void DelegatedFrameHostResizeLockWasReleased() = 0; | 58 virtual void DelegatedFrameHostResizeLockWasReleased() = 0; |
| 56 | 59 |
| 57 virtual void DelegatedFrameHostSendCompositorSwapAck( | 60 virtual void DelegatedFrameHostSendCompositorSwapAck( |
| 58 int output_surface_id, | 61 int output_surface_id, |
| 59 const cc::CompositorFrameAck& ack) = 0; | 62 const cc::CompositorFrameAck& ack) = 0; |
| 60 virtual void DelegatedFrameHostSendReclaimCompositorResources( | 63 virtual void DelegatedFrameHostSendReclaimCompositorResources( |
| 61 int output_surface_id, | 64 int output_surface_id, |
| 62 const cc::CompositorFrameAck& ack) = 0; | 65 const cc::CompositorFrameAck& ack) = 0; |
| 63 virtual void DelegatedFrameHostOnLostCompositorResources() = 0; | 66 virtual void DelegatedFrameHostOnLostCompositorResources() = 0; |
| 64 | 67 |
| 65 virtual void DelegatedFrameHostUpdateVSyncParameters( | 68 virtual void DelegatedFrameHostUpdateVSyncParameters( |
| 66 const base::TimeTicks& timebase, | 69 const base::TimeTicks& timebase, |
| 67 const base::TimeDelta& interval) = 0; | 70 const base::TimeDelta& interval) = 0; |
| 71 virtual void DelegatedFrameHostSendBeginFrame( |
| 72 const cc::BeginFrameArgs& args) = 0; |
| 68 }; | 73 }; |
| 69 | 74 |
| 70 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state | 75 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state |
| 71 // and functionality that is associated with delegated frames being sent from | 76 // and functionality that is associated with delegated frames being sent from |
| 72 // the RenderWidget. The DelegatedFrameHost will push these changes through to | 77 // the RenderWidget. The DelegatedFrameHost will push these changes through to |
| 73 // the ui::Compositor associated with its DelegatedFrameHostClient. | 78 // the ui::Compositor associated with its DelegatedFrameHostClient. |
| 74 class CONTENT_EXPORT DelegatedFrameHost | 79 class CONTENT_EXPORT DelegatedFrameHost |
| 75 : public ui::CompositorObserver, | 80 : public ui::CompositorObserver, |
| 81 public ui::CompositorBeginFrameObserver, |
| 76 public ui::CompositorVSyncManager::Observer, | 82 public ui::CompositorVSyncManager::Observer, |
| 77 public ui::LayerOwnerDelegate, | 83 public ui::LayerOwnerDelegate, |
| 78 public ImageTransportFactoryObserver, | 84 public ImageTransportFactoryObserver, |
| 79 public DelegatedFrameEvictorClient, | 85 public DelegatedFrameEvictorClient, |
| 80 public cc::DelegatedFrameResourceCollectionClient, | 86 public cc::DelegatedFrameResourceCollectionClient, |
| 81 public cc::SurfaceFactoryClient, | 87 public cc::SurfaceFactoryClient, |
| 82 public base::SupportsWeakPtr<DelegatedFrameHost> { | 88 public base::SupportsWeakPtr<DelegatedFrameHost> { |
| 83 public: | 89 public: |
| 84 DelegatedFrameHost(DelegatedFrameHostClient* client); | 90 DelegatedFrameHost(DelegatedFrameHostClient* client, |
| 91 bool begin_frame_scheduling_enabled); |
| 85 ~DelegatedFrameHost() override; | 92 ~DelegatedFrameHost() override; |
| 86 | 93 |
| 87 bool CanCopyToBitmap() const; | 94 bool CanCopyToBitmap() const; |
| 88 | 95 |
| 89 // Public interface exposed to RenderWidgetHostView. | 96 // Public interface exposed to RenderWidgetHostView. |
| 90 void SwapDelegatedFrame( | 97 void SwapDelegatedFrame( |
| 91 uint32 output_surface_id, | 98 uint32 output_surface_id, |
| 92 scoped_ptr<cc::DelegatedFrameData> frame_data, | 99 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 93 float frame_device_scale_factor, | 100 float frame_device_scale_factor, |
| 94 const std::vector<ui::LatencyInfo>& latency_info); | 101 const std::vector<ui::LatencyInfo>& latency_info); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 106 void CopyFromCompositingSurfaceToVideoFrame( | 113 void CopyFromCompositingSurfaceToVideoFrame( |
| 107 const gfx::Rect& src_subrect, | 114 const gfx::Rect& src_subrect, |
| 108 const scoped_refptr<media::VideoFrame>& target, | 115 const scoped_refptr<media::VideoFrame>& target, |
| 109 const base::Callback<void(bool)>& callback); | 116 const base::Callback<void(bool)>& callback); |
| 110 bool CanCopyToVideoFrame() const; | 117 bool CanCopyToVideoFrame() const; |
| 111 bool CanSubscribeFrame() const; | 118 bool CanSubscribeFrame() const; |
| 112 void BeginFrameSubscription( | 119 void BeginFrameSubscription( |
| 113 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); | 120 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); |
| 114 void EndFrameSubscription(); | 121 void EndFrameSubscription(); |
| 115 bool HasFrameSubscriber() const { return frame_subscriber_; } | 122 bool HasFrameSubscriber() const { return frame_subscriber_; } |
| 123 void OnSetNeedsBeginFrames(bool needs_begin_frames); |
| 116 | 124 |
| 117 // Exposed for tests. | 125 // Exposed for tests. |
| 118 cc::DelegatedFrameProvider* FrameProviderForTesting() const { | 126 cc::DelegatedFrameProvider* FrameProviderForTesting() const { |
| 119 return frame_provider_.get(); | 127 return frame_provider_.get(); |
| 120 } | 128 } |
| 121 cc::SurfaceId SurfaceIdForTesting() const { return surface_id_; } | 129 cc::SurfaceId SurfaceIdForTesting() const { return surface_id_; } |
| 122 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { | 130 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { |
| 123 OnCompositingDidCommit(compositor); | 131 OnCompositingDidCommit(compositor); |
| 124 } | 132 } |
| 125 bool ReleasedFrontLockActiveForTesting() const { | 133 bool ReleasedFrontLockActiveForTesting() const { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 140 DestroyedAfterCopyRequest); | 148 DestroyedAfterCopyRequest); |
| 141 | 149 |
| 142 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { | 150 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { |
| 143 return frame_subscriber_.get(); | 151 return frame_subscriber_.get(); |
| 144 } | 152 } |
| 145 bool ShouldCreateResizeLock(); | 153 bool ShouldCreateResizeLock(); |
| 146 void LockResources(); | 154 void LockResources(); |
| 147 void UnlockResources(); | 155 void UnlockResources(); |
| 148 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | 156 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); |
| 149 | 157 |
| 158 void StartObservingBeginFrames(); |
| 159 void StopObservingBeginFrames(); |
| 160 |
| 150 // Overridden from ui::CompositorObserver: | 161 // Overridden from ui::CompositorObserver: |
| 151 void OnCompositingDidCommit(ui::Compositor* compositor) override; | 162 void OnCompositingDidCommit(ui::Compositor* compositor) override; |
| 152 void OnCompositingStarted(ui::Compositor* compositor, | 163 void OnCompositingStarted(ui::Compositor* compositor, |
| 153 base::TimeTicks start_time) override; | 164 base::TimeTicks start_time) override; |
| 154 void OnCompositingEnded(ui::Compositor* compositor) override; | 165 void OnCompositingEnded(ui::Compositor* compositor) override; |
| 155 void OnCompositingAborted(ui::Compositor* compositor) override; | 166 void OnCompositingAborted(ui::Compositor* compositor) override; |
| 156 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; | 167 void OnCompositingLockStateChanged(ui::Compositor* compositor) override; |
| 157 void OnCompositingShuttingDown(ui::Compositor* compositor) override; | 168 void OnCompositingShuttingDown(ui::Compositor* compositor) override; |
| 158 | 169 |
| 159 // Overridden from ui::CompositorVSyncManager::Observer: | 170 // Overridden from ui::CompositorVSyncManager::Observer: |
| 160 void OnUpdateVSyncParameters(base::TimeTicks timebase, | 171 void OnUpdateVSyncParameters(base::TimeTicks timebase, |
| 161 base::TimeDelta interval) override; | 172 base::TimeDelta interval) override; |
| 162 | 173 |
| 174 // Overridden from ui::CompositorBeginFrameObserver: |
| 175 void OnSendBeginFrame(const cc::BeginFrameArgs& args) override; |
| 176 |
| 163 // Overridden from ui::LayerOwnerObserver: | 177 // Overridden from ui::LayerOwnerObserver: |
| 164 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; | 178 void OnLayerRecreated(ui::Layer* old_layer, ui::Layer* new_layer) override; |
| 165 | 179 |
| 166 // Overridden from ImageTransportFactoryObserver: | 180 // Overridden from ImageTransportFactoryObserver: |
| 167 void OnLostResources() override; | 181 void OnLostResources() override; |
| 168 | 182 |
| 169 bool ShouldSkipFrame(gfx::Size size_in_dip) const; | 183 bool ShouldSkipFrame(gfx::Size size_in_dip) const; |
| 170 | 184 |
| 171 // Lazily grab a resize lock if the aura window size doesn't match the current | 185 // Lazily grab a resize lock if the aura window size doesn't match the current |
| 172 // frame size, to give time to the renderer. | 186 // frame size, to give time to the renderer. |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 | 244 |
| 231 void DidReceiveFrameFromRenderer(const gfx::Rect& damage_rect); | 245 void DidReceiveFrameFromRenderer(const gfx::Rect& damage_rect); |
| 232 | 246 |
| 233 DelegatedFrameHostClient* const client_; | 247 DelegatedFrameHostClient* const client_; |
| 234 ui::Compositor* compositor_; | 248 ui::Compositor* compositor_; |
| 235 | 249 |
| 236 // True if this renders into a Surface, false if it renders into a delegated | 250 // True if this renders into a Surface, false if it renders into a delegated |
| 237 // layer. | 251 // layer. |
| 238 bool use_surfaces_; | 252 bool use_surfaces_; |
| 239 | 253 |
| 240 std::vector<base::Closure> on_compositing_did_commit_callbacks_; | |
| 241 | |
| 242 // The vsync manager we are observing for changes, if any. | 254 // The vsync manager we are observing for changes, if any. |
| 243 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; | 255 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; |
| 244 | 256 |
| 257 std::vector<base::Closure> on_compositing_did_commit_callbacks_; |
| 258 |
| 245 // The current VSync timebase and interval. These are zero until the first | 259 // The current VSync timebase and interval. These are zero until the first |
| 246 // call to OnUpdateVSyncParameters(). | 260 // call to OnUpdateVSyncParameters(). |
| 247 base::TimeTicks vsync_timebase_; | 261 base::TimeTicks vsync_timebase_; |
| 248 base::TimeDelta vsync_interval_; | 262 base::TimeDelta vsync_interval_; |
| 249 | 263 |
| 250 // With delegated renderer, this is the last output surface, used to | 264 // With delegated renderer, this is the last output surface, used to |
| 251 // disambiguate resources with the same id coming from different output | 265 // disambiguate resources with the same id coming from different output |
| 252 // surfaces. | 266 // surfaces. |
| 253 uint32 last_output_surface_id_; | 267 uint32 last_output_surface_id_; |
| 254 | 268 |
| (...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 | 325 // Callback used to pass the output request to the layer or to a function |
| 312 // specified by a test. | 326 // specified by a test. |
| 313 base::Callback<void(scoped_ptr<cc::CopyOutputRequest>)> | 327 base::Callback<void(scoped_ptr<cc::CopyOutputRequest>)> |
| 314 request_copy_of_output_callback_for_testing_; | 328 request_copy_of_output_callback_for_testing_; |
| 315 | 329 |
| 316 // YUV readback pipeline. | 330 // YUV readback pipeline. |
| 317 scoped_ptr<content::ReadbackYUVInterface> | 331 scoped_ptr<content::ReadbackYUVInterface> |
| 318 yuv_readback_pipeline_; | 332 yuv_readback_pipeline_; |
| 319 | 333 |
| 320 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; | 334 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; |
| 335 |
| 336 // True when unified BeginFrame scheduing is used. |
| 337 bool begin_frame_scheduling_enabled_; |
| 338 |
| 339 // True when RenderWidget needs a BeginFrame. |
| 340 bool needs_begin_frames_; |
| 341 |
| 342 // Pass |last_sent_begin_frame_args_| to compositor when |this| is added as a |
| 343 // CompositorBeginFrameObserver. With this, Compositor can determine whether |
| 344 // latest BeginFrameArgs can be used immediately or not. |
| 345 cc::BeginFrameArgs last_sent_begin_frame_args_; |
| 321 }; | 346 }; |
| 322 | 347 |
| 323 } // namespace content | 348 } // namespace content |
| 324 | 349 |
| 325 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 350 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ |
| OLD | NEW |