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 "components/viz/client/local_surface_id_provider.h" | 8 #include "components/viz/client/local_surface_id_provider.h" |
9 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" |
10 #include "ui/aura/client/transient_window_client.h" | 10 #include "ui/aura/client/transient_window_client.h" |
| 11 #include "ui/aura/env.h" |
11 #include "ui/aura/mus/client_surface_embedder.h" | 12 #include "ui/aura/mus/client_surface_embedder.h" |
12 #include "ui/aura/mus/property_converter.h" | 13 #include "ui/aura/mus/property_converter.h" |
13 #include "ui/aura/mus/window_tree_client.h" | 14 #include "ui/aura/mus/window_tree_client.h" |
14 #include "ui/aura/mus/window_tree_client_delegate.h" | 15 #include "ui/aura/mus/window_tree_client_delegate.h" |
15 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
16 #include "ui/aura/window_delegate.h" | 17 #include "ui/aura/window_delegate.h" |
17 #include "ui/aura/window_observer.h" | 18 #include "ui/aura/window_observer.h" |
18 #include "ui/base/class_property.h" | 19 #include "ui/base/class_property.h" |
19 #include "ui/display/display.h" | 20 #include "ui/display/display.h" |
20 #include "ui/display/screen.h" | 21 #include "ui/display/screen.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 window_tree_client_->SetCanAcceptDrops(this, can_accept_drops); | 89 window_tree_client_->SetCanAcceptDrops(this, can_accept_drops); |
89 } | 90 } |
90 | 91 |
91 void WindowPortMus::Embed( | 92 void WindowPortMus::Embed( |
92 ui::mojom::WindowTreeClientPtr client, | 93 ui::mojom::WindowTreeClientPtr client, |
93 uint32_t flags, | 94 uint32_t flags, |
94 const ui::mojom::WindowTree::EmbedCallback& callback) { | 95 const ui::mojom::WindowTree::EmbedCallback& callback) { |
95 window_tree_client_->Embed(window_, std::move(client), flags, callback); | 96 window_tree_client_->Embed(window_, std::move(client), flags, callback); |
96 } | 97 } |
97 | 98 |
98 std::unique_ptr<cc::CompositorFrameSink> | 99 std::unique_ptr<viz::ClientCompositorFrameSink> |
99 WindowPortMus::RequestCompositorFrameSink( | 100 WindowPortMus::RequestCompositorFrameSink( |
100 scoped_refptr<cc::ContextProvider> context_provider, | 101 scoped_refptr<cc::ContextProvider> context_provider, |
101 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { | 102 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) { |
102 cc::mojom::MojoCompositorFrameSinkPtrInfo sink_info; | 103 cc::mojom::MojoCompositorFrameSinkPtrInfo sink_info; |
103 cc::mojom::MojoCompositorFrameSinkRequest sink_request = | 104 cc::mojom::MojoCompositorFrameSinkRequest sink_request = |
104 mojo::MakeRequest(&sink_info); | 105 mojo::MakeRequest(&sink_info); |
105 cc::mojom::MojoCompositorFrameSinkClientPtr client; | 106 cc::mojom::MojoCompositorFrameSinkClientPtr client; |
106 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = | 107 cc::mojom::MojoCompositorFrameSinkClientRequest client_request = |
107 mojo::MakeRequest(&client); | 108 mojo::MakeRequest(&client); |
108 constexpr bool enable_surface_synchronization = true; | 109 constexpr bool enable_surface_synchronization = true; |
109 auto compositor_frame_sink = base::MakeUnique<viz::ClientCompositorFrameSink>( | 110 auto compositor_frame_sink = base::MakeUnique<viz::ClientCompositorFrameSink>( |
110 std::move(context_provider), nullptr /* worker_context_provider */, | 111 std::move(context_provider), nullptr /* worker_context_provider */, |
111 gpu_memory_buffer_manager, nullptr /* shared_bitmap_manager */, | 112 gpu_memory_buffer_manager, nullptr /* shared_bitmap_manager */, |
112 nullptr /* synthetic_begin_frame_source */, std::move(sink_info), | 113 nullptr /* synthetic_begin_frame_source */, std::move(sink_info), |
113 std::move(client_request), | 114 std::move(client_request), |
114 base::MakeUnique<viz::DefaultLocalSurfaceIdProvider>(), | 115 base::MakeUnique<viz::DefaultLocalSurfaceIdProvider>(), |
115 enable_surface_synchronization); | 116 enable_surface_synchronization); |
116 window_tree_client_->AttachCompositorFrameSink( | 117 window_tree_client_->AttachCompositorFrameSink( |
117 server_id(), std::move(sink_request), std::move(client)); | 118 server_id(), std::move(sink_request), std::move(client)); |
118 return std::move(compositor_frame_sink); | 119 return compositor_frame_sink; |
119 } | 120 } |
120 | 121 |
121 WindowPortMus::ServerChangeIdType WindowPortMus::ScheduleChange( | 122 WindowPortMus::ServerChangeIdType WindowPortMus::ScheduleChange( |
122 const ServerChangeType type, | 123 const ServerChangeType type, |
123 const ServerChangeData& data) { | 124 const ServerChangeData& data) { |
124 ServerChange change; | 125 ServerChange change; |
125 change.type = type; | 126 change.type = type; |
126 change.server_change_id = next_server_change_id_++; | 127 change.server_change_id = next_server_change_id_++; |
127 change.data = data; | 128 change.data = data; |
128 server_changes_.push_back(change); | 129 server_changes_.push_back(change); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 300 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
300 last_surface_size_in_pixels_ = surface_size_in_pixels; | 301 last_surface_size_in_pixels_ = surface_size_in_pixels; |
301 | 302 |
302 // If the FrameSinkId is available, then immediately embed the SurfaceId. | 303 // If the FrameSinkId is available, then immediately embed the SurfaceId. |
303 // The newly generated frame by the embedder will block in the display | 304 // The newly generated frame by the embedder will block in the display |
304 // compositor until the child submits a corresponding CompositorFrame or a | 305 // compositor until the child submits a corresponding CompositorFrame or a |
305 // deadline hits. | 306 // deadline hits. |
306 if (frame_sink_id_.is_valid()) | 307 if (frame_sink_id_.is_valid()) |
307 UpdatePrimarySurfaceInfo(); | 308 UpdatePrimarySurfaceInfo(); |
308 | 309 |
| 310 if (local_compositor_frame_sink_) |
| 311 local_compositor_frame_sink_->SetLocalSurfaceId(local_surface_id_); |
| 312 |
309 return local_surface_id_; | 313 return local_surface_id_; |
310 } | 314 } |
311 | 315 |
312 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | |
313 primary_surface_info_ = surface_info; | |
314 UpdateClientSurfaceEmbedder(); | |
315 if (window_->delegate()) | |
316 window_->delegate()->OnWindowSurfaceChanged(surface_info); | |
317 } | |
318 | |
319 void WindowPortMus::SetFallbackSurfaceInfo( | 316 void WindowPortMus::SetFallbackSurfaceInfo( |
320 const cc::SurfaceInfo& surface_info) { | 317 const cc::SurfaceInfo& surface_info) { |
| 318 if (!frame_sink_id_.is_valid()) { |
| 319 // |primary_surface_info_| shold not be valid, since we didn't know the |
| 320 // |frame_sink_id_|. |
| 321 DCHECK(!primary_surface_info_.is_valid()); |
| 322 frame_sink_id_ = surface_info.id().frame_sink_id(); |
| 323 UpdatePrimarySurfaceInfo(); |
| 324 } |
| 325 |
| 326 // The frame sink id should never be changed. |
| 327 DCHECK_EQ(surface_info.id().frame_sink_id(), frame_sink_id_); |
| 328 |
321 fallback_surface_info_ = surface_info; | 329 fallback_surface_info_ = surface_info; |
322 UpdateClientSurfaceEmbedder(); | 330 UpdateClientSurfaceEmbedder(); |
323 } | 331 } |
324 | 332 |
325 void WindowPortMus::DestroyFromServer() { | 333 void WindowPortMus::DestroyFromServer() { |
326 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 334 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
327 if (window_->parent()) { | 335 if (window_->parent()) { |
328 ServerChangeData data; | 336 ServerChangeData data; |
329 data.child_id = server_id(); | 337 data.child_id = server_id(); |
330 WindowPortMus* parent = Get(window_->parent()); | 338 WindowPortMus* parent = Get(window_->parent()); |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
419 const bool removed = RemoveChangeByTypeAndData( | 427 const bool removed = RemoveChangeByTypeAndData( |
420 ServerChangeType::TRANSIENT_REORDER, change_data); | 428 ServerChangeType::TRANSIENT_REORDER, change_data); |
421 DCHECK(removed); | 429 DCHECK(removed); |
422 } | 430 } |
423 | 431 |
424 void WindowPortMus::NotifyEmbeddedAppDisconnected() { | 432 void WindowPortMus::NotifyEmbeddedAppDisconnected() { |
425 for (WindowObserver& observer : *GetObservers(window_)) | 433 for (WindowObserver& observer : *GetObservers(window_)) |
426 observer.OnEmbeddedAppDisconnected(window_); | 434 observer.OnEmbeddedAppDisconnected(window_); |
427 } | 435 } |
428 | 436 |
| 437 bool WindowPortMus::HasLocalCompositorFrameSink() { |
| 438 return !!local_compositor_frame_sink_; |
| 439 } |
| 440 |
429 void WindowPortMus::OnPreInit(Window* window) { | 441 void WindowPortMus::OnPreInit(Window* window) { |
430 window_ = window; | 442 window_ = window; |
431 window_tree_client_->OnWindowMusCreated(this); | 443 window_tree_client_->OnWindowMusCreated(this); |
432 } | 444 } |
433 | 445 |
434 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { | 446 void WindowPortMus::OnDeviceScaleFactorChanged(float device_scale_factor) { |
435 if (window_->delegate()) | 447 if (window_->delegate()) |
436 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); | 448 window_->delegate()->OnDeviceScaleFactorChanged(device_scale_factor); |
437 } | 449 } |
438 | 450 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 // TODO(sky): investigate to see if we need to compare data. In particular do | 526 // TODO(sky): investigate to see if we need to compare data. In particular do |
515 // we ever have a case where changing a property cascades into changing the | 527 // we ever have a case where changing a property cascades into changing the |
516 // same property? | 528 // same property? |
517 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 529 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
518 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 530 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
519 std::move(data)); | 531 std::move(data)); |
520 } | 532 } |
521 | 533 |
522 std::unique_ptr<cc::CompositorFrameSink> | 534 std::unique_ptr<cc::CompositorFrameSink> |
523 WindowPortMus::CreateCompositorFrameSink() { | 535 WindowPortMus::CreateCompositorFrameSink() { |
524 // TODO(penghuang): Implement it for Mus. | 536 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
525 return nullptr; | 537 DCHECK(!local_compositor_frame_sink_); |
| 538 auto frame_sink = RequestCompositorFrameSink( |
| 539 nullptr, |
| 540 aura::Env::GetInstance()->context_factory()->GetGpuMemoryBufferManager()); |
| 541 local_compositor_frame_sink_ = frame_sink->GetWeakPtr(); |
| 542 return std::move(frame_sink); |
526 } | 543 } |
527 | 544 |
528 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 545 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
529 // TODO(penghuang): Implement it for Mus. | 546 // This is only used by WindowPortLocal in unit tests. |
530 return cc::SurfaceId(); | 547 return cc::SurfaceId(); |
531 } | 548 } |
532 | 549 |
533 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 550 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
534 bool embeds_surface = | 551 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
535 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 552 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
536 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 553 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
537 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 554 window_mus_type() != WindowMusType::LOCAL) { |
538 if (!embeds_surface) | |
539 return; | 555 return; |
| 556 } |
540 | 557 |
541 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 558 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
542 return; | 559 return; |
543 | 560 |
544 SetPrimarySurfaceInfo(cc::SurfaceInfo( | 561 primary_surface_info_ = cc::SurfaceInfo( |
545 cc::SurfaceId(frame_sink_id_, local_surface_id_), | 562 cc::SurfaceId(frame_sink_id_, local_surface_id_), |
546 ScaleFactorForDisplay(window_), last_surface_size_in_pixels_)); | 563 ScaleFactorForDisplay(window_), last_surface_size_in_pixels_); |
| 564 UpdateClientSurfaceEmbedder(); |
| 565 if (window_->delegate()) |
| 566 window_->delegate()->OnWindowSurfaceChanged(primary_surface_info_); |
547 } | 567 } |
548 | 568 |
549 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 569 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
550 bool embeds_surface = | 570 if (window_mus_type() != WindowMusType::TOP_LEVEL_IN_WM && |
551 window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 571 window_mus_type() != WindowMusType::EMBED_IN_OWNER && |
552 window_mus_type() == WindowMusType::EMBED_IN_OWNER || | 572 window_mus_type() != WindowMusType::DISPLAY_MANUALLY_CREATED && |
553 window_mus_type() == WindowMusType::DISPLAY_MANUALLY_CREATED; | 573 window_mus_type() != WindowMusType::LOCAL) { |
554 if (!embeds_surface) | |
555 return; | 574 return; |
| 575 } |
556 | 576 |
557 if (!client_surface_embedder_) { | 577 if (!client_surface_embedder_) { |
558 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 578 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
559 window_, window_tree_client_->normal_client_area_insets_); | 579 window_, window_tree_client_->normal_client_area_insets_); |
560 } | 580 } |
561 | 581 |
562 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 582 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
563 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 583 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
564 } | 584 } |
565 | 585 |
566 } // namespace aura | 586 } // namespace aura |
OLD | NEW |