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 "cc/output/context_provider.h" | |
| 8 #include "ui/aura/client/aura_constants.h" | 9 #include "ui/aura/client/aura_constants.h" | 
| 9 #include "ui/aura/client/transient_window_client.h" | 10 #include "ui/aura/client/transient_window_client.h" | 
| 11 #include "ui/aura/env.h" | |
| 10 #include "ui/aura/mus/client_surface_embedder.h" | 12 #include "ui/aura/mus/client_surface_embedder.h" | 
| 13 #include "ui/aura/mus/mus_context_factory.h" | |
| 11 #include "ui/aura/mus/property_converter.h" | 14 #include "ui/aura/mus/property_converter.h" | 
| 12 #include "ui/aura/mus/window_tree_client.h" | 15 #include "ui/aura/mus/window_tree_client.h" | 
| 13 #include "ui/aura/mus/window_tree_client_delegate.h" | 16 #include "ui/aura/mus/window_tree_client_delegate.h" | 
| 14 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" | 
| 15 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" | 
| 16 #include "ui/aura/window_observer.h" | 19 #include "ui/aura/window_observer.h" | 
| 17 #include "ui/base/class_property.h" | 20 #include "ui/base/class_property.h" | 
| 18 #include "ui/display/display.h" | 21 #include "ui/display/display.h" | 
| 19 #include "ui/display/screen.h" | 22 #include "ui/display/screen.h" | 
| 20 | 23 | 
| 21 namespace aura { | 24 namespace aura { | 
| 22 | 25 | 
| 23 namespace { | 26 namespace { | 
| 24 // Helper function to get the device_scale_factor() of the display::Display | 27 // Helper function to get the device_scale_factor() of the display::Display | 
| 25 // nearest to |window|. | 28 // nearest to |window|. | 
| 26 float ScaleFactorForDisplay(Window* window) { | 29 float ScaleFactorForDisplay(Window* window) { | 
| 27 return display::Screen::GetScreen() | 30 return display::Screen::GetScreen() | 
| 28 ->GetDisplayNearestWindow(window) | 31 ->GetDisplayNearestWindow(window) | 
| 29 .device_scale_factor(); | 32 .device_scale_factor(); | 
| 30 } | 33 } | 
| 34 | |
| 35 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference | |
| 36 // work is complete. | |
| 37 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { | |
| 38 public: | |
| 39 StubSurfaceReferenceFactory() = default; | |
| 40 | |
| 41 // cc::SurfaceReferenceFactory: | |
| 42 base::Closure CreateReference( | |
| 43 cc::SurfaceReferenceOwner* owner, | |
| 44 const cc::SurfaceId& surface_id) const override { | |
| 45 return base::Closure(); | |
| 46 } | |
| 47 | |
| 48 protected: | |
| 49 ~StubSurfaceReferenceFactory() override = default; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); | |
| 52 }; | |
| 31 } // namespace | 53 } // namespace | 
| 32 | 54 | 
| 33 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 55 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 
| 34 | 56 | 
| 35 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 57 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 
| 36 | 58 | 
| 37 // static | 59 // static | 
| 38 WindowMus* WindowMus::Get(Window* window) { | 60 WindowMus* WindowMus::Get(Window* window) { | 
| 39 return WindowPortMus::Get(window); | 61 return WindowPortMus::Get(window); | 
| 40 } | 62 } | 
| 41 | 63 | 
| 42 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 64 WindowPortMus::WindowPortMus(WindowTreeClient* client, | 
| 43 WindowMusType window_mus_type) | 65 WindowMusType window_mus_type) | 
| 44 : WindowMus(window_mus_type), window_tree_client_(client) {} | 66 : WindowMus(window_mus_type), | 
| 67 window_tree_client_(client), | |
| 68 weak_factory_(this) {} | |
| 45 | 69 | 
| 46 WindowPortMus::~WindowPortMus() { | 70 WindowPortMus::~WindowPortMus() { | 
| 47 client_surface_embedder_.reset(); | 71 client_surface_embedder_.reset(); | 
| 48 | 72 | 
| 49 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is | 73 // DESTROY is only scheduled from DestroyFromServer(), meaning if DESTROY is | 
| 50 // present then the server originated the change. | 74 // present then the server originated the change. | 
| 51 const WindowTreeClient::Origin origin = | 75 const WindowTreeClient::Origin origin = | 
| 52 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) | 76 RemoveChangeByTypeAndData(ServerChangeType::DESTROY, ServerChangeData()) | 
| 53 ? WindowTreeClient::Origin::SERVER | 77 ? WindowTreeClient::Origin::SERVER | 
| 54 : WindowTreeClient::Origin::CLIENT; | 78 : WindowTreeClient::Origin::CLIENT; | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 } | 138 } | 
| 115 | 139 | 
| 116 void WindowPortMus::RequestCompositorFrameSinkInternal( | 140 void WindowPortMus::RequestCompositorFrameSinkInternal( | 
| 117 scoped_refptr<cc::ContextProvider> context_provider, | 141 scoped_refptr<cc::ContextProvider> context_provider, | 
| 118 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 142 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager, | 
| 119 const CompositorFrameSinkCallback& callback) { | 143 const CompositorFrameSinkCallback& callback) { | 
| 120 DCHECK(frame_sink_id_.is_valid()); | 144 DCHECK(frame_sink_id_.is_valid()); | 
| 121 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> | 145 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> | 
| 122 compositor_frame_sink_binding; | 146 compositor_frame_sink_binding; | 
| 123 std::unique_ptr<ui::ClientCompositorFrameSink> compositor_frame_sink = | 147 std::unique_ptr<ui::ClientCompositorFrameSink> compositor_frame_sink = | 
| 124 ui::ClientCompositorFrameSink::Create( | 148 ui::ClientCompositorFrameSink::Create(std::move(context_provider), | 
| 125 frame_sink_id_, std::move(context_provider), | 149 gpu_memory_buffer_manager, | 
| 126 gpu_memory_buffer_manager, &compositor_frame_sink_binding); | 150 &compositor_frame_sink_binding); | 
| 127 AttachCompositorFrameSink(std::move(compositor_frame_sink_binding)); | 151 AttachCompositorFrameSink(std::move(compositor_frame_sink_binding)); | 
| 128 callback.Run(std::move(compositor_frame_sink)); | 152 callback.Run(std::move(compositor_frame_sink)); | 
| 129 } | 153 } | 
| 130 | 154 | 
| 131 void WindowPortMus::AttachCompositorFrameSink( | 155 void WindowPortMus::AttachCompositorFrameSink( | 
| 132 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> | 156 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> | 
| 133 compositor_frame_sink_binding) { | 157 compositor_frame_sink_binding) { | 
| 134 window_tree_client_->AttachCompositorFrameSink( | 158 window_tree_client_->AttachCompositorFrameSink( | 
| 135 server_id(), compositor_frame_sink_binding->TakeFrameSinkRequest(), | 159 server_id(), compositor_frame_sink_binding->TakeFrameSinkRequest(), | 
| 136 mojo::MakeProxy(compositor_frame_sink_binding->TakeFrameSinkClient())); | 160 mojo::MakeProxy(compositor_frame_sink_binding->TakeFrameSinkClient())); | 
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 // corresponding CompositorFrame or a deadline hits. | 338 // corresponding CompositorFrame or a deadline hits. | 
| 315 if (window_tree_client_->enable_surface_synchronization_ && | 339 if (window_tree_client_->enable_surface_synchronization_ && | 
| 316 frame_sink_id_.is_valid()) { | 340 frame_sink_id_.is_valid()) { | 
| 317 UpdatePrimarySurfaceInfo(); | 341 UpdatePrimarySurfaceInfo(); | 
| 318 } | 342 } | 
| 319 | 343 | 
| 320 return local_surface_id_; | 344 return local_surface_id_; | 
| 321 } | 345 } | 
| 322 | 346 | 
| 323 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 347 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 
| 348 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | |
| 349 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | |
| 324 primary_surface_info_ = surface_info; | 350 primary_surface_info_ = surface_info; | 
| 325 UpdateClientSurfaceEmbedder(); | 351 if (embeds_surface) { | 
| 352 UpdateClientSurfaceEmbedder(); | |
| 353 } else { | |
| 354 if (!ref_factory_) | |
| 
 
Fady Samuel
2017/05/16 10:26:41
what calls this?
 
Peng
2017/05/16 10:55:24
window_->layer()->SetShowPrimarySurface(surface_in
 
 | |
| 355 ref_factory_ = new StubSurfaceReferenceFactory(); | |
| 356 window_->layer()->SetBounds(gfx::Rect(window_->layer()->bounds().origin(), | |
| 357 surface_info.size_in_pixels())); | |
| 358 window_->layer()->SetShowPrimarySurface(surface_info, ref_factory_); | |
| 359 } | |
| 326 if (window_->delegate()) | 360 if (window_->delegate()) | 
| 327 window_->delegate()->OnWindowSurfaceChanged(surface_info); | 361 window_->delegate()->OnWindowSurfaceChanged(surface_info); | 
| 328 } | 362 } | 
| 329 | 363 | 
| 330 void WindowPortMus::SetFallbackSurfaceInfo( | 364 void WindowPortMus::SetFallbackSurfaceInfo( | 
| 331 const cc::SurfaceInfo& surface_info) { | 365 const cc::SurfaceInfo& surface_info) { | 
| 332 fallback_surface_info_ = surface_info; | 366 fallback_surface_info_ = surface_info; | 
| 333 UpdateClientSurfaceEmbedder(); | 367 UpdateClientSurfaceEmbedder(); | 
| 334 } | 368 } | 
| 335 | 369 | 
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 // TODO(sky): investigate to see if we need to compare data. In particular do | 549 // TODO(sky): investigate to see if we need to compare data. In particular do | 
| 516 // we ever have a case where changing a property cascades into changing the | 550 // we ever have a case where changing a property cascades into changing the | 
| 517 // same property? | 551 // same property? | 
| 518 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 552 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 
| 519 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 553 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 
| 520 std::move(data)); | 554 std::move(data)); | 
| 521 } | 555 } | 
| 522 | 556 | 
| 523 std::unique_ptr<cc::CompositorFrameSink> | 557 std::unique_ptr<cc::CompositorFrameSink> | 
| 524 WindowPortMus::CreateCompositorFrameSink() { | 558 WindowPortMus::CreateCompositorFrameSink() { | 
| 525 // TODO(penghuang): Implement it for Mus. | 559 // We only allow creating a compositor frame sink for a local window. | 
| 526 return nullptr; | 560 if (window_mus_type() != WindowMusType::LOCAL) | 
| 561 return nullptr; | |
| 562 | |
| 563 DCHECK(!frame_sink_id_.is_valid()); | |
| 564 window_tree_client_->GetFrameSinkId(server_id()); | |
| 
 
Fady Samuel
2017/05/16 10:28:03
Why do we need this?
 
Peng
2017/05/16 10:55:23
Right now, WS doesn't send frame sink id to client
 
 | |
| 565 | |
| 566 ui::ContextFactory* context_factory = | |
| 567 aura::Env::GetInstance()->context_factory(); | |
| 568 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> frame_sink_binding; | |
| 569 std::unique_ptr<ui::ClientCompositorFrameSink> frame_sink = | |
| 570 ui::ClientCompositorFrameSink::Create( | |
| 571 nullptr /* context_provider */, | |
| 572 context_factory->GetGpuMemoryBufferManager(), &frame_sink_binding); | |
| 573 frame_sink->SetSurfaceChangedCallback( | |
| 
 
Fady Samuel
2017/05/16 10:28:03
What is the purpose of this callback?
 
Peng
2017/05/16 10:55:23
The ClientCompositorFrameSink will generate new lo
 
 | |
| 574 base::Bind(&WindowPortMus::OnSurfaceChanged, weak_factory_.GetWeakPtr())); | |
| 575 AttachCompositorFrameSink(std::move(frame_sink_binding)); | |
| 576 return std::move(frame_sink); | |
| 527 } | 577 } | 
| 528 | 578 | 
| 529 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 579 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 
| 530 // TODO(penghuang): Implement it for Mus. | 580 // This method is only used by exo unittests which are not running against | 
| 581 // mus, so don't implement it now. | |
| 531 return cc::SurfaceId(); | 582 return cc::SurfaceId(); | 
| 532 } | 583 } | 
| 533 | 584 | 
| 534 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 585 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 
| 535 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 586 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 
| 536 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 587 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 
| 537 if (!embeds_surface || !window_tree_client_->enable_surface_synchronization_) | 588 if (embeds_surface && !window_tree_client_->enable_surface_synchronization_) | 
| 538 return; | 589 return; | 
| 539 | 590 | 
| 540 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 591 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 
| 541 return; | 592 return; | 
| 542 | 593 | 
| 543 SetPrimarySurfaceInfo( | 594 SetPrimarySurfaceInfo( | 
| 544 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 595 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 
| 545 ScaleFactorForDisplay(window_), last_surface_size_)); | 596 ScaleFactorForDisplay(window_), last_surface_size_)); | 
| 546 } | 597 } | 
| 547 | 598 | 
| 548 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 599 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 
| 549 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 600 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 
| 550 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 601 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 
| 551 if (!embeds_surface) | 602 if (!embeds_surface) | 
| 552 return; | 603 return; | 
| 553 | 604 | 
| 554 if (!client_surface_embedder_) { | 605 if (!client_surface_embedder_) { | 
| 555 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 606 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 
| 556 window_, window_tree_client_->normal_client_area_insets_); | 607 window_, window_tree_client_->normal_client_area_insets_); | 
| 557 } | 608 } | 
| 558 | 609 | 
| 559 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 610 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 
| 560 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 611 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 
| 561 } | 612 } | 
| 562 | 613 | 
| 614 void WindowPortMus::OnSurfaceChanged(const cc::LocalSurfaceId& local_surface_id, | |
| 
 
Fady Samuel
2017/05/16 10:26:42
I'm confused about when this happens then...
 
Peng
2017/05/16 10:55:23
See line 103 at https://codereview.chromium.org/28
 
 | |
| 615 const gfx::Size& surface_size) { | |
| 616 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); | |
| 617 local_surface_id_ = local_surface_id; | |
| 618 last_surface_size_ = surface_size; | |
| 619 UpdatePrimarySurfaceInfo(); | |
| 620 } | |
| 621 | |
| 563 } // namespace aura | 622 } // namespace aura | 
| OLD | NEW |