| 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/env.h" |
| 10 #include "ui/aura/mus/client_surface_embedder.h" | 11 #include "ui/aura/mus/client_surface_embedder.h" |
| 11 #include "ui/aura/mus/property_converter.h" | 12 #include "ui/aura/mus/property_converter.h" |
| 12 #include "ui/aura/mus/window_tree_client.h" | 13 #include "ui/aura/mus/window_tree_client.h" |
| 13 #include "ui/aura/mus/window_tree_client_delegate.h" | 14 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/aura/window_delegate.h" | 16 #include "ui/aura/window_delegate.h" |
| 16 #include "ui/aura/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
| 17 #include "ui/base/class_property.h" | 18 #include "ui/base/class_property.h" |
| 18 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 19 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 296 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 297 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 297 last_surface_size_in_pixels_ = surface_size_in_pixels; | 298 last_surface_size_in_pixels_ = surface_size_in_pixels; |
| 298 | 299 |
| 299 // If the FrameSinkId is available, then immediately embed the SurfaceId. | 300 // If the FrameSinkId is available, then immediately embed the SurfaceId. |
| 300 // The newly generated frame by the embedder will block in the display | 301 // The newly generated frame by the embedder will block in the display |
| 301 // compositor until the child submits a corresponding CompositorFrame or a | 302 // compositor until the child submits a corresponding CompositorFrame or a |
| 302 // deadline hits. | 303 // deadline hits. |
| 303 if (frame_sink_id_.is_valid()) | 304 if (frame_sink_id_.is_valid()) |
| 304 UpdatePrimarySurfaceInfo(); | 305 UpdatePrimarySurfaceInfo(); |
| 305 | 306 |
| 307 if (local_compositor_frame_sink_) |
| 308 local_compositor_frame_sink_->SetLocalSurfaceId(local_surface_id_); |
| 309 |
| 306 return local_surface_id_; | 310 return local_surface_id_; |
| 307 } | 311 } |
| 308 | 312 |
| 309 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | |
| 310 primary_surface_info_ = surface_info; | |
| 311 UpdateClientSurfaceEmbedder(); | |
| 312 if (window_->delegate()) | |
| 313 window_->delegate()->OnWindowSurfaceChanged(surface_info); | |
| 314 } | |
| 315 | |
| 316 void WindowPortMus::SetFallbackSurfaceInfo( | 313 void WindowPortMus::SetFallbackSurfaceInfo( |
| 317 const cc::SurfaceInfo& surface_info) { | 314 const cc::SurfaceInfo& surface_info) { |
| 315 if (!frame_sink_id_.is_valid()) { |
| 316 // |primary_surface_info_| shold not be valid, since we didn't know the |
| 317 // |frame_sink_id_|. |
| 318 DCHECK(!primary_surface_info_.is_valid()); |
| 319 frame_sink_id_ = surface_info.id().frame_sink_id(); |
| 320 UpdatePrimarySurfaceInfo(); |
| 321 } |
| 322 |
| 323 // The frame sink id should never be changed. |
| 324 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
| 325 |
| 318 fallback_surface_info_ = surface_info; | 326 fallback_surface_info_ = surface_info; |
| 319 UpdateClientSurfaceEmbedder(); | 327 UpdateClientSurfaceEmbedder(); |
| 320 } | 328 } |
| 321 | 329 |
| 322 void WindowPortMus::DestroyFromServer() { | 330 void WindowPortMus::DestroyFromServer() { |
| 323 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 331 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 324 if (window_->parent()) { | 332 if (window_->parent()) { |
| 325 ServerChangeData data; | 333 ServerChangeData data; |
| 326 data.child_id = server_id(); | 334 data.child_id = server_id(); |
| 327 WindowPortMus* parent = Get(window_->parent()); | 335 WindowPortMus* parent = Get(window_->parent()); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 const bool removed = RemoveChangeByTypeAndData( | 424 const bool removed = RemoveChangeByTypeAndData( |
| 417 ServerChangeType::TRANSIENT_REORDER, change_data); | 425 ServerChangeType::TRANSIENT_REORDER, change_data); |
| 418 DCHECK(removed); | 426 DCHECK(removed); |
| 419 } | 427 } |
| 420 | 428 |
| 421 void WindowPortMus::NotifyEmbeddedAppDisconnected() { | 429 void WindowPortMus::NotifyEmbeddedAppDisconnected() { |
| 422 for (WindowObserver& observer : *GetObservers(window_)) | 430 for (WindowObserver& observer : *GetObservers(window_)) |
| 423 observer.OnEmbeddedAppDisconnected(window_); | 431 observer.OnEmbeddedAppDisconnected(window_); |
| 424 } | 432 } |
| 425 | 433 |
| 434 bool WindowPortMus::HasLocalCompositorFrameSink() { |
| 435 return !!local_compositor_frame_sink_; |
| 436 } |
| 437 |
| 426 void WindowPortMus::OnPreInit(Window* window) { | 438 void WindowPortMus::OnPreInit(Window* window) { |
| 427 window_ = window; | 439 window_ = window; |
| 428 window_tree_client_->OnWindowMusCreated(this); | 440 window_tree_client_->OnWindowMusCreated(this); |
| 429 } | 441 } |
| 430 | 442 |
| 431 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { | 443 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { |
| 432 if (window_->delegate()) | 444 if (window_->delegate()) |
| 433 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); | 445 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); |
| 434 } | 446 } |
| 435 | 447 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 511 // TODO(sky): investigate to see if we need to compare data. In particular do | 523 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 512 // we ever have a case where changing a property cascades into changing the | 524 // we ever have a case where changing a property cascades into changing the |
| 513 // same property? | 525 // same property? |
| 514 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 526 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 515 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 527 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 516 std::move(data)); | 528 std::move(data)); |
| 517 } | 529 } |
| 518 | 530 |
| 519 std::unique_ptr<cc::CompositorFrameSink> | 531 std::unique_ptr<cc::CompositorFrameSink> |
| 520 WindowPortMus::CreateCompositorFrameSink() { | 532 WindowPortMus::CreateCompositorFrameSink() { |
| 521 // TODO(penghuang): Implement it for Mus. | 533 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| 522 return nullptr; | 534 DCHECK(!local_compositor_frame_sink_); |
| 535 auto frame_sink = RequestCompositorFrameSink( |
| 536 nullptr, |
| 537 aura::Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager()); |
| 538 auto* viz_frame_sink = |
| 539 static_cast<viz::ClientCompositorFrameSink*>(frame_sink.get()); |
| 540 local_compositor_frame_sink_ = viz_frame_sink->GetWeakPtr(); |
| 541 return frame_sink; |
| 523 } | 542 } |
| 524 | 543 |
| 525 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 544 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| 526 // TODO(penghuang): Implement it for Mus. | 545 // This is only used by WindowPortLocal in unit tests. |
| 527 return cc::SurfaceId(); | 546 return cc::SurfaceId(); |
| 528 } | 547 } |
| 529 | 548 |
| 530 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 549 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| 531 bool embeds_surface = | 550 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
| 532 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 551 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
| 533 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 552 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
| 534 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 553 window_mus_type() != WindowMusType::LOCAL) { |
| 535 if (!embeds_surface) | |
| 536 return; | 554 return; |
| 555 } |
| 537 | 556 |
| 538 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 557 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| 539 return; | 558 return; |
| 540 | 559 |
| 541 SetPrimarySurfaceInfo(cc::SurfaceInfo( | 560 primary_surface_info_ = cc::SurfaceInfo( |
| 542 cc::SurfaceId(frame_sink_id_, local_surface_id_), | 561 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 543 ScaleFactorForDisplay(window_), last_surface_size_in_pixels_)); | 562 ScaleFactorForDisplay(window_), last_surface_size_in_pixels_); |
| 563 UpdateClientSurfaceEmbedder(); |
| 564 if (window_->delegate()) |
| 565 window_->delegate()->OnWindowSurfaceChanged(primary_surface_info_); |
| 544 } | 566 } |
| 545 | 567 |
| 546 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 568 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| 547 bool embeds_surface = | 569 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
| 548 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 570 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
| 549 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 571 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
| 550 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 572 window_mus_type() != WindowMusType::LOCAL) { |
| 551 if (!embeds_surface) | |
| 552 return; | 573 return; |
| 574 } |
| 553 | 575 |
| 554 if (!client_surface_embedder_) { | 576 if (!client_surface_embedder_) { |
| 555 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 577 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 556 window_, window_tree_client_->normal_client_area_insets_); | 578 window_, window_tree_client_->normal_client_area_insets_); |
| 557 } | 579 } |
| 558 | 580 |
| 559 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 581 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 560 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 582 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 561 } | 583 } |
| 562 | 584 |
| 563 } // namespace aura | 585 } // namespace aura |
| OLD | NEW |