OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_SURFACE_H_ | 5 #ifndef CC_SURFACES_SURFACE_H_ |
6 #define CC_SURFACES_SURFACE_H_ | 6 #define CC_SURFACES_SURFACE_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 | 10 |
11 #include <map> | 11 #include <map> |
12 #include <memory> | 12 #include <memory> |
13 #include <set> | 13 #include <set> |
14 #include <unordered_set> | 14 #include <unordered_set> |
15 #include <vector> | 15 #include <vector> |
16 | 16 |
17 #include "base/callback.h" | 17 #include "base/callback.h" |
18 #include "base/macros.h" | 18 #include "base/macros.h" |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "base/optional.h" | 20 #include "base/optional.h" |
21 #include "cc/output/copy_output_request.h" | 21 #include "cc/output/copy_output_request.h" |
| 22 #include "cc/surfaces/compositor_frame_sink_support.h" |
22 #include "cc/surfaces/frame_sink_id.h" | 23 #include "cc/surfaces/frame_sink_id.h" |
23 #include "cc/surfaces/pending_frame_observer.h" | 24 #include "cc/surfaces/pending_frame_observer.h" |
24 #include "cc/surfaces/surface_factory.h" | |
25 #include "cc/surfaces/surface_id.h" | 25 #include "cc/surfaces/surface_id.h" |
26 #include "cc/surfaces/surface_sequence.h" | 26 #include "cc/surfaces/surface_sequence.h" |
27 #include "cc/surfaces/surfaces_export.h" | 27 #include "cc/surfaces/surfaces_export.h" |
28 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
29 | 29 |
30 namespace ui { | 30 namespace ui { |
31 class LatencyInfo; | 31 class LatencyInfo; |
32 } | 32 } |
33 | 33 |
34 namespace cc { | 34 namespace cc { |
35 | 35 |
36 class CompositorFrame; | 36 class CompositorFrame; |
37 class CopyOutputRequest; | 37 class CopyOutputRequest; |
38 class SurfaceFactory; | |
39 | 38 |
40 class CC_SURFACES_EXPORT Surface { | 39 class CC_SURFACES_EXPORT Surface { |
41 public: | 40 public: |
42 using DrawCallback = SurfaceFactory::DrawCallback; | 41 using WillDrawCallback = |
43 using WillDrawCallback = SurfaceFactory::WillDrawCallback; | 42 base::RepeatingCallback<void(const LocalSurfaceId&, const gfx::Rect&)>; |
44 | 43 |
45 Surface(const SurfaceId& id, base::WeakPtr<SurfaceFactory> factory); | 44 Surface( |
| 45 const SurfaceId& id, |
| 46 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support); |
46 ~Surface(); | 47 ~Surface(); |
47 | 48 |
48 const SurfaceId& surface_id() const { return surface_id_; } | 49 const SurfaceId& surface_id() const { return surface_id_; } |
49 const SurfaceId& previous_frame_surface_id() const { | 50 const SurfaceId& previous_frame_surface_id() const { |
50 return previous_frame_surface_id_; | 51 return previous_frame_surface_id_; |
51 } | 52 } |
52 | 53 |
53 void SetPreviousFrameSurface(Surface* surface); | 54 void SetPreviousFrameSurface(Surface* surface); |
54 | 55 |
55 // |draw_callback| is called once to notify the client that the previously | 56 // |draw_callback| is called once to notify the client that the previously |
56 // submitted CompositorFrame is processed and that another frame can be | 57 // submitted CompositorFrame is processed and that another frame can be |
57 // submitted. | 58 // submitted. |
58 // |will_draw_callback| is called when |surface| is scheduled for a draw and | 59 // |will_draw_callback| is called when |surface| is scheduled for a draw and |
59 // there is visible damage. | 60 // there is visible damage. |
60 void QueueFrame(CompositorFrame frame, | 61 void QueueFrame(CompositorFrame frame, |
61 const DrawCallback& draw_callback, | 62 const base::Closure& draw_callback, |
62 const WillDrawCallback& will_draw_callback); | 63 const WillDrawCallback& will_draw_callback); |
63 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); | 64 void RequestCopyOfOutput(std::unique_ptr<CopyOutputRequest> copy_request); |
64 | 65 |
65 // Notifies the Surface that a blocking SurfaceId now has an active frame. | 66 // Notifies the Surface that a blocking SurfaceId now has an active frame. |
66 void NotifySurfaceIdAvailable(const SurfaceId& surface_id); | 67 void NotifySurfaceIdAvailable(const SurfaceId& surface_id); |
67 | 68 |
68 void AddObserver(PendingFrameObserver* observer); | 69 void AddObserver(PendingFrameObserver* observer); |
69 void RemoveObserver(PendingFrameObserver* observer); | 70 void RemoveObserver(PendingFrameObserver* observer); |
70 | 71 |
71 // Called if a deadline has been hit and this surface is not yet active but | 72 // Called if a deadline has been hit and this surface is not yet active but |
(...skipping 14 matching lines...) Expand all Loading... |
86 // returns true before calling this method. | 87 // returns true before calling this method. |
87 const CompositorFrame& GetPendingFrame(); | 88 const CompositorFrame& GetPendingFrame(); |
88 | 89 |
89 // Returns a number that increments by 1 every time a new frame is enqueued. | 90 // Returns a number that increments by 1 every time a new frame is enqueued. |
90 int frame_index() const { return frame_index_; } | 91 int frame_index() const { return frame_index_; } |
91 | 92 |
92 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); | 93 void TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info); |
93 void RunDrawCallback(); | 94 void RunDrawCallback(); |
94 void RunWillDrawCallback(const gfx::Rect& damage_rect); | 95 void RunWillDrawCallback(const gfx::Rect& damage_rect); |
95 | 96 |
96 base::WeakPtr<SurfaceFactory> factory() { return factory_; } | 97 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support() { |
| 98 return compositor_frame_sink_support_; |
| 99 } |
97 | 100 |
98 // Add a SurfaceSequence that must be satisfied before the Surface is | 101 // Add a SurfaceSequence that must be satisfied before the Surface is |
99 // destroyed. | 102 // destroyed. |
100 void AddDestructionDependency(SurfaceSequence sequence); | 103 void AddDestructionDependency(SurfaceSequence sequence); |
101 | 104 |
102 // Satisfy all destruction dependencies that are contained in sequences, and | 105 // Satisfy all destruction dependencies that are contained in sequences, and |
103 // remove them from sequences. | 106 // remove them from sequences. |
104 void SatisfyDestructionDependencies( | 107 void SatisfyDestructionDependencies( |
105 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, | 108 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, |
106 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); | 109 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_id_namespaces); |
(...skipping 13 matching lines...) Expand all Loading... |
120 | 123 |
121 bool HasActiveFrame() const { return active_frame_data_.has_value(); } | 124 bool HasActiveFrame() const { return active_frame_data_.has_value(); } |
122 bool HasPendingFrame() const { return pending_frame_data_.has_value(); } | 125 bool HasPendingFrame() const { return pending_frame_data_.has_value(); } |
123 | 126 |
124 bool destroyed() const { return destroyed_; } | 127 bool destroyed() const { return destroyed_; } |
125 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } | 128 void set_destroyed(bool destroyed) { destroyed_ = destroyed; } |
126 | 129 |
127 private: | 130 private: |
128 struct FrameData { | 131 struct FrameData { |
129 FrameData(CompositorFrame&& frame, | 132 FrameData(CompositorFrame&& frame, |
130 const DrawCallback& draw_callback, | 133 const base::Closure& draw_callback, |
131 const WillDrawCallback& will_draw_callback); | 134 const WillDrawCallback& will_draw_callback); |
132 FrameData(FrameData&& other); | 135 FrameData(FrameData&& other); |
133 ~FrameData(); | 136 ~FrameData(); |
134 FrameData& operator=(FrameData&& other); | 137 FrameData& operator=(FrameData&& other); |
135 CompositorFrame frame; | 138 CompositorFrame frame; |
136 DrawCallback draw_callback; | 139 base::Closure draw_callback; |
137 WillDrawCallback will_draw_callback; | 140 WillDrawCallback will_draw_callback; |
138 }; | 141 }; |
139 | 142 |
140 void ActivatePendingFrame(); | 143 void ActivatePendingFrame(); |
141 // Called when all of the surface's dependencies have been resolved. | 144 // Called when all of the surface's dependencies have been resolved. |
142 void ActivateFrame(FrameData frame_data); | 145 void ActivateFrame(FrameData frame_data); |
143 void UpdateBlockingSurfaces(bool has_previous_pending_frame, | 146 void UpdateBlockingSurfaces(bool has_previous_pending_frame, |
144 const CompositorFrame& current_frame); | 147 const CompositorFrame& current_frame); |
145 | 148 |
146 void UnrefFrameResourcesAndRunDrawCallback( | 149 void UnrefFrameResourcesAndRunDrawCallback( |
147 base::Optional<FrameData> frame_data); | 150 base::Optional<FrameData> frame_data); |
148 void ClearCopyRequests(); | 151 void ClearCopyRequests(); |
149 | 152 |
150 void TakeLatencyInfoFromPendingFrame( | 153 void TakeLatencyInfoFromPendingFrame( |
151 std::vector<ui::LatencyInfo>* latency_info); | 154 std::vector<ui::LatencyInfo>* latency_info); |
152 static void TakeLatencyInfoFromFrame( | 155 static void TakeLatencyInfoFromFrame( |
153 CompositorFrame* frame, | 156 CompositorFrame* frame, |
154 std::vector<ui::LatencyInfo>* latency_info); | 157 std::vector<ui::LatencyInfo>* latency_info); |
155 | 158 |
156 SurfaceId surface_id_; | 159 SurfaceId surface_id_; |
157 SurfaceId previous_frame_surface_id_; | 160 SurfaceId previous_frame_surface_id_; |
158 base::WeakPtr<SurfaceFactory> factory_; | 161 base::WeakPtr<CompositorFrameSinkSupport> compositor_frame_sink_support_; |
159 | 162 |
160 base::Optional<FrameData> pending_frame_data_; | 163 base::Optional<FrameData> pending_frame_data_; |
161 base::Optional<FrameData> active_frame_data_; | 164 base::Optional<FrameData> active_frame_data_; |
162 int frame_index_; | 165 int frame_index_; |
163 bool destroyed_; | 166 bool destroyed_; |
164 std::vector<SurfaceSequence> destruction_dependencies_; | 167 std::vector<SurfaceSequence> destruction_dependencies_; |
165 | 168 |
166 base::flat_set<SurfaceId> blocking_surfaces_; | 169 base::flat_set<SurfaceId> blocking_surfaces_; |
167 base::ObserverList<PendingFrameObserver, true> observers_; | 170 base::ObserverList<PendingFrameObserver, true> observers_; |
168 | 171 |
169 DISALLOW_COPY_AND_ASSIGN(Surface); | 172 DISALLOW_COPY_AND_ASSIGN(Surface); |
170 }; | 173 }; |
171 | 174 |
172 } // namespace cc | 175 } // namespace cc |
173 | 176 |
174 #endif // CC_SURFACES_SURFACE_H_ | 177 #endif // CC_SURFACES_SURFACE_H_ |
OLD | NEW |