OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "components/exo/buffer.h" | 6 #include "components/exo/buffer.h" |
7 #include "components/exo/surface.h" | 7 #include "components/exo/surface.h" |
8 #include "components/exo/test/exo_test_base.h" | 8 #include "components/exo/test/exo_test_base.h" |
9 #include "components/exo/test/exo_test_helper.h" | 9 #include "components/exo/test/exo_test_helper.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
| 11 #include "ui/compositor/layer_tree_owner.h" |
11 #include "ui/gfx/gpu_memory_buffer.h" | 12 #include "ui/gfx/gpu_memory_buffer.h" |
| 13 #include "ui/wm/core/window_util.h" |
12 | 14 |
13 namespace exo { | 15 namespace exo { |
14 namespace { | 16 namespace { |
15 | 17 |
16 class SurfaceTest : public test::ExoTestBase, | 18 class SurfaceTest : public test::ExoTestBase, |
17 public ::testing::WithParamInterface<bool> { | 19 public ::testing::WithParamInterface<bool> { |
18 void SetUp() override { | 20 void SetUp() override { |
19 Surface::SetUseSurfaceLayer(GetParam()); | 21 Surface::SetUseSurfaceLayer(GetParam()); |
20 test::ExoTestBase::SetUp(); | 22 test::ExoTestBase::SetUp(); |
21 } | 23 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // account. | 119 // account. |
118 const float kBufferScale = 2.0f; | 120 const float kBufferScale = 2.0f; |
119 surface->Attach(buffer.get()); | 121 surface->Attach(buffer.get()); |
120 surface->SetBufferScale(kBufferScale); | 122 surface->SetBufferScale(kBufferScale); |
121 surface->Commit(); | 123 surface->Commit(); |
122 EXPECT_EQ( | 124 EXPECT_EQ( |
123 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(), | 125 gfx::ScaleToFlooredSize(buffer_size, 1.0f / kBufferScale).ToString(), |
124 surface->bounds().size().ToString()); | 126 surface->bounds().size().ToString()); |
125 } | 127 } |
126 | 128 |
| 129 TEST_P(SurfaceTest, RecreateLayer) { |
| 130 gfx::Size buffer_size(512, 512); |
| 131 std::unique_ptr<Buffer> buffer( |
| 132 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
| 133 std::unique_ptr<Surface> surface(new Surface); |
| 134 |
| 135 surface->Attach(buffer.get()); |
| 136 surface->Commit(); |
| 137 |
| 138 EXPECT_EQ(buffer_size, surface->bounds().size()); |
| 139 EXPECT_EQ(buffer_size, surface->layer()->bounds().size()); |
| 140 std::unique_ptr<ui::LayerTreeOwner> old_layer_owner = |
| 141 ::wm::RecreateLayers(surface.get(), nullptr); |
| 142 EXPECT_EQ(buffer_size, surface->bounds().size()); |
| 143 EXPECT_EQ(buffer_size, surface->layer()->bounds().size()); |
| 144 EXPECT_EQ(buffer_size, old_layer_owner->root()->bounds().size()); |
| 145 EXPECT_TRUE(surface->layer()->has_external_content()); |
| 146 EXPECT_TRUE(old_layer_owner->root()->has_external_content()); |
| 147 } |
| 148 |
127 TEST_P(SurfaceTest, SetViewport) { | 149 TEST_P(SurfaceTest, SetViewport) { |
128 gfx::Size buffer_size(1, 1); | 150 gfx::Size buffer_size(1, 1); |
129 std::unique_ptr<Buffer> buffer( | 151 std::unique_ptr<Buffer> buffer( |
130 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); | 152 new Buffer(exo_test_helper()->CreateGpuMemoryBuffer(buffer_size))); |
131 std::unique_ptr<Surface> surface(new Surface); | 153 std::unique_ptr<Surface> surface(new Surface); |
132 | 154 |
133 // This will update the bounds of the surface and take the viewport into | 155 // This will update the bounds of the surface and take the viewport into |
134 // account. | 156 // account. |
135 surface->Attach(buffer.get()); | 157 surface->Attach(buffer.get()); |
136 gfx::Size viewport(256, 256); | 158 gfx::Size viewport(256, 256); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 std::unique_ptr<Surface> surface(new Surface); | 233 std::unique_ptr<Surface> surface(new Surface); |
212 | 234 |
213 // Calling commit without a buffer should succeed. | 235 // Calling commit without a buffer should succeed. |
214 surface->Commit(); | 236 surface->Commit(); |
215 } | 237 } |
216 | 238 |
217 INSTANTIATE_TEST_CASE_P(, SurfaceTest, ::testing::Bool()); | 239 INSTANTIATE_TEST_CASE_P(, SurfaceTest, ::testing::Bool()); |
218 | 240 |
219 } // namespace | 241 } // namespace |
220 } // namespace exo | 242 } // namespace exo |
OLD | NEW |