khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_ |
| 6 | #define UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_ |
| 7 | |
| 8 | #include "base/macros.h" |
| 9 | #include "base/memory/ref_counted.h" |
danakj | f20f450 | 2017-09-26 17:13:31 | [diff] [blame] | 10 | #include "components/viz/common/frame_sinks/copy_output_request.h" |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 11 | #include "components/viz/common/resources/returned_resource.h" |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 12 | #include "components/viz/common/surfaces/parent_local_surface_id_allocator.h" |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame] | 13 | #include "components/viz/common/surfaces/surface_info.h" |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 14 | #include "components/viz/host/host_frame_sink_client.h" |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 15 | #include "components/viz/service/frame_sinks/compositor_frame_sink_support.h" |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 16 | #include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h" |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 17 | #include "ui/android/ui_android_export.h" |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 18 | #include "ui/compositor/compositor_lock.h" |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 19 | |
| 20 | namespace cc { |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 21 | class SurfaceLayer; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 22 | enum class SurfaceDrawStatus; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 23 | } // namespace cc |
| 24 | |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 25 | namespace viz { |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 26 | class CompositorFrame; |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 27 | class HostFrameSinkManager; |
| 28 | } // namespace viz |
| 29 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 30 | namespace ui { |
| 31 | class ViewAndroid; |
| 32 | class WindowAndroidCompositor; |
| 33 | |
| 34 | class UI_ANDROID_EXPORT DelegatedFrameHostAndroid |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 35 | : public viz::mojom::CompositorFrameSinkClient, |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 36 | public viz::ExternalBeginFrameSourceClient, |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 37 | public viz::HostFrameSinkClient, |
| 38 | public ui::CompositorLockClient { |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 39 | public: |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 40 | class Client { |
| 41 | public: |
| 42 | virtual void SetBeginFrameSource( |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 43 | viz::BeginFrameSource* begin_frame_source) = 0; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 44 | virtual void DidReceiveCompositorFrameAck() = 0; |
Brian Anderson | 69624e75 | 2018-03-01 23:25:03 | [diff] [blame] | 45 | virtual void DidPresentCompositorFrame(uint32_t presentation_token, |
| 46 | base::TimeTicks time, |
| 47 | base::TimeDelta refresh, |
| 48 | uint32_t flags) = 0; |
| 49 | virtual void DidDiscardCompositorFrame(uint32_t presentation_token) = 0; |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 50 | virtual void ReclaimResources( |
| 51 | const std::vector<viz::ReturnedResource>&) = 0; |
yiyix | ae38c33 | 2017-11-14 18:58:27 | [diff] [blame] | 52 | virtual void OnFrameTokenChanged(uint32_t frame_token) = 0; |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 53 | virtual void DidReceiveFirstFrameAfterNavigation() = 0; |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 54 | }; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 55 | |
| 56 | DelegatedFrameHostAndroid(ViewAndroid* view, |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 57 | viz::HostFrameSinkManager* host_frame_sink_manager, |
xlai | 9351829f | 2017-01-27 18:39:13 | [diff] [blame] | 58 | Client* client, |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 59 | const viz::FrameSinkId& frame_sink_id); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 60 | |
| 61 | ~DelegatedFrameHostAndroid() override; |
| 62 | |
Ria Jiang | d89b7055 | 2018-02-22 05:36:26 | [diff] [blame] | 63 | void SubmitCompositorFrame( |
| 64 | const viz::LocalSurfaceId& local_surface_id, |
| 65 | viz::CompositorFrame frame, |
danakj | 54af81a | 2018-05-24 23:59:02 | [diff] [blame] | 66 | base::Optional<viz::HitTestRegionList> hit_test_region_list); |
Fady Samuel | c296f5fb | 2017-07-21 04:02:19 | [diff] [blame] | 67 | void DidNotProduceFrame(const viz::BeginFrameAck& ack); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 68 | |
| 69 | void DestroyDelegatedContent(); |
| 70 | |
| 71 | bool HasDelegatedContent() const; |
| 72 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 73 | viz::FrameSinkId GetFrameSinkId() const; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 74 | |
Yuri Wiitala | b9ad27a | 2017-09-06 19:13:50 | [diff] [blame] | 75 | // Should only be called when the host has a content layer. Use this for one- |
| 76 | // off screen capture, not for video. Always provides RGBA_BITMAP |
| 77 | // CopyOutputResults. |
Yuri Wiitala | 419ed0f | 2018-02-22 23:21:38 | [diff] [blame] | 78 | void CopyFromCompositingSurface( |
| 79 | const gfx::Rect& src_subrect, |
| 80 | const gfx::Size& output_size, |
| 81 | base::OnceCallback<void(const SkBitmap&)> callback); |
| 82 | bool CanCopyFromCompositingSurface() const; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 83 | |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 84 | void CompositorFrameSinkChanged(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 85 | |
enne | a487a27 | 2016-09-30 19:56:18 | [diff] [blame] | 86 | // Called when this DFH is attached/detached from a parent browser compositor |
| 87 | // and needs to be attached to the surface hierarchy. |
staraz | aa23111 | 2017-02-07 17:53:24 | [diff] [blame] | 88 | void AttachToCompositor(WindowAndroidCompositor* compositor); |
| 89 | void DetachFromCompositor(); |
enne | a487a27 | 2016-09-30 19:56:18 | [diff] [blame] | 90 | |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 91 | void SynchronizeVisualProperties(gfx::Size size_in_pixels); |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 92 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 93 | // Called when we begin a resize operation. Takes the compositor lock until we |
| 94 | // receive a frame of the expected size. |
| 95 | void PixelSizeWillChange(const gfx::Size& pixel_size); |
| 96 | |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 97 | // Returns the ID for the current Surface. Returns an invalid ID if no |
| 98 | // surface exists (!HasDelegatedContent()). |
| 99 | const viz::SurfaceId& SurfaceId() const; |
| 100 | |
| 101 | // Returns the local surface ID for this delegated content. |
| 102 | const viz::LocalSurfaceId& GetLocalSurfaceId() const; |
kenrb | 2b5d08b | 2017-03-08 22:31:29 | [diff] [blame] | 103 | |
Fady Samuel | db67d4e3e | 2018-05-17 00:59:45 | [diff] [blame] | 104 | // TODO(fsamuel): We should move the viz::ParentLocalSurfaceIdAllocator to |
| 105 | // RenderWidgetHostViewAndroid. |
| 106 | viz::ParentLocalSurfaceIdAllocator* GetLocalSurfaceIdAllocator() { |
| 107 | return &local_surface_id_allocator_; |
| 108 | } |
| 109 | |
Saman Sami | 26a1fcd | 2018-04-10 17:12:21 | [diff] [blame] | 110 | void TakeFallbackContentFrom(DelegatedFrameHostAndroid* other); |
| 111 | |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 112 | void DidNavigate(); |
| 113 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 114 | private: |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 115 | // viz::mojom::CompositorFrameSinkClient implementation. |
samans | 8d3604f | 2017-04-11 22:15:30 | [diff] [blame] | 116 | void DidReceiveCompositorFrameAck( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 117 | const std::vector<viz::ReturnedResource>& resources) override; |
Peng Huang | 5207a6e | 2017-10-26 00:39:30 | [diff] [blame] | 118 | void DidPresentCompositorFrame(uint32_t presentation_token, |
| 119 | base::TimeTicks time, |
| 120 | base::TimeDelta refresh, |
| 121 | uint32_t flags) override; |
| 122 | void DidDiscardCompositorFrame(uint32_t presentation_token) override; |
Fady Samuel | c296f5fb | 2017-07-21 04:02:19 | [diff] [blame] | 123 | void OnBeginFrame(const viz::BeginFrameArgs& args) override; |
danakj | 30464ba1 | 2017-06-29 21:26:45 | [diff] [blame] | 124 | void ReclaimResources( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 125 | const std::vector<viz::ReturnedResource>& resources) override; |
Bill Orr | 372a126 | 2017-07-20 00:18:39 | [diff] [blame] | 126 | void OnBeginFramePausedChanged(bool paused) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 127 | |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 128 | // viz::ExternalBeginFrameSourceClient implementation. |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 129 | void OnNeedsBeginFrames(bool needs_begin_frames) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 130 | |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 131 | // viz::HostFrameSinkClient implementation. |
Fady Samuel | 5b7fb8e | 2017-08-08 16:58:22 | [diff] [blame] | 132 | void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override; |
yiyix | ae38c33 | 2017-11-14 18:58:27 | [diff] [blame] | 133 | void OnFrameTokenChanged(uint32_t frame_token) override; |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 134 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 135 | // ui::CompositorLockClient implementation. |
| 136 | void CompositorLockTimedOut() override; |
| 137 | |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 138 | void CreateNewCompositorFrameSinkSupport(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 139 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 140 | const viz::FrameSinkId frame_sink_id_; |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 141 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 142 | ViewAndroid* view_; |
| 143 | |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 144 | viz::HostFrameSinkManager* const host_frame_sink_manager_; |
staraz | aa23111 | 2017-02-07 17:53:24 | [diff] [blame] | 145 | WindowAndroidCompositor* registered_parent_compositor_ = nullptr; |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 146 | Client* client_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 147 | |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 148 | std::unique_ptr<viz::CompositorFrameSinkSupport> support_; |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 149 | viz::ExternalBeginFrameSource begin_frame_source_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 150 | |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame] | 151 | viz::SurfaceInfo surface_info_; |
samans | e7398c55 | 2017-03-21 21:36:28 | [diff] [blame] | 152 | bool has_transparent_background_ = false; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 153 | |
| 154 | scoped_refptr<cc::SurfaceLayer> content_layer_; |
| 155 | |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 156 | const bool enable_surface_synchronization_; |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 157 | const bool enable_viz_; |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 158 | viz::ParentLocalSurfaceIdAllocator local_surface_id_allocator_; |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 159 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 160 | // The size we are resizing to. Once we receive a frame of this size we can |
| 161 | // release any resize compositor lock. |
| 162 | gfx::Size expected_pixel_size_; |
| 163 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 164 | // A lock that is held from the point at which we attach to the compositor to |
| 165 | // the point at which we submit our first frame to the compositor. This |
| 166 | // ensures that the compositor doesn't swap without a frame available. |
| 167 | std::unique_ptr<ui::CompositorLock> compositor_attach_until_frame_lock_; |
| 168 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 169 | // A lock that is held from the point we begin resizing this frame to the |
| 170 | // point at which we receive a frame of the correct size. |
| 171 | std::unique_ptr<ui::CompositorLock> compositor_pending_resize_lock_; |
| 172 | |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 173 | // Whether we've received a frame from the renderer since navigating. |
| 174 | // Only used in Viz mode. |
| 175 | bool received_frame_after_navigation_ = false; |
| 176 | uint32_t parent_sequence_number_at_navigation_ = 0; |
| 177 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 178 | DISALLOW_COPY_AND_ASSIGN(DelegatedFrameHostAndroid); |
| 179 | }; |
| 180 | |
| 181 | } // namespace ui |
| 182 | |
| 183 | #endif // UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_ |