OLD | NEW |
(Empty) | |
| 1 // Copyright 2017 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. |
| 4 |
| 5 #include "cc/output/overlay_strategy_underlay_cast.h" |
| 6 |
| 7 #include "base/containers/adapters.h" |
| 8 #include "cc/quads/draw_quad.h" |
| 9 #include "cc/quads/solid_color_draw_quad.h" |
| 10 #include "ui/gfx/geometry/rect_conversions.h" |
| 11 |
| 12 namespace cc { |
| 13 |
| 14 OverlayStrategyUnderlayCast::OverlayStrategyUnderlayCast( |
| 15 OverlayCandidateValidator* capability_checker) |
| 16 : OverlayStrategyUnderlay(capability_checker) {} |
| 17 |
| 18 OverlayStrategyUnderlayCast::~OverlayStrategyUnderlayCast() {} |
| 19 |
| 20 bool OverlayStrategyUnderlayCast::Attempt( |
| 21 ResourceProvider* resource_provider, |
| 22 RenderPass* render_pass, |
| 23 OverlayCandidateList* candidate_list) { |
| 24 const QuadList& const_quad_list = render_pass->quad_list; |
| 25 bool found_underlay = false; |
| 26 gfx::Rect content_bounds; |
| 27 for (const auto* quad : base::Reversed(const_quad_list)) { |
| 28 if (OverlayCandidate::IsInvisibleQuad(quad)) |
| 29 continue; |
| 30 |
| 31 const auto& transform = quad->shared_quad_state->quad_to_target_transform; |
| 32 gfx::RectF quad_rect = gfx::RectF(quad->rect); |
| 33 transform.TransformRect(&quad_rect); |
| 34 |
| 35 bool is_underlay = false; |
| 36 if (!found_underlay) { |
| 37 OverlayCandidate candidate; |
| 38 is_underlay = |
| 39 OverlayCandidate::FromDrawQuad(resource_provider, quad, &candidate); |
| 40 found_underlay |= is_underlay; |
| 41 } |
| 42 |
| 43 if (!found_underlay && quad->material == DrawQuad::SOLID_COLOR) { |
| 44 const SolidColorDrawQuad* solid = SolidColorDrawQuad::MaterialCast(quad); |
| 45 if (solid->color == SK_ColorBLACK) |
| 46 continue; |
| 47 } |
| 48 |
| 49 if (is_underlay) { |
| 50 content_bounds.Subtract(ToEnclosedRect(quad_rect)); |
| 51 } else { |
| 52 content_bounds.Union(ToEnclosingRect(quad_rect)); |
| 53 } |
| 54 } |
| 55 |
| 56 if (found_underlay) { |
| 57 content_bounds_.resize(1); |
| 58 content_bounds_[0] = content_bounds; |
| 59 } else { |
| 60 content_bounds_.clear(); |
| 61 } |
| 62 return OverlayStrategyUnderlay::Attempt(resource_provider, render_pass, |
| 63 candidate_list); |
| 64 } |
| 65 |
| 66 void OverlayStrategyUnderlayCast::GetContentBounds( |
| 67 std::vector<gfx::Rect>* bounds) { |
| 68 DCHECK(bounds); |
| 69 bounds->insert(bounds->end(), content_bounds_.begin(), content_bounds_.end()); |
| 70 } |
| 71 |
| 72 } // namespace cc |
OLD | NEW |