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/render_surface_impl.h" | 5 #include "cc/layers/render_surface_impl.h" |
6 | 6 |
| 7 #include "cc/layers/append_quads_data.h" |
| 8 #include "cc/layers/content_layer.h" |
7 #include "cc/test/layer_test_common.h" | 9 #include "cc/test/layer_test_common.h" |
| 10 #include "cc/test/layer_tree_pixel_test.h" |
| 11 #include "cc/test/solid_color_content_layer_client.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
9 | 13 |
10 namespace cc { | 14 namespace cc { |
11 namespace { | 15 namespace { |
12 | 16 |
13 TEST(RenderSurfaceLayerImplTest, Occlusion) { | 17 TEST(RenderSurfaceLayerImplTest, Occlusion) { |
14 gfx::Size layer_size(1000, 1000); | 18 gfx::Size layer_size(1000, 1000); |
15 gfx::Size viewport_size(1000, 1000); | 19 gfx::Size viewport_size(1000, 1000); |
16 | 20 |
17 LayerTestCommon::LayerImplTest impl; | 21 LayerTestCommon::LayerImplTest impl; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 impl.quad_list(), | 60 impl.quad_list(), |
57 gfx::Rect(layer_size), | 61 gfx::Rect(layer_size), |
58 occluded, | 62 occluded, |
59 &partially_occluded_count); | 63 &partially_occluded_count); |
60 // The layer outputs one quad, which is partially occluded. | 64 // The layer outputs one quad, which is partially occluded. |
61 EXPECT_EQ(1u, impl.quad_list().size()); | 65 EXPECT_EQ(1u, impl.quad_list().size()); |
62 EXPECT_EQ(1u, partially_occluded_count); | 66 EXPECT_EQ(1u, partially_occluded_count); |
63 } | 67 } |
64 } | 68 } |
65 | 69 |
| 70 class RenderSurfaceImplHiDpiTest : public LayerTreePixelTest { |
| 71 protected: |
| 72 RenderSurfaceImplHiDpiTest() |
| 73 : device_scale_factor_(1.f), |
| 74 content_size_(100), |
| 75 background_client_(SK_ColorWHITE), |
| 76 green_client_(SK_ColorGREEN), |
| 77 blue_client_(SK_ColorBLUE) {} |
| 78 |
| 79 virtual void InitializeSettings(LayerTreeSettings* settings) OVERRIDE { |
| 80 // Required so that device scale is inherited by content scale. |
| 81 settings->layer_transforms_should_scale_layer_contents = true; |
| 82 } |
| 83 |
| 84 virtual void SetupTree() OVERRIDE { |
| 85 layer_tree_host()->SetDeviceScaleFactor(device_scale_factor_); |
| 86 LayerTreePixelTest::SetupTree(); |
| 87 } |
| 88 |
| 89 virtual void DrawLayersOnThread(LayerTreeHostImpl* host_impl) OVERRIDE { |
| 90 LayerImpl* root_impl = host_impl->active_tree()->root_layer(); |
| 91 |
| 92 LayerImpl* layer_impl = root_impl->children()[0]; |
| 93 layer_impl->CreateRenderSurface(); |
| 94 layer_impl->draw_properties().render_target = layer_impl; |
| 95 |
| 96 RenderSurfaceImpl* render_surface = layer_impl->render_surface(); |
| 97 render_surface->SetContentRect(layer_impl->visible_content_rect()); |
| 98 render_surface->SetClipRect(layer_impl->clip_rect()); |
| 99 render_surface->SetDrawOpacity(1.f); |
| 100 |
| 101 MockOcclusionTracker<LayerImpl> occlusion_tracker; |
| 102 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 103 AppendQuadsData append_quads_data; |
| 104 render_surface->AppendQuads(render_pass.get(), |
| 105 occlusion_tracker, |
| 106 &append_quads_data, |
| 107 false, |
| 108 RenderPass::Id(2, 0)); |
| 109 |
| 110 ASSERT_EQ(1u, render_pass->shared_quad_state_list.size()); |
| 111 SharedQuadState* quad_state = render_pass->shared_quad_state_list[0]; |
| 112 |
| 113 int expected_size = content_size_ * device_scale_factor_; |
| 114 ASSERT_EQ(expected_size, quad_state->content_bounds.width()); |
| 115 ASSERT_EQ(expected_size, quad_state->content_bounds.height()); |
| 116 } |
| 117 |
| 118 void RunDpiTest(int content_size, float device_scale_factor) { |
| 119 content_size_ = content_size; |
| 120 int half_content = content_size / 2; |
| 121 |
| 122 scoped_refptr<ContentLayer> background = |
| 123 ContentLayer::Create(&background_client_); |
| 124 background->SetBounds(gfx::Size(content_size, content_size)); |
| 125 background->SetIsDrawable(true); |
| 126 |
| 127 scoped_refptr<ContentLayer> green = ContentLayer::Create(&green_client_); |
| 128 green->SetBounds(gfx::Size(content_size, content_size)); |
| 129 green->SetIsDrawable(true); |
| 130 background->AddChild(green); |
| 131 |
| 132 scoped_refptr<ContentLayer> blue = ContentLayer::Create(&blue_client_); |
| 133 blue->SetBounds(gfx::Size(half_content, half_content)); |
| 134 blue->SetPosition(gfx::Point(half_content, half_content)); |
| 135 blue->SetIsDrawable(true); |
| 136 green->AddChild(blue); |
| 137 |
| 138 device_scale_factor_ = device_scale_factor; |
| 139 |
| 140 this->impl_side_painting_ = false; |
| 141 RunPixelTest( |
| 142 SOFTWARE_WITH_DEFAULT, |
| 143 background, |
| 144 base::FilePath(FILE_PATH_LITERAL("green_small_with_blue_corner.png"))); |
| 145 } |
| 146 |
| 147 float device_scale_factor_; |
| 148 int content_size_; |
| 149 SolidColorContentLayerClient background_client_; |
| 150 SolidColorContentLayerClient green_client_; |
| 151 SolidColorContentLayerClient blue_client_; |
| 152 }; |
| 153 |
| 154 TEST_F(RenderSurfaceImplHiDpiTest, TestStandardDpi) { |
| 155 RunDpiTest(100, 1.f); |
| 156 } |
| 157 |
| 158 TEST_F(RenderSurfaceImplHiDpiTest, TestHiDpi) { |
| 159 RunDpiTest(50, 2.f); |
| 160 } |
| 161 |
66 } // namespace | 162 } // namespace |
67 } // namespace cc | 163 } // namespace cc |
OLD | NEW |