| 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_SURFACE_HOST_H_ |
| 6 #define CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 6 #define CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_SURFACE_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" | |
| 10 #include "cc/output/copy_output_result.h" | 9 #include "cc/output/copy_output_result.h" |
| 10 #include "cc/surfaces/surface_factory_client.h" |
| 11 #include "content/browser/compositor/delegated_frame_host.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" |
| 21 #include "ui/compositor/layer_owner_delegate.h" | 22 #include "ui/compositor/layer_owner_delegate.h" |
| 22 #include "ui/gfx/rect_conversions.h" | 23 #include "ui/gfx/rect_conversions.h" |
| 23 | 24 |
| 24 namespace media { | 25 namespace cc { |
| 25 class VideoFrame; | 26 class SurfaceFactory; |
| 26 } | 27 } |
| 27 | 28 |
| 28 namespace content { | 29 namespace content { |
| 29 | 30 |
| 30 class DelegatedFrameHost; | |
| 31 class ReadbackYUVInterface; | 31 class ReadbackYUVInterface; |
| 32 class RenderWidgetHostViewFrameSubscriber; | |
| 33 class RenderWidgetHostImpl; | |
| 34 class ResizeLock; | |
| 35 | 32 |
| 36 // The DelegatedFrameHostClient is the interface from the DelegatedFrameHost, | 33 class CONTENT_EXPORT DelegatedFrameSurfaceHost |
| 37 // which manages delegated frames, and the ui::Compositor being used to | 34 : public DelegatedFrameHost, |
| 38 // display them. | 35 public ui::CompositorObserver, |
| 39 class CONTENT_EXPORT DelegatedFrameHostClient { | |
| 40 public: | |
| 41 virtual ui::Compositor* GetCompositor() const = 0; | |
| 42 virtual ui::Layer* GetLayer() = 0; | |
| 43 virtual RenderWidgetHostImpl* GetHost() = 0; | |
| 44 virtual void SchedulePaintInRect(const gfx::Rect& damage_rect_in_dip) = 0; | |
| 45 virtual bool IsVisible() = 0; | |
| 46 virtual scoped_ptr<ResizeLock> CreateResizeLock( | |
| 47 bool defer_compositor_lock) = 0; | |
| 48 virtual gfx::Size DesiredFrameSize() = 0; | |
| 49 | |
| 50 // TODO(ccameron): It is likely that at least one of these two functions is | |
| 51 // redundant. Find which one, and delete it. | |
| 52 virtual float CurrentDeviceScaleFactor() = 0; | |
| 53 virtual gfx::Size ConvertViewSizeToPixel(const gfx::Size& size) = 0; | |
| 54 | |
| 55 // These are to be overridden for testing only. | |
| 56 // TODO(ccameron): This is convoluted. Make the tests that need to override | |
| 57 // these functions test DelegatedFrameHost directly (rather than do it | |
| 58 // through RenderWidgetHostViewAura). | |
| 59 virtual DelegatedFrameHost* GetDelegatedFrameHost() const = 0; | |
| 60 virtual bool ShouldCreateResizeLock(); | |
| 61 virtual void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | |
| 62 }; | |
| 63 | |
| 64 // The DelegatedFrameHost is used to host all of the RenderWidgetHostView state | |
| 65 // and functionality that is associated with delegated frames being sent from | |
| 66 // the RenderWidget. The DelegatedFrameHost will push these changes through to | |
| 67 // the ui::Compositor associated with its DelegatedFrameHostClient. | |
| 68 class CONTENT_EXPORT DelegatedFrameHost | |
| 69 : public ui::CompositorObserver, | |
| 70 public ui::CompositorVSyncManager::Observer, | 36 public ui::CompositorVSyncManager::Observer, |
| 71 public ui::LayerOwnerDelegate, | 37 public ui::LayerOwnerDelegate, |
| 72 public ImageTransportFactoryObserver, | 38 public ImageTransportFactoryObserver, |
| 73 public DelegatedFrameEvictorClient, | 39 public DelegatedFrameEvictorClient, |
| 74 public cc::DelegatedFrameResourceCollectionClient, | 40 public cc::SurfaceFactoryClient, |
| 75 public base::SupportsWeakPtr<DelegatedFrameHost> { | 41 public base::SupportsWeakPtr<DelegatedFrameSurfaceHost> { |
| 76 public: | 42 public: |
| 77 DelegatedFrameHost(DelegatedFrameHostClient* client); | 43 DelegatedFrameSurfaceHost(DelegatedFrameHostClient* client); |
| 78 virtual ~DelegatedFrameHost(); | 44 virtual ~DelegatedFrameSurfaceHost(); |
| 79 | |
| 80 bool CanCopyToBitmap() const; | |
| 81 | 45 |
| 82 // Public interface exposed to RenderWidgetHostView. | 46 // Public interface exposed to RenderWidgetHostView. |
| 83 void SwapDelegatedFrame( | 47 virtual bool CanCopyToBitmap() const OVERRIDE; |
| 48 virtual void SwapDelegatedFrame( |
| 84 uint32 output_surface_id, | 49 uint32 output_surface_id, |
| 85 scoped_ptr<cc::DelegatedFrameData> frame_data, | 50 scoped_ptr<cc::DelegatedFrameData> frame_data, |
| 86 float frame_device_scale_factor, | 51 float frame_device_scale_factor, |
| 87 const std::vector<ui::LatencyInfo>& latency_info); | 52 const std::vector<ui::LatencyInfo>& latency_info) OVERRIDE; |
| 88 void WasHidden(); | 53 virtual void WasHidden() OVERRIDE; |
| 89 void WasShown(); | 54 virtual void WasShown() OVERRIDE; |
| 90 void WasResized(); | 55 virtual void WasResized() OVERRIDE; |
| 91 gfx::Size GetRequestedRendererSize() const; | 56 virtual gfx::Size GetRequestedRendererSize() const OVERRIDE; |
| 92 void AddedToWindow(); | 57 virtual void AddedToWindow() OVERRIDE; |
| 93 void RemovingFromWindow(); | 58 virtual void RemovingFromWindow() OVERRIDE; |
| 94 void CopyFromCompositingSurface( | 59 virtual void CopyFromCompositingSurface( |
| 95 const gfx::Rect& src_subrect, | 60 const gfx::Rect& src_subrect, |
| 96 const gfx::Size& dst_size, | 61 const gfx::Size& dst_size, |
| 97 const base::Callback<void(bool, const SkBitmap&)>& callback, | 62 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 98 const SkColorType color_type); | 63 const SkColorType color_type) OVERRIDE; |
| 99 void CopyFromCompositingSurfaceToVideoFrame( | 64 virtual void CopyFromCompositingSurfaceToVideoFrame( |
| 100 const gfx::Rect& src_subrect, | 65 const gfx::Rect& src_subrect, |
| 101 const scoped_refptr<media::VideoFrame>& target, | 66 const scoped_refptr<media::VideoFrame>& target, |
| 102 const base::Callback<void(bool)>& callback); | 67 const base::Callback<void(bool)>& callback) OVERRIDE; |
| 103 bool CanCopyToVideoFrame() const; | 68 virtual bool CanCopyToVideoFrame() const OVERRIDE; |
| 104 bool CanSubscribeFrame() const; | 69 virtual bool CanSubscribeFrame() const OVERRIDE; |
| 105 void BeginFrameSubscription( | 70 virtual void BeginFrameSubscription( |
| 106 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber); | 71 scoped_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) OVERRIDE; |
| 107 void EndFrameSubscription(); | 72 virtual void EndFrameSubscription() OVERRIDE; |
| 108 bool HasFrameSubscriber() const { return frame_subscriber_; } | 73 virtual bool HasFrameSubscriber() const OVERRIDE; |
| 74 virtual void SetLayerOwner(ui::LayerOwner* layer_owner) OVERRIDE; |
| 109 | 75 |
| 110 // Exposed for tests. | 76 virtual cc::DelegatedFrameProvider* FrameProviderForTesting() const OVERRIDE; |
| 111 cc::DelegatedFrameProvider* FrameProviderForTesting() const { | 77 virtual void OnCompositingDidCommitForTesting( |
| 112 return frame_provider_.get(); | 78 ui::Compositor* compositor) OVERRIDE; |
| 113 } | |
| 114 void OnCompositingDidCommitForTesting(ui::Compositor* compositor) { | |
| 115 OnCompositingDidCommit(compositor); | |
| 116 } | |
| 117 bool ShouldCreateResizeLockForTesting() { return ShouldCreateResizeLock(); } | |
| 118 | 79 |
| 119 private: | 80 private: |
| 120 friend class DelegatedFrameHostClient; | 81 friend class DelegatedFrameHostClient; |
| 121 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, | 82 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, |
| 122 SkippedDelegatedFrames); | 83 SkippedDelegatedFrames); |
| 123 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, | 84 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraTest, |
| 124 DiscardDelegatedFramesWithLocking); | 85 DiscardDelegatedFramesWithLocking); |
| 125 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest, | 86 FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewAuraCopyRequestTest, |
| 126 DestroyedAfterCopyRequest); | 87 DestroyedAfterCopyRequest); |
| 127 | 88 |
| 128 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { | 89 RenderWidgetHostViewFrameSubscriber* frame_subscriber() const { |
| 129 return frame_subscriber_.get(); | 90 return frame_subscriber_.get(); |
| 130 } | 91 } |
| 131 bool ShouldCreateResizeLock(); | 92 virtual bool ShouldCreateResizeLock() OVERRIDE; |
| 132 void RequestCopyOfOutput(scoped_ptr<cc::CopyOutputRequest> request); | 93 virtual void RequestCopyOfOutput( |
| 94 scoped_ptr<cc::CopyOutputRequest> request) OVERRIDE; |
| 133 | 95 |
| 134 void LockResources(); | 96 virtual void LockResources() OVERRIDE; |
| 135 void UnlockResources(); | 97 virtual void UnlockResources() OVERRIDE; |
| 136 | 98 |
| 137 // Overridden from ui::CompositorObserver: | 99 // Overridden from ui::CompositorObserver: |
| 138 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE; | 100 virtual void OnCompositingDidCommit(ui::Compositor* compositor) OVERRIDE; |
| 139 virtual void OnCompositingStarted(ui::Compositor* compositor, | 101 virtual void OnCompositingStarted(ui::Compositor* compositor, |
| 140 base::TimeTicks start_time) OVERRIDE; | 102 base::TimeTicks start_time) OVERRIDE; |
| 141 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; | 103 virtual void OnCompositingEnded(ui::Compositor* compositor) OVERRIDE; |
| 142 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE; | 104 virtual void OnCompositingAborted(ui::Compositor* compositor) OVERRIDE; |
| 143 virtual void OnCompositingLockStateChanged( | 105 virtual void OnCompositingLockStateChanged( |
| 144 ui::Compositor* compositor) OVERRIDE; | 106 ui::Compositor* compositor) OVERRIDE; |
| 145 | 107 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 const gfx::Size& dst_size_in_pixel, | 142 const gfx::Size& dst_size_in_pixel, |
| 181 const SkColorType color_type, | 143 const SkColorType color_type, |
| 182 const base::Callback<void(bool, const SkBitmap&)>& callback, | 144 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 183 scoped_ptr<cc::CopyOutputResult> result); | 145 scoped_ptr<cc::CopyOutputResult> result); |
| 184 static void PrepareBitmapCopyOutputResult( | 146 static void PrepareBitmapCopyOutputResult( |
| 185 const gfx::Size& dst_size_in_pixel, | 147 const gfx::Size& dst_size_in_pixel, |
| 186 const SkColorType color_type, | 148 const SkColorType color_type, |
| 187 const base::Callback<void(bool, const SkBitmap&)>& callback, | 149 const base::Callback<void(bool, const SkBitmap&)>& callback, |
| 188 scoped_ptr<cc::CopyOutputResult> result); | 150 scoped_ptr<cc::CopyOutputResult> result); |
| 189 static void CopyFromCompositingSurfaceHasResultForVideo( | 151 static void CopyFromCompositingSurfaceHasResultForVideo( |
| 190 base::WeakPtr<DelegatedFrameHost> rwhva, | 152 base::WeakPtr<DelegatedFrameSurfaceHost> rwhva, |
| 191 scoped_refptr<OwnedMailbox> subscriber_texture, | 153 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 192 scoped_refptr<media::VideoFrame> video_frame, | 154 scoped_refptr<media::VideoFrame> video_frame, |
| 193 const base::Callback<void(bool)>& callback, | 155 const base::Callback<void(bool)>& callback, |
| 194 scoped_ptr<cc::CopyOutputResult> result); | 156 scoped_ptr<cc::CopyOutputResult> result); |
| 195 static void CopyFromCompositingSurfaceFinishedForVideo( | 157 static void CopyFromCompositingSurfaceFinishedForVideo( |
| 196 base::WeakPtr<DelegatedFrameHost> rwhva, | 158 base::WeakPtr<DelegatedFrameSurfaceHost> rwhva, |
| 197 const base::Callback<void(bool)>& callback, | 159 const base::Callback<void(bool)>& callback, |
| 198 scoped_refptr<OwnedMailbox> subscriber_texture, | 160 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 199 scoped_ptr<cc::SingleReleaseCallback> release_callback, | 161 scoped_ptr<cc::SingleReleaseCallback> release_callback, |
| 200 bool result); | 162 bool result); |
| 201 static void ReturnSubscriberTexture( | 163 static void ReturnSubscriberTexture( |
| 202 base::WeakPtr<DelegatedFrameHost> rwhva, | 164 base::WeakPtr<DelegatedFrameSurfaceHost> rwhva, |
| 203 scoped_refptr<OwnedMailbox> subscriber_texture, | 165 scoped_refptr<OwnedMailbox> subscriber_texture, |
| 204 uint32 sync_point); | 166 uint32 sync_point); |
| 205 | 167 |
| 206 void SendDelegatedFrameAck(uint32 output_surface_id); | 168 void SendDelegatedFrameAck(uint32 output_surface_id); |
| 207 void SendReturnedDelegatedResources(uint32 output_surface_id); | 169 void SendReturnedDelegatedResources(uint32 output_surface_id); |
| 208 | 170 |
| 209 // DelegatedFrameEvictorClient implementation. | 171 // DelegatedFrameEvictorClient implementation. |
| 210 virtual void EvictDelegatedFrame() OVERRIDE; | 172 virtual void EvictDelegatedFrame() OVERRIDE; |
| 211 | 173 |
| 212 // cc::DelegatedFrameProviderClient implementation. | 174 // cc::SurfaceFactoryClient implementation. |
| 213 virtual void UnusedResourcesAreAvailable() OVERRIDE; | 175 virtual void ReturnResources( |
| 176 const cc::ReturnedResourceArray& resources) OVERRIDE; |
| 214 | 177 |
| 215 void DidReceiveFrameFromRenderer(); | 178 void DidReceiveFrameFromRenderer(); |
| 216 | 179 |
| 217 DelegatedFrameHostClient* client_; | 180 DelegatedFrameHostClient* client_; |
| 218 | 181 |
| 219 std::vector<base::Closure> on_compositing_did_commit_callbacks_; | 182 std::vector<base::Closure> on_compositing_did_commit_callbacks_; |
| 220 | 183 |
| 221 // The vsync manager we are observing for changes, if any. | 184 // The vsync manager we are observing for changes, if any. |
| 222 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; | 185 scoped_refptr<ui::CompositorVSyncManager> vsync_manager_; |
| 223 | 186 |
| 224 // With delegated renderer, this is the last output surface, used to | 187 // With delegated renderer, this is the last output surface, used to |
| 225 // disambiguate resources with the same id coming from different output | 188 // disambiguate resources with the same id coming from different output |
| 226 // surfaces. | 189 // surfaces. |
| 227 uint32 last_output_surface_id_; | 190 uint32 last_output_surface_id_; |
| 228 | 191 |
| 229 // The number of delegated frame acks that are pending, to delay resource | 192 // The number of delegated frame acks that are pending, to delay resource |
| 230 // returns until the acks are sent. | 193 // returns until the acks are sent. |
| 231 int pending_delegated_ack_count_; | 194 int pending_delegated_ack_count_; |
| 232 | 195 |
| 233 // True after a delegated frame has been skipped, until a frame is not | 196 // True after a delegated frame has been skipped, until a frame is not |
| 234 // skipped. | 197 // skipped. |
| 235 bool skipped_frames_; | 198 bool skipped_frames_; |
| 236 std::vector<ui::LatencyInfo> skipped_latency_info_list_; | 199 std::vector<ui::LatencyInfo> skipped_latency_info_list_; |
| 237 | 200 |
| 238 // Holds delegated resources that have been given to a DelegatedFrameProvider, | 201 scoped_ptr<cc::SurfaceIdAllocator> id_allocator_; |
| 239 // and gives back resources when they are no longer in use for return to the | 202 scoped_ptr<cc::SurfaceFactory> surface_factory_; |
| 240 // renderer. | 203 cc::SurfaceId surface_id_; |
| 241 scoped_refptr<cc::DelegatedFrameResourceCollection> resource_collection_; | 204 gfx::Size current_surface_size_; |
| 242 | 205 cc::ReturnedResourceArray surface_returned_resources_; |
| 243 // Provides delegated frame updates to the cc::DelegatedRendererLayer. | |
| 244 scoped_refptr<cc::DelegatedFrameProvider> frame_provider_; | |
| 245 | 206 |
| 246 // This lock is the one waiting for a frame of the right size to come back | 207 // 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 | 208 // 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 | 209 // 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 | 210 // 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 | 211 // 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. | 212 // renderer of producing a frame of the right size. |
| 252 scoped_ptr<ResizeLock> resize_lock_; | 213 scoped_ptr<ResizeLock> resize_lock_; |
| 253 | 214 |
| 254 // Keeps track of the current frame size. | 215 // Keeps track of the current frame size. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 268 }; | 229 }; |
| 269 CanLockCompositorState can_lock_compositor_; | 230 CanLockCompositorState can_lock_compositor_; |
| 270 | 231 |
| 271 base::TimeTicks last_draw_ended_; | 232 base::TimeTicks last_draw_ended_; |
| 272 | 233 |
| 273 // Subscriber that listens to frame presentation events. | 234 // Subscriber that listens to frame presentation events. |
| 274 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_; | 235 scoped_ptr<RenderWidgetHostViewFrameSubscriber> frame_subscriber_; |
| 275 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_; | 236 std::vector<scoped_refptr<OwnedMailbox> > idle_frame_subscriber_textures_; |
| 276 | 237 |
| 277 // YUV readback pipeline. | 238 // YUV readback pipeline. |
| 278 scoped_ptr<content::ReadbackYUVInterface> | 239 scoped_ptr<content::ReadbackYUVInterface> yuv_readback_pipeline_; |
| 279 yuv_readback_pipeline_; | |
| 280 | 240 |
| 281 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; | 241 scoped_ptr<DelegatedFrameEvictor> delegated_frame_evictor_; |
| 282 }; | 242 }; |
| 283 | 243 |
| 284 } // namespace content | 244 } // namespace content |
| 285 | 245 |
| 286 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_HOST_H_ | 246 #endif // CONTENT_BROWSER_COMPOSITOR_DELEGATED_FRAME_SURFACE_HOST_H_ |
| OLD | NEW |