| 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" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "cc/base/switches.h" |
| 14 #include "cc/surfaces/surface_info.h" | 15 #include "cc/surfaces/surface_info.h" |
| 15 #include "mojo/public/cpp/bindings/map.h" | 16 #include "mojo/public/cpp/bindings/map.h" |
| 16 #include "services/ui/public/cpp/property_type_converters.h" | 17 #include "services/ui/public/cpp/property_type_converters.h" |
| 17 #include "services/ui/public/interfaces/window_manager.mojom.h" | 18 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 20 #include "ui/aura/client/capture_client.h" | 21 #include "ui/aura/client/capture_client.h" |
| 21 #include "ui/aura/client/capture_client_observer.h" | 22 #include "ui/aura/client/capture_client_observer.h" |
| 22 #include "ui/aura/client/default_capture_client.h" | 23 #include "ui/aura/client/default_capture_client.h" |
| 23 #include "ui/aura/client/focus_client.h" | 24 #include "ui/aura/client/focus_client.h" |
| 24 #include "ui/aura/client/transient_window_client.h" | 25 #include "ui/aura/client/transient_window_client.h" |
| 25 #include "ui/aura/mus/capture_synchronizer.h" | 26 #include "ui/aura/mus/capture_synchronizer.h" |
| 27 #include "ui/aura/mus/client_surface_embedder.h" |
| 26 #include "ui/aura/mus/focus_synchronizer.h" | 28 #include "ui/aura/mus/focus_synchronizer.h" |
| 27 #include "ui/aura/mus/property_converter.h" | 29 #include "ui/aura/mus/property_converter.h" |
| 28 #include "ui/aura/mus/window_mus.h" | 30 #include "ui/aura/mus/window_mus.h" |
| 29 #include "ui/aura/mus/window_port_mus.h" | 31 #include "ui/aura/mus/window_port_mus.h" |
| 30 #include "ui/aura/mus/window_tree_client_delegate.h" | 32 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 31 #include "ui/aura/mus/window_tree_client_observer.h" | 33 #include "ui/aura/mus/window_tree_client_observer.h" |
| 32 #include "ui/aura/mus/window_tree_host_mus.h" | 34 #include "ui/aura/mus/window_tree_host_mus.h" |
| 33 #include "ui/aura/test/aura_mus_test_base.h" | 35 #include "ui/aura/test/aura_mus_test_base.h" |
| 34 #include "ui/aura/test/mus/test_window_tree.h" | 36 #include "ui/aura/test/mus/test_window_tree.h" |
| 35 #include "ui/aura/test/mus/window_tree_client_private.h" | 37 #include "ui/aura/test/mus/window_tree_client_private.h" |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 // Note that this implicitly casts arguments to the aura storage type, int64_t. | 96 // Note that this implicitly casts arguments to the aura storage type, int64_t. |
| 95 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) { | 97 std::vector<uint8_t> ConvertToPropertyTransportValue(int64_t value) { |
| 96 return mojo::ConvertTo<std::vector<uint8_t>>(value); | 98 return mojo::ConvertTo<std::vector<uint8_t>>(value); |
| 97 } | 99 } |
| 98 | 100 |
| 99 } // namespace | 101 } // namespace |
| 100 | 102 |
| 101 using WindowTreeClientWmTest = test::AuraMusWmTestBase; | 103 using WindowTreeClientWmTest = test::AuraMusWmTestBase; |
| 102 using WindowTreeClientClientTest = test::AuraMusClientTestBase; | 104 using WindowTreeClientClientTest = test::AuraMusClientTestBase; |
| 103 | 105 |
| 106 // WindowTreeClientWmTest with --enable-surface-synchronization. |
| 107 class WindowTreeClientWmTestSurfaceSync : public WindowTreeClientWmTest { |
| 108 public: |
| 109 WindowTreeClientWmTestSurfaceSync() {} |
| 110 ~WindowTreeClientWmTestSurfaceSync() override {} |
| 111 |
| 112 // WindowTreeClientWmTest: |
| 113 void SetUp() override { |
| 114 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 115 cc::switches::kEnableSurfaceSynchronization); |
| 116 WindowTreeClientWmTest::SetUp(); |
| 117 } |
| 118 |
| 119 private: |
| 120 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientWmTestSurfaceSync); |
| 121 }; |
| 122 |
| 104 // WindowTreeClientWmTest with --force-device-scale-factor=2. | 123 // WindowTreeClientWmTest with --force-device-scale-factor=2. |
| 105 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest { | 124 class WindowTreeClientWmTestHighDPI : public WindowTreeClientWmTest { |
| 106 public: | 125 public: |
| 107 WindowTreeClientWmTestHighDPI() {} | 126 WindowTreeClientWmTestHighDPI() {} |
| 108 ~WindowTreeClientWmTestHighDPI() override {} | 127 ~WindowTreeClientWmTestHighDPI() override {} |
| 109 | 128 |
| 110 // WindowTreeClientWmTest: | 129 // WindowTreeClientWmTest: |
| 111 void SetUp() override { | 130 void SetUp() override { |
| 112 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 131 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 113 switches::kForceDeviceScaleFactor, "2"); | 132 switches::kForceDeviceScaleFactor, "2"); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 137 void OnPointerEventObserved(const ui::PointerEvent& event, | 156 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 138 Window* target) override { | 157 Window* target) override { |
| 139 last_event_observed_.reset(new ui::PointerEvent(event)); | 158 last_event_observed_.reset(new ui::PointerEvent(event)); |
| 140 } | 159 } |
| 141 | 160 |
| 142 private: | 161 private: |
| 143 std::unique_ptr<ui::PointerEvent> last_event_observed_; | 162 std::unique_ptr<ui::PointerEvent> last_event_observed_; |
| 144 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientClientTestHighDPI); | 163 DISALLOW_COPY_AND_ASSIGN(WindowTreeClientClientTestHighDPI); |
| 145 }; | 164 }; |
| 146 | 165 |
| 147 // Verifies that a ClientSurfaceEmbedder will only be allocated if a window | |
| 148 // is visible that embeds a WindowTreeClient. | |
| 149 TEST_F(WindowTreeClientWmTest, ClientSurfaceEmbedderIfVisible) { | |
| 150 Window window(nullptr); | |
| 151 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds | |
| 152 // when their sizes change. | |
| 153 window.SetProperty(aura::client::kEmbedType, | |
| 154 aura::client::WindowEmbedType::EMBED_IN_OWNER); | |
| 155 window.Init(ui::LAYER_NOT_DRAWN); | |
| 156 | |
| 157 WindowMus* window_mus = WindowMus::Get(&window); | |
| 158 const cc::SurfaceId surface_id( | |
| 159 cc::FrameSinkId(1, 1), | |
| 160 cc::LocalSurfaceId(1, base::UnguessableToken::Create())); | |
| 161 constexpr float device_scale_factor = 1.f; | |
| 162 constexpr gfx::Size size(100, 100); | |
| 163 | |
| 164 window_mus->SetPrimarySurfaceInfo( | |
| 165 cc::SurfaceInfo(surface_id, device_scale_factor, size)); | |
| 166 | |
| 167 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); | |
| 168 ASSERT_NE(nullptr, window_port_mus); | |
| 169 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | |
| 170 | |
| 171 // Showing the window results in the creation of a ClientSurfaceEmbedder. | |
| 172 window.Show(); | |
| 173 EXPECT_NE(nullptr, window_port_mus->client_surface_embedder()); | |
| 174 | |
| 175 // Hiding it again removes the ClientSurfaceEmbedder. | |
| 176 window.Hide(); | |
| 177 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | |
| 178 | |
| 179 // Setting an invalid cc::SurfaceInfo also eliminates the | |
| 180 // ClientSurfaceEmbedder. | |
| 181 window.Show(); | |
| 182 EXPECT_NE(nullptr, window_port_mus->client_surface_embedder()); | |
| 183 window_mus->SetPrimarySurfaceInfo(cc::SurfaceInfo()); | |
| 184 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | |
| 185 } | |
| 186 | |
| 187 // Verifies bounds are reverted if the server replied that the change failed. | 166 // Verifies bounds are reverted if the server replied that the change failed. |
| 188 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { | 167 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { |
| 189 Window window(nullptr); | 168 Window window(nullptr); |
| 190 window.Init(ui::LAYER_NOT_DRAWN); | 169 window.Init(ui::LAYER_NOT_DRAWN); |
| 191 const gfx::Rect original_bounds(window.bounds()); | 170 const gfx::Rect original_bounds(window.bounds()); |
| 192 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 171 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 193 ASSERT_NE(new_bounds, window.bounds()); | 172 ASSERT_NE(new_bounds, window.bounds()); |
| 194 window.SetBounds(new_bounds); | 173 window.SetBounds(new_bounds); |
| 195 EXPECT_EQ(new_bounds, window.bounds()); | 174 EXPECT_EQ(new_bounds, window.bounds()); |
| 196 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, | 175 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 218 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); | 197 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); |
| 219 | 198 |
| 220 // Reverting the change should also revert the cc::LocalSurfaceId. | 199 // Reverting the change should also revert the cc::LocalSurfaceId. |
| 221 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, | 200 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, |
| 222 false)); | 201 false)); |
| 223 EXPECT_EQ(original_bounds, window.bounds()); | 202 EXPECT_EQ(original_bounds, window.bounds()); |
| 224 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); | 203 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); |
| 225 } | 204 } |
| 226 | 205 |
| 227 // Verifies that a ClientSurfaceEmbedder is created for a window once it has | 206 // Verifies that a ClientSurfaceEmbedder is created for a window once it has |
| 228 // a bounds, a valid FrameSinkId and is visible. | 207 // a bounds, and a valid FrameSinkId. |
| 229 TEST_F(WindowTreeClientWmTest, ClientSurfaceEmbedderOnValidEmbedding) { | 208 TEST_F(WindowTreeClientWmTestSurfaceSync, |
| 209 ClientSurfaceEmbedderOnValidEmbedding) { |
| 230 Window window(nullptr); | 210 Window window(nullptr); |
| 231 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds | 211 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds |
| 232 // when their sizes change. | 212 // when their sizes change. |
| 233 window.SetProperty(aura::client::kEmbedType, | 213 window.SetProperty(aura::client::kEmbedType, |
| 234 aura::client::WindowEmbedType::EMBED_IN_OWNER); | 214 aura::client::WindowEmbedType::EMBED_IN_OWNER); |
| 235 window.Init(ui::LAYER_NOT_DRAWN); | 215 window.Init(ui::LAYER_NOT_DRAWN); |
| 236 | 216 |
| 217 // The window will allocate a cc::LocalSurfaceId once it has a bounds. |
| 218 WindowMus* window_mus = WindowMus::Get(&window); |
| 219 ASSERT_NE(nullptr, window_mus); |
| 220 EXPECT_FALSE(window_mus->GetLocalSurfaceId().is_valid()); |
| 237 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); | 221 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); |
| 238 ASSERT_NE(new_bounds, window.bounds()); | 222 ASSERT_NE(new_bounds, window.bounds()); |
| 239 window.SetBounds(new_bounds); | 223 window.SetBounds(new_bounds); |
| 240 EXPECT_EQ(new_bounds, window.bounds()); | 224 EXPECT_EQ(new_bounds, window.bounds()); |
| 241 WindowMus* window_mus = WindowMus::Get(&window); | |
| 242 ASSERT_NE(nullptr, window_mus); | |
| 243 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); | 225 EXPECT_TRUE(window_mus->GetLocalSurfaceId().is_valid()); |
| 244 | 226 |
| 245 // An ClientSurfaceEmbedder isn't created UNTIL the window is visible and has | 227 // An ClientSurfaceEmbedder isn't created UNTIL the window has a bounds and |
| 246 // a valid FrameSinkId. | 228 // a valid FrameSinkId. |
| 247 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); | 229 WindowPortMus* window_port_mus = WindowPortMus::Get(&window); |
| 248 ASSERT_NE(nullptr, window_port_mus); | 230 ASSERT_NE(nullptr, window_port_mus); |
| 249 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | 231 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); |
| 250 | 232 |
| 251 // The window is now visible, but doesn't yet have a FrameSinkId. | |
| 252 window.Show(); | |
| 253 EXPECT_EQ(nullptr, window_port_mus->client_surface_embedder()); | |
| 254 | |
| 255 // Now that the window has a valid FrameSinkId, it can embed the client in a | 233 // Now that the window has a valid FrameSinkId, it can embed the client in a |
| 256 // CompositorFrame. | 234 // CompositorFrame. |
| 257 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window), | 235 window_tree_client()->OnFrameSinkIdAllocated(server_id(&window), |
| 258 cc::FrameSinkId(1, 1)); | 236 cc::FrameSinkId(1, 1)); |
| 259 EXPECT_NE(nullptr, window_port_mus->client_surface_embedder()); | 237 ClientSurfaceEmbedder* client_surface_embedder = |
| 238 window_port_mus->client_surface_embedder(); |
| 239 ASSERT_NE(nullptr, client_surface_embedder); |
| 240 |
| 241 // Until the fallback surface fills the window, we will have gutter. |
| 242 ui::Layer* right_gutter = client_surface_embedder->RightGutterForTesting(); |
| 243 ASSERT_NE(nullptr, right_gutter); |
| 244 EXPECT_EQ(gfx::Rect(100, 100), right_gutter->bounds()); |
| 245 // We don't have a bottom gutter if the fallback surface size is (0, 0) as the |
| 246 // right gutter will fill the whole area. |
| 247 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); |
| 248 |
| 249 // When a SurfaceInfo arrives from the window server, we use it as the |
| 250 // fallback SurfaceInfo. Here we issue the PrimarySurfaceInfo back to the |
| 251 // client lib. This should cause the gutter to go away, eliminating overdraw. |
| 252 window_tree_client()->OnWindowSurfaceChanged( |
| 253 server_id(&window), window_port_mus->PrimarySurfaceInfoForTesting()); |
| 254 |
| 255 // The gutter is gone. |
| 256 ASSERT_EQ(nullptr, client_surface_embedder->BottomGutterForTesting()); |
| 257 ASSERT_EQ(nullptr, client_surface_embedder->RightGutterForTesting()); |
| 260 } | 258 } |
| 261 | 259 |
| 262 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when | 260 // Verifies that the cc::LocalSurfaceId generated by an embedder changes when |
| 263 // the size changes, but not when the position changes. | 261 // the size changes, but not when the position changes. |
| 264 TEST_F(WindowTreeClientWmTest, SetBoundsLocalSurfaceIdChanges) { | 262 TEST_F(WindowTreeClientWmTest, SetBoundsLocalSurfaceIdChanges) { |
| 265 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id()); | 263 ASSERT_EQ(base::nullopt, window_tree()->last_local_surface_id()); |
| 266 Window window(nullptr); | 264 Window window(nullptr); |
| 267 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds | 265 // TOP_LEVEL_IN_WM and EMBED_IN_OWNER windows allocate cc::LocalSurfaceIds |
| 268 // when their sizes change. | 266 // when their sizes change. |
| 269 window.SetProperty(aura::client::kEmbedType, | 267 window.SetProperty(aura::client::kEmbedType, |
| (...skipping 1956 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2226 window_tree()->GetEventResult(event_id)); | 2224 window_tree()->GetEventResult(event_id)); |
| 2227 EXPECT_TRUE(window_delegate1.got_move()); | 2225 EXPECT_TRUE(window_delegate1.got_move()); |
| 2228 EXPECT_FALSE(window_delegate2.got_move()); | 2226 EXPECT_FALSE(window_delegate2.got_move()); |
| 2229 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, | 2227 gfx::Point transformed_event_location_in_dip(event_location_in_dip.x() + 20, |
| 2230 event_location_in_dip.y() + 30); | 2228 event_location_in_dip.y() + 30); |
| 2231 EXPECT_EQ(transformed_event_location_in_dip, | 2229 EXPECT_EQ(transformed_event_location_in_dip, |
| 2232 window_delegate1.last_event_location()); | 2230 window_delegate1.last_event_location()); |
| 2233 } | 2231 } |
| 2234 | 2232 |
| 2235 } // namespace aura | 2233 } // namespace aura |
| OLD | NEW |