| 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_aggregator.h" | 5 #include "cc/surfaces/surface_aggregator.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/stl_util.h" |
| 12 #include "base/trace_event/trace_event.h" | 13 #include "base/trace_event/trace_event.h" |
| 13 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
| 14 #include "cc/output/compositor_frame.h" | 15 #include "cc/output/compositor_frame.h" |
| 15 #include "cc/output/delegated_frame_data.h" | 16 #include "cc/output/delegated_frame_data.h" |
| 16 #include "cc/quads/draw_quad.h" | 17 #include "cc/quads/draw_quad.h" |
| 17 #include "cc/quads/render_pass_draw_quad.h" | 18 #include "cc/quads/render_pass_draw_quad.h" |
| 18 #include "cc/quads/shared_quad_state.h" | 19 #include "cc/quads/shared_quad_state.h" |
| 19 #include "cc/quads/surface_draw_quad.h" | 20 #include "cc/quads/surface_draw_quad.h" |
| 20 #include "cc/surfaces/surface.h" | 21 #include "cc/surfaces/surface.h" |
| 21 #include "cc/surfaces/surface_factory.h" | 22 #include "cc/surfaces/surface_factory.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 33 for (auto it = request_range.first; it != request_range.second; ++it) { | 34 for (auto it = request_range.first; it != request_range.second; ++it) { |
| 34 DCHECK(it->second); | 35 DCHECK(it->second); |
| 35 output_requests->push_back(scoped_ptr<CopyOutputRequest>(it->second)); | 36 output_requests->push_back(scoped_ptr<CopyOutputRequest>(it->second)); |
| 36 it->second = nullptr; | 37 it->second = nullptr; |
| 37 } | 38 } |
| 38 copy_requests->erase(request_range.first, request_range.second); | 39 copy_requests->erase(request_range.first, request_range.second); |
| 39 } | 40 } |
| 40 | 41 |
| 41 } // namespace | 42 } // namespace |
| 42 | 43 |
| 43 SurfaceAggregator::SurfaceAggregator(SurfaceManager* manager, | 44 SurfaceAggregator::SurfaceAggregator(SurfaceAggregatorClient* client, |
| 45 SurfaceManager* manager, |
| 44 ResourceProvider* provider, | 46 ResourceProvider* provider, |
| 45 bool aggregate_only_damaged) | 47 bool aggregate_only_damaged) |
| 46 : manager_(manager), | 48 : client_(client), |
| 49 manager_(manager), |
| 47 provider_(provider), | 50 provider_(provider), |
| 48 next_render_pass_id_(1), | 51 next_render_pass_id_(1), |
| 49 aggregate_only_damaged_(aggregate_only_damaged) { | 52 aggregate_only_damaged_(aggregate_only_damaged) { |
| 50 DCHECK(manager_); | 53 DCHECK(manager_); |
| 51 } | 54 } |
| 52 | 55 |
| 53 SurfaceAggregator::~SurfaceAggregator() {} | 56 SurfaceAggregator::~SurfaceAggregator() { |
| 57 // Notify client of all surfaces being removed. |
| 58 contained_surfaces_.clear(); |
| 59 ProcessAddedAndRemovedSurfaces(); |
| 60 } |
| 54 | 61 |
| 55 // Create a clip rect for an aggregated quad from the original clip rect and | 62 // Create a clip rect for an aggregated quad from the original clip rect and |
| 56 // the clip rect from the surface it's on. | 63 // the clip rect from the surface it's on. |
| 57 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( | 64 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( |
| 58 const ClipData& surface_clip, | 65 const ClipData& surface_clip, |
| 59 const ClipData& quad_clip, | 66 const ClipData& quad_clip, |
| 60 const gfx::Transform& target_transform) { | 67 const gfx::Transform& target_transform) { |
| 61 ClipData out_clip; | 68 ClipData out_clip; |
| 62 if (surface_clip.is_clipped) | 69 if (surface_clip.is_clipped) |
| 63 out_clip = surface_clip; | 70 out_clip = surface_clip; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 provider_->SetChildNeedsSyncPoints( | 135 provider_->SetChildNeedsSyncPoints( |
| 129 child_id, surface->factory()->needs_sync_points()); | 136 child_id, surface->factory()->needs_sync_points()); |
| 130 } | 137 } |
| 131 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 138 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
| 132 return child_id; | 139 return child_id; |
| 133 } else { | 140 } else { |
| 134 return it->second; | 141 return it->second; |
| 135 } | 142 } |
| 136 } | 143 } |
| 137 | 144 |
| 145 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
| 146 const Surface* surface, |
| 147 const RenderPass& source, |
| 148 const gfx::Rect& full_rect) const { |
| 149 auto it = previous_contained_surfaces_.find(surface->surface_id()); |
| 150 if (it == previous_contained_surfaces_.end()) |
| 151 return full_rect; |
| 138 | 152 |
| 139 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, | 153 int previous_index = it->second; |
| 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()) | 154 if (previous_index == surface->frame_index()) |
| 144 return gfx::Rect(); | 155 return gfx::Rect(); |
| 145 else if (previous_index == surface->frame_index() - 1) | 156 if (previous_index == surface->frame_index() - 1) |
| 146 return source.damage_rect; | 157 return source.damage_rect; |
| 147 return full_rect; | 158 return full_rect; |
| 148 } | 159 } |
| 149 | 160 |
| 150 void SurfaceAggregator::HandleSurfaceQuad( | 161 void SurfaceAggregator::HandleSurfaceQuad( |
| 151 const SurfaceDrawQuad* surface_quad, | 162 const SurfaceDrawQuad* surface_quad, |
| 152 const gfx::Transform& target_transform, | 163 const gfx::Transform& target_transform, |
| 153 const ClipData& clip_rect, | 164 const ClipData& clip_rect, |
| 154 RenderPass* dest_pass) { | 165 RenderPass* dest_pass) { |
| 155 SurfaceId surface_id = surface_quad->surface_id; | 166 SurfaceId surface_id = surface_quad->surface_id; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 source.has_transparent_background); | 454 source.has_transparent_background); |
| 444 | 455 |
| 445 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, | 456 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 446 child_to_parent_map, gfx::Transform(), ClipData(), | 457 child_to_parent_map, gfx::Transform(), ClipData(), |
| 447 copy_pass.get(), surface->surface_id()); | 458 copy_pass.get(), surface->surface_id()); |
| 448 | 459 |
| 449 dest_pass_list_->push_back(copy_pass.Pass()); | 460 dest_pass_list_->push_back(copy_pass.Pass()); |
| 450 } | 461 } |
| 451 } | 462 } |
| 452 | 463 |
| 453 void SurfaceAggregator::RemoveUnreferencedChildren() { | 464 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { |
| 454 for (const auto& surface : previous_contained_surfaces_) { | 465 for (const auto& surface : previous_contained_surfaces_) { |
| 455 if (!contained_surfaces_.count(surface.first)) { | 466 if (!contained_surfaces_.count(surface.first)) { |
| 467 // Release resources of removed surface. |
| 456 SurfaceToResourceChildIdMap::iterator it = | 468 SurfaceToResourceChildIdMap::iterator it = |
| 457 surface_id_to_resource_child_id_.find(surface.first); | 469 surface_id_to_resource_child_id_.find(surface.first); |
| 458 if (it != surface_id_to_resource_child_id_.end()) { | 470 if (it != surface_id_to_resource_child_id_.end()) { |
| 459 provider_->DestroyChild(it->second); | 471 provider_->DestroyChild(it->second); |
| 460 surface_id_to_resource_child_id_.erase(it); | 472 surface_id_to_resource_child_id_.erase(it); |
| 461 } | 473 } |
| 462 | 474 |
| 475 // Notify client of removed surface. |
| 476 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
| 477 if (surface_ptr) { |
| 478 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); |
| 479 client_->RemoveSurface(surface_ptr); |
| 480 } |
| 481 } |
| 482 } |
| 483 |
| 484 for (const auto& surface : contained_surfaces_) { |
| 485 if (!previous_contained_surfaces_.count(surface.first)) { |
| 486 // Notify client of added surface. |
| 463 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); | 487 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
| 464 if (surface_ptr) | 488 if (surface_ptr) |
| 465 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); | 489 client_->AddSurface(surface_ptr); |
| 466 } | 490 } |
| 467 } | 491 } |
| 468 } | 492 } |
| 469 | 493 |
| 470 // Walk the Surface tree from surface_id. Validate the resources of the current | 494 // Walk the Surface tree from surface_id. Validate the resources of the current |
| 471 // surface and its descendants, check if there are any copy requests, and | 495 // surface and its descendants, check if there are any copy requests, and |
| 472 // return the combined damage rect. | 496 // return the combined damage rect. |
| 473 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id) { | 497 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id) { |
| 474 if (referenced_surfaces_.count(surface_id)) | 498 if (referenced_surfaces_.count(surface_id)) |
| 475 return gfx::Rect(); | 499 return gfx::Rect(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface); | 623 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface); |
| 600 referenced_surfaces_.erase(it); | 624 referenced_surfaces_.erase(it); |
| 601 | 625 |
| 602 DCHECK(referenced_surfaces_.empty()); | 626 DCHECK(referenced_surfaces_.empty()); |
| 603 | 627 |
| 604 if (dest_pass_list_->empty()) | 628 if (dest_pass_list_->empty()) |
| 605 return nullptr; | 629 return nullptr; |
| 606 dest_pass_list_->back()->damage_rect = root_damage_rect_; | 630 dest_pass_list_->back()->damage_rect = root_damage_rect_; |
| 607 | 631 |
| 608 dest_pass_list_ = NULL; | 632 dest_pass_list_ = NULL; |
| 609 RemoveUnreferencedChildren(); | 633 ProcessAddedAndRemovedSurfaces(); |
| 610 contained_surfaces_.swap(previous_contained_surfaces_); | 634 contained_surfaces_.swap(previous_contained_surfaces_); |
| 611 contained_surfaces_.clear(); | 635 contained_surfaces_.clear(); |
| 612 | 636 |
| 613 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin(); | 637 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin(); |
| 614 it != previous_contained_surfaces_.end(); | 638 it != previous_contained_surfaces_.end(); |
| 615 ++it) { | 639 ++it) { |
| 616 Surface* surface = manager_->GetSurfaceForId(it->first); | 640 Surface* surface = manager_->GetSurfaceForId(it->first); |
| 617 if (surface) | 641 if (surface) |
| 618 surface->TakeLatencyInfo(&frame->metadata.latency_info); | 642 surface->TakeLatencyInfo(&frame->metadata.latency_info); |
| 619 } | 643 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 635 | 659 |
| 636 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 660 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { |
| 637 auto it = previous_contained_surfaces_.find(surface_id); | 661 auto it = previous_contained_surfaces_.find(surface_id); |
| 638 if (it == previous_contained_surfaces_.end()) | 662 if (it == previous_contained_surfaces_.end()) |
| 639 return; | 663 return; |
| 640 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 664 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 641 it->second = 0; | 665 it->second = 0; |
| 642 } | 666 } |
| 643 | 667 |
| 644 } // namespace cc | 668 } // namespace cc |
| OLD | NEW |