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/quads/draw_quad.h"
13 OverlayStrategySingleOnTop::OverlayStrategySingleOnTop(
14 OverlayCandidateValidator
* capability_checker
,
15 ResourceProvider
* resource_provider
)
16 : OverlayStrategyCommon(capability_checker
, resource_provider
) {
19 bool OverlayStrategySingleOnTop::Attempt(
20 RenderPassList
* render_passes_in_draw_order
,
21 OverlayCandidateList
* candidate_list
) {
22 // Only attempt to handle very simple case for now.
23 if (!capability_checker_
)
26 RenderPass
* root_render_pass
= render_passes_in_draw_order
->back();
27 DCHECK(root_render_pass
);
29 OverlayCandidate candidate
;
30 QuadList
& quad_list
= root_render_pass
->quad_list
;
31 auto candidate_iterator
= quad_list
.end();
32 for (auto it
= quad_list
.begin(); it
!= quad_list
.end(); ++it
) {
33 const DrawQuad
* draw_quad
= *it
;
34 if (IsOverlayQuad(draw_quad
)) {
35 // Check that no prior quads overlap it.
36 bool intersects
= false;
37 gfx::RectF rect
= draw_quad
->rect
;
38 draw_quad
->quadTransform().TransformRect(&rect
);
39 for (auto overlap_iter
= quad_list
.cbegin(); overlap_iter
!= it
;
41 gfx::RectF overlap_rect
= overlap_iter
->rect
;
42 overlap_iter
->quadTransform().TransformRect(&overlap_rect
);
43 if (rect
.Intersects(overlap_rect
) && !IsInvisibleQuad(*overlap_iter
)) {
48 if (intersects
|| !GetCandidateQuadInfo(*draw_quad
, &candidate
))
50 candidate_iterator
= it
;
54 if (candidate_iterator
== quad_list
.end())
57 // Add our primary surface.
58 OverlayCandidateList candidates
;
59 OverlayCandidate main_image
;
60 main_image
.display_rect
= root_render_pass
->output_rect
;
61 candidates
.push_back(main_image
);
64 candidate
.plane_z_order
= 1;
65 candidates
.push_back(candidate
);
68 capability_checker_
->CheckOverlaySupport(&candidates
);
70 // If the candidate can be handled by an overlay, create a pass for it.
71 if (candidates
[1].overlay_handled
) {
72 quad_list
.EraseAndInvalidateAllPointers(candidate_iterator
);
73 candidate_list
->swap(candidates
);