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
3 // found in the LICENSE file.
5 #include "cc/output/overlay_strategy_single_on_top.h"
9 #include "cc/output/overlay_candidate_validator.h"
10 #include "cc/quads/draw_quad.h"
14 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop(
15 OverlayCandidateValidator
* capability_checker
)
16 : OverlayStrategyCommon(capability_checker
) {
19 bool OverlayStrategySingleOnTop::TryOverlay(
20 OverlayCandidateValidator
* capability_checker
,
22 RenderPassList
* render_passes_in_draw_order
,
23 OverlayCandidateList
* candidate_list
,
24 const OverlayCandidate
& candidate
,
25 QuadList::Iterator candidate_iterator
) {
26 RenderPass
* root_render_pass
= render_passes_in_draw_order
->back();
27 QuadList
& quad_list
= root_render_pass
->quad_list
;
28 const DrawQuad
* draw_quad
= *candidate_iterator
;
29 gfx::RectF rect
= draw_quad
->rect
;
30 draw_quad
->shared_quad_state
->quad_to_target_transform
.TransformRect(&rect
);
32 // Check that no prior quads overlap it.
33 for (auto overlap_iter
= quad_list
.cbegin();
34 overlap_iter
!= candidate_iterator
; ++overlap_iter
) {
35 gfx::RectF overlap_rect
= overlap_iter
->rect
;
36 overlap_iter
->shared_quad_state
->quad_to_target_transform
.TransformRect(
38 if (rect
.Intersects(overlap_rect
) && !IsInvisibleQuad(*overlap_iter
))
42 // Add our primary surface.
43 OverlayCandidateList candidates
;
44 OverlayCandidate main_image
;
45 main_image
.display_rect
= root_render_pass
->output_rect
;
46 candidates
.push_back(main_image
);
49 candidates
.push_back(candidate
);
50 candidates
.back().plane_z_order
= 1;
53 capability_checker
->CheckOverlaySupport(&candidates
);
55 // If the candidate can be handled by an overlay, create a pass for it.
56 if (candidates
[1].overlay_handled
) {
57 quad_list
.EraseAndInvalidateAllPointers(candidate_iterator
);
58 candidate_list
->swap(candidates
);