OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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 CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 5 #ifndef CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
6 #define CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 6 #define CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
7 | 7 |
8 #include <memory> | 8 #include <memory> |
9 #include <unordered_set> | 9 #include <unordered_set> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
14 #include "cc/output/compositor_frame.h" | 14 #include "cc/output/compositor_frame.h" |
15 #include "cc/scheduler/begin_frame_source.h" | 15 #include "cc/scheduler/begin_frame_source.h" |
16 #include "cc/surfaces/framesink_manager_client.h" | 16 #include "cc/surfaces/framesink_manager_client.h" |
17 #include "cc/surfaces/pending_frame_observer.h" | |
17 #include "cc/surfaces/referenced_surface_tracker.h" | 18 #include "cc/surfaces/referenced_surface_tracker.h" |
18 #include "cc/surfaces/surface_factory.h" | |
19 #include "cc/surfaces/surface_factory_client.h" | |
20 #include "cc/surfaces/surface_id.h" | 19 #include "cc/surfaces/surface_id.h" |
20 #include "cc/surfaces/surface_resource_holder.h" | |
21 #include "cc/surfaces/surface_resource_holder_client.h" | 21 #include "cc/surfaces/surface_resource_holder_client.h" |
22 #include "cc/surfaces/surfaces_export.h" | 22 #include "cc/surfaces/surfaces_export.h" |
23 | 23 |
24 namespace cc { | 24 namespace cc { |
25 namespace test { | |
26 class CompositorFrameSinkSupportTest; | |
27 } | |
25 | 28 |
26 class CompositorFrameSinkSupportClient; | 29 class CompositorFrameSinkSupportClient; |
30 class SurfaceAggregator; | |
27 class SurfaceManager; | 31 class SurfaceManager; |
28 | 32 |
29 class CC_SURFACES_EXPORT CompositorFrameSinkSupport | 33 class CC_SURFACES_EXPORT CompositorFrameSinkSupport |
30 : public SurfaceFactoryClient, | 34 : public BeginFrameObserver, |
31 public BeginFrameObserver, | |
32 public SurfaceResourceHolderClient, | 35 public SurfaceResourceHolderClient, |
33 public FrameSinkManagerClient { | 36 public FrameSinkManagerClient, |
37 public PendingFrameObserver { | |
34 public: | 38 public: |
35 static std::unique_ptr<CompositorFrameSinkSupport> Create( | 39 static std::unique_ptr<CompositorFrameSinkSupport> Create( |
36 CompositorFrameSinkSupportClient* client, | 40 CompositorFrameSinkSupportClient* client, |
37 SurfaceManager* surface_manager, | 41 SurfaceManager* surface_manager, |
38 const FrameSinkId& frame_sink_id, | 42 const FrameSinkId& frame_sink_id, |
39 bool is_root, | 43 bool is_root, |
40 bool handles_frame_sink_id_invalidation, | 44 bool handles_frame_sink_id_invalidation, |
41 bool needs_sync_points); | 45 bool needs_sync_points); |
42 | 46 |
43 ~CompositorFrameSinkSupport() override; | 47 ~CompositorFrameSinkSupport() override; |
44 | 48 |
45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } | 49 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } |
46 | 50 |
47 Surface* current_surface_for_testing() { | 51 Surface* current_surface_for_testing() { return current_surface_.get(); } |
48 return surface_factory_->current_surface_for_testing(); | 52 SurfaceManager* surface_manager() { return surface_manager_; } |
49 } | 53 bool needs_sync_points() { return needs_sync_points_; } |
50 | 54 |
51 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const { | 55 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const { |
52 return reference_tracker_; | 56 return reference_tracker_; |
53 } | 57 } |
54 | 58 |
55 // SurfaceFactoryClient implementation. | |
56 void ReferencedSurfacesChanged( | |
57 const LocalSurfaceId& local_surface_id, | |
58 const std::vector<SurfaceId>* active_referenced_surfaces) override; | |
59 | |
60 // SurfaceResourceHolderClient implementation. | 59 // SurfaceResourceHolderClient implementation. |
61 void ReturnResources(const ReturnedResourceArray& resources) override; | 60 void ReturnResources(const ReturnedResourceArray& resources) override; |
62 | 61 |
63 // FrameSinkManagerClient implementation. | 62 // FrameSinkManagerClient implementation. |
64 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; | 63 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; |
65 | 64 |
66 void EvictFrame(); | 65 void EvictFrame(); |
67 void SetNeedsBeginFrame(bool needs_begin_frame); | 66 void SetNeedsBeginFrame(bool needs_begin_frame); |
68 void BeginFrameDidNotSwap(const BeginFrameAck& ack); | 67 void BeginFrameDidNotSwap(const BeginFrameAck& ack); |
69 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, | 68 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, |
70 CompositorFrame frame); | 69 CompositorFrame frame); |
71 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> request); | 70 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> request); |
72 void ClaimTemporaryReference(const SurfaceId& surface_id); | 71 void ClaimTemporaryReference(const SurfaceId& surface_id); |
73 | 72 |
74 protected: | 73 protected: |
75 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client, | 74 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client, |
76 const FrameSinkId& frame_sink_id, | 75 const FrameSinkId& frame_sink_id, |
77 bool is_root, | 76 bool is_root, |
78 bool handles_frame_sink_id_invalidation); | 77 bool handles_frame_sink_id_invalidation); |
79 | 78 |
80 void Init(SurfaceManager* surface_manager, bool needs_sync_points); | 79 void Init(SurfaceManager* surface_manager, bool needs_sync_points); |
81 | 80 |
82 private: | 81 private: |
82 // Surface calls ReceiveFromChild from Surface::QueueFrame to receive and | |
danakj
2017/05/01 22:21:39
It looks like this is creating a method-call patte
Alex Z.
2017/05/02 14:46:17
CompositorFrameSinkSupport now calls ReceiveFromCh
| |
83 // track the resources referenced from the CompositorFrame regardless of | |
84 // whether it's pending or active. | |
85 // Surface calls UnrefResources in | |
86 // Surface::UnrefFrameResourcesAndRunDrawCallback. It unrefs resources | |
87 // referenced from a the CompositorFrame when it's no longer needed (e.g. | |
88 // when the Surface is destroyed, or when the frame is activated). | |
89 // TODO(staraz): Make a SurfaceClient interface so Surface has access to these | |
90 // methods without having to be a friend. | |
91 friend class Surface; | |
92 | |
93 // SurfaceAggregator calls RefResources in PrewalkTree to validate the | |
danakj
2017/05/01 22:21:39
I don't understand this pattern here of making fri
Alex Z.
2017/05/02 16:34:32
Ref/UnrefResources are public now. I added a TODO
| |
94 // resources. | |
95 // SurfaceAggregator calls UnrefResources in UnrefHelper, which is passed to | |
96 // ResourceProvider::CreateChild as |return_callback|. | |
97 friend class SurfaceAggregator; | |
98 | |
99 // CompositorFrameSinkSupportTest calls RefResources and UnrefResources in its | |
100 // resources life time tests. The tests verify that the resources referenced | |
101 // by a combination of CompositorFrames and external references are returned | |
102 // at the correct occasion. | |
103 friend class test::CompositorFrameSinkSupportTest; | |
104 | |
105 void ReceiveFromChild(const TransferableResourceArray& resources); | |
106 void RefResources(const TransferableResourceArray& resources); | |
107 void UnrefResources(const ReturnedResourceArray& resources); | |
108 | |
83 // Update surface references with SurfaceManager for current CompositorFrame | 109 // Update surface references with SurfaceManager for current CompositorFrame |
84 // that has |local_surface_id|. UpdateReferences() must be called on | 110 // that has |local_surface_id|. UpdateReferences() must be called on |
85 // |reference_tracker_| before calling this. Will add and remove top-level | 111 // |reference_tracker_| before calling this. Will add and remove top-level |
86 // root references if |display_| is not null. | 112 // root references if |display_| is not null. |
87 void UpdateSurfaceReferences(const SurfaceId& last_surface_id, | 113 void UpdateSurfaceReferences(const SurfaceId& last_surface_id, |
88 const LocalSurfaceId& local_surface_id); | 114 const LocalSurfaceId& local_surface_id); |
89 | 115 |
90 void AddTopLevelRootReference(const SurfaceId& surface_id); | 116 void AddTopLevelRootReference(const SurfaceId& surface_id); |
91 void RemoveTopLevelRootReference(const SurfaceId& surface_id); | 117 void RemoveTopLevelRootReference(const SurfaceId& surface_id); |
118 void ReferencedSurfacesChanged( | |
119 const LocalSurfaceId& local_surface_id, | |
120 const std::vector<SurfaceId>* active_referenced_surfaces); | |
92 | 121 |
93 void DidReceiveCompositorFrameAck(); | 122 void DidReceiveCompositorFrameAck(); |
94 void WillDrawSurface(const LocalSurfaceId& local_surface_id, | 123 void WillDrawSurface(const LocalSurfaceId& local_surface_id, |
95 const gfx::Rect& damage_rect); | 124 const gfx::Rect& damage_rect); |
96 | 125 |
97 // BeginFrameObserver implementation. | 126 // BeginFrameObserver implementation. |
98 void OnBeginFrame(const BeginFrameArgs& args) override; | 127 void OnBeginFrame(const BeginFrameArgs& args) override; |
99 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; | 128 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; |
100 void OnBeginFrameSourcePausedChanged(bool paused) override; | 129 void OnBeginFrameSourcePausedChanged(bool paused) override; |
101 | 130 |
131 // PendingFrameObserver implementation. | |
132 void OnSurfaceActivated(Surface* surface) override; | |
133 void OnSurfaceDependenciesChanged( | |
134 Surface* surface, | |
135 const SurfaceDependencies& added_dependencies, | |
136 const SurfaceDependencies& removed_dependencies) override; | |
137 void OnSurfaceDiscarded(Surface* surface) override; | |
138 | |
102 void UpdateNeedsBeginFramesInternal(); | 139 void UpdateNeedsBeginFramesInternal(); |
140 std::unique_ptr<Surface> CreateSurface( | |
141 const LocalSurfaceId& local_surface_id); | |
142 void DestroyCurrentSurface(); | |
103 | 143 |
104 CompositorFrameSinkSupportClient* const client_; | 144 CompositorFrameSinkSupportClient* const client_; |
105 | 145 |
106 SurfaceManager* surface_manager_ = nullptr; | 146 SurfaceManager* surface_manager_ = nullptr; |
107 | 147 |
108 const FrameSinkId frame_sink_id_; | 148 const FrameSinkId frame_sink_id_; |
109 | 149 |
110 std::unique_ptr<SurfaceFactory> surface_factory_; | 150 SurfaceResourceHolder surface_resource_holder_; |
151 | |
152 std::unique_ptr<Surface> current_surface_; | |
111 // Counts the number of CompositorFrames that have been submitted and have not | 153 // Counts the number of CompositorFrames that have been submitted and have not |
112 // yet received an ACK. | 154 // yet received an ACK. |
113 int ack_pending_count_ = 0; | 155 int ack_pending_count_ = 0; |
114 ReturnedResourceArray surface_returned_resources_; | 156 ReturnedResourceArray surface_returned_resources_; |
115 | 157 |
116 // The begin frame source being observered. Null if none. | 158 // The begin frame source being observered. Null if none. |
117 BeginFrameSource* begin_frame_source_ = nullptr; | 159 BeginFrameSource* begin_frame_source_ = nullptr; |
118 | 160 |
119 // The last begin frame args generated by the begin frame source. | 161 // The last begin frame args generated by the begin frame source. |
120 BeginFrameArgs last_begin_frame_args_; | 162 BeginFrameArgs last_begin_frame_args_; |
121 | 163 |
122 // Whether a request for begin frames has been issued. | 164 // Whether a request for begin frames has been issued. |
123 bool needs_begin_frame_ = false; | 165 bool needs_begin_frame_ = false; |
124 | 166 |
125 // Whether or not a frame observer has been added. | 167 // Whether or not a frame observer has been added. |
126 bool added_frame_observer_ = false; | 168 bool added_frame_observer_ = false; |
127 | 169 |
128 // Track the surface references for the surface corresponding to this | 170 // Track the surface references for the surface corresponding to this |
129 // compositor frame sink. | 171 // compositor frame sink. |
130 ReferencedSurfaceTracker reference_tracker_; | 172 ReferencedSurfaceTracker reference_tracker_; |
131 | 173 |
132 const bool is_root_; | 174 const bool is_root_; |
175 bool needs_sync_points_; | |
176 bool seen_first_frame_activation_ = false; | |
133 | 177 |
134 // TODO(staraz): Remove this flag once ui::Compositor no longer needs to call | 178 // TODO(staraz): Remove this flag once ui::Compositor no longer needs to call |
135 // RegisterFrameSinkId(). | 179 // RegisterFrameSinkId(). |
136 // A surfaceSequence's validity is bound to the lifetime of the parent | 180 // A surfaceSequence's validity is bound to the lifetime of the parent |
137 // FrameSink that created it. We track the lifetime of FrameSinks through | 181 // FrameSink that created it. We track the lifetime of FrameSinks through |
138 // RegisterFrameSinkId and InvalidateFrameSinkId. During startup and GPU | 182 // RegisterFrameSinkId and InvalidateFrameSinkId. During startup and GPU |
139 // restart, a SurfaceSequence created by the top most layer compositor may be | 183 // restart, a SurfaceSequence created by the top most layer compositor may be |
140 // used prior to the creation of the associated CompositorFrameSinkSupport. | 184 // used prior to the creation of the associated CompositorFrameSinkSupport. |
141 // CompositorFrameSinkSupport is created asynchronously when a new GPU channel | 185 // CompositorFrameSinkSupport is created asynchronously when a new GPU channel |
142 // is established. Once we switch to SurfaceReferences, this ordering concern | 186 // is established. Once we switch to SurfaceReferences, this ordering concern |
143 // goes away and we can remove this bool. | 187 // goes away and we can remove this bool. |
144 const bool handles_frame_sink_id_invalidation_; | 188 const bool handles_frame_sink_id_invalidation_; |
145 | 189 |
146 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; | 190 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; |
147 | 191 |
148 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); | 192 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); |
149 }; | 193 }; |
150 | 194 |
151 } // namespace cc | 195 } // namespace cc |
152 | 196 |
153 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ | 197 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ |
OLD | NEW |