| 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 "content/browser/compositor/image_transport_factory.h" | 12 #include "content/browser/compositor/image_transport_factory.h" |
| 12 #include "content/browser/compositor/owned_mailbox.h" | 13 #include "content/browser/compositor/owned_mailbox.h" |
| 13 #include "content/browser/renderer_host/delegated_frame_evictor.h" | 14 #include "content/browser/renderer_host/delegated_frame_evictor.h" |
| 14 #include "content/browser/renderer_host/dip_util.h" | 15 #include "content/browser/renderer_host/dip_util.h" |
| 15 #include "content/browser/renderer_host/render_widget_host_impl.h" | 16 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 16 #include "content/public/browser/render_process_host.h" | 17 #include "content/public/browser/render_process_host.h" |
| 17 #include "ui/compositor/compositor.h" | 18 #include "ui/compositor/compositor.h" |
| 18 #include "ui/compositor/compositor_observer.h" | 19 #include "ui/compositor/compositor_observer.h" |
| 19 #include "ui/compositor/compositor_vsync_manager.h" | 20 #include "ui/compositor/compositor_vsync_manager.h" |
| 20 #include "ui/compositor/layer.h" | 21 #include "ui/compositor/layer.h" |
| 22 #include "ui/compositor/layer_owner.h" |
| 21 #include "ui/compositor/layer_owner_delegate.h" | 23 #include "ui/compositor/layer_owner_delegate.h" |
| 22 #include "ui/gfx/rect_conversions.h" | 24 #include "ui/gfx/rect_conversions.h" |
| 23 | 25 |
| 26 namespace cc { |
| 27 class SurfaceFactory; |
| 28 } |
| 29 |
| 24 namespace media { | 30 namespace media { |
| 25 class VideoFrame; | 31 class VideoFrame; |
| 26 } | 32 } |
| 27 | 33 |
| 28 namespace content { | 34 namespace content { |
| 29 | 35 |
| 30 class DelegatedFrameHost; | 36 class DelegatedFrameHost; |
| 31 class ReadbackYUVInterface; | |
| 32 class RenderWidgetHostViewFrameSubscriber; | 37 class RenderWidgetHostViewFrameSubscriber; |
| 33 class RenderWidgetHostImpl; | 38 class RenderWidgetHostImpl; |
| 34 class ResizeLock; | 39 class ResizeLock; |
| 35 | 40 |
| 36 // The DelegatedFrameHostClient is the interface from the DelegatedFrameHost, | 41 // The DelegatedFrameHostClient is the interface from the DelegatedFrameHost, |
| 37 // which manages delegated frames, and the ui::Compositor being used to | 42 // which manages delegated frames, and the ui::Compositor being used to |
| 38 // display them. | 43 // display them. |
| 39 class CONTENT_EXPORT DelegatedFrameHostClient { | 44 class CONTENT_EXPORT DelegatedFrameHostClient { |
| 40 public: | 45 public: |
| 41 virtual ui::Compositor* GetCompositor() const = 0; | 46 virtual ui::Compositor* GetCompositor() const = 0; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 58 // through RenderWidgetHostViewAura). | 63 // through RenderWidgetHostViewAura). |
| 59 virtual DelegatedFrameHost* GetDelegatedFrameHost() const = 0; | 64 virtual DelegatedFrameHost* GetDelegatedFrameHost() const = 0; |
| 60 virtual bool ShouldCreateResizeLock(); | 65 virtual bool ShouldCreateResizeLock(); |
| 61 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | 66 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state | 69 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state |
| 65 // and functionality that is associated with delegated frames being sent from | 70 // and functionality that is associated with delegated frames being sent from |
| 66 // the RenderWidget. The DelegatedFrameHost will push these changes through to | 71 // the RenderWidget. The DelegatedFrameHost will push these changes through to |
| 67 // the ui::Compositor associated with its DelegatedFrameHostClient. | 72 // the ui::Compositor associated with its DelegatedFrameHostClient. |
| 68 class CONTENT_EXPORT DelegatedFrameHost | 73 class CONTENT_EXPORT DelegatedFrameHost { |
| 69 : public ui::CompositorObserver, | |
| 70 public ui::CompositorVSyncManager::Observer, | |
| 71 public ui::LayerOwnerDelegate, | |
| 72 public ImageTransportFactoryObserver, | |
| 73 public DelegatedFrameEvictorClient, | |
| 74 public cc::DelegatedFrameResourceCollectionClient, | |
| 75 public base::SupportsWeakPtr<DelegatedFrameHost> { | |
| 76 public: | 74 public: |
| 77 DelegatedFrameHost(DelegatedFrameHostClient* client); | 75 static DelegatedFrameHost* Create(DelegatedFrameHostClient* client); |
| 78 virtual ~DelegatedFrameHost(); | |
| 79 | 76 |
| 80 bool CanCopyToBitmap() const; | 77 virtual ~DelegatedFrameHost() {} |
| 81 | 78 |
| 82 // Public interface exposed to RenderWidgetHostView. | 79 // Public interface exposed to RenderWidgetHostView. |
| 83 void SwapDelegatedFrame( | 80 virtual bool CanCopyToBitmap() const = 0; |
| 81 virtual void SwapDelegatedFrame( |
| 84 uint32 output_surface_id, | 82 uint32 output_surface_id, |
| 85 scoped_ptr<cc::DelegatedFrameData> frame_data, | 83 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 86 float frame_device_scale_factor, | 84 float frame_device_scale_factor, |
| 87 const std::vector<ui::LatencyInfo>& latency_info); | 85 const std::vector<ui::LatencyInfo>& latency_info) = 0; |
| 88 void WasHidden(); | 86 virtual void WasHidden() = 0; |
| 89 void WasShown(); | 87 virtual void WasShown() = 0; |
| 90 void WasResized(); | 88 virtual void WasResized() = 0; |
| 91 gfx::Size GetRequestedRendererSize() const; | 89 virtual gfx::Size GetRequestedRendererSize() const = 0; |
| 92 void AddedToWindow(); | 90 virtual void AddedToWindow() = 0; |
| 93 void RemovingFromWindow(); | 91 virtual void RemovingFromWindow() = 0; |
| 94 void CopyFromCompositingSurface( | 92 virtual void CopyFromCompositingSurface( |
| 95 const gfx::Rect& src_subrect, | 93 const gfx::Rect& src_subrect, |
| 96 const gfx::Size& dst_size, | 94 const gfx::Size& dst_size, |
| 97 const base::Callback<void(bool, const SkBitmap&)>& callback, | 95 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 98 const SkColorType color_type); | 96 const SkColorType color_type) = 0; |
| 99 void CopyFromCompositingSurfaceToVideoFrame( | 97 virtual void CopyFromCompositingSurfaceToVideoFrame( |
| 100 const gfx::Rect& src_subrect, | 98 const gfx::Rect& src_subrect, |
| 101 const scoped_refptr<media::VideoFrame>& target, | 99 const scoped_refptr<media::VideoFrame>& target, |
| 102 const base::Callback<void(bool)>& callback); | 100 const base::Callback<void(bool)>& callback) = 0; |
| 103 bool CanCopyToVideoFrame() const; | 101 virtual bool CanCopyToVideoFrame() const = 0; |
| 104 bool CanSubscribeFrame() const; | 102 virtual bool CanSubscribeFrame() const = 0; |
| 105 void BeginFrameSubscription( | 103 virtual void BeginFrameSubscription( |
| 106 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); | 104 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) = 0; |
| 107 void EndFrameSubscription(); | 105 virtual void EndFrameSubscription() = 0; |
| 108 bool HasFrameSubscriber() const { return frame_subscriber_; } | 106 virtual bool HasFrameSubscriber() const = 0; |
| 107 virtual void SetLayerOwner(ui::LayerOwner* layer_owner) = 0; |
| 109 | 108 |
| 110 // Exposed for tests. | 109 // Exposed for tests. |
| 111 cc::DelegatedFrameProvider* FrameProviderForTesting() const { | 110 virtual cc::DelegatedFrameProvider* FrameProviderForTesting() const = 0; |
| 112 return frame_provider_.get(); | 111 virtual void OnCompositingDidCommitForTesting(ui::Compositor* compositor) = 0; |
| 113 } | |
| 114 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { | |
| 115 OnCompositingDidCommit(compositor); | |
| 116 } | |
| 117 bool ShouldCreateResizeLockForTesting() { return ShouldCreateResizeLock(); } | 112 bool ShouldCreateResizeLockForTesting() { return ShouldCreateResizeLock(); } |
| 118 | 113 |
| 119 private: | 114 private: |
| 120 friend class DelegatedFrameHostClient; | 115 friend class DelegatedFrameHostClient; |
| 121 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, | 116 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, |
| 122 SkippedDelegatedFrames); | 117 SkippedDelegatedFrames); |
| 123 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, | 118 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, |
| 124 DiscardDelegatedFramesWithLocking); | 119 DiscardDelegatedFramesWithLocking); |
| 125 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest, | 120 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest, |
| 126 DestroyedAfterCopyRequest); | 121 DestroyedAfterCopyRequest); |
| 127 | 122 |
| 128 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { | 123 virtual bool ShouldCreateResizeLock() = 0; |
| 129 return frame_subscriber_.get(); | 124 virtual void RequestCopyOfOutput( |
| 130 } | 125 scoped_ptr<cc::CopyOutputRequest> request) = 0; |
| 131 bool ShouldCreateResizeLock(); | |
| 132 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | |
| 133 | 126 |
| 134 void LockResources(); | 127 virtual void LockResources() = 0; |
| 135 void UnlockResources(); | 128 virtual void UnlockResources() = 0; |
| 136 | |
| 137 // Overridden from ui::CompositorObserver: | |
| 138 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE; | |
| 139 virtual void OnCompositingStarted(ui::Compositor* compositor, | |
| 140 base::TimeTicks start_time) OVERRIDE; | |
| 141 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; | |
| 142 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE; | |
| 143 virtual void OnCompositingLockStateChanged( | |
| 144 ui::Compositor* compositor) OVERRIDE; | |
| 145 | |
| 146 // Overridden from ui::CompositorVSyncManager::Observer: | |
| 147 virtual void OnUpdateVSyncParameters(base::TimeTicks timebase, | |
| 148 base::TimeDelta interval) OVERRIDE; | |
| 149 | |
| 150 // Overridden from ui::LayerOwnerObserver: | |
| 151 virtual void OnLayerRecreated(ui::Layer* old_layer, | |
| 152 ui::Layer* new_layer) OVERRIDE; | |
| 153 | |
| 154 // Overridden from ImageTransportFactoryObserver: | |
| 155 virtual void OnLostResources() OVERRIDE; | |
| 156 | |
| 157 bool ShouldSkipFrame(gfx::Size size_in_dip) const; | |
| 158 | |
| 159 // Lazily grab a resize lock if the aura window size doesn't match the current | |
| 160 // frame size, to give time to the renderer. | |
| 161 void MaybeCreateResizeLock(); | |
| 162 | |
| 163 // Checks if the resize lock can be released because we received an new frame. | |
| 164 void CheckResizeLock(); | |
| 165 | |
| 166 // Run all on compositing commit callbacks. | |
| 167 void RunOnCommitCallbacks(); | |
| 168 | |
| 169 // Add on compositing commit callback. | |
| 170 void AddOnCommitCallbackAndDisableLocks(const base::Closure& callback); | |
| 171 | |
| 172 // Called after async thumbnailer task completes. Scales and crops the result | |
| 173 // of the copy. | |
| 174 static void CopyFromCompositingSurfaceHasResult( | |
| 175 const gfx::Size& dst_size_in_pixel, | |
| 176 const SkColorType color_type, | |
| 177 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 178 scoped_ptr<cc::CopyOutputResult> result); | |
| 179 static void PrepareTextureCopyOutputResult( | |
| 180 const gfx::Size& dst_size_in_pixel, | |
| 181 const SkColorType color_type, | |
| 182 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 183 scoped_ptr<cc::CopyOutputResult> result); | |
| 184 static void PrepareBitmapCopyOutputResult( | |
| 185 const gfx::Size& dst_size_in_pixel, | |
| 186 const SkColorType color_type, | |
| 187 const base::Callback<void(bool, const SkBitmap&)>& callback, | |
| 188 scoped_ptr<cc::CopyOutputResult> result); | |
| 189 static void CopyFromCompositingSurfaceHasResultForVideo( | |
| 190 base::WeakPtr<DelegatedFrameHost> rwhva, | |
| 191 scoped_refptr<OwnedMailbox> subscriber_texture, | |
| 192 scoped_refptr<media::VideoFrame> video_frame, | |
| 193 const base::Callback<void(bool)>& callback, | |
| 194 scoped_ptr<cc::CopyOutputResult> result); | |
| 195 static void CopyFromCompositingSurfaceFinishedForVideo( | |
| 196 base::WeakPtr<DelegatedFrameHost> rwhva, | |
| 197 const base::Callback<void(bool)>& callback, | |
| 198 scoped_refptr<OwnedMailbox> subscriber_texture, | |
| 199 scoped_ptr<cc::SingleReleaseCallback> release_callback, | |
| 200 bool result); | |
| 201 static void ReturnSubscriberTexture( | |
| 202 base::WeakPtr<DelegatedFrameHost> rwhva, | |
| 203 scoped_refptr<OwnedMailbox> subscriber_texture, | |
| 204 uint32 sync_point); | |
| 205 | |
| 206 void SendDelegatedFrameAck(uint32 output_surface_id); | |
| 207 void SendReturnedDelegatedResources(uint32 output_surface_id); | |
| 208 | |
| 209 // DelegatedFrameEvictorClient implementation. | |
| 210 virtual void EvictDelegatedFrame() OVERRIDE; | |
| 211 | |
| 212 // cc::DelegatedFrameProviderClient implementation. | |
| 213 virtual void UnusedResourcesAreAvailable() OVERRIDE; | |
| 214 | |
| 215 void DidReceiveFrameFromRenderer(); | |
| 216 | |
| 217 DelegatedFrameHostClient* client_; | |
| 218 | |
| 219 std::vector<base::Closure> on_compositing_did_commit_callbacks_; | |
| 220 | |
| 221 // The vsync manager we are observing for changes, if any. | |
| 222 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; | |
| 223 | |
| 224 // With delegated renderer, this is the last output surface, used to | |
| 225 // disambiguate resources with the same id coming from different output | |
| 226 // surfaces. | |
| 227 uint32 last_output_surface_id_; | |
| 228 | |
| 229 // The number of delegated frame acks that are pending, to delay resource | |
| 230 // returns until the acks are sent. | |
| 231 int pending_delegated_ack_count_; | |
| 232 | |
| 233 // True after a delegated frame has been skipped, until a frame is not | |
| 234 // skipped. | |
| 235 bool skipped_frames_; | |
| 236 std::vector<ui::LatencyInfo> skipped_latency_info_list_; | |
| 237 | |
| 238 // Holds delegated resources that have been given to a DelegatedFrameProvider, | |
| 239 // and gives back resources when they are no longer in use for return to the | |
| 240 // renderer. | |
| 241 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; | |
| 242 | |
| 243 // Provides delegated frame updates to the cc::DelegatedRendererLayer. | |
| 244 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; | |
| 245 | |
| 246 // This lock is the one waiting for a frame of the right size to come back | |
| 247 // from the renderer/GPU process. It is set from the moment the aura window | |
| 248 // got resized, to the moment we committed the renderer frame of the same | |
| 249 // size. It keeps track of the size we expect from the renderer, and locks the | |
| 250 // compositor, as well as the UI for a short time to give a chance to the | |
| 251 // renderer of producing a frame of the right size. | |
| 252 scoped_ptr<ResizeLock> resize_lock_; | |
| 253 | |
| 254 // Keeps track of the current frame size. | |
| 255 gfx::Size current_frame_size_in_dip_; | |
| 256 | |
| 257 // This lock is for waiting for a front surface to become available to draw. | |
| 258 scoped_refptr<ui::CompositorLock> released_front_lock_; | |
| 259 | |
| 260 enum CanLockCompositorState { | |
| 261 YES_CAN_LOCK, | |
| 262 // We locked, so at some point we'll need to kick a frame. | |
| 263 YES_DID_LOCK, | |
| 264 // No. A lock timed out, we need to kick a new frame before locking again. | |
| 265 NO_PENDING_RENDERER_FRAME, | |
| 266 // No. We've got a frame, but it hasn't been committed. | |
| 267 NO_PENDING_COMMIT, | |
| 268 }; | |
| 269 CanLockCompositorState can_lock_compositor_; | |
| 270 | |
| 271 base::TimeTicks last_draw_ended_; | |
| 272 | |
| 273 // Subscriber that listens to frame presentation events. | |
| 274 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_; | |
| 275 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_; | |
| 276 | |
| 277 // YUV readback pipeline. | |
| 278 scoped_ptr<content::ReadbackYUVInterface> | |
| 279 yuv_readback_pipeline_; | |
| 280 | |
| 281 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; | |
| 282 }; | 129 }; |
| 283 | 130 |
| 284 } // namespace content | 131 } // namespace content |
| 285 | 132 |
| 286 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 133 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ |
| OLD | NEW |