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 { | |
|
Fady Samuel
2017/05/18 16:48:51
Remove this.
Peng
2017/05/18 19:37:59
Done.
| |
| 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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 262 ServerChangeData data; | 286 ServerChangeData data; |
| 263 data.property_name = property_name; | 287 data.property_name = property_name; |
| 264 ScopedServerChange change(this, ServerChangeType::PROPERTY, data); | 288 ScopedServerChange change(this, ServerChangeType::PROPERTY, data); |
| 265 GetPropertyConverter()->SetPropertyFromTransportValue(window_, property_name, | 289 GetPropertyConverter()->SetPropertyFromTransportValue(window_, property_name, |
| 266 property_data); | 290 property_data); |
| 267 } | 291 } |
| 268 | 292 |
| 269 void WindowPortMus::SetFrameSinkIdFromServer( | 293 void WindowPortMus::SetFrameSinkIdFromServer( |
| 270 const cc::FrameSinkId& frame_sink_id) { | 294 const cc::FrameSinkId& frame_sink_id) { |
| 271 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 295 DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 272 window_mus_type() == WindowMusType::EMBED_IN_OWNER); | 296 window_mus_type() == WindowMusType::EMBED_IN_OWNER || |
| 297 window_mus_type() == WindowMusType::LOCAL); | |
| 273 frame_sink_id_ = frame_sink_id; | 298 frame_sink_id_ = frame_sink_id; |
| 274 UpdatePrimarySurfaceInfo(); | 299 UpdatePrimarySurfaceInfo(); |
| 275 } | 300 } |
| 276 | 301 |
| 277 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( | 302 const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( |
| 278 const gfx::Size& surface_size) { | 303 const gfx::Size& surface_size) { |
| 279 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) | 304 if (last_surface_size_ == surface_size && local_surface_id_.is_valid()) |
| 280 return local_surface_id_; | 305 return local_surface_id_; |
| 281 | 306 |
| 282 local_surface_id_ = local_surface_id_allocator_.GenerateId(); | 307 local_surface_id_ = local_surface_id_allocator_.GenerateId(); |
| 283 last_surface_size_ = surface_size; | 308 last_surface_size_ = surface_size; |
| 284 | 309 |
| 285 // If surface synchronization is enabled and the FrameSinkId is available, | 310 // If surface synchronization is enabled and the FrameSinkId is available, |
| 286 // then immediately embed the SurfaceId. The newly generated frame by the | 311 // then immediately embed the SurfaceId. The newly generated frame by the |
| 287 // embedder will block in the display compositor until the child submits a | 312 // embedder will block in the display compositor until the child submits a |
| 288 // corresponding CompositorFrame or a deadline hits. | 313 // corresponding CompositorFrame or a deadline hits. |
| 289 if (window_tree_client_->enable_surface_synchronization_ && | 314 if (window_tree_client_->enable_surface_synchronization_ && |
| 290 frame_sink_id_.is_valid()) { | 315 frame_sink_id_.is_valid()) { |
| 291 UpdatePrimarySurfaceInfo(); | 316 UpdatePrimarySurfaceInfo(); |
| 292 } | 317 } |
| 293 | 318 |
| 294 return local_surface_id_; | 319 return local_surface_id_; |
| 295 } | 320 } |
| 296 | 321 |
| 297 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { | 322 void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { |
| 323 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | |
| 324 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | |
| 298 primary_surface_info_ = surface_info; | 325 primary_surface_info_ = surface_info; |
| 299 UpdateClientSurfaceEmbedder(); | 326 if (embeds_surface) { |
| 327 UpdateClientSurfaceEmbedder(); | |
|
Fady Samuel
2017/05/18 16:48:51
Undo this change. Always use ClientSurfaceEmbedder
Peng
2017/05/18 19:37:59
Done.
| |
| 328 } else { | |
| 329 if (!ref_factory_) | |
| 330 ref_factory_ = new StubSurfaceReferenceFactory(); | |
| 331 window_->layer()->SetBounds(gfx::Rect(window_->layer()->bounds().origin(), | |
| 332 surface_info.size_in_pixels())); | |
| 333 window_->layer()->SetShowPrimarySurface(surface_info, ref_factory_); | |
| 334 } | |
| 300 if (window_->delegate()) | 335 if (window_->delegate()) |
| 301 window_->delegate()->OnWindowSurfaceChanged(surface_info); | 336 window_->delegate()->OnWindowSurfaceChanged(surface_info); |
| 302 } | 337 } |
| 303 | 338 |
| 304 void WindowPortMus::SetFallbackSurfaceInfo( | 339 void WindowPortMus::SetFallbackSurfaceInfo( |
| 305 const cc::SurfaceInfo& surface_info) { | 340 const cc::SurfaceInfo& surface_info) { |
| 306 fallback_surface_info_ = surface_info; | 341 fallback_surface_info_ = surface_info; |
| 307 UpdateClientSurfaceEmbedder(); | 342 UpdateClientSurfaceEmbedder(); |
| 308 } | 343 } |
| 309 | 344 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 // TODO(sky): investigate to see if we need to compare data. In particular do | 524 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 490 // we ever have a case where changing a property cascades into changing the | 525 // we ever have a case where changing a property cascades into changing the |
| 491 // same property? | 526 // same property? |
| 492 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 527 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 493 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 528 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 494 std::move(data)); | 529 std::move(data)); |
| 495 } | 530 } |
| 496 | 531 |
| 497 std::unique_ptr<cc::CompositorFrameSink> | 532 std::unique_ptr<cc::CompositorFrameSink> |
| 498 WindowPortMus::CreateCompositorFrameSink() { | 533 WindowPortMus::CreateCompositorFrameSink() { |
| 499 // TODO(penghuang): Implement it for Mus. | 534 // We only allow creating a compositor frame sink for a local window. |
| 500 return nullptr; | 535 if (window_mus_type() != WindowMusType::LOCAL) |
| 536 return nullptr; | |
| 537 | |
| 538 DCHECK(!frame_sink_id_.is_valid()); | |
| 539 window_tree_client_->GetFrameSinkId(server_id()); | |
| 540 | |
| 541 ui::ContextFactory* context_factory = | |
| 542 aura::Env::GetInstance()->context_factory(); | |
| 543 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> frame_sink_binding; | |
| 544 // The compositor frame sink is for a local window, so we don't need surface | |
| 545 // synchronization. | |
| 546 const bool enable_surface_synchronization = false; | |
| 547 std::unique_ptr<ui::ClientCompositorFrameSink> frame_sink = | |
| 548 ui::ClientCompositorFrameSink::Create( | |
| 549 nullptr /* context_provider */, | |
| 550 context_factory->GetGpuMemoryBufferManager(), &frame_sink_binding, | |
| 551 enable_surface_synchronization); | |
| 552 frame_sink->SetSurfaceChangedCallback( | |
| 553 base::Bind(&WindowPortMus::OnSurfaceChanged, weak_factory_.GetWeakPtr())); | |
|
Fady Samuel
2017/05/18 16:48:51
This is fundamentally not compatible with surface
Peng
2017/05/18 19:37:59
Done.
| |
| 554 AttachCompositorFrameSink(std::move(frame_sink_binding)); | |
| 555 return std::move(frame_sink); | |
| 501 } | 556 } |
| 502 | 557 |
| 503 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 558 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| 504 // TODO(penghuang): Implement it for Mus. | 559 // This method is only used by exo unittests which are not running against |
| 560 // mus, so don't implement it now. | |
| 505 return cc::SurfaceId(); | 561 return cc::SurfaceId(); |
| 506 } | 562 } |
| 507 | 563 |
| 508 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 564 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| 509 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 565 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 510 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 566 window_mus_type() == WindowMusType::EMBED_IN_OWNER; |
| 511 if (!embeds_surface || !window_tree_client_->enable_surface_synchronization_) | 567 if (embeds_surface && !window_tree_client_->enable_surface_synchronization_) |
|
Fady Samuel
2017/05/18 16:48:51
Undo this?
Peng
2017/05/18 19:37:59
Done.
| |
| 512 return; | 568 return; |
| 513 | 569 |
| 514 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) | 570 if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| 515 return; | 571 return; |
| 516 | 572 |
| 517 SetPrimarySurfaceInfo( | 573 SetPrimarySurfaceInfo( |
| 518 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), | 574 cc::SurfaceInfo(cc::SurfaceId(frame_sink_id_, local_surface_id_), |
| 519 ScaleFactorForDisplay(window_), last_surface_size_)); | 575 ScaleFactorForDisplay(window_), last_surface_size_)); |
| 520 } | 576 } |
| 521 | 577 |
| 522 void WindowPortMus::UpdateClientSurfaceEmbedder() { | 578 void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| 523 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 579 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 524 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 580 window_mus_type() == WindowMusType::EMBED_IN_OWNER; |
| 525 if (!embeds_surface) | 581 if (!embeds_surface) |
| 526 return; | 582 return; |
| 527 | 583 |
| 528 if (!client_surface_embedder_) { | 584 if (!client_surface_embedder_) { |
| 529 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 585 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 530 window_, window_tree_client_->normal_client_area_insets_); | 586 window_, window_tree_client_->normal_client_area_insets_); |
| 531 } | 587 } |
| 532 | 588 |
| 533 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 589 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 534 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 590 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 535 } | 591 } |
| 536 | 592 |
| 593 void WindowPortMus::OnSurfaceChanged(const cc::LocalSurfaceId& local_surface_id, | |
|
Fady Samuel
2017/05/18 16:48:51
Remove this.
Peng
2017/05/18 19:37:59
Done.
| |
| 594 const gfx::Size& surface_size) { | |
| 595 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); | |
| 596 local_surface_id_ = local_surface_id; | |
| 597 last_surface_size_ = surface_size; | |
| 598 UpdatePrimarySurfaceInfo(); | |
| 599 } | |
| 600 | |
| 537 } // namespace aura | 601 } // namespace aura |
| OLD | NEW |