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

Side by Side Diff: cc/surfaces/surface.cc

Issue 2449853004: Getting rid of DelegatedFrameData (Closed)
Patch Set: IsEmpty + rebase Created 4 years, 1 month 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 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 #include "cc/surfaces/surface.h" 5 #include "cc/surfaces/surface.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
11 11
12 #include "base/optional.h"
danakj 2016/10/27 23:06:56 already in the .h so not needed
Saman Sami 2016/10/28 16:47:35 Done.
12 #include "cc/base/container_util.h" 13 #include "cc/base/container_util.h"
13 #include "cc/output/compositor_frame.h" 14 #include "cc/output/compositor_frame.h"
14 #include "cc/output/copy_output_request.h" 15 #include "cc/output/copy_output_request.h"
15 #include "cc/surfaces/surface_factory.h" 16 #include "cc/surfaces/surface_factory.h"
16 #include "cc/surfaces/surface_id_allocator.h" 17 #include "cc/surfaces/surface_id_allocator.h"
17 #include "cc/surfaces/surface_manager.h" 18 #include "cc/surfaces/surface_manager.h"
18 19
19 namespace cc { 20 namespace cc {
20 21
21 // The frame index starts at 2 so that empty frames will be treated as 22 // The frame index starts at 2 so that empty frames will be treated as
22 // completely damaged the first time they're drawn from. 23 // completely damaged the first time they're drawn from.
23 static const int kFrameIndexStart = 2; 24 static const int kFrameIndexStart = 2;
24 25
25 Surface::Surface(const SurfaceId& id, SurfaceFactory* factory) 26 Surface::Surface(const SurfaceId& id, SurfaceFactory* factory)
26 : surface_id_(id), 27 : surface_id_(id),
27 previous_frame_surface_id_(id), 28 previous_frame_surface_id_(id),
28 factory_(factory->AsWeakPtr()), 29 factory_(factory->AsWeakPtr()),
29 frame_index_(kFrameIndexStart), 30 frame_index_(kFrameIndexStart),
30 destroyed_(false) {} 31 destroyed_(false) {}
31 32
32 Surface::~Surface() { 33 Surface::~Surface() {
33 ClearCopyRequests(); 34 ClearCopyRequests();
34 if (current_frame_.delegated_frame_data && factory_) { 35 if (current_frame_ && factory_) {
35 UnrefFrameResources(current_frame_.delegated_frame_data.get()); 36 UnrefFrameResources(*current_frame_);
36 } 37 }
37 if (!draw_callback_.is_null()) 38 if (!draw_callback_.is_null())
38 draw_callback_.Run(); 39 draw_callback_.Run();
39 } 40 }
40 41
41 void Surface::SetPreviousFrameSurface(Surface* surface) { 42 void Surface::SetPreviousFrameSurface(Surface* surface) {
42 DCHECK(surface); 43 DCHECK(surface);
43 frame_index_ = surface->frame_index() + 1; 44 frame_index_ = surface->frame_index() + 1;
44 previous_frame_surface_id_ = surface->surface_id(); 45 previous_frame_surface_id_ = surface->surface_id();
45 } 46 }
46 47
47 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) { 48 void Surface::QueueFrame(CompositorFrame frame, const DrawCallback& callback) {
48 DCHECK(factory_); 49 DCHECK(factory_);
49 ClearCopyRequests(); 50 ClearCopyRequests();
50 51
51 if (frame.delegated_frame_data) { 52 TakeLatencyInfo(&frame.metadata.latency_info);
52 TakeLatencyInfo(&frame.metadata.latency_info);
53 }
54 53
55 CompositorFrame previous_frame = std::move(current_frame_); 54 base::Optional<CompositorFrame> previous_frame = std::move(current_frame_);
56 current_frame_ = std::move(frame); 55 current_frame_ = std::move(frame);
57 56
58 if (current_frame_.delegated_frame_data) { 57 if (current_frame_) {
59 factory_->ReceiveFromChild( 58 factory_->ReceiveFromChild(current_frame_->resource_list);
60 current_frame_.delegated_frame_data->resource_list);
61 } 59 }
62 60
63 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't 61 // Empty frames shouldn't be drawn and shouldn't contribute damage, so don't
64 // increment frame index for them. 62 // increment frame index for them.
65 if (current_frame_.delegated_frame_data && 63 if (current_frame_ && !current_frame_->render_pass_list.empty()) {
66 !current_frame_.delegated_frame_data->render_pass_list.empty()) {
67 ++frame_index_; 64 ++frame_index_;
68 } 65 }
69 66
70 previous_frame_surface_id_ = surface_id(); 67 previous_frame_surface_id_ = surface_id();
71 68
72 std::vector<SurfaceId> new_referenced_surfaces; 69 std::vector<SurfaceId> new_referenced_surfaces;
73 new_referenced_surfaces = current_frame_.metadata.referenced_surfaces; 70 new_referenced_surfaces = current_frame_->metadata.referenced_surfaces;
74 71
75 if (previous_frame.delegated_frame_data) 72 if (previous_frame)
76 UnrefFrameResources(previous_frame.delegated_frame_data.get()); 73 UnrefFrameResources(*previous_frame);
77 74
78 if (!draw_callback_.is_null()) 75 if (!draw_callback_.is_null())
79 draw_callback_.Run(); 76 draw_callback_.Run();
80 draw_callback_ = callback; 77 draw_callback_ = callback;
81 78
82 bool referenced_surfaces_changed = 79 bool referenced_surfaces_changed =
83 (referenced_surfaces_ != new_referenced_surfaces); 80 (referenced_surfaces_ != new_referenced_surfaces);
84 referenced_surfaces_ = new_referenced_surfaces; 81 referenced_surfaces_ = new_referenced_surfaces;
85 std::vector<uint32_t> satisfies_sequences = 82 std::vector<uint32_t> satisfies_sequences =
86 std::move(current_frame_.metadata.satisfies_sequences); 83 std::move(current_frame_->metadata.satisfies_sequences);
87 84
88 if (referenced_surfaces_changed || !satisfies_sequences.empty()) { 85 if (referenced_surfaces_changed || !satisfies_sequences.empty()) {
89 // Notify the manager that sequences were satisfied either if some new 86 // Notify the manager that sequences were satisfied either if some new
90 // sequences were satisfied, or if the set of referenced surfaces changed 87 // sequences were satisfied, or if the set of referenced surfaces changed
91 // to force a GC to happen. 88 // to force a GC to happen.
92 factory_->manager()->DidSatisfySequences(surface_id_.frame_sink_id(), 89 factory_->manager()->DidSatisfySequences(surface_id_.frame_sink_id(),
93 &satisfies_sequences); 90 &satisfies_sequences);
94 } 91 }
95 } 92 }
96 93
97 void Surface::RequestCopyOfOutput( 94 void Surface::RequestCopyOfOutput(
98 std::unique_ptr<CopyOutputRequest> copy_request) { 95 std::unique_ptr<CopyOutputRequest> copy_request) {
99 if (current_frame_.delegated_frame_data && 96 if (current_frame_ && !current_frame_->render_pass_list.empty()) {
100 !current_frame_.delegated_frame_data->render_pass_list.empty()) {
101 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests = 97 std::vector<std::unique_ptr<CopyOutputRequest>>& copy_requests =
102 current_frame_.delegated_frame_data->render_pass_list.back() 98 current_frame_->render_pass_list.back()->copy_requests;
103 ->copy_requests;
104 99
105 if (void* source = copy_request->source()) { 100 if (void* source = copy_request->source()) {
106 // Remove existing CopyOutputRequests made on the Surface by the same 101 // Remove existing CopyOutputRequests made on the Surface by the same
107 // source. 102 // source.
108 auto to_remove = 103 auto to_remove =
109 std::remove_if(copy_requests.begin(), copy_requests.end(), 104 std::remove_if(copy_requests.begin(), copy_requests.end(),
110 [source](const std::unique_ptr<CopyOutputRequest>& x) { 105 [source](const std::unique_ptr<CopyOutputRequest>& x) {
111 return x->source() == source; 106 return x->source() == source;
112 }); 107 });
113 copy_requests.erase(to_remove, copy_requests.end()); 108 copy_requests.erase(to_remove, copy_requests.end());
114 } 109 }
115 copy_requests.push_back(std::move(copy_request)); 110 copy_requests.push_back(std::move(copy_request));
116 } else { 111 } else {
117 copy_request->SendEmptyResult(); 112 copy_request->SendEmptyResult();
118 } 113 }
119 } 114 }
120 115
121 void Surface::TakeCopyOutputRequests( 116 void Surface::TakeCopyOutputRequests(
122 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>* 117 std::multimap<RenderPassId, std::unique_ptr<CopyOutputRequest>>*
123 copy_requests) { 118 copy_requests) {
124 DCHECK(copy_requests->empty()); 119 DCHECK(copy_requests->empty());
125 if (current_frame_.delegated_frame_data) { 120 if (current_frame_) {
126 for (const auto& render_pass : 121 for (const auto& render_pass : current_frame_->render_pass_list) {
127 current_frame_.delegated_frame_data->render_pass_list) {
128 for (auto& request : render_pass->copy_requests) { 122 for (auto& request : render_pass->copy_requests) {
129 copy_requests->insert( 123 copy_requests->insert(
130 std::make_pair(render_pass->id, std::move(request))); 124 std::make_pair(render_pass->id, std::move(request)));
131 } 125 }
132 render_pass->copy_requests.clear(); 126 render_pass->copy_requests.clear();
133 } 127 }
134 } 128 }
135 } 129 }
136 130
137 const CompositorFrame& Surface::GetEligibleFrame() { 131 const CompositorFrame& Surface::GetEligibleFrame() {
138 return current_frame_; 132 return current_frame_.value();
danakj 2016/10/27 23:06:56 DCHECK current_frame_ exists please
Saman Sami 2016/10/28 16:47:35 Done.
139 } 133 }
140 134
141 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) { 135 void Surface::TakeLatencyInfo(std::vector<ui::LatencyInfo>* latency_info) {
142 if (!current_frame_.delegated_frame_data) 136 if (!current_frame_)
143 return; 137 return;
144 if (latency_info->empty()) { 138 if (latency_info->empty()) {
145 current_frame_.metadata.latency_info.swap(*latency_info); 139 current_frame_->metadata.latency_info.swap(*latency_info);
146 return; 140 return;
147 } 141 }
148 std::copy(current_frame_.metadata.latency_info.begin(), 142 std::copy(current_frame_->metadata.latency_info.begin(),
149 current_frame_.metadata.latency_info.end(), 143 current_frame_->metadata.latency_info.end(),
150 std::back_inserter(*latency_info)); 144 std::back_inserter(*latency_info));
151 current_frame_.metadata.latency_info.clear(); 145 current_frame_->metadata.latency_info.clear();
152 } 146 }
153 147
154 void Surface::RunDrawCallbacks() { 148 void Surface::RunDrawCallbacks() {
155 if (!draw_callback_.is_null()) { 149 if (!draw_callback_.is_null()) {
156 DrawCallback callback = draw_callback_; 150 DrawCallback callback = draw_callback_;
157 draw_callback_ = DrawCallback(); 151 draw_callback_ = DrawCallback();
158 callback.Run(); 152 callback.Run();
159 } 153 }
160 } 154 }
161 155
162 void Surface::AddDestructionDependency(SurfaceSequence sequence) { 156 void Surface::AddDestructionDependency(SurfaceSequence sequence) {
163 destruction_dependencies_.push_back(sequence); 157 destruction_dependencies_.push_back(sequence);
164 } 158 }
165 159
166 void Surface::SatisfyDestructionDependencies( 160 void Surface::SatisfyDestructionDependencies(
167 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences, 161 std::unordered_set<SurfaceSequence, SurfaceSequenceHash>* sequences,
168 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) { 162 std::unordered_set<FrameSinkId, FrameSinkIdHash>* valid_frame_sink_ids) {
169 destruction_dependencies_.erase( 163 destruction_dependencies_.erase(
170 std::remove_if(destruction_dependencies_.begin(), 164 std::remove_if(destruction_dependencies_.begin(),
171 destruction_dependencies_.end(), 165 destruction_dependencies_.end(),
172 [sequences, valid_frame_sink_ids](SurfaceSequence seq) { 166 [sequences, valid_frame_sink_ids](SurfaceSequence seq) {
173 return (!!sequences->erase(seq) || 167 return (!!sequences->erase(seq) ||
174 !valid_frame_sink_ids->count(seq.frame_sink_id)); 168 !valid_frame_sink_ids->count(seq.frame_sink_id));
175 }), 169 }),
176 destruction_dependencies_.end()); 170 destruction_dependencies_.end());
177 } 171 }
178 172
179 void Surface::UnrefFrameResources(DelegatedFrameData* frame_data) { 173 void Surface::UnrefFrameResources(const CompositorFrame& frame) {
180 ReturnedResourceArray resources; 174 ReturnedResourceArray resources;
181 TransferableResource::ReturnResources(frame_data->resource_list, &resources); 175 TransferableResource::ReturnResources(frame.resource_list, &resources);
182 // No point in returning same sync token to sender. 176 // No point in returning same sync token to sender.
183 for (auto& resource : resources) 177 for (auto& resource : resources)
184 resource.sync_token.Clear(); 178 resource.sync_token.Clear();
185 factory_->UnrefResources(resources); 179 factory_->UnrefResources(resources);
186 } 180 }
187 181
188 void Surface::ClearCopyRequests() { 182 void Surface::ClearCopyRequests() {
189 if (current_frame_.delegated_frame_data) { 183 if (current_frame_) {
190 for (const auto& render_pass : 184 for (const auto& render_pass : current_frame_->render_pass_list) {
191 current_frame_.delegated_frame_data->render_pass_list) {
192 for (const auto& copy_request : render_pass->copy_requests) 185 for (const auto& copy_request : render_pass->copy_requests)
193 copy_request->SendEmptyResult(); 186 copy_request->SendEmptyResult();
194 } 187 }
195 } 188 }
196 } 189 }
197 190
198 } // namespace cc 191 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698