| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/test/layer_test_common.h" | 5 #include "cc/test/layer_test_common.h" |
| 6 | 6 |
| 7 #include "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
| 8 #include "cc/base/region.h" | 8 #include "cc/base/region.h" |
| 9 #include "cc/layers/append_quads_data.h" | 9 #include "cc/layers/append_quads_data.h" |
| 10 #include "cc/quads/draw_quad.h" | 10 #include "cc/quads/draw_quad.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 | 35 |
| 36 return false; | 36 return false; |
| 37 } | 37 } |
| 38 | 38 |
| 39 void LayerTestCommon::VerifyQuadsExactlyCoverRect(const QuadList& quads, | 39 void LayerTestCommon::VerifyQuadsExactlyCoverRect(const QuadList& quads, |
| 40 const gfx::Rect& rect) { | 40 const gfx::Rect& rect) { |
| 41 Region remaining = rect; | 41 Region remaining = rect; |
| 42 | 42 |
| 43 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { | 43 for (auto iter = quads.cbegin(); iter != quads.cend(); ++iter) { |
| 44 gfx::RectF quad_rectf = MathUtil::MapClippedRect( | 44 gfx::RectF quad_rectf = MathUtil::MapClippedRect( |
| 45 iter->shared_quad_state->content_to_target_transform, | 45 iter->shared_quad_state->quad_to_target_transform, |
| 46 gfx::RectF(iter->rect)); | 46 gfx::RectF(iter->rect)); |
| 47 | 47 |
| 48 // Before testing for exact coverage in the integer world, assert that | 48 // Before testing for exact coverage in the integer world, assert that |
| 49 // rounding will not round the rect incorrectly. | 49 // rounding will not round the rect incorrectly. |
| 50 ASSERT_TRUE(CanRectFBeSafelyRoundedToRect(quad_rectf)); | 50 ASSERT_TRUE(CanRectFBeSafelyRoundedToRect(quad_rectf)); |
| 51 | 51 |
| 52 gfx::Rect quad_rect = gfx::ToEnclosingRect(quad_rectf); | 52 gfx::Rect quad_rect = gfx::ToEnclosingRect(quad_rectf); |
| 53 | 53 |
| 54 EXPECT_TRUE(rect.Contains(quad_rect)) << quad_string << iter.index() | 54 EXPECT_TRUE(rect.Contains(quad_rect)) << quad_string << iter.index() |
| 55 << " rect: " << rect.ToString() | 55 << " rect: " << rect.ToString() |
| 56 << " quad: " << quad_rect.ToString(); | 56 << " quad: " << quad_rect.ToString(); |
| 57 EXPECT_TRUE(remaining.Contains(quad_rect)) | 57 EXPECT_TRUE(remaining.Contains(quad_rect)) |
| 58 << quad_string << iter.index() << " remaining: " << remaining.ToString() | 58 << quad_string << iter.index() << " remaining: " << remaining.ToString() |
| 59 << " quad: " << quad_rect.ToString(); | 59 << " quad: " << quad_rect.ToString(); |
| 60 remaining.Subtract(quad_rect); | 60 remaining.Subtract(quad_rect); |
| 61 } | 61 } |
| 62 | 62 |
| 63 EXPECT_TRUE(remaining.IsEmpty()); | 63 EXPECT_TRUE(remaining.IsEmpty()); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // static | 66 // static |
| 67 void LayerTestCommon::VerifyQuadsAreOccluded(const QuadList& quads, | 67 void LayerTestCommon::VerifyQuadsAreOccluded(const QuadList& quads, |
| 68 const gfx::Rect& occluded, | 68 const gfx::Rect& occluded, |
| 69 size_t* partially_occluded_count) { | 69 size_t* partially_occluded_count) { |
| 70 // No quad should exist if it's fully occluded. | 70 // No quad should exist if it's fully occluded. |
| 71 for (const auto& quad : quads) { | 71 for (const auto& quad : quads) { |
| 72 gfx::Rect target_visible_rect = MathUtil::MapEnclosingClippedRect( | 72 gfx::Rect target_visible_rect = MathUtil::MapEnclosingClippedRect( |
| 73 quad->shared_quad_state->content_to_target_transform, | 73 quad->shared_quad_state->quad_to_target_transform, quad->visible_rect); |
| 74 quad->visible_rect); | |
| 75 EXPECT_FALSE(occluded.Contains(target_visible_rect)); | 74 EXPECT_FALSE(occluded.Contains(target_visible_rect)); |
| 76 } | 75 } |
| 77 | 76 |
| 78 // Quads that are fully occluded on one axis only should be shrunken. | 77 // Quads that are fully occluded on one axis only should be shrunken. |
| 79 for (const auto& quad : quads) { | 78 for (const auto& quad : quads) { |
| 80 gfx::Rect target_rect = MathUtil::MapEnclosingClippedRect( | 79 gfx::Rect target_rect = MathUtil::MapEnclosingClippedRect( |
| 81 quad->shared_quad_state->content_to_target_transform, quad->rect); | 80 quad->shared_quad_state->quad_to_target_transform, quad->rect); |
| 82 if (!quad->shared_quad_state->content_to_target_transform | 81 if (!quad->shared_quad_state->quad_to_target_transform |
| 83 .IsIdentityOrIntegerTranslation()) { | 82 .IsIdentityOrIntegerTranslation()) { |
| 84 DCHECK(quad->shared_quad_state->content_to_target_transform | 83 DCHECK(quad->shared_quad_state->quad_to_target_transform |
| 85 .IsPositiveScaleOrTranslation()) | 84 .IsPositiveScaleOrTranslation()) |
| 86 << quad->shared_quad_state->content_to_target_transform.ToString(); | 85 << quad->shared_quad_state->quad_to_target_transform.ToString(); |
| 87 gfx::RectF target_rectf = MathUtil::MapClippedRect( | 86 gfx::RectF target_rectf = MathUtil::MapClippedRect( |
| 88 quad->shared_quad_state->content_to_target_transform, quad->rect); | 87 quad->shared_quad_state->quad_to_target_transform, quad->rect); |
| 89 // Scale transforms allowed, as long as the final transformed rect | 88 // Scale transforms allowed, as long as the final transformed rect |
| 90 // ends up on integer boundaries for ease of testing. | 89 // ends up on integer boundaries for ease of testing. |
| 91 DCHECK_EQ(target_rectf.ToString(), gfx::RectF(target_rect).ToString()); | 90 DCHECK_EQ(target_rectf.ToString(), gfx::RectF(target_rect).ToString()); |
| 92 } | 91 } |
| 93 gfx::Rect target_visible_rect = MathUtil::MapEnclosingClippedRect( | 92 gfx::Rect target_visible_rect = MathUtil::MapEnclosingClippedRect( |
| 94 quad->shared_quad_state->content_to_target_transform, | 93 quad->shared_quad_state->quad_to_target_transform, quad->visible_rect); |
| 95 quad->visible_rect); | |
| 96 | 94 |
| 97 bool fully_occluded_horizontal = target_rect.x() >= occluded.x() && | 95 bool fully_occluded_horizontal = target_rect.x() >= occluded.x() && |
| 98 target_rect.right() <= occluded.right(); | 96 target_rect.right() <= occluded.right(); |
| 99 bool fully_occluded_vertical = target_rect.y() >= occluded.y() && | 97 bool fully_occluded_vertical = target_rect.y() >= occluded.y() && |
| 100 target_rect.bottom() <= occluded.bottom(); | 98 target_rect.bottom() <= occluded.bottom(); |
| 101 bool should_be_occluded = | 99 bool should_be_occluded = |
| 102 target_rect.Intersects(occluded) && | 100 target_rect.Intersects(occluded) && |
| 103 (fully_occluded_vertical || fully_occluded_horizontal); | 101 (fully_occluded_vertical || fully_occluded_horizontal); |
| 104 if (!should_be_occluded) { | 102 if (!should_be_occluded) { |
| 105 EXPECT_EQ(quad->rect.ToString(), quad->visible_rect.ToString()); | 103 EXPECT_EQ(quad->rect.ToString(), quad->visible_rect.ToString()); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 render_pass_->shared_quad_state_list.clear(); | 175 render_pass_->shared_quad_state_list.clear(); |
| 178 | 176 |
| 179 surface_impl->AppendQuads( | 177 surface_impl->AppendQuads( |
| 180 render_pass_.get(), gfx::Transform(), | 178 render_pass_.get(), gfx::Transform(), |
| 181 Occlusion(gfx::Transform(), SimpleEnclosedRegion(occluded), | 179 Occlusion(gfx::Transform(), SimpleEnclosedRegion(occluded), |
| 182 SimpleEnclosedRegion()), | 180 SimpleEnclosedRegion()), |
| 183 SK_ColorBLACK, 1.f, nullptr, &data, RenderPassId(1, 1)); | 181 SK_ColorBLACK, 1.f, nullptr, &data, RenderPassId(1, 1)); |
| 184 } | 182 } |
| 185 | 183 |
| 186 } // namespace cc | 184 } // namespace cc |
| OLD | NEW |