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