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 #include "cc/surfaces/surface.h" | 5 #include "cc/surfaces/surface.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "cc/output/compositor_frame.h" | 9 #include "cc/output/compositor_frame.h" |
10 #include "cc/output/copy_output_request.h" | 10 #include "cc/output/copy_output_request.h" |
11 #include "cc/surfaces/surface_factory.h" | 11 #include "cc/surfaces/surface_factory.h" |
12 #include "cc/surfaces/surface_id_allocator.h" | 12 #include "cc/surfaces/surface_id_allocator.h" |
13 #include "cc/surfaces/surface_manager.h" | 13 #include "cc/surfaces/surface_manager.h" |
14 | 14 |
15 namespace cc { | 15 namespace cc { |
16 | 16 |
17 namespace { | |
18 template <typename Collection, typename Value> | |
mithro-old
2015/10/01 03:00:23
nit: Could we get a comment about why this is here
brianderson
2015/10/07 20:54:48
No longer needed with a std::set.
| |
19 void EraseValueAndCompact(Collection* collection, const Value& value) { | |
20 collection->erase(std::remove(collection->begin(), collection->end(), value), | |
21 collection->end()); | |
22 } | |
23 } // namespace | |
24 | |
17 // The frame index starts at 2 so that empty frames will be treated as | 25 // The frame index starts at 2 so that empty frames will be treated as |
18 // completely damaged the first time they're drawn from. | 26 // completely damaged the first time they're drawn from. |
19 static const int kFrameIndexStart = 2; | 27 static const int kFrameIndexStart = 2; |
20 | 28 |
21 Surface::Surface(SurfaceId id, SurfaceFactory* factory) | 29 Surface::Surface(SurfaceId id, SurfaceFactory* factory) |
22 : surface_id_(id), | 30 : surface_id_(id), |
23 factory_(factory->AsWeakPtr()), | 31 factory_(factory->AsWeakPtr()), |
24 frame_index_(kFrameIndexStart), | 32 frame_index_(kFrameIndexStart), |
25 destroyed_(false) {} | 33 destroyed_(false) {} |
26 | 34 |
27 Surface::~Surface() { | 35 Surface::~Surface() { |
28 ClearCopyRequests(); | 36 ClearCopyRequests(); |
29 if (current_frame_ && factory_) { | 37 if (current_frame_ && factory_) { |
30 ReturnedResourceArray current_resources; | 38 ReturnedResourceArray current_resources; |
31 TransferableResource::ReturnResources( | 39 TransferableResource::ReturnResources( |
32 current_frame_->delegated_frame_data->resource_list, | 40 current_frame_->delegated_frame_data->resource_list, |
33 ¤t_resources); | 41 ¤t_resources); |
34 factory_->UnrefResources(current_resources); | 42 factory_->UnrefResources(current_resources); |
35 } | 43 } |
36 if (!draw_callback_.is_null()) | 44 if (!draw_callback_.is_null()) |
37 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); | 45 draw_callback_.Run(SurfaceDrawStatus::DRAW_SKIPPED); |
46 | |
47 if (factory_) | |
48 factory_->SetBeginFrameSource(surface_id_, NULL); | |
38 } | 49 } |
39 | 50 |
40 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, | 51 void Surface::QueueFrame(scoped_ptr<CompositorFrame> frame, |
41 const DrawCallback& callback) { | 52 const DrawCallback& callback) { |
42 DCHECK(factory_); | 53 DCHECK(factory_); |
43 ClearCopyRequests(); | 54 ClearCopyRequests(); |
44 | 55 |
45 if (frame) { | 56 if (frame) { |
46 TakeLatencyInfo(&frame->metadata.latency_info); | 57 TakeLatencyInfo(&frame->metadata.latency_info); |
47 } | 58 } |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
157 destruction_dependencies_.erase( | 168 destruction_dependencies_.erase( |
158 std::remove_if(destruction_dependencies_.begin(), | 169 std::remove_if(destruction_dependencies_.begin(), |
159 destruction_dependencies_.end(), | 170 destruction_dependencies_.end(), |
160 [sequences, valid_id_namespaces](SurfaceSequence seq) { | 171 [sequences, valid_id_namespaces](SurfaceSequence seq) { |
161 return (!!sequences->erase(seq) || | 172 return (!!sequences->erase(seq) || |
162 !valid_id_namespaces->count(seq.id_namespace)); | 173 !valid_id_namespaces->count(seq.id_namespace)); |
163 }), | 174 }), |
164 destruction_dependencies_.end()); | 175 destruction_dependencies_.end()); |
165 } | 176 } |
166 | 177 |
178 void Surface::AddBeginFrameSource(BeginFrameSource* begin_frame_source) { | |
179 DCHECK(base::STLIsSorted(begin_frame_sources_)); | |
180 | |
181 // Find the insertion point. | |
182 auto insert_index = begin_frame_sources_.begin(); | |
183 while (insert_index != begin_frame_sources_.end()) { | |
184 if (begin_frame_source < *insert_index) | |
185 break; | |
186 insert_index++; | |
187 } | |
188 | |
189 // Verify it doesn't already exist and insert it. | |
190 DCHECK(insert_index == begin_frame_sources_.end() || | |
191 *insert_index != begin_frame_source); | |
192 begin_frame_sources_.insert(insert_index, begin_frame_source); | |
193 UpdatePrimaryBeginFrameSource(); | |
194 } | |
195 | |
196 void Surface::RemoveBeginFrameSource(BeginFrameSource* begin_frame_source) { | |
197 DCHECK(ContainsValue(begin_frame_sources_, begin_frame_source)); | |
198 EraseValueAndCompact(&begin_frame_sources_, begin_frame_source); | |
199 UpdatePrimaryBeginFrameSource(); | |
200 } | |
201 | |
202 void Surface::UpdatePrimaryBeginFrameSource() { | |
203 // Ensure the BeginFrameSources are sorted so our we make a stable decision | |
204 // regarding which source is primary. | |
205 // TODO(brianderson): Do something smarter based on coverage instead. | |
206 DCHECK(base::STLIsSorted(begin_frame_sources_)); | |
207 | |
208 BeginFrameSource* primary_source = nullptr; | |
209 if (!begin_frame_sources_.empty()) | |
210 primary_source = begin_frame_sources_[0]; | |
211 | |
212 if (factory_) | |
213 factory_->SetBeginFrameSource(surface_id_, primary_source); | |
214 } | |
215 | |
167 void Surface::ClearCopyRequests() { | 216 void Surface::ClearCopyRequests() { |
168 if (current_frame_) { | 217 if (current_frame_) { |
169 for (const auto& render_pass : | 218 for (const auto& render_pass : |
170 current_frame_->delegated_frame_data->render_pass_list) { | 219 current_frame_->delegated_frame_data->render_pass_list) { |
171 for (const auto& copy_request : render_pass->copy_requests) | 220 for (const auto& copy_request : render_pass->copy_requests) |
172 copy_request->SendEmptyResult(); | 221 copy_request->SendEmptyResult(); |
173 } | 222 } |
174 } | 223 } |
175 } | 224 } |
176 | 225 |
177 } // namespace cc | 226 } // namespace cc |
OLD | NEW |