Android NTP: Most visited tile clicks should have PageTransition.AUTO_BOOKMARK
[chromium-blink-merge.git] / cc / surfaces / surface_aggregator.cc
bloba2b56b574ccadec623435a3bdaee651d74571468
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
3 // found in the LICENSE file.
5 #include "cc/surfaces/surface_aggregator.h"
7 #include <map>
9 #include "base/bind.h"
10 #include "base/containers/hash_tables.h"
11 #include "base/logging.h"
12 #include "base/trace_event/trace_event.h"
13 #include "cc/base/math_util.h"
14 #include "cc/output/compositor_frame.h"
15 #include "cc/output/delegated_frame_data.h"
16 #include "cc/quads/draw_quad.h"
17 #include "cc/quads/render_pass_draw_quad.h"
18 #include "cc/quads/shared_quad_state.h"
19 #include "cc/quads/surface_draw_quad.h"
20 #include "cc/surfaces/surface.h"
21 #include "cc/surfaces/surface_factory.h"
22 #include "cc/surfaces/surface_manager.h"
23 #include "cc/trees/blocking_task_runner.h"
25 namespace cc {
26 namespace {
28 void MoveMatchingRequests(
29 RenderPassId id,
30 std::multimap<RenderPassId, CopyOutputRequest*>* copy_requests,
31 ScopedPtrVector<CopyOutputRequest>* output_requests) {
32 auto request_range = copy_requests->equal_range(id);
33 for (auto it = request_range.first; it != request_range.second; ++it) {
34 DCHECK(it->second);
35 output_requests->push_back(scoped_ptr<CopyOutputRequest>(it->second));
36 it->second = nullptr;
38 copy_requests->erase(request_range.first, request_range.second);
41 } // namespace
43 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager,
44 ResourceProvider* provider,
45 bool aggregate_only_damaged)
46 : manager_(manager),
47 provider_(provider),
48 next_render_pass_id_(1),
49 aggregate_only_damaged_(aggregate_only_damaged) {
50 DCHECK(manager_);
53 SurfaceAggregator::~SurfaceAggregator() {}
55 // Create a clip rect for an aggregated quad from the original clip rect and
56 // the clip rect from the surface it's on.
57 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect(
58 const ClipData& surface_clip,
59 const ClipData& quad_clip,
60 const gfx::Transform& target_transform) {
61 ClipData out_clip;
62 if (surface_clip.is_clipped)
63 out_clip = surface_clip;
65 if (quad_clip.is_clipped) {
66 // TODO(jamesr): This only works if target_transform maps integer
67 // rects to integer rects.
68 gfx::Rect final_clip =
69 MathUtil::MapEnclosingClippedRect(target_transform, quad_clip.rect);
70 if (out_clip.is_clipped)
71 out_clip.rect.Intersect(final_clip);
72 else
73 out_clip.rect = final_clip;
74 out_clip.is_clipped = true;
77 return out_clip;
80 class SurfaceAggregator::RenderPassIdAllocator {
81 public:
82 explicit RenderPassIdAllocator(int* next_index) : next_index_(next_index) {}
83 ~RenderPassIdAllocator() {}
85 void AddKnownPass(RenderPassId id) {
86 if (id_to_index_map_.find(id) != id_to_index_map_.end())
87 return;
88 id_to_index_map_[id] = (*next_index_)++;
91 RenderPassId Remap(RenderPassId id) {
92 DCHECK(id_to_index_map_.find(id) != id_to_index_map_.end());
93 return RenderPassId(1, id_to_index_map_[id]);
96 private:
97 base::hash_map<RenderPassId, int> id_to_index_map_;
98 int* next_index_;
100 DISALLOW_COPY_AND_ASSIGN(RenderPassIdAllocator);
103 static void UnrefHelper(base::WeakPtr<SurfaceFactory> surface_factory,
104 const ReturnedResourceArray& resources,
105 BlockingTaskRunner* main_thread_task_runner) {
106 if (surface_factory)
107 surface_factory->UnrefResources(resources);
110 RenderPassId SurfaceAggregator::RemapPassId(RenderPassId surface_local_pass_id,
111 SurfaceId surface_id) {
112 RenderPassIdAllocator* allocator = render_pass_allocator_map_.get(surface_id);
113 if (!allocator) {
114 allocator = new RenderPassIdAllocator(&next_render_pass_id_);
115 render_pass_allocator_map_.set(surface_id, make_scoped_ptr(allocator));
117 allocator->AddKnownPass(surface_local_pass_id);
118 return allocator->Remap(surface_local_pass_id);
121 int SurfaceAggregator::ChildIdForSurface(Surface* surface) {
122 SurfaceToResourceChildIdMap::iterator it =
123 surface_id_to_resource_child_id_.find(surface->surface_id());
124 if (it == surface_id_to_resource_child_id_.end()) {
125 int child_id =
126 provider_->CreateChild(base::Bind(&UnrefHelper, surface->factory()));
127 if (surface->factory()) {
128 provider_->SetChildNeedsSyncPoints(
129 child_id, surface->factory()->needs_sync_points());
131 surface_id_to_resource_child_id_[surface->surface_id()] = child_id;
132 return child_id;
133 } else {
134 return it->second;
139 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface,
140 const RenderPass& source,
141 const gfx::Rect& full_rect) {
142 int previous_index = previous_contained_surfaces_[surface->surface_id()];
143 if (previous_index == surface->frame_index())
144 return gfx::Rect();
145 else if (previous_index == surface->frame_index() - 1)
146 return source.damage_rect;
147 return full_rect;
150 void SurfaceAggregator::HandleSurfaceQuad(
151 const SurfaceDrawQuad* surface_quad,
152 const gfx::Transform& target_transform,
153 const ClipData& clip_rect,
154 RenderPass* dest_pass) {
155 SurfaceId surface_id = surface_quad->surface_id;
156 // If this surface's id is already in our referenced set then it creates
157 // a cycle in the graph and should be dropped.
158 if (referenced_surfaces_.count(surface_id))
159 return;
160 Surface* surface = manager_->GetSurfaceForId(surface_id);
161 if (!surface)
162 return;
163 const CompositorFrame* frame = surface->GetEligibleFrame();
164 if (!frame)
165 return;
166 const DelegatedFrameData* frame_data = frame->delegated_frame_data.get();
167 if (!frame_data)
168 return;
170 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests;
171 surface->TakeCopyOutputRequests(&copy_requests);
173 const RenderPassList& render_pass_list = frame_data->render_pass_list;
174 if (!valid_surfaces_.count(surface->surface_id())) {
175 for (auto& request : copy_requests) {
176 request.second->SendEmptyResult();
177 delete request.second;
179 return;
182 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
183 // TODO(vmpstr): provider check is a hack for unittests that don't set up a
184 // resource provider.
185 ResourceProvider::ResourceIdMap empty_map;
186 const ResourceProvider::ResourceIdMap& child_to_parent_map =
187 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface))
188 : empty_map;
189 bool merge_pass =
190 surface_quad->shared_quad_state->opacity == 1.f && copy_requests.empty();
192 const RenderPassList& referenced_passes = render_pass_list;
193 size_t passes_to_copy =
194 merge_pass ? referenced_passes.size() - 1 : referenced_passes.size();
195 for (size_t j = 0; j < passes_to_copy; ++j) {
196 const RenderPass& source = *referenced_passes[j];
198 size_t sqs_size = source.shared_quad_state_list.size();
199 size_t dq_size = source.quad_list.size();
200 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size));
202 RenderPassId remapped_pass_id = RemapPassId(source.id, surface_id);
204 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(),
205 source.transform_to_root_target,
206 source.has_transparent_background);
208 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests);
210 // Contributing passes aggregated in to the pass list need to take the
211 // transform of the surface quad into account to update their transform to
212 // the root surface.
213 copy_pass->transform_to_root_target.ConcatTransform(
214 surface_quad->shared_quad_state->quad_to_target_transform);
215 copy_pass->transform_to_root_target.ConcatTransform(target_transform);
216 copy_pass->transform_to_root_target.ConcatTransform(
217 dest_pass->transform_to_root_target);
219 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list,
220 child_to_parent_map, gfx::Transform(), ClipData(),
221 copy_pass.get(), surface_id);
223 dest_pass_list_->push_back(copy_pass.Pass());
226 gfx::Transform surface_transform =
227 surface_quad->shared_quad_state->quad_to_target_transform;
228 surface_transform.ConcatTransform(target_transform);
230 const RenderPass& last_pass = *render_pass_list.back();
231 if (merge_pass) {
232 // TODO(jamesr): Clean up last pass special casing.
233 const QuadList& quads = last_pass.quad_list;
235 // Intersect the transformed visible rect and the clip rect to create a
236 // smaller cliprect for the quad.
237 ClipData surface_quad_clip_rect(
238 true, MathUtil::MapEnclosingClippedRect(
239 surface_quad->shared_quad_state->quad_to_target_transform,
240 surface_quad->visible_rect));
241 if (surface_quad->shared_quad_state->is_clipped) {
242 surface_quad_clip_rect.rect.Intersect(
243 surface_quad->shared_quad_state->clip_rect);
246 ClipData quads_clip =
247 CalculateClipRect(clip_rect, surface_quad_clip_rect, target_transform);
249 CopyQuadsToPass(quads, last_pass.shared_quad_state_list,
250 child_to_parent_map, surface_transform, quads_clip,
251 dest_pass, surface_id);
252 } else {
253 RenderPassId remapped_pass_id = RemapPassId(last_pass.id, surface_id);
255 SharedQuadState* shared_quad_state =
256 CopySharedQuadState(surface_quad->shared_quad_state, target_transform,
257 clip_rect, dest_pass);
259 RenderPassDrawQuad* quad =
260 dest_pass->CreateAndAppendDrawQuad<RenderPassDrawQuad>();
261 quad->SetNew(shared_quad_state,
262 surface_quad->rect,
263 surface_quad->visible_rect,
264 remapped_pass_id,
266 gfx::Vector2dF(),
267 gfx::Size(),
268 FilterOperations(),
269 gfx::Vector2dF(),
270 FilterOperations());
273 referenced_surfaces_.erase(it);
276 SharedQuadState* SurfaceAggregator::CopySharedQuadState(
277 const SharedQuadState* source_sqs,
278 const gfx::Transform& target_transform,
279 const ClipData& clip_rect,
280 RenderPass* dest_render_pass) {
281 SharedQuadState* copy_shared_quad_state =
282 dest_render_pass->CreateAndAppendSharedQuadState();
283 copy_shared_quad_state->CopyFrom(source_sqs);
284 // target_transform contains any transformation that may exist
285 // between the context that these quads are being copied from (i.e. the
286 // surface's draw transform when aggregated from within a surface) to the
287 // target space of the pass. This will be identity except when copying the
288 // root draw pass from a surface into a pass when the surface draw quad's
289 // transform is not identity.
290 copy_shared_quad_state->quad_to_target_transform.ConcatTransform(
291 target_transform);
293 ClipData new_clip_rect = CalculateClipRect(
294 clip_rect, ClipData(source_sqs->is_clipped, source_sqs->clip_rect),
295 target_transform);
296 copy_shared_quad_state->is_clipped = new_clip_rect.is_clipped;
297 copy_shared_quad_state->clip_rect = new_clip_rect.rect;
298 return copy_shared_quad_state;
301 static gfx::Rect CalculateQuadSpaceDamageRect(
302 const gfx::Transform& quad_to_target_transform,
303 const gfx::Transform& target_to_root_transform,
304 const gfx::Rect& root_damage_rect) {
305 gfx::Transform quad_to_root_transform(target_to_root_transform,
306 quad_to_target_transform);
307 gfx::Transform inverse_transform(gfx::Transform::kSkipInitialization);
308 bool inverse_valid = quad_to_root_transform.GetInverse(&inverse_transform);
309 DCHECK(inverse_valid);
311 return MathUtil::ProjectEnclosingClippedRect(inverse_transform,
312 root_damage_rect);
315 void SurfaceAggregator::CopyQuadsToPass(
316 const QuadList& source_quad_list,
317 const SharedQuadStateList& source_shared_quad_state_list,
318 const ResourceProvider::ResourceIdMap& child_to_parent_map,
319 const gfx::Transform& target_transform,
320 const ClipData& clip_rect,
321 RenderPass* dest_pass,
322 SurfaceId surface_id) {
323 const SharedQuadState* last_copied_source_shared_quad_state = nullptr;
324 const SharedQuadState* dest_shared_quad_state = nullptr;
325 // If the current frame has copy requests then aggregate the entire
326 // thing, as otherwise parts of the copy requests may be ignored.
327 const bool ignore_undamaged = aggregate_only_damaged_ && !has_copy_requests_;
328 // Damage rect in the quad space of the current shared quad state.
329 // TODO(jbauman): This rect may contain unnecessary area if
330 // transform isn't axis-aligned.
331 gfx::Rect damage_rect_in_quad_space;
333 SharedQuadStateList::ConstIterator sqs_iter =
334 source_shared_quad_state_list.begin();
335 for (const auto& quad : source_quad_list) {
336 while (quad->shared_quad_state != *sqs_iter) {
337 ++sqs_iter;
338 DCHECK(sqs_iter != source_shared_quad_state_list.end());
340 DCHECK_EQ(quad->shared_quad_state, *sqs_iter);
342 if (quad->material == DrawQuad::SURFACE_CONTENT) {
343 const SurfaceDrawQuad* surface_quad = SurfaceDrawQuad::MaterialCast(quad);
344 // HandleSurfaceQuad may add other shared quad state, so reset the
345 // current data.
346 last_copied_source_shared_quad_state = nullptr;
348 if (ignore_undamaged) {
349 gfx::Transform quad_to_target_transform(
350 target_transform,
351 quad->shared_quad_state->quad_to_target_transform);
352 damage_rect_in_quad_space = CalculateQuadSpaceDamageRect(
353 quad_to_target_transform, dest_pass->transform_to_root_target,
354 root_damage_rect_);
355 if (!damage_rect_in_quad_space.Intersects(quad->visible_rect))
356 continue;
358 HandleSurfaceQuad(surface_quad, target_transform, clip_rect, dest_pass);
359 } else {
360 if (quad->shared_quad_state != last_copied_source_shared_quad_state) {
361 dest_shared_quad_state = CopySharedQuadState(
362 quad->shared_quad_state, target_transform, clip_rect, dest_pass);
363 last_copied_source_shared_quad_state = quad->shared_quad_state;
364 if (aggregate_only_damaged_ && !has_copy_requests_) {
365 damage_rect_in_quad_space = CalculateQuadSpaceDamageRect(
366 dest_shared_quad_state->quad_to_target_transform,
367 dest_pass->transform_to_root_target, root_damage_rect_);
371 if (ignore_undamaged) {
372 if (!damage_rect_in_quad_space.Intersects(quad->visible_rect))
373 continue;
376 DrawQuad* dest_quad;
377 if (quad->material == DrawQuad::RENDER_PASS) {
378 const RenderPassDrawQuad* pass_quad =
379 RenderPassDrawQuad::MaterialCast(quad);
380 RenderPassId original_pass_id = pass_quad->render_pass_id;
381 RenderPassId remapped_pass_id =
382 RemapPassId(original_pass_id, surface_id);
384 dest_quad = dest_pass->CopyFromAndAppendRenderPassDrawQuad(
385 pass_quad, dest_shared_quad_state, remapped_pass_id);
386 } else {
387 dest_quad =
388 dest_pass->CopyFromAndAppendDrawQuad(quad, dest_shared_quad_state);
390 if (!child_to_parent_map.empty()) {
391 for (ResourceId& resource_id : dest_quad->resources) {
392 ResourceProvider::ResourceIdMap::const_iterator it =
393 child_to_parent_map.find(resource_id);
394 DCHECK(it != child_to_parent_map.end());
396 DCHECK_EQ(it->first, resource_id);
397 ResourceId remapped_id = it->second;
398 resource_id = remapped_id;
405 void SurfaceAggregator::CopyPasses(const DelegatedFrameData* frame_data,
406 Surface* surface) {
407 // The root surface is allowed to have copy output requests, so grab them
408 // off its render passes.
409 std::multimap<RenderPassId, CopyOutputRequest*> copy_requests;
410 surface->TakeCopyOutputRequests(&copy_requests);
412 const RenderPassList& source_pass_list = frame_data->render_pass_list;
413 DCHECK(valid_surfaces_.count(surface->surface_id()));
414 if (!valid_surfaces_.count(surface->surface_id()))
415 return;
417 // TODO(vmpstr): provider check is a hack for unittests that don't set up a
418 // resource provider.
419 ResourceProvider::ResourceIdMap empty_map;
420 const ResourceProvider::ResourceIdMap& child_to_parent_map =
421 provider_ ? provider_->GetChildToParentMap(ChildIdForSurface(surface))
422 : empty_map;
423 for (size_t i = 0; i < source_pass_list.size(); ++i) {
424 const RenderPass& source = *source_pass_list[i];
426 size_t sqs_size = source.shared_quad_state_list.size();
427 size_t dq_size = source.quad_list.size();
428 scoped_ptr<RenderPass> copy_pass(RenderPass::Create(sqs_size, dq_size));
430 MoveMatchingRequests(source.id, &copy_requests, &copy_pass->copy_requests);
432 RenderPassId remapped_pass_id =
433 RemapPassId(source.id, surface->surface_id());
435 copy_pass->SetAll(remapped_pass_id, source.output_rect, gfx::Rect(),
436 source.transform_to_root_target,
437 source.has_transparent_background);
439 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list,
440 child_to_parent_map, gfx::Transform(), ClipData(),
441 copy_pass.get(), surface->surface_id());
443 dest_pass_list_->push_back(copy_pass.Pass());
447 void SurfaceAggregator::RemoveUnreferencedChildren() {
448 for (const auto& surface : previous_contained_surfaces_) {
449 if (!contained_surfaces_.count(surface.first)) {
450 SurfaceToResourceChildIdMap::iterator it =
451 surface_id_to_resource_child_id_.find(surface.first);
452 if (it != surface_id_to_resource_child_id_.end()) {
453 provider_->DestroyChild(it->second);
454 surface_id_to_resource_child_id_.erase(it);
457 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first);
458 if (surface_ptr)
459 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED);
464 // Walk the Surface tree from surface_id. Validate the resources of the current
465 // surface and its descendants, check if there are any copy requests, and
466 // return the combined damage rect.
467 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id) {
468 if (referenced_surfaces_.count(surface_id))
469 return gfx::Rect();
470 Surface* surface = manager_->GetSurfaceForId(surface_id);
471 if (!surface) {
472 contained_surfaces_[surface_id] = 0;
473 return gfx::Rect();
475 contained_surfaces_[surface_id] = surface->frame_index();
476 const CompositorFrame* surface_frame = surface->GetEligibleFrame();
477 if (!surface_frame)
478 return gfx::Rect();
479 const DelegatedFrameData* frame_data =
480 surface_frame->delegated_frame_data.get();
481 if (!frame_data)
482 return gfx::Rect();
483 int child_id = 0;
484 // TODO(jbauman): hack for unit tests that don't set up rp
485 if (provider_) {
486 child_id = ChildIdForSurface(surface);
487 if (surface->factory())
488 surface->factory()->RefResources(frame_data->resource_list);
489 provider_->ReceiveFromChild(child_id, frame_data->resource_list);
492 ResourceProvider::ResourceIdSet referenced_resources;
493 size_t reserve_size = frame_data->resource_list.size();
494 #if defined(COMPILER_MSVC)
495 referenced_resources.reserve(reserve_size);
496 #elif defined(COMPILER_GCC)
497 // Pre-standard hash-tables only implement resize, which behaves similarly
498 // to reserve for these keys. Resizing to 0 may also be broken (particularly
499 // on stlport).
500 // TODO(jbauman): Replace with reserve when C++11 is supported everywhere.
501 if (reserve_size)
502 referenced_resources.resize(reserve_size);
503 #endif
505 bool invalid_frame = false;
506 ResourceProvider::ResourceIdMap empty_map;
507 const ResourceProvider::ResourceIdMap& child_to_parent_map =
508 provider_ ? provider_->GetChildToParentMap(child_id) : empty_map;
510 // Each pair in the vector is a child surface and the transform from its
511 // target to the root target of this surface.
512 std::vector<std::pair<SurfaceId, gfx::Transform>> child_surfaces;
513 for (const auto& render_pass : frame_data->render_pass_list) {
514 for (const auto& quad : render_pass->quad_list) {
515 if (quad->material == DrawQuad::SURFACE_CONTENT) {
516 const SurfaceDrawQuad* surface_quad =
517 SurfaceDrawQuad::MaterialCast(quad);
518 gfx::Transform target_to_surface_transform(
519 render_pass->transform_to_root_target,
520 surface_quad->shared_quad_state->quad_to_target_transform);
521 child_surfaces.push_back(std::make_pair(surface_quad->surface_id,
522 target_to_surface_transform));
525 if (!provider_)
526 continue;
527 for (ResourceId resource_id : quad->resources) {
528 if (!child_to_parent_map.count(resource_id)) {
529 invalid_frame = true;
530 break;
532 referenced_resources.insert(resource_id);
537 if (invalid_frame)
538 return gfx::Rect();
539 valid_surfaces_.insert(surface->surface_id());
541 if (provider_)
542 provider_->DeclareUsedResourcesFromChild(child_id, referenced_resources);
544 for (const auto& render_pass : frame_data->render_pass_list)
545 has_copy_requests_ |= !render_pass->copy_requests.empty();
547 gfx::Rect damage_rect;
548 if (!frame_data->render_pass_list.empty()) {
549 RenderPass* last_pass = frame_data->render_pass_list.back();
550 damage_rect =
551 DamageRectForSurface(surface, *last_pass, last_pass->output_rect);
554 // Avoid infinite recursion by adding current surface to
555 // referenced_surfaces_.
556 SurfaceSet::iterator it =
557 referenced_surfaces_.insert(surface->surface_id()).first;
558 for (const auto& surface_info : child_surfaces) {
559 gfx::Rect surface_damage = PrewalkTree(surface_info.first);
560 damage_rect.Union(
561 MathUtil::MapEnclosingClippedRect(surface_info.second, surface_damage));
563 referenced_surfaces_.erase(it);
564 return damage_rect;
567 scoped_ptr<CompositorFrame> SurfaceAggregator::Aggregate(SurfaceId surface_id) {
568 Surface* surface = manager_->GetSurfaceForId(surface_id);
569 DCHECK(surface);
570 contained_surfaces_[surface_id] = surface->frame_index();
571 const CompositorFrame* root_surface_frame = surface->GetEligibleFrame();
572 if (!root_surface_frame)
573 return nullptr;
574 TRACE_EVENT0("cc", "SurfaceAggregator::Aggregate");
576 scoped_ptr<CompositorFrame> frame(new CompositorFrame);
577 frame->delegated_frame_data = make_scoped_ptr(new DelegatedFrameData);
579 DCHECK(root_surface_frame->delegated_frame_data);
581 dest_resource_list_ = &frame->delegated_frame_data->resource_list;
582 dest_pass_list_ = &frame->delegated_frame_data->render_pass_list;
584 valid_surfaces_.clear();
585 has_copy_requests_ = false;
586 root_damage_rect_ = PrewalkTree(surface_id);
588 SurfaceSet::iterator it = referenced_surfaces_.insert(surface_id).first;
589 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface);
590 referenced_surfaces_.erase(it);
592 DCHECK(referenced_surfaces_.empty());
594 if (dest_pass_list_->empty())
595 return nullptr;
596 dest_pass_list_->back()->damage_rect = root_damage_rect_;
598 dest_pass_list_ = NULL;
599 RemoveUnreferencedChildren();
600 contained_surfaces_.swap(previous_contained_surfaces_);
601 contained_surfaces_.clear();
603 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin();
604 it != previous_contained_surfaces_.end();
605 ++it) {
606 Surface* surface = manager_->GetSurfaceForId(it->first);
607 if (surface)
608 surface->TakeLatencyInfo(&frame->metadata.latency_info);
611 // TODO(jamesr): Aggregate all resource references into the returned frame's
612 // resource list.
614 return frame.Pass();
617 void SurfaceAggregator::ReleaseResources(SurfaceId surface_id) {
618 SurfaceToResourceChildIdMap::iterator it =
619 surface_id_to_resource_child_id_.find(surface_id);
620 if (it != surface_id_to_resource_child_id_.end()) {
621 provider_->DestroyChild(it->second);
622 surface_id_to_resource_child_id_.erase(it);
626 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) {
627 auto it = previous_contained_surfaces_.find(surface_id);
628 if (it == previous_contained_surfaces_.end())
629 return;
630 // Set the last drawn index as 0 to ensure full damage next time it's drawn.
631 it->second = 0;
634 } // namespace cc