Chromium Code Reviews| 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 14 matching lines...) Expand all Loading... | |
| 34 | 35 |
| 35 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 36 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
| 36 | 37 |
| 37 // static | 38 // static |
| 38 WindowMus* WindowMus::Get(Window* window) { | 39 WindowMus* WindowMus::Get(Window* window) { |
| 39 return WindowPortMus::Get(window); | 40 return WindowPortMus::Get(window); |
| 40 } | 41 } |
| 41 | 42 |
| 42 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 43 WindowPortMus::WindowPortMus(WindowTreeClient* client, |
| 43 WindowMusType window_mus_type) | 44 WindowMusType window_mus_type) |
| 44 : WindowMus(window_mus_type), window_tree_client_(client) {} | 45 : WindowMus(window_mus_type), |
| 46 window_tree_client_(client), | |
| 47 weak_factory_(this) {} | |
| 45 | 48 |
| 46 WindowPortMus::~WindowPortMus() { | 49 WindowPortMus::~WindowPortMus() { |
| 47 client_surface_embedder_.reset(); | 50 client_surface_embedder_.reset(); |
| 48 | 51 |
| 49 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is | 52 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is |
| 50 // present then the server originated the change. | 53 // present then the server originated the change. |
| 51 const WindowTreeClient::Origin origin = | 54 const WindowTreeClient::Origin origin = |
| 52 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) | 55 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) |
| 53 ? WindowTreeClient::Origin::SERVER | 56 ? WindowTreeClient::Origin::SERVER |
| 54 : WindowTreeClient::Origin::CLIENT; | 57 : WindowTreeClient::Origin::CLIENT; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 } | 90 } |
| 88 | 91 |
| 89 void WindowPortMus::Embed( | 92 void WindowPortMus::Embed( |
| 90 ui::mojom::WindowTreeClientPtr client, | 93 ui::mojom::WindowTreeClientPtr client, |
| 91 uint32_t flags, | 94 uint32_t flags, |
| 92 const ui::mojom::WindowTree::EmbedCallback& callback) { | 95 const ui::mojom::WindowTree::EmbedCallback& callback) { |
| 93 window_tree_client_->Embed(window_, std::move(client), flags, callback); | 96 window_tree_client_->Embed(window_, std::move(client), flags, callback); |
| 94 } | 97 } |
| 95 | 98 |
| 96 std::unique_ptr<cc::CompositorFrameSink> | 99 std::unique_ptr<cc::CompositorFrameSink> |
| 97 WindowPortMus::RequestCompositorFrameSink( | 100 WindowPortMus::CreateCompositorFrameSinkWithContextAndBufferManager( |
| 98 scoped_refptr<cc::ContextProvider> context_provider, | 101 scoped_refptr<cc::ContextProvider> context_provider, |
| 99 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 102 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
| 100 cc::mojom::MojoCompositorFrameSinkPtrInfo sink_info; | 103 cc::mojom::MojoCompositorFrameSinkPtrInfo sink_info; |
| 101 cc::mojom::MojoCompositorFrameSinkRequest sink_request = | 104 cc::mojom::MojoCompositorFrameSinkRequest sink_request = |
| 102 mojo::MakeRequest(&sink_info); | 105 mojo::MakeRequest(&sink_info); |
| 103 cc::mojom::MojoCompositorFrameSinkClientPtr client; | 106 cc::mojom::MojoCompositorFrameSinkClientPtr client; |
| 104 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = | 107 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = |
| 105 mojo::MakeRequest(&client); | 108 mojo::MakeRequest(&client); |
| 106 constexpr bool enable_surface_synchronization = true; | 109 // For a "local window", we need ClientCompositorFrameSink to generate local |
| 110 // surface id. | |
| 111 bool generate_local_surface_id = window_mus_type() == WindowMusType::LOCAL; | |
|
Fady Samuel
2017/05/30 18:36:42
The parent should allocate the LocalSurfaceId. Let
sky
2017/05/30 19:37:29
One comment here. Currently the client that initia
Peng
2017/05/30 19:46:28
For a local window, actually we don't have the con
Peng
2017/05/31 20:12:25
Done. By Allocating local surface id in WindowPort
| |
| 107 auto compositor_frame_sink = base::MakeUnique<viz::ClientCompositorFrameSink>( | 112 auto compositor_frame_sink = base::MakeUnique<viz::ClientCompositorFrameSink>( |
| 108 std::move(context_provider), gpu_memory_buffer_manager, | 113 std::move(context_provider), gpu_memory_buffer_manager, |
| 109 std::move(sink_info), std::move(client_request), | 114 std::move(sink_info), std::move(client_request), |
| 110 enable_surface_synchronization); | 115 generate_local_surface_id); |
| 111 window_tree_client_->AttachCompositorFrameSink( | 116 window_tree_client_->AttachCompositorFrameSink( |
| 112 server_id(), std::move(sink_request), std::move(client)); | 117 server_id(), std::move(sink_request), std::move(client)); |
| 113 return std::move(compositor_frame_sink); | 118 return std::move(compositor_frame_sink); |
| 114 } | 119 } |
| 115 | 120 |
| 116 WindowPortMus::ServerChangeIdType WindowPortMus::ScheduleChange( | 121 WindowPortMus::ServerChangeIdType WindowPortMus::ScheduleChange( |
| 117 const ServerChangeType type, | 122 const ServerChangeType type, |
| 118 const ServerChangeData& data) { | 123 const ServerChangeData& data) { |
| 119 ServerChange change; | 124 ServerChange change; |
| 120 change.type = type; | 125 change.type = type; |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 // If the FrameSinkId is available, then immediately embed the SurfaceId. | 287 // If the FrameSinkId is available, then immediately embed the SurfaceId. |
| 283 // The newly generated frame by the embedder will block in the display | 288 // The newly generated frame by the embedder will block in the display |
| 284 // compositor until the child submits a corresponding CompositorFrame or a | 289 // compositor until the child submits a corresponding CompositorFrame or a |
| 285 // deadline hits. | 290 // deadline hits. |
| 286 if (frame_sink_id_.is_valid()) | 291 if (frame_sink_id_.is_valid()) |
| 287 UpdatePrimarySurfaceInfo(); | 292 UpdatePrimarySurfaceInfo(); |
| 288 | 293 |
| 289 return local_surface_id_; | 294 return local_surface_id_; |
| 290 } | 295 } |
| 291 | 296 |
| 292 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 297 void WindowPortMus::SetSurfaceInfoFromServer( |
|
Fady Samuel
2017/05/30 20:35:30
Please don't delete this either.
|
Fady Samuel
2017/05/30 18:36:41
This doesn't match our discussion. Let's keep the
Peng
2017/05/30 19:46:28
I thought to generate in ClientCompositorFrameSink
Fady Samuel
2017/05/30 19:51:31
This introduces a special case for local windows s
|
| 293 primary_surface_info_ = surface_info; | 298 const cc::SurfaceInfo& surface_info) { |
| 294 UpdateClientSurfaceEmbedder(); | 299 if (!frame_sink_id_.is_valid()) { |
| 295 if (window_->delegate()) | 300 // This only happens for a "local" window, because the |
| 296 window_->delegate()->OnWindowSurfaceChanged(surface_info); | 301 // |SetFrameSinkIdFromServer| will not be called for a "local" window. |
| 297 } | 302 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| 303 // |primary_surface_info_| shold not be valid, since we didn't know the | |
| 304 // |frame_sink_id_|. | |
| 305 DCHECK(!primary_surface_info_.is_valid()); | |
| 306 frame_sink_id_ = surface_info.id().frame_sink_id(); | |
| 307 UpdatePrimarySurfaceInfo(); | |
| 308 } | |
| 298 | 309 |
| 299 void WindowPortMus::SetFallbackSurfaceInfo( | 310 // The frame sink id should never be changed. |
| 300 const cc::SurfaceInfo& surface_info) { | 311 DCECHK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
| 312 | |
| 313 // If the window is informed of a surface from server then that surface ID is | |
| 314 // guaranteed to be available in the display compositor so we set it as the | |
| 315 // fallback. For embedded window, the primary SurfaceInfo is created by the | |
| 316 // embedder, and the LocalSurfaceId is allocated by the embedder. | |
| 301 fallback_surface_info_ = surface_info; | 317 fallback_surface_info_ = surface_info; |
| 302 UpdateClientSurfaceEmbedder(); | 318 UpdateClientSurfaceEmbedder(); |
| 303 } | 319 } |
| 304 | 320 |
| 305 void WindowPortMus::DestroyFromServer() { | 321 void WindowPortMus::DestroyFromServer() { |
| 306 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 322 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 307 if (window_->parent()) { | 323 if (window_->parent()) { |
| 308 ServerChangeData data; | 324 ServerChangeData data; |
| 309 data.child_id = server_id(); | 325 data.child_id = server_id(); |
| 310 WindowPortMus* parent = Get(window_->parent()); | 326 WindowPortMus* parent = Get(window_->parent()); |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 484 // TODO(sky): investigate to see if we need to compare data. In particular do | 500 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 485 // we ever have a case where changing a property cascades into changing the | 501 // we ever have a case where changing a property cascades into changing the |
| 486 // same property? | 502 // same property? |
| 487 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 503 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 488 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 504 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 489 std::move(data)); | 505 std::move(data)); |
| 490 } | 506 } |
| 491 | 507 |
| 492 std::unique_ptr<cc::CompositorFrameSink> | 508 std::unique_ptr<cc::CompositorFrameSink> |
| 493 WindowPortMus::CreateCompositorFrameSink() { | 509 WindowPortMus::CreateCompositorFrameSink() { |
| 494 // TODO(penghuang): Implement it for Mus. | 510 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| 495 return nullptr; | 511 auto frame_sink = CreateCompositorFrameSinkWithContextAndBufferManager( |
| 512 nullptr, | |
| 513 aura::Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager()); | |
| 514 auto* viz_frame_sink = | |
| 515 static_cast<viz::ClientCompositorFrameSink*>(frame_sink.get()); | |
| 516 viz_frame_sink->SetSurfaceChangedCallback( | |
| 517 base::Bind(&WindowPortMus::OnSurfaceChangedForLocalWindow, | |
| 518 weak_factory_.GetWeakPtr())); | |
| 519 return frame_sink; | |
| 496 } | 520 } |
| 497 | 521 |
| 498 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 522 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| 499 // TODO(penghuang): Implement it for Mus. | 523 // This method is only used by exo unittests which are not running against |
| 524 // mus, so don't implement it now. | |
| 500 return cc::SurfaceId(); | 525 return cc::SurfaceId(); |
| 501 } | 526 } |
| 502 | 527 |
| 503 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 528 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| 504 bool embeds_surface = | 529 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
| 505 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 530 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
| 506 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 531 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
| 507 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 532 window_mus_type() != WindowMusType::LOCAL) |
| 508 if (!embeds_surface) | |
| 509 return; | 533 return; |
| 510 | 534 |
| 511 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 535 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| 512 return; | 536 return; |
| 513 | 537 |
| 514 SetPrimarySurfaceInfo( | 538 primary_surface_info_ = |
| 515 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 539 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 516 ScaleFactorForDisplay(window_), last_surface_size_)); | 540 ScaleFactorForDisplay(window_), last_surface_size_); |
| 541 UpdateClientSurfaceEmbedder(); | |
| 542 if (window_->delegate()) | |
| 543 window_->delegate()->OnWindowSurfaceChanged(primary_surface_info_); | |
| 517 } | 544 } |
| 518 | 545 |
| 519 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 546 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| 520 bool embeds_surface = | |
| 521 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | |
| 522 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | |
| 523 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | |
| 524 if (!embeds_surface) | |
| 525 return; | |
| 526 | |
| 527 if (!client_surface_embedder_) { | 547 if (!client_surface_embedder_) { |
| 528 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 548 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 529 window_, window_tree_client_->normal_client_area_insets_); | 549 window_, window_tree_client_->normal_client_area_insets_); |
| 530 } | 550 } |
| 531 | 551 |
| 532 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 552 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 533 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 553 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 534 } | 554 } |
| 535 | 555 |
| 556 void WindowPortMus::OnSurfaceChangedForLocalWindow( | |
|
Fady Samuel
2017/05/30 18:36:42
Please don't special case local windows?
Peng
2017/05/31 20:12:25
Done. By allocating local_surface_id in GetOrAlloc
| |
| 557 const cc::LocalSurfaceId& local_surface_id, | |
| 558 const gfx::Size& size) { | |
| 559 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); | |
| 560 local_surface_id_ = local_surface_id; | |
| 561 last_surface_size_ = size; | |
| 562 | |
| 563 // For the first frame, the |frame_sink_id_| will be null, and then the | |
| 564 // |UpdatePrimarySurfaceInfo| will not update the |primary_surface_info_|, | |
| 565 // instead the |primary_surface_info_| will be updated until we receive the | |
| 566 // surface info via |SetSurfaceInfoFromServer|. | |
| 567 UpdatePrimarySurfaceInfo(); | |
| 568 } | |
| 569 | |
| 536 } // namespace aura | 570 } // namespace aura |
| OLD | NEW |