| 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 for (const auto& surface : previous_contained_surfaces_) { |
| 59 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
| 60 if (surface_ptr) |
| 61 client_->RemoveSurface(surface_ptr); |
| 62 } |
| 63 } |
| 54 | 64 |
| 55 // Create a clip rect for an aggregated quad from the original clip rect and | 65 // Create a clip rect for an aggregated quad from the original clip rect and |
| 56 // the clip rect from the surface it's on. | 66 // the clip rect from the surface it's on. |
| 57 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( | 67 SurfaceAggregator::ClipData SurfaceAggregator::CalculateClipRect( |
| 58 const ClipData& surface_clip, | 68 const ClipData& surface_clip, |
| 59 const ClipData& quad_clip, | 69 const ClipData& quad_clip, |
| 60 const gfx::Transform& target_transform) { | 70 const gfx::Transform& target_transform) { |
| 61 ClipData out_clip; | 71 ClipData out_clip; |
| 62 if (surface_clip.is_clipped) | 72 if (surface_clip.is_clipped) |
| 63 out_clip = surface_clip; | 73 out_clip = surface_clip; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 provider_->SetChildNeedsSyncPoints( | 138 provider_->SetChildNeedsSyncPoints( |
| 129 child_id, surface->factory()->needs_sync_points()); | 139 child_id, surface->factory()->needs_sync_points()); |
| 130 } | 140 } |
| 131 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; | 141 surface_id_to_resource_child_id_[surface->surface_id()] = child_id; |
| 132 return child_id; | 142 return child_id; |
| 133 } else { | 143 } else { |
| 134 return it->second; | 144 return it->second; |
| 135 } | 145 } |
| 136 } | 146 } |
| 137 | 147 |
| 148 gfx::Rect SurfaceAggregator::DamageRectForSurface( |
| 149 const Surface* surface, |
| 150 const RenderPass& source, |
| 151 const gfx::Rect& full_rect) const { |
| 152 auto it = previous_contained_surfaces_.find(surface->surface_id()); |
| 153 if (it == previous_contained_surfaces_.end()) |
| 154 return full_rect; |
| 138 | 155 |
| 139 gfx::Rect SurfaceAggregator::DamageRectForSurface(const Surface* surface, | 156 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()) | 157 if (previous_index == surface->frame_index()) |
| 144 return gfx::Rect(); | 158 return gfx::Rect(); |
| 145 else if (previous_index == surface->frame_index() - 1) | 159 if (previous_index == surface->frame_index() - 1) |
| 146 return source.damage_rect; | 160 return source.damage_rect; |
| 147 return full_rect; | 161 return full_rect; |
| 148 } | 162 } |
| 149 | 163 |
| 150 void SurfaceAggregator::HandleSurfaceQuad( | 164 void SurfaceAggregator::HandleSurfaceQuad( |
| 151 const SurfaceDrawQuad* surface_quad, | 165 const SurfaceDrawQuad* surface_quad, |
| 152 const gfx::Transform& target_transform, | 166 const gfx::Transform& target_transform, |
| 153 const ClipData& clip_rect, | 167 const ClipData& clip_rect, |
| 154 RenderPass* dest_pass) { | 168 RenderPass* dest_pass) { |
| 155 SurfaceId surface_id = surface_quad->surface_id; | 169 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); | 457 source.has_transparent_background); |
| 444 | 458 |
| 445 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, | 459 CopyQuadsToPass(source.quad_list, source.shared_quad_state_list, |
| 446 child_to_parent_map, gfx::Transform(), ClipData(), | 460 child_to_parent_map, gfx::Transform(), ClipData(), |
| 447 copy_pass.get(), surface->surface_id()); | 461 copy_pass.get(), surface->surface_id()); |
| 448 | 462 |
| 449 dest_pass_list_->push_back(copy_pass.Pass()); | 463 dest_pass_list_->push_back(copy_pass.Pass()); |
| 450 } | 464 } |
| 451 } | 465 } |
| 452 | 466 |
| 453 void SurfaceAggregator::RemoveUnreferencedChildren() { | 467 void SurfaceAggregator::ProcessAddedAndRemovedSurfaces() { |
| 454 for (const auto& surface : previous_contained_surfaces_) { | 468 for (const auto& surface : previous_contained_surfaces_) { |
| 455 if (!contained_surfaces_.count(surface.first)) { | 469 if (!contained_surfaces_.count(surface.first)) { |
| 470 // Release resources of removed surface. |
| 456 SurfaceToResourceChildIdMap::iterator it = | 471 SurfaceToResourceChildIdMap::iterator it = |
| 457 surface_id_to_resource_child_id_.find(surface.first); | 472 surface_id_to_resource_child_id_.find(surface.first); |
| 458 if (it != surface_id_to_resource_child_id_.end()) { | 473 if (it != surface_id_to_resource_child_id_.end()) { |
| 459 provider_->DestroyChild(it->second); | 474 provider_->DestroyChild(it->second); |
| 460 surface_id_to_resource_child_id_.erase(it); | 475 surface_id_to_resource_child_id_.erase(it); |
| 461 } | 476 } |
| 462 | 477 |
| 478 // Notify client of removed surface. |
| 479 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
| 480 if (surface_ptr) { |
| 481 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); |
| 482 client_->RemoveSurface(surface_ptr); |
| 483 } |
| 484 } |
| 485 } |
| 486 |
| 487 for (const auto& surface : contained_surfaces_) { |
| 488 if (!previous_contained_surfaces_.count(surface.first)) { |
| 489 // Notify client of added surface. |
| 463 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); | 490 Surface* surface_ptr = manager_->GetSurfaceForId(surface.first); |
| 464 if (surface_ptr) | 491 if (surface_ptr) |
| 465 surface_ptr->RunDrawCallbacks(SurfaceDrawStatus::DRAW_SKIPPED); | 492 client_->AddSurface(surface_ptr); |
| 466 } | 493 } |
| 467 } | 494 } |
| 468 } | 495 } |
| 469 | 496 |
| 470 // Walk the Surface tree from surface_id. Validate the resources of the current | 497 // 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 | 498 // surface and its descendants, check if there are any copy requests, and |
| 472 // return the combined damage rect. | 499 // return the combined damage rect. |
| 473 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id) { | 500 gfx::Rect SurfaceAggregator::PrewalkTree(SurfaceId surface_id) { |
| 474 if (referenced_surfaces_.count(surface_id)) | 501 if (referenced_surfaces_.count(surface_id)) |
| 475 return gfx::Rect(); | 502 return gfx::Rect(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 595 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface); | 622 CopyPasses(root_surface_frame->delegated_frame_data.get(), surface); |
| 596 referenced_surfaces_.erase(it); | 623 referenced_surfaces_.erase(it); |
| 597 | 624 |
| 598 DCHECK(referenced_surfaces_.empty()); | 625 DCHECK(referenced_surfaces_.empty()); |
| 599 | 626 |
| 600 if (dest_pass_list_->empty()) | 627 if (dest_pass_list_->empty()) |
| 601 return nullptr; | 628 return nullptr; |
| 602 dest_pass_list_->back()->damage_rect = root_damage_rect_; | 629 dest_pass_list_->back()->damage_rect = root_damage_rect_; |
| 603 | 630 |
| 604 dest_pass_list_ = NULL; | 631 dest_pass_list_ = NULL; |
| 605 RemoveUnreferencedChildren(); | 632 ProcessAddedAndRemovedSurfaces(); |
| 606 contained_surfaces_.swap(previous_contained_surfaces_); | 633 contained_surfaces_.swap(previous_contained_surfaces_); |
| 607 contained_surfaces_.clear(); | 634 contained_surfaces_.clear(); |
| 608 | 635 |
| 609 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin(); | 636 for (SurfaceIndexMap::iterator it = previous_contained_surfaces_.begin(); |
| 610 it != previous_contained_surfaces_.end(); | 637 it != previous_contained_surfaces_.end(); |
| 611 ++it) { | 638 ++it) { |
| 612 Surface* surface = manager_->GetSurfaceForId(it->first); | 639 Surface* surface = manager_->GetSurfaceForId(it->first); |
| 613 if (surface) | 640 if (surface) |
| 614 surface->TakeLatencyInfo(&frame->metadata.latency_info); | 641 surface->TakeLatencyInfo(&frame->metadata.latency_info); |
| 615 } | 642 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 631 | 658 |
| 632 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { | 659 void SurfaceAggregator::SetFullDamageForSurface(SurfaceId surface_id) { |
| 633 auto it = previous_contained_surfaces_.find(surface_id); | 660 auto it = previous_contained_surfaces_.find(surface_id); |
| 634 if (it == previous_contained_surfaces_.end()) | 661 if (it == previous_contained_surfaces_.end()) |
| 635 return; | 662 return; |
| 636 // Set the last drawn index as 0 to ensure full damage next time it's drawn. | 663 // Set the last drawn index as 0 to ensure full damage next time it's drawn. |
| 637 it->second = 0; | 664 it->second = 0; |
| 638 } | 665 } |
| 639 | 666 |
| 640 } // namespace cc | 667 } // namespace cc |
| OLD | NEW |