| 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 #include "ui/gfx/geometry/rect_conversions.h" |
| 11 | 11 |
| 12 namespace cc { | 12 namespace cc { |
| 13 | 13 |
| 14 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop( | 14 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop( |
| 15 OverlayCandidateValidator* capability_checker) | 15 OverlayCandidateValidator* capability_checker) |
| 16 : capability_checker_(capability_checker) { | 16 : capability_checker_(capability_checker) { |
| 17 DCHECK(capability_checker); | 17 DCHECK(capability_checker); |
| 18 } | 18 } |
| 19 | 19 |
| 20 OverlayStrategySingleOnTop::~OverlayStrategySingleOnTop() {} | 20 OverlayStrategySingleOnTop::~OverlayStrategySingleOnTop() {} |
| 21 | 21 |
| 22 bool OverlayStrategySingleOnTop::Attempt( | 22 bool OverlayStrategySingleOnTop::Attempt( |
| 23 ResourceProvider* resource_provider, | 23 ResourceProvider* resource_provider, |
| 24 RenderPass* render_pass, | 24 RenderPass* render_pass, |
| 25 OverlayCandidateList* candidate_list, | 25 OverlayCandidateList* candidate_list, |
| 26 std::vector<gfx::Rect>* content_bounds) { | 26 std::vector<gfx::Rect>* content_bounds) { |
| 27 QuadList* quad_list = &render_pass->quad_list; | 27 QuadList* quad_list = &render_pass->quad_list; |
| 28 // Build a list of candidates with the associated quad. |
| 29 OverlayCandidate best_candidate; |
| 30 QuadList::Iterator best_quad_it = quad_list->end(); |
| 28 for (auto it = quad_list->begin(); it != quad_list->end(); ++it) { | 31 for (auto it = quad_list->begin(); it != quad_list->end(); ++it) { |
| 29 OverlayCandidate candidate; | 32 OverlayCandidate candidate; |
| 30 if (OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate) && | 33 if (OverlayCandidate::FromDrawQuad(resource_provider, *it, &candidate) && |
| 31 TryOverlay(quad_list, candidate_list, candidate, it)) { | 34 // TODO(dcastagna): Remove this once drm platform supports transforms. |
| 32 return true; | 35 candidate.transform == gfx::OVERLAY_TRANSFORM_NONE && |
| 36 !OverlayCandidate::IsOccluded(candidate, quad_list->cbegin(), it)) { |
| 37 if (candidate.display_rect.size().GetArea() > |
| 38 best_candidate.display_rect.size().GetArea()) { |
| 39 best_candidate = candidate; |
| 40 best_quad_it = it; |
| 41 } |
| 33 } | 42 } |
| 34 } | 43 } |
| 44 if (best_quad_it == quad_list->end()) |
| 45 return false; |
| 46 |
| 47 if (TryOverlay(quad_list, candidate_list, best_candidate, best_quad_it)) |
| 48 return true; |
| 35 | 49 |
| 36 return false; | 50 return false; |
| 37 } | 51 } |
| 38 | 52 |
| 39 bool OverlayStrategySingleOnTop::TryOverlay( | 53 bool OverlayStrategySingleOnTop::TryOverlay( |
| 40 QuadList* quad_list, | 54 QuadList* quad_list, |
| 41 OverlayCandidateList* candidate_list, | 55 OverlayCandidateList* candidate_list, |
| 42 const OverlayCandidate& candidate, | 56 const OverlayCandidate& candidate, |
| 43 QuadList::Iterator candidate_iterator) { | 57 QuadList::Iterator candidate_iterator) { |
| 44 // Reject transformed overlays. | |
| 45 // TODO(dcastagna): Remove this once drm platform supports transforms. | |
| 46 if (candidate.transform != gfx::OVERLAY_TRANSFORM_NONE) | |
| 47 return false; | |
| 48 // Check that no prior quads overlap it. | |
| 49 if (OverlayCandidate::IsOccluded(candidate, quad_list->cbegin(), | |
| 50 candidate_iterator)) | |
| 51 return false; | |
| 52 | |
| 53 // Add the overlay. | 58 // Add the overlay. |
| 54 OverlayCandidateList new_candidate_list = *candidate_list; | 59 OverlayCandidateList new_candidate_list = *candidate_list; |
| 55 new_candidate_list.push_back(candidate); | 60 new_candidate_list.push_back(candidate); |
| 56 new_candidate_list.back().plane_z_order = 1; | 61 new_candidate_list.back().plane_z_order = 1; |
| 57 | 62 |
| 58 // Check for support. | 63 // Check for support. |
| 59 capability_checker_->CheckOverlaySupport(&new_candidate_list); | 64 capability_checker_->CheckOverlaySupport(&new_candidate_list); |
| 60 | 65 |
| 61 const OverlayCandidate& overlay_candidate = new_candidate_list.back(); | 66 const OverlayCandidate& overlay_candidate = new_candidate_list.back(); |
| 62 // If the candidate can be handled by an overlay, create a pass for it. | 67 // If the candidate can be handled by an overlay, create a pass for it. |
| 63 if (overlay_candidate.overlay_handled) { | 68 if (overlay_candidate.overlay_handled) { |
| 64 quad_list->EraseAndInvalidateAllPointers(candidate_iterator); | 69 quad_list->EraseAndInvalidateAllPointers(candidate_iterator); |
| 65 candidate_list->swap(new_candidate_list); | 70 candidate_list->swap(new_candidate_list); |
| 66 return true; | 71 return true; |
| 67 } | 72 } |
| 68 | 73 |
| 69 return false; | 74 return false; |
| 70 } | 75 } |
| 71 | 76 |
| 72 } // namespace cc | 77 } // namespace cc |
| OLD | NEW |