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" |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame] | 12 | #include "components/viz/common/surfaces/surface_info.h" |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 13 | #include "components/viz/host/host_frame_sink_client.h" |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 14 | #include "components/viz/service/frame_sinks/compositor_frame_sink_support.h" |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 15 | #include "services/viz/public/interfaces/compositing/compositor_frame_sink.mojom.h" |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 16 | #include "ui/android/ui_android_export.h" |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame^] | 17 | #include "ui/compositor/compositor_lock.h" |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 18 | |
| 19 | namespace cc { |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 20 | class SurfaceLayer; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 21 | enum class SurfaceDrawStatus; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 22 | } // namespace cc |
| 23 | |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 24 | namespace viz { |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 25 | class CompositorFrame; |
Fady Samuel | dea5e8f | 2017-07-19 21:41:33 | [diff] [blame] | 26 | class FrameSinkManagerImpl; |
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; |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 45 | virtual void ReclaimResources( |
| 46 | const std::vector<viz::ReturnedResource>&) = 0; |
yiyix | ae38c33 | 2017-11-14 18:58:27 | [diff] [blame] | 47 | virtual void OnFrameTokenChanged(uint32_t frame_token) = 0; |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 48 | }; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 49 | |
| 50 | DelegatedFrameHostAndroid(ViewAndroid* view, |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 51 | viz::HostFrameSinkManager* host_frame_sink_manager, |
Fady Samuel | dea5e8f | 2017-07-19 21:41:33 | [diff] [blame] | 52 | viz::FrameSinkManagerImpl* frame_sink_manager, |
xlai | 9351829f | 2017-01-27 18:39:13 | [diff] [blame] | 53 | Client* client, |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 54 | const viz::FrameSinkId& frame_sink_id); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 55 | |
| 56 | ~DelegatedFrameHostAndroid() override; |
| 57 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 58 | void SubmitCompositorFrame(const viz::LocalSurfaceId& local_surface_id, |
danakj | 5e0a12b | 2017-09-25 17:26:49 | [diff] [blame] | 59 | viz::CompositorFrame frame); |
Fady Samuel | c296f5fb | 2017-07-21 04:02:19 | [diff] [blame] | 60 | void DidNotProduceFrame(const viz::BeginFrameAck& ack); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 61 | |
| 62 | void DestroyDelegatedContent(); |
| 63 | |
| 64 | bool HasDelegatedContent() const; |
| 65 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 66 | viz::FrameSinkId GetFrameSinkId() const; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 67 | |
Yuri Wiitala | b9ad27a | 2017-09-06 19:13:50 | [diff] [blame] | 68 | // Should only be called when the host has a content layer. Use this for one- |
| 69 | // off screen capture, not for video. Always provides RGBA_BITMAP |
| 70 | // CopyOutputResults. |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 71 | void RequestCopyOfSurface( |
| 72 | WindowAndroidCompositor* compositor, |
| 73 | const gfx::Rect& src_subrect_in_pixel, |
Fady Samuel | dfecb7d | 2017-07-26 11:41:04 | [diff] [blame] | 74 | viz::CopyOutputRequest::CopyOutputRequestCallback result_callback); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 75 | |
danakj | 1120f4c | 2016-09-15 02:05:32 | [diff] [blame] | 76 | void CompositorFrameSinkChanged(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 77 | |
enne | a487a27 | 2016-09-30 19:56:18 | [diff] [blame] | 78 | // Called when this DFH is attached/detached from a parent browser compositor |
| 79 | // and needs to be attached to the surface hierarchy. |
staraz | aa23111 | 2017-02-07 17:53:24 | [diff] [blame] | 80 | void AttachToCompositor(WindowAndroidCompositor* compositor); |
| 81 | void DetachFromCompositor(); |
enne | a487a27 | 2016-09-30 19:56:18 | [diff] [blame] | 82 | |
kenrb | 2b5d08b | 2017-03-08 22:31:29 | [diff] [blame] | 83 | // Returns the ID for the current Surface. |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 84 | viz::SurfaceId SurfaceId() const; |
kenrb | 2b5d08b | 2017-03-08 22:31:29 | [diff] [blame] | 85 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 86 | private: |
kylechar | 9075b08 | 2017-09-12 16:59:10 | [diff] [blame] | 87 | // viz::mojom::CompositorFrameSinkClient implementation. |
samans | 8d3604f | 2017-04-11 22:15:30 | [diff] [blame] | 88 | void DidReceiveCompositorFrameAck( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 89 | const std::vector<viz::ReturnedResource>& resources) override; |
Peng Huang | 5207a6e | 2017-10-26 00:39:30 | [diff] [blame] | 90 | void DidPresentCompositorFrame(uint32_t presentation_token, |
| 91 | base::TimeTicks time, |
| 92 | base::TimeDelta refresh, |
| 93 | uint32_t flags) override; |
| 94 | void DidDiscardCompositorFrame(uint32_t presentation_token) override; |
Fady Samuel | c296f5fb | 2017-07-21 04:02:19 | [diff] [blame] | 95 | void OnBeginFrame(const viz::BeginFrameArgs& args) override; |
danakj | 30464ba1 | 2017-06-29 21:26:45 | [diff] [blame] | 96 | void ReclaimResources( |
Fady Samuel | 4f7f0fb3 | 2017-07-28 15:33:37 | [diff] [blame] | 97 | const std::vector<viz::ReturnedResource>& resources) override; |
Bill Orr | 372a126 | 2017-07-20 00:18:39 | [diff] [blame] | 98 | void OnBeginFramePausedChanged(bool paused) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 99 | |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 100 | // viz::ExternalBeginFrameSourceClient implementation. |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 101 | void OnNeedsBeginFrames(bool needs_begin_frames) override; |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 102 | |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 103 | // viz::HostFrameSinkClient implementation. |
Fady Samuel | 5b7fb8e | 2017-08-08 16:58:22 | [diff] [blame] | 104 | void OnFirstSurfaceActivation(const viz::SurfaceInfo& surface_info) override; |
yiyix | ae38c33 | 2017-11-14 18:58:27 | [diff] [blame] | 105 | void OnFrameTokenChanged(uint32_t frame_token) override; |
Fady Samuel | bac0f1a | 2017-08-02 15:54:02 | [diff] [blame] | 106 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame^] | 107 | // ui::CompositorLockClient implementation. |
| 108 | void CompositorLockTimedOut() override; |
| 109 | |
samans | b779eca | 2017-03-02 22:16:37 | [diff] [blame] | 110 | void CreateNewCompositorFrameSinkSupport(); |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 111 | |
Fady Samuel | d5c2618 | 2017-07-12 02:43:33 | [diff] [blame] | 112 | const viz::FrameSinkId frame_sink_id_; |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 113 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 114 | ViewAndroid* view_; |
| 115 | |
kylechar | a090016 | 2017-07-14 17:35:25 | [diff] [blame] | 116 | viz::HostFrameSinkManager* const host_frame_sink_manager_; |
Fady Samuel | dea5e8f | 2017-07-19 21:41:33 | [diff] [blame] | 117 | viz::FrameSinkManagerImpl* const frame_sink_manager_; |
staraz | aa23111 | 2017-02-07 17:53:24 | [diff] [blame] | 118 | WindowAndroidCompositor* registered_parent_compositor_ = nullptr; |
eseckler | 8c15fc3 | 2016-12-20 20:22:20 | [diff] [blame] | 119 | Client* client_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 120 | |
danakj | c391f33 | 2017-07-12 20:45:52 | [diff] [blame] | 121 | std::unique_ptr<viz::CompositorFrameSinkSupport> support_; |
Fady Samuel | c645ffe | 2017-07-24 17:28:20 | [diff] [blame] | 122 | viz::ExternalBeginFrameSource begin_frame_source_; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 123 | |
Fady Samuel | 1a21156e | 2017-07-13 04:57:29 | [diff] [blame] | 124 | viz::SurfaceInfo surface_info_; |
samans | e7398c55 | 2017-03-21 21:36:28 | [diff] [blame] | 125 | bool has_transparent_background_ = false; |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 126 | |
| 127 | scoped_refptr<cc::SurfaceLayer> content_layer_; |
| 128 | |
Eric Karl | 465a525 | 2018-01-10 21:16:27 | [diff] [blame^] | 129 | // A lock that is held from the point at which we attach to the compositor to |
| 130 | // the point at which we submit our first frame to the compositor. This |
| 131 | // ensures that the compositor doesn't swap without a frame available. |
| 132 | std::unique_ptr<ui::CompositorLock> compositor_attach_until_frame_lock_; |
| 133 | |
khushalsagar | a693aa7 | 2016-08-16 22:18:06 | [diff] [blame] | 134 | DISALLOW_COPY_AND_ASSIGN(DelegatedFrameHostAndroid); |
| 135 | }; |
| 136 | |
| 137 | } // namespace ui |
| 138 | |
| 139 | #endif // UI_ANDROID_DELEGATED_FRAME_HOST_ANDROID_H_ |