Chromium Code Reviews| 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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 // Note that this implicitly casts arguments to the aura storage type, int64_t. | 97 // Note that this implicitly casts arguments to the aura storage type, int64_t. |
| 98 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) { | 98 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) { |
| 99 return mojo::ConvertTo<std::vector<uint8_t>>(value); | 99 return mojo::ConvertTo<std::vector<uint8_t>>(value); |
| 100 } | 100 } |
| 101 | 101 |
| 102 } // namespace | 102 } // namespace |
| 103 | 103 |
| 104 using WindowTreeClientWmTest = test::AuraMusWmTestBase; | 104 using WindowTreeClientWmTest = test::AuraMusWmTestBase; |
| 105 using WindowTreeClientClientTest = test::AuraMusClientTestBase; | 105 using WindowTreeClientClientTest = test::AuraMusClientTestBase; |
| 106 | 106 |
| 107 // WindowTreeClientWmTest with --enable-surface-synchronization. | 107 enum class UseHighDPI { YES, NO }; |
| 108 class WindowTreeClientWmTestSurfaceSync : public WindowTreeClientWmTest { | 108 |
| 109 class WindowTreeClientWmTestSurfaceSync | |
| 110 : public WindowTreeClientWmTest, | |
| 111 public ::testing::WithParamInterface<UseHighDPI> { | |
|
sadrul
2017/05/30 21:33:26
Just use WithParamInterface<bool>?
Fady Samuel
2017/05/30 21:40:22
Done.
| |
| 109 public: | 112 public: |
| 110 WindowTreeClientWmTestSurfaceSync() {} | 113 WindowTreeClientWmTestSurfaceSync() {} |
| 111 ~WindowTreeClientWmTestSurfaceSync() override {} | 114 ~WindowTreeClientWmTestSurfaceSync() override {} |
| 112 | 115 |
| 113 // WindowTreeClientWmTest: | 116 // WindowTreeClientWmTest: |
| 114 void SetUp() override { | 117 void SetUp() override { |
| 115 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 118 if (GetParam() == UseHighDPI::YES) { |
| 116 cc::switches::kEnableSurfaceSynchronization); | 119 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 120 switches::kForceDeviceScaleFactor, "2"); | |
| 121 } | |
| 117 WindowTreeClientWmTest::SetUp(); | 122 WindowTreeClientWmTest::SetUp(); |
| 118 } | 123 } |
| 119 | 124 |
| 120 private: | 125 private: |
| 121 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestSurfaceSync); | 126 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestSurfaceSync); |
| 122 }; | 127 }; |
| 123 | 128 |
| 124 // WindowTreeClientWmTest with --force-device-scale-factor=2. | 129 // WindowTreeClientWmTest with --force-device-scale-factor=2. |
| 125 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest { | 130 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest { |
| 126 public: | 131 public: |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 197 ASSERT_NE(nullptr, window_mus); | 202 ASSERT_NE(nullptr, window_mus); |
| 198 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); | 203 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); |
| 199 | 204 |
| 200 // Reverting the change should also revert the cc::LocalSurfaceId. | 205 // Reverting the change should also revert the cc::LocalSurfaceId. |
| 201 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, | 206 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, |
| 202 false)); | 207 false)); |
| 203 EXPECT_EQ(original_bounds, window.bounds()); | 208 EXPECT_EQ(original_bounds, window.bounds()); |
| 204 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); | 209 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); |
| 205 } | 210 } |
| 206 | 211 |
| 212 INSTANTIATE_TEST_CASE_P(/* no prefix */, | |
| 213 WindowTreeClientWmTestSurfaceSync, | |
| 214 ::testing::Values(UseHighDPI::YES, UseHighDPI::NO)); | |
|
sadrul
2017/05/30 21:33:26
::testing::Bool()
Fady Samuel
2017/05/30 21:40:22
Done.
| |
| 215 | |
| 207 // Verifies that a ClientSurfaceEmbedder is created for a window once it has | 216 // Verifies that a ClientSurfaceEmbedder is created for a window once it has |
| 208 // a bounds, and a valid FrameSinkId. | 217 // a bounds, and a valid FrameSinkId. |
| 209 TEST_F(WindowTreeClientWmTestSurfaceSync, | 218 TEST_P(WindowTreeClientWmTestSurfaceSync, |
| 210 ClientSurfaceEmbedderOnValidEmbedding) { | 219 ClientSurfaceEmbedderOnValidEmbedding) { |
| 211 Window window(nullptr); | 220 Window window(nullptr); |
| 212 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds | 221 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds |
| 213 // when their sizes change. | 222 // when their sizes change. |
| 214 window.SetProperty(aura::client::kEmbedType, | 223 window.SetProperty(aura::client::kEmbedType, |
| 215 aura::client::WindowEmbedType::EMBED_IN_OWNER); | 224 aura::client::WindowEmbedType::EMBED_IN_OWNER); |
| 216 window.Init(ui::LAYER_NOT_DRAWN); | 225 window.Init(ui::LAYER_NOT_DRAWN); |
| 217 | 226 |
| 218 // The window will allocate a cc::LocalSurfaceId once it has a bounds. | 227 // The window will allocate a cc::LocalSurfaceId once it has a bounds. |
| 219 WindowMus* window_mus = WindowMus::Get(&window); | 228 WindowMus* window_mus = WindowMus::Get(&window); |
| 220 ASSERT_NE(nullptr, window_mus); | 229 ASSERT_NE(nullptr, window_mus); |
| 221 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); | 230 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); |
| 222 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 231 gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 223 ASSERT_NE(new_bounds, window.bounds()); | 232 ASSERT_NE(new_bounds, window.bounds()); |
| 224 window.SetBounds(new_bounds); | 233 window.SetBounds(new_bounds); |
| 225 EXPECT_EQ(new_bounds, window.bounds()); | 234 EXPECT_EQ(new_bounds, window.bounds()); |
| 226 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); | 235 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); |
| 227 | 236 |
| 228 // An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and | 237 // An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and |
| 229 // a valid FrameSinkId. | 238 // a valid FrameSinkId. |
| 230 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); | 239 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); |
| 231 ASSERT_NE(nullptr, window_port_mus); | 240 ASSERT_NE(nullptr, window_port_mus); |
| 232 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | 241 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); |
| 233 | 242 |
| 234 // Now that the window has a valid FrameSinkId, it can embed the client in a | 243 // Now that the window has a valid FrameSinkId, it can embed the client in a |
| 235 // CompositorFrame. | 244 // CompositorFrame. |
| 236 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window), | 245 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window), |
| 237 cc::FrameSinkId(1, 1)); | 246 cc::FrameSinkId(1, 1)); |
| 238 ClientSurfaceEmbedder* client_surface_embedder = | 247 ClientSurfaceEmbedder* client_surface_embedder = |
| 239 window_port_mus->client_surface_embedder(); | 248 window_port_mus->client_surface_embedder(); |
| 240 ASSERT_NE(nullptr, client_surface_embedder); | 249 ASSERT_NE(nullptr, client_surface_embedder); |
| 241 | 250 |
| 242 // Until the fallback surface fills the window, we will have gutter. | 251 // Until the fallback surface fills the window, we will have gutter. |
| 243 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting(); | 252 { |
| 244 ASSERT_NE(nullptr, right_gutter); | 253 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting(); |
| 245 EXPECT_EQ(gfx::Rect(100, 100), right_gutter->bounds()); | 254 ASSERT_NE(nullptr, right_gutter); |
| 246 // We don't have a bottom gutter if the fallback surface size is (0, 0) as the | 255 EXPECT_EQ(gfx::Rect(100, 100), right_gutter->bounds()); |
| 247 // right gutter will fill the whole area. | 256 // We don't have a bottom gutter if the fallback surface size is (0, 0) as |
| 248 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); | 257 // the right gutter will fill the whole area. |
| 258 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); | |
| 259 } | |
| 249 | 260 |
| 250 // When a SurfaceInfo arrives from the window server, we use it as the | 261 // When a SurfaceInfo arrives from the window server, we use it as the |
| 251 // fallback SurfaceInfo. Here we issue the PrimarySurfaceInfo back to the | 262 // fallback SurfaceInfo. Here we issue the PrimarySurfaceInfo back to the |
| 252 // client lib. This should cause the gutter to go away, eliminating overdraw. | 263 // client lib. This should cause the gutter to go away, eliminating overdraw. |
| 253 window_tree_client()->OnWindowSurfaceChanged( | 264 window_tree_client()->OnWindowSurfaceChanged( |
| 254 server_id(&window), window_port_mus->PrimarySurfaceInfoForTesting()); | 265 server_id(&window), window_port_mus->PrimarySurfaceInfoForTesting()); |
| 255 | 266 |
| 256 // The gutter is gone. | 267 // The gutter is gone. |
| 257 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); | 268 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); |
| 258 ASSERT_EQ(nullptr, client_surface_embedder->RightGutterForTesting()); | 269 ASSERT_EQ(nullptr, client_surface_embedder->RightGutterForTesting()); |
| 270 | |
| 271 // Resize again: we should have gutter. | |
| 272 new_bounds.SetRect(0, 0, 150, 150); | |
| 273 ASSERT_NE(new_bounds, window.bounds()); | |
| 274 window.SetBounds(new_bounds); | |
| 275 ASSERT_NE(nullptr, client_surface_embedder->BottomGutterForTesting()); | |
| 276 ASSERT_NE(nullptr, client_surface_embedder->RightGutterForTesting()); | |
| 277 | |
| 278 // Until the fallback surface fills the window, we will have gutter. | |
| 279 { | |
| 280 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting(); | |
| 281 ASSERT_NE(nullptr, right_gutter); | |
| 282 EXPECT_EQ(gfx::Rect(100, 0, 50, 150), right_gutter->bounds()); | |
| 283 | |
| 284 ui::Layer* bottom_gutter = | |
| 285 client_surface_embedder->BottomGutterForTesting(); | |
| 286 ASSERT_NE(nullptr, bottom_gutter); | |
| 287 EXPECT_EQ(gfx::Rect(0, 100, 100, 50), bottom_gutter->bounds()); | |
| 288 } | |
| 259 } | 289 } |
| 260 | 290 |
| 261 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when | 291 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when |
| 262 // the size changes, but not when the position changes. | 292 // the size changes, but not when the position changes. |
| 263 TEST_F(WindowTreeClientWmTest, SetBoundsLocalSurfaceIdChanges) { | 293 TEST_P(WindowTreeClientWmTestSurfaceSync, SetBoundsLocalSurfaceIdChanges) { |
| 264 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id()); | 294 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id()); |
| 265 Window window(nullptr); | 295 Window window(nullptr); |
| 266 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds | 296 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds |
| 267 // when their sizes change. | 297 // when their sizes change. |
| 268 window.SetProperty(aura::client::kEmbedType, | 298 window.SetProperty(aura::client::kEmbedType, |
| 269 aura::client::WindowEmbedType::EMBED_IN_OWNER); | 299 aura::client::WindowEmbedType::EMBED_IN_OWNER); |
| 270 window.Init(ui::LAYER_NOT_DRAWN); | 300 window.Init(ui::LAYER_NOT_DRAWN); |
| 271 | 301 |
| 272 // Resize the window and verify that we've allocated a cc::LocalSurfaceId. | 302 // Resize the window and verify that we've allocated a cc::LocalSurfaceId. |
| 273 const gfx::Rect new_bounds(0, 0, 100, 100); | 303 const gfx::Rect new_bounds(0, 0, 100, 100); |
| (...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2438 window.Init(ui::LAYER_NOT_DRAWN); | 2468 window.Init(ui::LAYER_NOT_DRAWN); |
| 2439 DeleteWindowTreeClient(); | 2469 DeleteWindowTreeClient(); |
| 2440 | 2470 |
| 2441 // And it should be possible to create Windows after the WindowTreeClient has | 2471 // And it should be possible to create Windows after the WindowTreeClient has |
| 2442 // been deleted. | 2472 // been deleted. |
| 2443 aura::Window window2(nullptr); | 2473 aura::Window window2(nullptr); |
| 2444 window2.Init(ui::LAYER_NOT_DRAWN); | 2474 window2.Init(ui::LAYER_NOT_DRAWN); |
| 2445 } | 2475 } |
| 2446 | 2476 |
| 2447 } // namespace aura | 2477 } // namespace aura |
| OLD | NEW |