Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: ui/aura/mus/window_tree_client_unittest.cc

Issue 2873473002: Aura-Mus: Fix high-DPI gutter (Closed)
Patch Set: Addressed sadrul's comments Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_port_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 class WindowTreeClientWmTestSurfaceSync
108 class WindowTreeClientWmTestSurfaceSync : public WindowTreeClientWmTest { 108 : public WindowTreeClientWmTest,
109 public ::testing::WithParamInterface<bool> {
109 public: 110 public:
110 WindowTreeClientWmTestSurfaceSync() {} 111 WindowTreeClientWmTestSurfaceSync() {}
111 ~WindowTreeClientWmTestSurfaceSync() override {} 112 ~WindowTreeClientWmTestSurfaceSync() override {}
112 113
113 // WindowTreeClientWmTest: 114 // WindowTreeClientWmTest:
114 void SetUp() override { 115 void SetUp() override {
115 base::CommandLine::ForCurrentProcess()->AppendSwitch( 116 if (GetParam()) {
116 cc::switches::kEnableSurfaceSynchronization); 117 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
118 switches::kForceDeviceScaleFactor, "2");
119 }
117 WindowTreeClientWmTest::SetUp(); 120 WindowTreeClientWmTest::SetUp();
118 } 121 }
119 122
120 private: 123 private:
121 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestSurfaceSync); 124 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestSurfaceSync);
122 }; 125 };
123 126
124 // WindowTreeClientWmTest with --force-device-scale-factor=2. 127 // WindowTreeClientWmTest with --force-device-scale-factor=2.
125 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest { 128 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest {
126 public: 129 public:
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ASSERT_NE(nullptr, window_mus); 200 ASSERT_NE(nullptr, window_mus);
198 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); 201 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid());
199 202
200 // Reverting the change should also revert the cc::LocalSurfaceId. 203 // Reverting the change should also revert the cc::LocalSurfaceId.
201 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, 204 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
202 false)); 205 false));
203 EXPECT_EQ(original_bounds, window.bounds()); 206 EXPECT_EQ(original_bounds, window.bounds());
204 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); 207 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid());
205 } 208 }
206 209
210 INSTANTIATE_TEST_CASE_P(/* no prefix */,
211 WindowTreeClientWmTestSurfaceSync,
212 ::testing::Bool());
213
207 // Verifies that a ClientSurfaceEmbedder is created for a window once it has 214 // Verifies that a ClientSurfaceEmbedder is created for a window once it has
208 // a bounds, and a valid FrameSinkId. 215 // a bounds, and a valid FrameSinkId.
209 TEST_F(WindowTreeClientWmTestSurfaceSync, 216 TEST_P(WindowTreeClientWmTestSurfaceSync,
210 ClientSurfaceEmbedderOnValidEmbedding) { 217 ClientSurfaceEmbedderOnValidEmbedding) {
211 Window window(nullptr); 218 Window window(nullptr);
212 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds 219 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds
213 // when their sizes change. 220 // when their sizes change.
214 window.SetProperty(aura::client::kEmbedType, 221 window.SetProperty(aura::client::kEmbedType,
215 aura::client::WindowEmbedType::EMBED_IN_OWNER); 222 aura::client::WindowEmbedType::EMBED_IN_OWNER);
216 window.Init(ui::LAYER_NOT_DRAWN); 223 window.Init(ui::LAYER_NOT_DRAWN);
217 224
218 // The window will allocate a cc::LocalSurfaceId once it has a bounds. 225 // The window will allocate a cc::LocalSurfaceId once it has a bounds.
219 WindowMus* window_mus = WindowMus::Get(&window); 226 WindowMus* window_mus = WindowMus::Get(&window);
220 ASSERT_NE(nullptr, window_mus); 227 ASSERT_NE(nullptr, window_mus);
221 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); 228 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid());
222 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 229 gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
223 ASSERT_NE(new_bounds, window.bounds()); 230 ASSERT_NE(new_bounds, window.bounds());
224 window.SetBounds(new_bounds); 231 window.SetBounds(new_bounds);
225 EXPECT_EQ(new_bounds, window.bounds()); 232 EXPECT_EQ(new_bounds, window.bounds());
226 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); 233 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid());
227 234
228 // An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and 235 // An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and
229 // a valid FrameSinkId. 236 // a valid FrameSinkId.
230 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); 237 WindowPortMus* window_port_mus = WindowPortMus::Get(&window);
231 ASSERT_NE(nullptr, window_port_mus); 238 ASSERT_NE(nullptr, window_port_mus);
232 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); 239 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder());
233 240
234 // Now that the window has a valid FrameSinkId, it can embed the client in a 241 // Now that the window has a valid FrameSinkId, it can embed the client in a
235 // CompositorFrame. 242 // CompositorFrame.
236 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window), 243 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window),
237 cc::FrameSinkId(1, 1)); 244 cc::FrameSinkId(1, 1));
238 ClientSurfaceEmbedder* client_surface_embedder = 245 ClientSurfaceEmbedder* client_surface_embedder =
239 window_port_mus->client_surface_embedder(); 246 window_port_mus->client_surface_embedder();
240 ASSERT_NE(nullptr, client_surface_embedder); 247 ASSERT_NE(nullptr, client_surface_embedder);
241 248
242 // Until the fallback surface fills the window, we will have gutter. 249 // Until the fallback surface fills the window, we will have gutter.
243 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting(); 250 {
244 ASSERT_NE(nullptr, right_gutter); 251 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting();
245 EXPECT_EQ(gfx::Rect(100, 100), right_gutter->bounds()); 252 ASSERT_NE(nullptr, right_gutter);
246 // We don't have a bottom gutter if the fallback surface size is (0, 0) as the 253 EXPECT_EQ(gfx::Rect(100, 100), right_gutter->bounds());
247 // right gutter will fill the whole area. 254 // We don't have a bottom gutter if the fallback surface size is (0, 0) as
248 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); 255 // the right gutter will fill the whole area.
256 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting());
257 }
249 258
250 // When a SurfaceInfo arrives from the window server, we use it as the 259 // When a SurfaceInfo arrives from the window server, we use it as the
251 // fallback SurfaceInfo. Here we issue the PrimarySurfaceInfo back to the 260 // fallback SurfaceInfo. Here we issue the PrimarySurfaceInfo back to the
252 // client lib. This should cause the gutter to go away, eliminating overdraw. 261 // client lib. This should cause the gutter to go away, eliminating overdraw.
253 window_tree_client()->OnWindowSurfaceChanged( 262 window_tree_client()->OnWindowSurfaceChanged(
254 server_id(&window), window_port_mus->PrimarySurfaceInfoForTesting()); 263 server_id(&window), window_port_mus->PrimarySurfaceInfoForTesting());
255 264
256 // The gutter is gone. 265 // The gutter is gone.
257 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); 266 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting());
258 ASSERT_EQ(nullptr, client_surface_embedder->RightGutterForTesting()); 267 ASSERT_EQ(nullptr, client_surface_embedder->RightGutterForTesting());
268
269 // Resize again: we should have gutter.
270 new_bounds.SetRect(0, 0, 150, 150);
271 ASSERT_NE(new_bounds, window.bounds());
272 window.SetBounds(new_bounds);
273 ASSERT_NE(nullptr, client_surface_embedder->BottomGutterForTesting());
274 ASSERT_NE(nullptr, client_surface_embedder->RightGutterForTesting());
275
276 // Until the fallback surface fills the window, we will have gutter.
277 {
278 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting();
279 ASSERT_NE(nullptr, right_gutter);
280 EXPECT_EQ(gfx::Rect(100, 0, 50, 150), right_gutter->bounds());
281
282 ui::Layer* bottom_gutter =
283 client_surface_embedder->BottomGutterForTesting();
284 ASSERT_NE(nullptr, bottom_gutter);
285 EXPECT_EQ(gfx::Rect(0, 100, 100, 50), bottom_gutter->bounds());
286 }
259 } 287 }
260 288
261 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when 289 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when
262 // the size changes, but not when the position changes. 290 // the size changes, but not when the position changes.
263 TEST_F(WindowTreeClientWmTest, SetBoundsLocalSurfaceIdChanges) { 291 TEST_P(WindowTreeClientWmTestSurfaceSync, SetBoundsLocalSurfaceIdChanges) {
264 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id()); 292 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id());
265 Window window(nullptr); 293 Window window(nullptr);
266 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds 294 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds
267 // when their sizes change. 295 // when their sizes change.
268 window.SetProperty(aura::client::kEmbedType, 296 window.SetProperty(aura::client::kEmbedType,
269 aura::client::WindowEmbedType::EMBED_IN_OWNER); 297 aura::client::WindowEmbedType::EMBED_IN_OWNER);
270 window.Init(ui::LAYER_NOT_DRAWN); 298 window.Init(ui::LAYER_NOT_DRAWN);
271 299
272 // Resize the window and verify that we've allocated a cc::LocalSurfaceId. 300 // Resize the window and verify that we've allocated a cc::LocalSurfaceId.
273 const gfx::Rect new_bounds(0, 0, 100, 100); 301 const gfx::Rect new_bounds(0, 0, 100, 100);
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2438 window.Init(ui::LAYER_NOT_DRAWN); 2466 window.Init(ui::LAYER_NOT_DRAWN);
2439 DeleteWindowTreeClient(); 2467 DeleteWindowTreeClient();
2440 2468
2441 // And it should be possible to create Windows after the WindowTreeClient has 2469 // And it should be possible to create Windows after the WindowTreeClient has
2442 // been deleted. 2470 // been deleted.
2443 aura::Window window2(nullptr); 2471 aura::Window window2(nullptr);
2444 window2.Init(ui::LAYER_NOT_DRAWN); 2472 window2.Init(ui::LAYER_NOT_DRAWN);
2445 } 2473 }
2446 2474
2447 } // namespace aura 2475 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/window_port_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698