Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Side by Side Diff: cc/surfaces/compositor_frame_sink_support.h

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Merge unit tests Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25
26 class CompositorFrameSinkSupportClient; 26 class CompositorFrameSinkSupportClient;
27 class SurfaceManager; 27 class SurfaceManager;
28 28
29 class CC_SURFACES_EXPORT CompositorFrameSinkSupport 29 class CC_SURFACES_EXPORT CompositorFrameSinkSupport
30 : public SurfaceFactoryClient, 30 : public BeginFrameObserver,
31 public BeginFrameObserver,
32 public SurfaceResourceHolderClient, 31 public SurfaceResourceHolderClient,
33 public FrameSinkManagerClient { 32 public FrameSinkManagerClient,
33 public PendingFrameObserver {
34 public: 34 public:
35 static std::unique_ptr<CompositorFrameSinkSupport> Create( 35 static std::unique_ptr<CompositorFrameSinkSupport> Create(
36 CompositorFrameSinkSupportClient* client, 36 CompositorFrameSinkSupportClient* client,
37 SurfaceManager* surface_manager, 37 SurfaceManager* surface_manager,
38 const FrameSinkId& frame_sink_id, 38 const FrameSinkId& frame_sink_id,
39 bool is_root, 39 bool is_root,
40 bool handles_frame_sink_id_invalidation, 40 bool handles_frame_sink_id_invalidation,
41 bool needs_sync_points); 41 bool needs_sync_points);
42 42
43 ~CompositorFrameSinkSupport() override; 43 ~CompositorFrameSinkSupport() override;
44 44
45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; } 45 const FrameSinkId& frame_sink_id() const { return frame_sink_id_; }
46 46
47 Surface* current_surface_for_testing() { 47 Surface* current_surface_for_testing() { return current_surface_.get(); }
48 return surface_factory_->current_surface_for_testing(); 48 SurfaceManager* surface_manager() { return surface_manager_; }
49 } 49 bool needs_sync_points() { return needs_sync_points_; }
50 50
51 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const { 51 const ReferencedSurfaceTracker& ReferenceTrackerForTesting() const {
52 return reference_tracker_; 52 return reference_tracker_;
53 } 53 }
54 54
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. 55 // SurfaceResourceHolderClient implementation.
61 void ReturnResources(const ReturnedResourceArray& resources) override; 56 void ReturnResources(const ReturnedResourceArray& resources) override;
62 57
63 // FrameSinkManagerClient implementation. 58 // FrameSinkManagerClient implementation.
64 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override; 59 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override;
65 60
66 void EvictFrame(); 61 void EvictFrame();
67 void SetNeedsBeginFrame(bool needs_begin_frame); 62 void SetNeedsBeginFrame(bool needs_begin_frame);
68 void BeginFrameDidNotSwap(const BeginFrameAck& ack); 63 void BeginFrameDidNotSwap(const BeginFrameAck& ack);
69 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id, 64 void SubmitCompositorFrame(const LocalSurfaceId& local_surface_id,
70 CompositorFrame frame); 65 CompositorFrame frame);
71 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> request); 66 void RequestCopyOfSurface(std::unique_ptr<CopyOutputRequest> request);
72 void ForceReclaimResources(); 67 void ForceReclaimResources();
73 void ClaimTemporaryReference(const SurfaceId& surface_id); 68 void ClaimTemporaryReference(const SurfaceId& surface_id);
74 69
70 void ReceiveFromChild(const TransferableResourceArray& resources);
71 void RefResources(const TransferableResourceArray& resources);
72 void UnrefResources(const ReturnedResourceArray& resources);
73
74 void ForceAck();
75
75 protected: 76 protected:
76 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client, 77 CompositorFrameSinkSupport(CompositorFrameSinkSupportClient* client,
77 const FrameSinkId& frame_sink_id, 78 const FrameSinkId& frame_sink_id,
78 bool is_root, 79 bool is_root,
79 bool handles_frame_sink_id_invalidation); 80 bool handles_frame_sink_id_invalidation);
80 81
81 void Init(SurfaceManager* surface_manager, bool needs_sync_points); 82 void Init(SurfaceManager* surface_manager, bool needs_sync_points);
82 83
83 private: 84 private:
84 // Update surface references with SurfaceManager for current CompositorFrame 85 // Update surface references with SurfaceManager for current CompositorFrame
85 // that has |local_surface_id|. UpdateReferences() must be called on 86 // that has |local_surface_id|. UpdateReferences() must be called on
86 // |reference_tracker_| before calling this. Will add and remove top-level 87 // |reference_tracker_| before calling this. Will add and remove top-level
87 // root references if |display_| is not null. 88 // root references if |display_| is not null.
88 void UpdateSurfaceReferences(const SurfaceId& last_surface_id, 89 void UpdateSurfaceReferences(const SurfaceId& last_surface_id,
89 const LocalSurfaceId& local_surface_id); 90 const LocalSurfaceId& local_surface_id);
90 91
91 void AddTopLevelRootReference(const SurfaceId& surface_id); 92 void AddTopLevelRootReference(const SurfaceId& surface_id);
92 void RemoveTopLevelRootReference(const SurfaceId& surface_id); 93 void RemoveTopLevelRootReference(const SurfaceId& surface_id);
94 void ReferencedSurfacesChanged(
95 const LocalSurfaceId& local_surface_id,
96 const std::vector<SurfaceId>* active_referenced_surfaces);
93 97
94 void DidReceiveCompositorFrameAck(); 98 void DidReceiveCompositorFrameAck();
95 void WillDrawSurface(const LocalSurfaceId& local_surface_id, 99 void WillDrawSurface(const LocalSurfaceId& local_surface_id,
96 const gfx::Rect& damage_rect); 100 const gfx::Rect& damage_rect);
97 101
98 // BeginFrameObserver implementation. 102 // BeginFrameObserver implementation.
99 void OnBeginFrame(const BeginFrameArgs& args) override; 103 void OnBeginFrame(const BeginFrameArgs& args) override;
100 const BeginFrameArgs& LastUsedBeginFrameArgs() const override; 104 const BeginFrameArgs& LastUsedBeginFrameArgs() const override;
101 void OnBeginFrameSourcePausedChanged(bool paused) override; 105 void OnBeginFrameSourcePausedChanged(bool paused) override;
102 106
107 // PendingFrameObserver implementation.
108 void OnSurfaceActivated(Surface* surface) override;
109 void OnSurfaceDependenciesChanged(
110 Surface* surface,
111 const SurfaceDependencies& added_dependencies,
112 const SurfaceDependencies& removed_dependencies) override;
113 void OnSurfaceDiscarded(Surface* surface) override;
114
103 void UpdateNeedsBeginFramesInternal(); 115 void UpdateNeedsBeginFramesInternal();
116 std::unique_ptr<Surface> CreateSurface(
117 const LocalSurfaceId& local_surface_id);
118 void DestroyCurrentSurface();
104 119
105 CompositorFrameSinkSupportClient* const client_; 120 CompositorFrameSinkSupportClient* const client_;
106 121
107 SurfaceManager* surface_manager_ = nullptr; 122 SurfaceManager* surface_manager_ = nullptr;
108 123
109 const FrameSinkId frame_sink_id_; 124 const FrameSinkId frame_sink_id_;
110 125
111 std::unique_ptr<SurfaceFactory> surface_factory_; 126 SurfaceResourceHolder surface_resource_holder_;
127
128 std::unique_ptr<Surface> current_surface_;
112 // Counts the number of CompositorFrames that have been submitted and have not 129 // Counts the number of CompositorFrames that have been submitted and have not
113 // yet received an ACK. 130 // yet received an ACK.
114 int ack_pending_count_ = 0; 131 int ack_pending_count_ = 0;
115 ReturnedResourceArray surface_returned_resources_; 132 ReturnedResourceArray surface_returned_resources_;
116 133
117 // The begin frame source being observered. Null if none. 134 // The begin frame source being observered. Null if none.
118 BeginFrameSource* begin_frame_source_ = nullptr; 135 BeginFrameSource* begin_frame_source_ = nullptr;
119 136
120 // The last begin frame args generated by the begin frame source. 137 // The last begin frame args generated by the begin frame source.
121 BeginFrameArgs last_begin_frame_args_; 138 BeginFrameArgs last_begin_frame_args_;
122 139
123 // Whether a request for begin frames has been issued. 140 // Whether a request for begin frames has been issued.
124 bool needs_begin_frame_ = false; 141 bool needs_begin_frame_ = false;
125 142
126 // Whether or not a frame observer has been added. 143 // Whether or not a frame observer has been added.
127 bool added_frame_observer_ = false; 144 bool added_frame_observer_ = false;
128 145
129 // Track the surface references for the surface corresponding to this 146 // Track the surface references for the surface corresponding to this
130 // compositor frame sink. 147 // compositor frame sink.
131 ReferencedSurfaceTracker reference_tracker_; 148 ReferencedSurfaceTracker reference_tracker_;
132 149
133 const bool is_root_; 150 const bool is_root_;
151 bool needs_sync_points_;
152 bool seen_first_frame_activation_ = false;
134 153
135 // TODO(staraz): Remove this flag once ui::Compositor no longer needs to call 154 // TODO(staraz): Remove this flag once ui::Compositor no longer needs to call
136 // RegisterFrameSinkId(). 155 // RegisterFrameSinkId().
137 // A surfaceSequence's validity is bound to the lifetime of the parent 156 // A surfaceSequence's validity is bound to the lifetime of the parent
138 // FrameSink that created it. We track the lifetime of FrameSinks through 157 // FrameSink that created it. We track the lifetime of FrameSinks through
139 // RegisterFrameSinkId and InvalidateFrameSinkId. During startup and GPU 158 // RegisterFrameSinkId and InvalidateFrameSinkId. During startup and GPU
140 // restart, a SurfaceSequence created by the top most layer compositor may be 159 // restart, a SurfaceSequence created by the top most layer compositor may be
141 // used prior to the creation of the associated CompositorFrameSinkSupport. 160 // used prior to the creation of the associated CompositorFrameSinkSupport.
142 // CompositorFrameSinkSupport is created asynchronously when a new GPU channel 161 // CompositorFrameSinkSupport is created asynchronously when a new GPU channel
143 // is established. Once we switch to SurfaceReferences, this ordering concern 162 // is established. Once we switch to SurfaceReferences, this ordering concern
144 // goes away and we can remove this bool. 163 // goes away and we can remove this bool.
145 const bool handles_frame_sink_id_invalidation_; 164 const bool handles_frame_sink_id_invalidation_;
146 165
147 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_; 166 base::WeakPtrFactory<CompositorFrameSinkSupport> weak_factory_;
148 167
149 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport); 168 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupport);
150 }; 169 };
151 170
152 } // namespace cc 171 } // namespace cc
153 172
154 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_ 173 #endif // CC_SURFACES_COMPOSITOR_FRAME_SINK_SUPPORT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698