| 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 460 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 | 539 // 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 | 540 // we ever have a case where changing a property cascades into changing the |
| 517 // same property? | 541 // same property? |
| 518 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 542 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 519 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, | 543 window_tree_client_->OnWindowMusPropertyChanged(this, key, old_value, |
| 520 std::move(data)); | 544 std::move(data)); |
| 521 } | 545 } |
| 522 | 546 |
| 523 std::unique_ptr<cc::CompositorFrameSink> | 547 std::unique_ptr<cc::CompositorFrameSink> |
| 524 WindowPortMus::CreateCompositorFrameSink() { | 548 WindowPortMus::CreateCompositorFrameSink() { |
| 525 // TODO(penghuang): Implement it for Mus. | 549 // We only allow creating a compositor frame sink for a local window. |
| 526 return nullptr; | 550 if (window_mus_type() != WindowMusType::LOCAL) |
| 551 return nullptr; |
| 552 |
| 553 DCHECK(!frame_sink_id_.is_valid()); |
| 554 frame_sink_id_ = window_tree_client_->GetFrameSinkId(server_id()); |
| 555 |
| 556 ui::ContextFactory* context_factory = |
| 557 aura::Env::GetInstance()->context_factory(); |
| 558 std::unique_ptr<ui::ClientCompositorFrameSinkBinding> frame_sink_binding; |
| 559 std::unique_ptr<ui::ClientCompositorFrameSink> frame_sink = |
| 560 ui::ClientCompositorFrameSink::Create( |
| 561 frame_sink_id_, nullptr /* context_provider */, |
| 562 context_factory->GetGpuMemoryBufferManager(), &frame_sink_binding); |
| 563 // ui::ClientCompositorFrameSink allocates local surface id if surface |
| 564 // synchronization is disabled, so we need set the SurfaceChangedCallback |
| 565 // for updating primary surface. |
| 566 if (!window_tree_client_->enable_surface_synchronization_) { |
| 567 frame_sink->SetSurfaceChangedCallback(base::Bind( |
| 568 &WindowPortMus::OnSurfaceChanged, weak_factory_.GetWeakPtr())); |
| 569 } |
| 570 AttachCompositorFrameSink(std::move(frame_sink_binding)); |
| 571 return std::move(frame_sink); |
| 527 } | 572 } |
| 528 | 573 |
| 529 cc::SurfaceId WindowPortMus::GetSurfaceId() const { | 574 cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| 530 // TODO(penghuang): Implement it for Mus. | 575 // TODO(penghuang): Implement it for Mus. |
| 531 return cc::SurfaceId(); | 576 return cc::SurfaceId(); |
| 532 } | 577 } |
| 533 | 578 |
| 534 void WindowPortMus::UpdatePrimarySurfaceInfo() { | 579 void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| 535 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || | 580 bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| 536 window_mus_type() == WindowMusType::EMBED_IN_OWNER; | 581 window_mus_type() == WindowMusType::EMBED_IN_OWNER; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 553 | 598 |
| 554 if (!client_surface_embedder_) { | 599 if (!client_surface_embedder_) { |
| 555 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( | 600 client_surface_embedder_ = base::MakeUnique<ClientSurfaceEmbedder>( |
| 556 window_, window_tree_client_->normal_client_area_insets_); | 601 window_, window_tree_client_->normal_client_area_insets_); |
| 557 } | 602 } |
| 558 | 603 |
| 559 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); | 604 client_surface_embedder_->SetPrimarySurfaceInfo(primary_surface_info_); |
| 560 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); | 605 client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| 561 } | 606 } |
| 562 | 607 |
| 608 void WindowPortMus::OnSurfaceChanged(const cc::SurfaceId& surface_id, |
| 609 const gfx::Size& surface_size) { |
| 610 DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| 611 DCHECK(!window_tree_client_->enable_surface_synchronization_); |
| 612 DCHECK_EQ(surface_id.frame_sink_id(), frame_sink_id_); |
| 613 if (!ref_factory_) |
| 614 ref_factory_ = new StubSurfaceReferenceFactory(); |
| 615 |
| 616 window_->layer()->SetBounds( |
| 617 gfx::Rect(window_->layer()->bounds().origin(), surface_size)); |
| 618 window_->layer()->SetShowPrimarySurface( |
| 619 cc::SurfaceInfo(surface_id, 1.0f, surface_size), ref_factory_); |
| 620 } |
| 621 |
| 563 } // namespace aura | 622 } // namespace aura |
| OLD | NEW |