| 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/output/overlay_strategy_single_on_top.h" | 5 #include "cc/output/overlay_strategy_single_on_top.h" |
| 6 | 6 |
| 7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
| 8 #include "cc/output/overlay_candidate_validator.h" | 8 #include "cc/output/overlay_candidate_validator.h" |
| 9 #include "cc/quads/draw_quad.h" | 9 #include "cc/quads/draw_quad.h" |
| 10 #include "ui/gfx/geometry/rect_conversions.h" |
| 10 | 11 |
| 11 namespace cc { | 12 namespace cc { |
| 12 | 13 |
| 13 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop( | 14 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop( |
| 14 OverlayCandidateValidator* capability_checker) | 15 OverlayCandidateValidator* capability_checker) |
| 15 : capability_checker_(capability_checker) { | 16 : capability_checker_(capability_checker) { |
| 16 DCHECK(capability_checker); | 17 DCHECK(capability_checker); |
| 17 } | 18 } |
| 18 | 19 |
| 19 OverlayStrategySingleOnTop::~OverlayStrategySingleOnTop() {} | 20 OverlayStrategySingleOnTop::~OverlayStrategySingleOnTop() {} |
| 20 | 21 |
| 21 bool OverlayStrategySingleOnTop::Attempt(ResourceProvider* resource_provider, | 22 bool OverlayStrategySingleOnTop::Attempt(ResourceProvider* resource_provider, |
| 22 RenderPassList* render_passes, | 23 RenderPassList* render_passes, |
| 23 OverlayCandidateList* candidate_list) { | 24 OverlayCandidateList* candidate_list, |
| 25 gfx::Rect* damage_rect) { |
| 24 QuadList* quad_list = &render_passes->back()->quad_list; | 26 QuadList* quad_list = &render_passes->back()->quad_list; |
| 25 for (auto it = quad_list->begin(); it != quad_list->end(); ++it) { | 27 for (auto it = quad_list->begin(); it != quad_list->end(); ++it) { |
| 26 OverlayCandidate candidate; | 28 OverlayCandidate candidate; |
| 27 if (OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate) && | 29 if (OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate) && |
| 28 TryOverlay(quad_list, candidate_list, candidate, it)) { | 30 TryOverlay(quad_list, candidate_list, candidate, it, damage_rect)) { |
| 29 return true; | 31 return true; |
| 30 } | 32 } |
| 31 } | 33 } |
| 32 | 34 |
| 33 return false; | 35 return false; |
| 34 } | 36 } |
| 35 | 37 |
| 36 bool OverlayStrategySingleOnTop::TryOverlay( | 38 bool OverlayStrategySingleOnTop::TryOverlay( |
| 37 QuadList* quad_list, | 39 QuadList* quad_list, |
| 38 OverlayCandidateList* candidate_list, | 40 OverlayCandidateList* candidate_list, |
| 39 const OverlayCandidate& candidate, | 41 const OverlayCandidate& candidate, |
| 40 QuadList::Iterator candidate_iterator) { | 42 QuadList::Iterator candidate_iterator, |
| 43 gfx::Rect* damage_rect) { |
| 41 // Check that no prior quads overlap it. | 44 // Check that no prior quads overlap it. |
| 42 for (auto overlap_iter = quad_list->cbegin(); | 45 for (auto overlap_iter = quad_list->cbegin(); |
| 43 overlap_iter != candidate_iterator; ++overlap_iter) { | 46 overlap_iter != candidate_iterator; ++overlap_iter) { |
| 44 gfx::RectF overlap_rect = MathUtil::MapClippedRect( | 47 gfx::RectF overlap_rect = MathUtil::MapClippedRect( |
| 45 overlap_iter->shared_quad_state->quad_to_target_transform, | 48 overlap_iter->shared_quad_state->quad_to_target_transform, |
| 46 gfx::RectF(overlap_iter->rect)); | 49 gfx::RectF(overlap_iter->rect)); |
| 47 if (candidate.display_rect.Intersects(overlap_rect) && | 50 if (candidate.display_rect.Intersects(overlap_rect) && |
| 48 !OverlayCandidate::IsInvisibleQuad(*overlap_iter)) | 51 !OverlayCandidate::IsInvisibleQuad(*overlap_iter)) |
| 49 return false; | 52 return false; |
| 50 } | 53 } |
| 51 | 54 |
| 52 // Add the overlay. | 55 // Add the overlay. |
| 53 OverlayCandidateList new_candidate_list = *candidate_list; | 56 OverlayCandidateList new_candidate_list = *candidate_list; |
| 54 new_candidate_list.push_back(candidate); | 57 new_candidate_list.push_back(candidate); |
| 55 new_candidate_list.back().plane_z_order = 1; | 58 new_candidate_list.back().plane_z_order = 1; |
| 56 | 59 |
| 57 // Check for support. | 60 // Check for support. |
| 58 capability_checker_->CheckOverlaySupport(&new_candidate_list); | 61 capability_checker_->CheckOverlaySupport(&new_candidate_list); |
| 59 | 62 |
| 63 const OverlayCandidate& overlay_candidate = new_candidate_list.back(); |
| 60 // If the candidate can be handled by an overlay, create a pass for it. | 64 // If the candidate can be handled by an overlay, create a pass for it. |
| 61 if (new_candidate_list.back().overlay_handled) { | 65 if (overlay_candidate.overlay_handled) { |
| 62 quad_list->EraseAndInvalidateAllPointers(candidate_iterator); | 66 quad_list->EraseAndInvalidateAllPointers(candidate_iterator); |
| 63 candidate_list->swap(new_candidate_list); | 67 candidate_list->swap(new_candidate_list); |
| 68 damage_rect->Subtract(ToEnclosedRect(overlay_candidate.display_rect)); |
| 64 return true; | 69 return true; |
| 65 } | 70 } |
| 66 | 71 |
| 67 return false; | 72 return false; |
| 68 } | 73 } |
| 69 | 74 |
| 70 } // namespace cc | 75 } // namespace cc |
| OLD | NEW |