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