| 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/layers/append_quads_data.h" |
| 10 #include "cc/test/layer_test_common.h" | 10 #include "cc/test/layer_test_common.h" |
| 11 #include "cc/trees/layer_tree_host_common.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace cc { | 14 namespace cc { |
| 14 namespace { | 15 namespace { |
| 15 | 16 |
| 16 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); | 17 static constexpr FrameSinkId kArbitraryFrameSinkId(1, 1); |
| 17 | 18 |
| 19 TEST(SurfaceLayerImplTest, OcclusionWithDeviceScaleFactor) { |
| 20 float device_scale_factor = 1.25f; |
| 21 |
| 22 gfx::Size layer_size(1000, 1000); |
| 23 gfx::Size scaled_surface_size( |
| 24 gfx::ScaleToCeiledSize(layer_size, device_scale_factor)); |
| 25 gfx::Size viewport_size(1250, 1325); |
| 26 |
| 27 const LocalSurfaceId kArbitraryLocalSurfaceId( |
| 28 9, base::UnguessableToken::Create()); |
| 29 |
| 30 LayerTestCommon::LayerImplTest impl; |
| 31 |
| 32 SurfaceLayerImpl* surface_layer_impl = |
| 33 impl.AddChildToRoot<SurfaceLayerImpl>(); |
| 34 surface_layer_impl->SetBounds(layer_size); |
| 35 surface_layer_impl->SetDrawsContent(true); |
| 36 SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalSurfaceId); |
| 37 surface_layer_impl->SetSurfaceInfo( |
| 38 SurfaceInfo(surface_id, device_scale_factor, scaled_surface_size)); |
| 39 |
| 40 LayerImplList layer_list; |
| 41 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 42 impl.root_layer_for_testing(), viewport_size, device_scale_factor, |
| 43 &layer_list); |
| 44 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 45 |
| 46 { |
| 47 SCOPED_TRACE("No occlusion"); |
| 48 gfx::Rect occluded; |
| 49 impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); |
| 50 |
| 51 LayerTestCommon::VerifyQuadsExactlyCoverRect( |
| 52 impl.quad_list(), gfx::Rect(scaled_surface_size)); |
| 53 EXPECT_EQ(1u, impl.quad_list().size()); |
| 54 } |
| 55 |
| 56 { |
| 57 SCOPED_TRACE("Full occlusion"); |
| 58 gfx::Rect occluded(scaled_surface_size); |
| 59 impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); |
| 60 |
| 61 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect()); |
| 62 EXPECT_EQ(impl.quad_list().size(), 0u); |
| 63 } |
| 64 |
| 65 { |
| 66 SCOPED_TRACE("Partial occlusion"); |
| 67 gfx::Rect occluded(gfx::ScaleToEnclosingRect(gfx::Rect(200, 0, 800, 1000), |
| 68 device_scale_factor)); |
| 69 impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); |
| 70 |
| 71 size_t partially_occluded_count = 0; |
| 72 LayerTestCommon::VerifyQuadsAreOccluded(impl.quad_list(), occluded, |
| 73 &partially_occluded_count); |
| 74 // The layer outputs one quad, which is partially occluded. |
| 75 EXPECT_EQ(1u, impl.quad_list().size()); |
| 76 EXPECT_EQ(1u, partially_occluded_count); |
| 77 } |
| 78 { |
| 79 SCOPED_TRACE("No outside occlusion"); |
| 80 gfx::Rect occluded(gfx::ScaleToEnclosingRect(gfx::Rect(0, 1000, 1250, 300), |
| 81 device_scale_factor)); |
| 82 impl.AppendQuadsWithOcclusion(surface_layer_impl, occluded); |
| 83 |
| 84 LayerTestCommon::VerifyQuadsExactlyCoverRect( |
| 85 impl.quad_list(), gfx::Rect(scaled_surface_size)); |
| 86 EXPECT_EQ(1u, impl.quad_list().size()); |
| 87 } |
| 88 } |
| 89 |
| 18 TEST(SurfaceLayerImplTest, Occlusion) { | 90 TEST(SurfaceLayerImplTest, Occlusion) { |
| 19 gfx::Size layer_size(1000, 1000); | 91 gfx::Size layer_size(1000, 1000); |
| 20 gfx::Size viewport_size(1000, 1000); | 92 gfx::Size viewport_size(1000, 1000); |
| 21 const LocalSurfaceId kArbitraryLocalSurfaceId( | 93 const LocalSurfaceId kArbitraryLocalSurfaceId( |
| 22 9, base::UnguessableToken::Create()); | 94 9, base::UnguessableToken::Create()); |
| 23 | 95 |
| 24 LayerTestCommon::LayerImplTest impl; | 96 LayerTestCommon::LayerImplTest impl; |
| 25 | 97 |
| 26 SurfaceLayerImpl* surface_layer_impl = | 98 SurfaceLayerImpl* surface_layer_impl = |
| 27 impl.AddChildToRoot<SurfaceLayerImpl>(); | 99 impl.AddChildToRoot<SurfaceLayerImpl>(); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 gfx::RectF layer_rect(layer_size.width(), layer_size.height()); | 192 gfx::RectF layer_rect(layer_size.width(), layer_size.height()); |
| 121 gfx::RectF transformed_layer_rect = | 193 gfx::RectF transformed_layer_rect = |
| 122 MathUtil::MapClippedRect(target_space_transform, layer_rect); | 194 MathUtil::MapClippedRect(target_space_transform, layer_rect); |
| 123 | 195 |
| 124 // Check if quad rect in target space matches layer rect in target space | 196 // Check if quad rect in target space matches layer rect in target space |
| 125 EXPECT_EQ(transformed_quad_rect, transformed_layer_rect); | 197 EXPECT_EQ(transformed_quad_rect, transformed_layer_rect); |
| 126 } | 198 } |
| 127 | 199 |
| 128 } // namespace | 200 } // namespace |
| 129 } // namespace cc | 201 } // namespace cc |
| OLD | NEW |