Update V8 to version 4.5.7.
[chromium-blink-merge.git] / cc / output / overlay_strategy_single_on_top.cc
blob65b039e6052b0761d820f642677db35e9239cf1f
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"
7 #include <limits>
9 #include "cc/quads/draw_quad.h"
11 namespace cc {
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_)
24 return false;
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;
40 ++overlap_iter) {
41 gfx::RectF overlap_rect = overlap_iter->rect;
42 overlap_iter->quadTransform().TransformRect(&overlap_rect);
43 if (rect.Intersects(overlap_rect) && !IsInvisibleQuad(*overlap_iter)) {
44 intersects = true;
45 break;
48 if (intersects || !GetCandidateQuadInfo(*draw_quad, &candidate))
49 continue;
50 candidate_iterator = it;
51 break;
54 if (candidate_iterator == quad_list.end())
55 return false;
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);
63 // Add the overlay.
64 candidate.plane_z_order = 1;
65 candidates.push_back(candidate);
67 // Check for support.
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);
74 return true;
76 return false;
79 } // namespace cc