Chromium Code Reviews| 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, LayerBoundsDiffFromSurfaceLayerSize) { | |
| 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 | |
|
danakj
2016/11/28 22:26:23
what is interesting about the given condition? her
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 78 gfx::Size layer_size(400, 100); | |
| 79 gfx::Size surface_size(300, 300); | |
| 80 float surface_scale = 1.f; | |
| 81 gfx::Transform target_space_transform( | |
| 82 surface_layer_impl->draw_properties().target_space_transform); | |
| 83 | |
| 84 // Surface_layer_impl will be set after PushProperties. | |
|
danakj
2016/11/28 22:26:22
Does this mean to say the below is mimicing the be
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 85 surface_layer_impl->SetBounds(layer_size); | |
| 86 surface_layer_impl->SetDrawsContent(true); | |
| 87 SurfaceId surface_id(kArbitraryFrameSinkId, kArbitraryLocalFrameId); | |
| 88 surface_layer_impl->SetSurfaceId(surface_id); | |
| 89 surface_layer_impl->SetSurfaceScale(surface_scale); | |
| 90 surface_layer_impl->SetSurfaceSize(surface_size); | |
| 91 surface_layer_impl->SetScaleLayerBoundsWithSurfaceSize(true); | |
| 92 | |
| 93 // Calling test function AppendQuads. | |
|
danakj
2016/11/28 22:26:23
This comment isn't adding value
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 94 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); | |
| 95 AppendQuadsData data; | |
| 96 surface_layer_impl->AppendQuads(render_pass.get(), &data); | |
| 97 | |
| 98 const QuadList& quads = render_pass->quad_list; | |
| 99 ASSERT_EQ(1u, quads.size()); | |
| 100 const SharedQuadState* shared_quad_state = quads.front()->shared_quad_state; | |
| 101 | |
|
danakj
2016/11/28 22:26:23
A comment explaining the math below is helpful in
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 102 gfx::Transform transform(target_space_transform); | |
|
danakj
2016/11/28 22:26:23
expected_transform is a helpful name
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 103 float scale_x = ((float)surface_size.width()) / layer_size.width(); | |
|
danakj
2016/11/28 22:26:23
static_cast not c-style https://google.github.io/s
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 104 float scale_y = ((float)surface_size.height()) / layer_size.height(); | |
| 105 transform.Scale(SK_MScalar1 / scale_x, SK_MScalar1 / scale_y); | |
| 106 EXPECT_EQ(transform, shared_quad_state->quad_to_target_transform); | |
| 107 | |
| 108 // Obtain quad rect in target space by applying SQS->quad_to_target_transform | |
| 109 // to quad_rect | |
| 110 gfx::RectF quad_rect(quads.front()->rect); | |
| 111 transform.TransformRect(&quad_rect); | |
|
danakj
2016/11/28 22:26:22
Don't use gfx::Transform::TransformRect in cc/. In
| |
| 112 | |
| 113 // Obtain layer rect in target space by applying target_space_transform on | |
| 114 // layer rect. | |
| 115 gfx::RectF layer_rect((float)layer_size.width(), (float)layer_size.height()); | |
|
danakj
2016/11/28 22:26:23
no c-style casts. you shouldn't need any cast here
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 116 target_space_transform.TransformRect(&layer_rect); | |
|
danakj
2016/11/28 22:26:22
Don't use gfx::Transform::TransformRect in cc/. In
xlai (Olivia)
2016/12/13 17:29:18
Done.
| |
| 117 | |
| 118 // Check if quad rect in target space matches layer rect in target space | |
| 119 EXPECT_EQ(quad_rect, layer_rect); | |
| 120 } | |
| 121 | |
| 69 } // namespace | 122 } // namespace |
| 70 } // namespace cc | 123 } // namespace cc |
| OLD | NEW |