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_underlay.h"
7 #include "cc/output/overlay_candidate_validator.h"
8 #include "cc/quads/draw_quad.h"
9 #include "cc/quads/solid_color_draw_quad.h"
13 OverlayStrategyUnderlay::OverlayStrategyUnderlay(
14 OverlayCandidateValidator
* capability_checker
,
15 ResourceProvider
* resource_provider
)
16 : OverlayStrategyCommon(capability_checker
, resource_provider
) {
19 bool OverlayStrategyUnderlay::Attempt(
20 RenderPassList
* render_passes_in_draw_order
,
21 OverlayCandidateList
* candidate_list
) {
22 if (!capability_checker_
)
25 RenderPass
* root_render_pass
= render_passes_in_draw_order
->back();
26 DCHECK(root_render_pass
);
28 OverlayCandidate candidate
;
29 QuadList
& quad_list
= root_render_pass
->quad_list
;
30 auto candidate_iterator
= quad_list
.end();
31 for (auto it
= quad_list
.begin(); it
!= quad_list
.end(); ++it
) {
32 if (IsOverlayQuad(*it
) && GetCandidateQuadInfo(**it
, &candidate
)) {
33 candidate_iterator
= it
;
37 if (candidate_iterator
== quad_list
.end())
40 // Add our primary surface.
41 OverlayCandidateList candidates
;
42 OverlayCandidate main_image
;
43 main_image
.display_rect
= root_render_pass
->output_rect
;
44 candidates
.push_back(main_image
);
47 candidate
.plane_z_order
= -1;
48 candidates
.push_back(candidate
);
51 capability_checker_
->CheckOverlaySupport(&candidates
);
53 // If the candidate can be handled by an overlay, create a pass for it. We
54 // need to switch out the video quad with a black transparent one.
55 if (candidates
[1].overlay_handled
) {
56 const SharedQuadState
* shared_quad_state
=
57 candidate_iterator
->shared_quad_state
;
58 gfx::Rect rect
= candidate_iterator
->visible_rect
;
59 SolidColorDrawQuad
* replacement
=
60 quad_list
.ReplaceExistingElement
<SolidColorDrawQuad
>(
62 replacement
->SetAll(shared_quad_state
, rect
, rect
, rect
, false,
63 SK_ColorTRANSPARENT
, true);
64 candidate_list
->swap(candidates
);