| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_port_mus.h" | 5 #include "ui/aura/mus/window_port_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 9 #include "ui/aura/client/transient_window_client.h" | 9 #include "ui/aura/client/transient_window_client.h" |
| 10 #include "ui/aura/mus/client_surface_embedder.h" | 10 #include "ui/aura/mus/client_surface_embedder.h" |
| 11 #include "ui/aura/mus/property_converter.h" | 11 #include "ui/aura/mus/property_converter.h" |
| 12 #include "ui/aura/mus/window_tree_client.h" | 12 #include "ui/aura/mus/window_tree_client.h" |
| 13 #include "ui/aura/mus/window_tree_client_delegate.h" | 13 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 14 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 17 #include "ui/aura/window_tree_host.h" |
| 17 #include "ui/base/class_property.h" | 18 #include "ui/base/class_property.h" |
| 19 #include "ui/display/display.h" |
| 20 #include "ui/display/screen.h" |
| 18 | 21 |
| 19 namespace aura { | 22 namespace aura { |
| 20 | 23 |
| 24 namespace { |
| 25 // Helper function to get the device_scale_factor() of the display::Display |
| 26 // nearest to |window|. |
| 27 float ScaleFactorForDisplay(Window* window) { |
| 28 return display::Screen::GetScreen() |
| 29 ->GetDisplayNearestWindow(window) |
| 30 .device_scale_factor(); |
| 31 } |
| 32 } |
| 33 |
| 21 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 34 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
| 22 | 35 |
| 23 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 36 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
| 24 | 37 |
| 25 // static | 38 // static |
| 26 WindowMus* WindowMus::Get(Window* window) { | 39 WindowMus* WindowMus::Get(Window* window) { |
| 27 return WindowPortMus::Get(window); | 40 return WindowPortMus::Get(window); |
| 28 } | 41 } |
| 29 | 42 |
| 30 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 43 WindowPortMus::WindowPortMus(WindowTreeClient* client, |
| 31 WindowMusType window_mus_type) | 44 WindowMusType window_mus_type) |
| 32 : WindowMus(window_mus_type), window_tree_client_(client) {} | 45 : WindowMus(window_mus_type), window_tree_client_(client) {} |
| 33 | 46 |
| 34 WindowPortMus::~WindowPortMus() { | 47 WindowPortMus::~WindowPortMus() { |
| 35 if (surface_info_.is_valid()) | 48 if (surface_info_.is_valid()) |
| 36 SetSurfaceInfoFromServer(cc::SurfaceInfo()); | 49 SetPrimarySurfaceInfo(cc::SurfaceInfo()); |
| 37 | 50 |
| 38 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is | 51 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is |
| 39 // present then the server originated the change. | 52 // present then the server originated the change. |
| 40 const WindowTreeClient::Origin origin = | 53 const WindowTreeClient::Origin origin = |
| 41 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) | 54 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) |
| 42 ? WindowTreeClient::Origin::SERVER | 55 ? WindowTreeClient::Origin::SERVER |
| 43 : WindowTreeClient::Origin::CLIENT; | 56 : WindowTreeClient::Origin::CLIENT; |
| 44 window_tree_client_->OnWindowMusDestroyed(this, origin); | 57 window_tree_client_->OnWindowMusDestroyed(this, origin); |
| 45 } | 58 } |
| 46 | 59 |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void WindowPortMus::SetPropertyFromServer( | 274 void WindowPortMus::SetPropertyFromServer( |
| 262 const std::string& property_name, | 275 const std::string& property_name, |
| 263 const std::vector<uint8_t>* property_data) { | 276 const std::vector<uint8_t>* property_data) { |
| 264 ServerChangeData data; | 277 ServerChangeData data; |
| 265 data.property_name = property_name; | 278 data.property_name = property_name; |
| 266 ScopedServerChange change(this, ServerChangeType::PROPERTY, data); | 279 ScopedServerChange change(this, ServerChangeType::PROPERTY, data); |
| 267 GetPropertyConverter()->SetPropertyFromTransportValue(window_, property_name, | 280 GetPropertyConverter()->SetPropertyFromTransportValue(window_, property_name, |
| 268 property_data); | 281 property_data); |
| 269 } | 282 } |
| 270 | 283 |
| 284 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { |
| 285 // The fact that SetSurfaceIdFromServer was called means that this window |
| 286 // corresponds to an embedded client. |
| 287 if (!client_surface_embedder && window_ && surface_info.is_valid()) |
| 288 client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_); |
| 289 |
| 290 if (surface_info.is_valid() && window_->IsVisible()) |
| 291 client_surface_embedder->UpdateSurface(surface_info); |
| 292 else |
| 293 client_surface_embedder.reset(); |
| 294 |
| 295 surface_info_ = surface_info; |
| 296 } |
| 297 |
| 298 void WindowPortMus::SetFallbackSurfaceInfo( |
| 299 const cc::SurfaceInfo& surface_info) { |
| 300 // The fact that SetSurfaceIdFromServer was called means that this window |
| 301 // corresponds to an embedded client. |
| 302 if (!client_surface_embedder) |
| 303 client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_); |
| 304 |
| 305 client_surface_embedder->SetFallbackSurfaceInfo(surface_info); |
| 306 } |
| 307 |
| 271 void WindowPortMus::SetFrameSinkIdFromServer( | 308 void WindowPortMus::SetFrameSinkIdFromServer( |
| 272 const cc::FrameSinkId& frame_sink_id) { | 309 const cc::FrameSinkId& frame_sink_id) { |
| 273 frame_sink_id_ = frame_sink_id; | 310 frame_sink_id_ = frame_sink_id; |
| 274 if (!pending_compositor_frame_sink_request_.is_null()) { | 311 if (!pending_compositor_frame_sink_request_.is_null()) { |
| 275 // TOP_LEVEL_IN_WM, and EMBED_IN_OWNER windows should not be requesting | 312 // TOP_LEVEL_IN_WM, and EMBED_IN_OWNER windows should not be requesting |
| 276 // CompositorFrameSinks. | 313 // CompositorFrameSinks. |
| 277 DCHECK_NE(WindowMusType::TOP_LEVEL_IN_WM, window_mus_type()); | 314 DCHECK_NE(WindowMusType::TOP_LEVEL_IN_WM, window_mus_type()); |
| 278 DCHECK_NE(WindowMusType::EMBED_IN_OWNER, window_mus_type()); | 315 DCHECK_NE(WindowMusType::EMBED_IN_OWNER, window_mus_type()); |
| 279 base::ResetAndReturn(&pending_compositor_frame_sink_request_).Run(); | 316 base::ResetAndReturn(&pending_compositor_frame_sink_request_).Run(); |
| 317 return; |
| 280 } | 318 } |
| 281 // TODO(fsamuel): If the window type is TOP_LEVEL_IN_WM or EMBED_IN_OWNER then | 319 // TODO(fsamuel): If the window type is TOP_LEVEL_IN_WM or EMBED_IN_OWNER then |
| 282 // we should check if we have a cc::LocalSurfaeId ready as well. If we do, | 320 // we should check if we have a cc::LocalSurfaeId ready as well. If we do, |
| 283 // then we are ready to embed. | 321 // then we are ready to embed. |
| 322 if ((window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 323 window_mus_type() == WindowMusType::EMBED_IN_OWNER) && |
| 324 local_surface_id_.is_valid()) { |
| 325 cc::SurfaceInfo surface_info( |
| 326 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 327 ScaleFactorForDisplay(window_), window_->bounds().size()); |
| 328 SetPrimarySurfaceInfo(surface_info); |
| 329 } |
| 284 } | 330 } |
| 285 | 331 |
| 286 void WindowPortMus::SetSurfaceInfoFromServer( | 332 const cc::LocalSurfaceId& WindowPortMus::GetLocalSurfaceId() { |
| 287 const cc::SurfaceInfo& surface_info) { | 333 return local_surface_id_; |
| 288 if (surface_info_.is_valid()) { | 334 } |
| 289 const cc::SurfaceId& existing_surface_id = surface_info_.id(); | 335 |
| 290 const cc::SurfaceId& new_surface_id = surface_info.id(); | 336 const cc::LocalSurfaceId& WindowPortMus::AllocateLocalSurfaceIdForSize( |
| 291 if (existing_surface_id.is_valid() && | 337 const gfx::Size& new_size) { |
| 292 existing_surface_id != new_surface_id) { | 338 if (last_size_ == new_size && local_surface_id_.is_valid()) |
| 293 // TODO(kylechar): Start return reference here? | 339 return local_surface_id_; |
| 294 } | 340 |
| 341 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 342 last_size_ = new_size; |
| 343 |
| 344 // If we have a valid FrameSinkId and LocalSurfaceId then we can embed |
| 345 // the content of the window now. |
| 346 if (frame_sink_id_.is_valid()) { |
| 347 // TODO(fsamuel): DCHECK That we have the right window type. |
| 348 cc::SurfaceInfo surface_info( |
| 349 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 350 ScaleFactorForDisplay(window_), new_size); |
| 351 SetPrimarySurfaceInfo(surface_info); |
| 295 } | 352 } |
| 296 | 353 return local_surface_id_; |
| 297 // The fact that SetSurfaceIdFromServer was called means that this window | |
| 298 // corresponds to an embedded client. | |
| 299 if (!client_surface_embedder && surface_info.is_valid()) | |
| 300 client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_); | |
| 301 | |
| 302 if (surface_info.is_valid()) | |
| 303 client_surface_embedder->UpdateSurface(surface_info); | |
| 304 else | |
| 305 client_surface_embedder.reset(); | |
| 306 | |
| 307 surface_info_ = surface_info; | |
| 308 } | 354 } |
| 309 | 355 |
| 310 void WindowPortMus::DestroyFromServer() { | 356 void WindowPortMus::DestroyFromServer() { |
| 311 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 357 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 312 if (window_->parent()) { | 358 if (window_->parent()) { |
| 313 ServerChangeData data; | 359 ServerChangeData data; |
| 314 data.child_id = server_id(); | 360 data.child_id = server_id(); |
| 315 WindowPortMus* parent = Get(window_->parent()); | 361 WindowPortMus* parent = Get(window_->parent()); |
| 316 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( | 362 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
| 317 parent, ServerChangeType::REMOVE, data); | 363 parent, ServerChangeType::REMOVE, data); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 change_data) == server_changes_.end()) { | 487 change_data) == server_changes_.end()) { |
| 442 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); | 488 window_tree_client_->OnWindowMusMoveChild(this, current_index, dest_index); |
| 443 } | 489 } |
| 444 } | 490 } |
| 445 | 491 |
| 446 void WindowPortMus::OnVisibilityChanged(bool visible) { | 492 void WindowPortMus::OnVisibilityChanged(bool visible) { |
| 447 ServerChangeData change_data; | 493 ServerChangeData change_data; |
| 448 change_data.visible = visible; | 494 change_data.visible = visible; |
| 449 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) | 495 if (!RemoveChangeByTypeAndData(ServerChangeType::VISIBLE, change_data)) |
| 450 window_tree_client_->OnWindowMusSetVisible(this, visible); | 496 window_tree_client_->OnWindowMusSetVisible(this, visible); |
| 497 // Update the ClientSurfaceEmbedder on visibility change. |
| 498 if (surface_info_.is_valid()) |
| 499 SetPrimarySurfaceInfo(surface_info_); |
| 451 } | 500 } |
| 452 | 501 |
| 453 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, | 502 void WindowPortMus::OnDidChangeBounds(const gfx::Rect& old_bounds, |
| 454 const gfx::Rect& new_bounds) { | 503 const gfx::Rect& new_bounds) { |
| 455 ServerChangeData change_data; | 504 ServerChangeData change_data; |
| 456 change_data.bounds_in_dip = new_bounds; | 505 change_data.bounds_in_dip = new_bounds; |
| 457 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) | 506 if (!RemoveChangeByTypeAndData(ServerChangeType::BOUNDS, change_data)) |
| 458 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); | 507 window_tree_client_->OnWindowMusBoundsChanged(this, old_bounds, new_bounds); |
| 459 } | 508 } |
| 460 | 509 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 482 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 531 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
| 483 // TODO(sky): investigate to see if we need to compare data. In particular do | 532 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 484 // we ever have a case where changing a property cascades into changing the | 533 // we ever have a case where changing a property cascades into changing the |
| 485 // same property? | 534 // same property? |
| 486 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 535 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 487 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 536 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 488 std::move(data)); | 537 std::move(data)); |
| 489 } | 538 } |
| 490 | 539 |
| 491 } // namespace aura | 540 } // namespace aura |
| OLD | NEW |