OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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_cast_underlay.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 OverlayStrategyCastUnderlay::OverlayStrategyCastUnderlay( |
| 15 OverlayCandidateValidator* capability_checker) |
| 16 : OverlayStrategyUnderlay(capability_checker), |
| 17 have_swap_with_damage_rect_(false) {} |
| 18 |
| 19 OverlayStrategyCastUnderlay::~OverlayStrategyCastUnderlay() {} |
| 20 |
| 21 bool OverlayStrategyCastUnderlay::GetSwapWithDamageRect(gfx::Rect* rect) { |
| 22 DCHECK(rect); |
| 23 *rect = swap_with_damage_rect_; |
| 24 return have_swap_with_damage_rect_; |
| 25 } |
| 26 |
| 27 bool OverlayStrategyCastUnderlay::Attempt( |
| 28 ResourceProvider* resource_provider, |
| 29 RenderPass* render_pass, |
| 30 OverlayCandidateList* candidate_list) { |
| 31 const QuadList& const_quad_list = render_pass->quad_list; |
| 32 bool found_underlay = false; |
| 33 gfx::Rect damage; |
| 34 for (const auto* quad : base::Reversed(const_quad_list)) { |
| 35 if (OverlayCandidate::IsInvisibleQuad(quad)) |
| 36 continue; |
| 37 |
| 38 const auto& transform = quad->shared_quad_state->quad_to_target_transform; |
| 39 gfx::RectF quad_rect = gfx::RectF(quad->rect); |
| 40 transform.TransformRect(&quad_rect); |
| 41 |
| 42 bool is_underlay = false; |
| 43 if (!found_underlay) { |
| 44 OverlayCandidate candidate; |
| 45 is_underlay = |
| 46 OverlayCandidate::FromDrawQuad(resource_provider, quad, &candidate); |
| 47 found_underlay |= is_underlay; |
| 48 } |
| 49 |
| 50 if (!found_underlay && quad->material == DrawQuad::SOLID_COLOR) { |
| 51 const SolidColorDrawQuad* solid = SolidColorDrawQuad::MaterialCast(quad); |
| 52 if (solid->color == SK_ColorBLACK) |
| 53 continue; |
| 54 } |
| 55 |
| 56 if (is_underlay) { |
| 57 damage.Subtract(ToEnclosedRect(quad_rect)); |
| 58 } else { |
| 59 damage.Union(ToEnclosingRect(quad_rect)); |
| 60 } |
| 61 } |
| 62 |
| 63 have_swap_with_damage_rect_ = found_underlay; |
| 64 if (found_underlay) { |
| 65 swap_with_damage_rect_ = damage; |
| 66 } |
| 67 |
| 68 return OverlayStrategyUnderlay::Attempt(resource_provider, render_pass, |
| 69 candidate_list); |
| 70 } |
| 71 |
| 72 } // namespace cc |
OLD | NEW |