Adding Peter Thatcher to the owners file.
[chromium-blink-merge.git] / cc / output / overlay_strategy_underlay.cc
blob631ce03d95a015c82b7c7be972bfcfc2a918f3cc
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/quads/draw_quad.h"
8 #include "cc/quads/solid_color_draw_quad.h"
10 namespace cc {
12 OverlayStrategyUnderlay::OverlayStrategyUnderlay(
13 OverlayCandidateValidator* capability_checker,
14 ResourceProvider* resource_provider)
15 : OverlayStrategyCommon(capability_checker, resource_provider) {
18 bool OverlayStrategyUnderlay::Attempt(
19 RenderPassList* render_passes_in_draw_order,
20 OverlayCandidateList* candidate_list) {
21 if (!capability_checker_)
22 return false;
24 RenderPass* root_render_pass = render_passes_in_draw_order->back();
25 DCHECK(root_render_pass);
27 OverlayCandidate candidate;
28 QuadList& quad_list = root_render_pass->quad_list;
29 auto candidate_iterator = quad_list.end();
30 for (auto it = quad_list.begin(); it != quad_list.end(); ++it) {
31 if (IsOverlayQuad(*it) && GetCandidateQuadInfo(**it, &candidate)) {
32 candidate_iterator = it;
33 break;
36 if (candidate_iterator == quad_list.end())
37 return false;
39 // Add our primary surface.
40 OverlayCandidateList candidates;
41 OverlayCandidate main_image;
42 main_image.display_rect = root_render_pass->output_rect;
43 candidates.push_back(main_image);
45 // Add the overlay.
46 candidate.plane_z_order = -1;
47 candidates.push_back(candidate);
49 // Check for support.
50 capability_checker_->CheckOverlaySupport(&candidates);
52 // If the candidate can be handled by an overlay, create a pass for it. We
53 // need to switch out the video quad with a black transparent one.
54 if (candidates[1].overlay_handled) {
55 const SharedQuadState* shared_quad_state =
56 candidate_iterator->shared_quad_state;
57 gfx::Rect rect = candidate_iterator->visible_rect;
58 SolidColorDrawQuad* replacement =
59 quad_list.ReplaceExistingElement<SolidColorDrawQuad>(
60 candidate_iterator);
61 replacement->SetAll(shared_quad_state, rect, rect, rect, false,
62 SK_ColorTRANSPARENT, true);
63 candidate_list->swap(candidates);
64 return true;
66 return false;
69 } // namespace cc