OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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/layers/surface_layer_impl.h" | 5 #include "cc/layers/surface_layer_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
| 9 #include "cc/layers/append_quads_data.h" |
9 #include "cc/test/layer_test_common.h" | 10 #include "cc/test/layer_test_common.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 namespace { | 14 namespace { |
14 | 15 |
15 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 16 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
16 | 17 |
17 TEST(SurfaceLayerImplTest, Occlusion) { | 18 TEST(SurfaceLayerImplTest, Occlusion) { |
18 gfx::Size layer_size(1000, 1000); | 19 gfx::Size layer_size(1000, 1000); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 60 |
60 size_t partially_occluded_count = 0; | 61 size_t partially_occluded_count = 0; |
61 LayerTestCommon::VerifyQuadsAreOccluded( | 62 LayerTestCommon::VerifyQuadsAreOccluded( |
62 impl.quad_list(), occluded, &partially_occluded_count); | 63 impl.quad_list(), occluded, &partially_occluded_count); |
63 // The layer outputs one quad, which is partially occluded. | 64 // The layer outputs one quad, which is partially occluded. |
64 EXPECT_EQ(1u, impl.quad_list().size()); | 65 EXPECT_EQ(1u, impl.quad_list().size()); |
65 EXPECT_EQ(1u, partially_occluded_count); | 66 EXPECT_EQ(1u, partially_occluded_count); |
66 } | 67 } |
67 } | 68 } |
68 | 69 |
| 70 TEST(SurfaceLayerImplTest, SurfaceStretchedToLayerBounds) { |
| 71 LayerTestCommon::LayerImplTest impl; |
| 72 SurfaceLayerImpl* surface_layer_impl = |
| 73 impl.AddChildToRoot<SurfaceLayerImpl>(); |
| 74 const LocalFrameId kArbitraryLocalFrameId(9, |
| 75 base::UnguessableToken::Create()); |
| 76 |
| 77 // Given condition: layer and surface have different size and different |
| 78 // aspect ratios. |
| 79 gfx::Size layer_size(400, 100); |
| 80 gfx::Size surface_size(300, 300); |
| 81 float surface_scale = 1.f; |
| 82 gfx::Transform target_space_transform( |
| 83 surface_layer_impl->draw_properties().target_space_transform); |
| 84 |
| 85 // The following code is mimicking the PushPropertiesTo from pending to |
| 86 // active tree. |
| 87 surface_layer_impl->SetBounds(layer_size); |
| 88 surface_layer_impl->SetDrawsContent(true); |
| 89 SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalFrameId); |
| 90 surface_layer_impl->SetSurfaceId(surface_id); |
| 91 surface_layer_impl->SetSurfaceScale(surface_scale); |
| 92 surface_layer_impl->SetSurfaceSize(surface_size); |
| 93 surface_layer_impl->SetStretchContentToFillBounds(true); |
| 94 |
| 95 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 96 AppendQuadsData data; |
| 97 surface_layer_impl->AppendQuads(render_pass.get(), &data); |
| 98 |
| 99 const QuadList& quads = render_pass->quad_list; |
| 100 ASSERT_EQ(1u, quads.size()); |
| 101 const SharedQuadState* shared_quad_state = quads.front()->shared_quad_state; |
| 102 |
| 103 // We expect that the transform for the quad stretches the quad to cover the |
| 104 // entire bounds of the layer. |
| 105 gfx::Transform expected_transform(target_space_transform); |
| 106 float scale_x = static_cast<float>(surface_size.width()) / layer_size.width(); |
| 107 float scale_y = |
| 108 static_cast<float>(surface_size.height()) / layer_size.height(); |
| 109 expected_transform.Scale(SK_MScalar1 / scale_x, SK_MScalar1 / scale_y); |
| 110 EXPECT_EQ(expected_transform, shared_quad_state->quad_to_target_transform); |
| 111 |
| 112 // Obtain quad rect in target space by applying SQS->quad_to_target_transform |
| 113 // to quad_rect |
| 114 gfx::RectF quad_rect(quads.front()->rect); |
| 115 gfx::RectF transformed_quad_rect = |
| 116 MathUtil::MapClippedRect(expected_transform, quad_rect); |
| 117 |
| 118 // Obtain layer rect in target space by applying target_space_transform on |
| 119 // layer rect. |
| 120 gfx::RectF layer_rect(layer_size.width(), layer_size.height()); |
| 121 gfx::RectF transformed_layer_rect = |
| 122 MathUtil::MapClippedRect(target_space_transform, layer_rect); |
| 123 |
| 124 // Check if quad rect in target space matches layer rect in target space |
| 125 EXPECT_EQ(transformed_quad_rect, transformed_layer_rect); |
| 126 } |
| 127 |
69 } // namespace | 128 } // namespace |
70 } // namespace cc | 129 } // namespace cc |
OLD | NEW |