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" |
Fady Samuel | dba483c | 2018-05-30 04:42:35 | [diff] [blame^] | 10 | #include "cc/layers/deadline_policy.h" |
danakj | f20f450 | 2017-09-26 17:13:31 | [diff] [blame] | 11 | #include "components/viz/common/frame_sinks/copy_output_request.h" |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 12 | #include "components/viz/common/resources/returned_resource.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 | |
Fady Samuel | dba483c | 2018-05-30 04:42:35 | [diff] [blame^] | 69 | void EvictDelegatedFrame(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 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 | |
Fady Samuel | dba483c | 2018-05-30 04:42:35 | [diff] [blame^] | 91 | void EmbedSurface(const viz::LocalSurfaceId& new_pending_local_surface_id, |
| 92 | const gfx::Size& new_pending_size_in_pixels, |
| 93 | cc::DeadlinePolicy deadline_policy); |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 94 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 95 | // Called when we begin a resize operation. Takes the compositor lock until we |
| 96 | // receive a frame of the expected size. |
| 97 | void PixelSizeWillChange(const gfx::Size& pixel_size); |
| 98 | |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 99 | // Returns the ID for the current Surface. Returns an invalid ID if no |
| 100 | // surface exists (!HasDelegatedContent()). |
| 101 | const viz::SurfaceId& SurfaceId() const; |
| 102 | |
Saman Sami | 26a1fcd | 2018-04-10 17:12:21 | [diff] [blame] | 103 | void TakeFallbackContentFrom(DelegatedFrameHostAndroid* other); |
| 104 | |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 105 | void DidNavigate(); |
| 106 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 107 | private: |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 108 | // viz::mojom::CompositorFrameSinkClient implementation. |
samans | 8d3604f | 2017-04-11 22:15:30 | [diff] [blame] | 109 | void DidReceiveCompositorFrameAck( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 110 | const std::vector<viz::ReturnedResource>& resources) override; |
Peng Huang | 5207a6e | 2017-10-26 00:39:30 | [diff] [blame] | 111 | void DidPresentCompositorFrame(uint32_t presentation_token, |
| 112 | base::TimeTicks time, |
| 113 | base::TimeDelta refresh, |
| 114 | uint32_t flags) override; |
| 115 | void DidDiscardCompositorFrame(uint32_t presentation_token) override; |
Fady Samuel | c296f5fb | 2017-07-21 04:02:19 | [diff] [blame] | 116 | void OnBeginFrame(const viz::BeginFrameArgs& args) override; |
danakj | 30464ba1 | 2017-06-29 21:26:45 | [diff] [blame] | 117 | void ReclaimResources( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 118 | const std::vector<viz::ReturnedResource>& resources) override; |
Bill Orr | 372a126 | 2017-07-20 00:18:39 | [diff] [blame] | 119 | void OnBeginFramePausedChanged(bool paused) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 120 | |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 121 | // viz::ExternalBeginFrameSourceClient implementation. |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 122 | void OnNeedsBeginFrames(bool needs_begin_frames) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 123 | |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 124 | // viz::HostFrameSinkClient implementation. |
Fady Samuel | 5b7fb8e | 2017-08-08 16:58:22 | [diff] [blame] | 125 | void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override; |
yiyix | ae38c33 | 2017-11-14 18:58:27 | [diff] [blame] | 126 | void OnFrameTokenChanged(uint32_t frame_token) override; |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 127 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 128 | // ui::CompositorLockClient implementation. |
| 129 | void CompositorLockTimedOut() override; |
| 130 | |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 131 | void CreateNewCompositorFrameSinkSupport(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 132 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 133 | const viz::FrameSinkId frame_sink_id_; |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 134 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 135 | ViewAndroid* view_; |
| 136 | |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 137 | viz::HostFrameSinkManager* const host_frame_sink_manager_; |
staraz | aa23111 | 2017-02-07 17:53:24 | [diff] [blame] | 138 | WindowAndroidCompositor* registered_parent_compositor_ = nullptr; |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 139 | Client* client_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 140 | |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 141 | std::unique_ptr<viz::CompositorFrameSinkSupport> support_; |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 142 | viz::ExternalBeginFrameSource begin_frame_source_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 143 | |
samans | e7398c55 | 2017-03-21 21:36:28 | [diff] [blame] | 144 | bool has_transparent_background_ = false; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 145 | |
| 146 | scoped_refptr<cc::SurfaceLayer> content_layer_; |
| 147 | |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 148 | const bool enable_surface_synchronization_; |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 149 | const bool enable_viz_; |
Eric Karl | baa55ff3 | 2018-01-18 00:46:11 | [diff] [blame] | 150 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 151 | // The size we are resizing to. Once we receive a frame of this size we can |
| 152 | // release any resize compositor lock. |
| 153 | gfx::Size expected_pixel_size_; |
| 154 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame] | 155 | // A lock that is held from the point at which we attach to the compositor to |
| 156 | // the point at which we submit our first frame to the compositor. This |
| 157 | // ensures that the compositor doesn't swap without a frame available. |
| 158 | std::unique_ptr<ui::CompositorLock> compositor_attach_until_frame_lock_; |
| 159 | |
Eric Karl | b8823c31 | 2018-05-09 03:08:39 | [diff] [blame] | 160 | // A lock that is held from the point we begin resizing this frame to the |
| 161 | // point at which we receive a frame of the correct size. |
| 162 | std::unique_ptr<ui::CompositorLock> compositor_pending_resize_lock_; |
| 163 | |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 164 | // Whether we've received a frame from the renderer since navigating. |
Fady Samuel | dba483c | 2018-05-30 04:42:35 | [diff] [blame^] | 165 | // Only used when surface synchronization is on. |
| 166 | uint32_t first_parent_sequence_number_after_navigation_ = 0; |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 167 | bool received_frame_after_navigation_ = false; |
Fady Samuel | dba483c | 2018-05-30 04:42:35 | [diff] [blame^] | 168 | |
| 169 | // The local surface id as of the most recent call to |
| 170 | // EmbedSurface. This is the surface that we expect future frames to |
| 171 | // reference. This will eventually equal the active surface. |
| 172 | viz::LocalSurfaceId pending_local_surface_id_; |
Eric Karl | db7eb24 | 2018-05-16 17:16:59 | [diff] [blame] | 173 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 174 | DISALLOW_COPY_AND_ASSIGN(DelegatedFrameHostAndroid); |
| 175 | }; |
| 176 | |
| 177 | } // namespace ui |
| 178 | |
| 179 | #endif // UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_ |