Chromium Code Reviews| Index: ui/aura/mus/window_port_mus.cc |
| diff --git a/ui/aura/mus/window_port_mus.cc b/ui/aura/mus/window_port_mus.cc |
| index b946380ee01b382faa7ee45716b51182c7f698b6..ac611ae773e53ffae2532d0b7e266e14c23c705c 100644 |
| --- a/ui/aura/mus/window_port_mus.cc |
| +++ b/ui/aura/mus/window_port_mus.cc |
| @@ -5,9 +5,12 @@ |
| #include "ui/aura/mus/window_port_mus.h" |
| #include "base/memory/ptr_util.h" |
| +#include "cc/output/context_provider.h" |
| #include "ui/aura/client/aura_constants.h" |
| #include "ui/aura/client/transient_window_client.h" |
| +#include "ui/aura/env.h" |
| #include "ui/aura/mus/client_surface_embedder.h" |
| +#include "ui/aura/mus/mus_context_factory.h" |
| #include "ui/aura/mus/property_converter.h" |
| #include "ui/aura/mus/window_tree_client.h" |
| #include "ui/aura/mus/window_tree_client_delegate.h" |
| @@ -28,6 +31,25 @@ float ScaleFactorForDisplay(Window* window) { |
| ->GetDisplayNearestWindow(window) |
| .device_scale_factor(); |
| } |
| + |
| +// TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference |
| +// work is complete. |
| +class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { |
|
Fady Samuel
2017/05/18 16:48:51
Remove this.
Peng
2017/05/18 19:37:59
Done.
|
| + public: |
| + StubSurfaceReferenceFactory() = default; |
| + |
| + // cc::SurfaceReferenceFactory: |
| + base::Closure CreateReference( |
| + cc::SurfaceReferenceOwner* owner, |
| + const cc::SurfaceId& surface_id) const override { |
| + return base::Closure(); |
| + } |
| + |
| + protected: |
| + ~StubSurfaceReferenceFactory() override = default; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); |
| +}; |
| } // namespace |
| WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
| @@ -41,7 +63,9 @@ WindowMus* WindowMus::Get(Window* window) { |
| WindowPortMus::WindowPortMus(WindowTreeClient* client, |
| WindowMusType window_mus_type) |
| - : WindowMus(window_mus_type), window_tree_client_(client) {} |
| + : WindowMus(window_mus_type), |
| + window_tree_client_(client), |
| + weak_factory_(this) {} |
| WindowPortMus::~WindowPortMus() { |
| client_surface_embedder_.reset(); |
| @@ -269,7 +293,8 @@ void WindowPortMus::SetPropertyFromServer( |
| void WindowPortMus::SetFrameSinkIdFromServer( |
| const cc::FrameSinkId& frame_sink_id) { |
| DCHECK(window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| - window_mus_type() == WindowMusType::EMBED_IN_OWNER); |
| + window_mus_type() == WindowMusType::EMBED_IN_OWNER || |
| + window_mus_type() == WindowMusType::LOCAL); |
| frame_sink_id_ = frame_sink_id; |
| UpdatePrimarySurfaceInfo(); |
| } |
| @@ -295,8 +320,18 @@ const cc::LocalSurfaceId& WindowPortMus::GetOrAllocateLocalSurfaceId( |
| } |
| void WindowPortMus::SetPrimarySurfaceInfo(const cc::SurfaceInfo& surface_info) { |
| + bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| + window_mus_type() == WindowMusType::EMBED_IN_OWNER; |
| primary_surface_info_ = surface_info; |
| - UpdateClientSurfaceEmbedder(); |
| + if (embeds_surface) { |
| + UpdateClientSurfaceEmbedder(); |
|
Fady Samuel
2017/05/18 16:48:51
Undo this change. Always use ClientSurfaceEmbedder
Peng
2017/05/18 19:37:59
Done.
|
| + } else { |
| + if (!ref_factory_) |
| + ref_factory_ = new StubSurfaceReferenceFactory(); |
| + window_->layer()->SetBounds(gfx::Rect(window_->layer()->bounds().origin(), |
| + surface_info.size_in_pixels())); |
| + window_->layer()->SetShowPrimarySurface(surface_info, ref_factory_); |
| + } |
| if (window_->delegate()) |
| window_->delegate()->OnWindowSurfaceChanged(surface_info); |
| } |
| @@ -496,19 +531,40 @@ void WindowPortMus::OnPropertyChanged(const void* key, |
| std::unique_ptr<cc::CompositorFrameSink> |
| WindowPortMus::CreateCompositorFrameSink() { |
| - // TODO(penghuang): Implement it for Mus. |
| - return nullptr; |
| + // We only allow creating a compositor frame sink for a local window. |
| + if (window_mus_type() != WindowMusType::LOCAL) |
| + return nullptr; |
| + |
| + DCHECK(!frame_sink_id_.is_valid()); |
| + window_tree_client_->GetFrameSinkId(server_id()); |
| + |
| + ui::ContextFactory* context_factory = |
| + aura::Env::GetInstance()->context_factory(); |
| + std::unique_ptr<ui::ClientCompositorFrameSinkBinding> frame_sink_binding; |
| + // The compositor frame sink is for a local window, so we don't need surface |
| + // synchronization. |
| + const bool enable_surface_synchronization = false; |
| + std::unique_ptr<ui::ClientCompositorFrameSink> frame_sink = |
| + ui::ClientCompositorFrameSink::Create( |
| + nullptr /* context_provider */, |
| + context_factory->GetGpuMemoryBufferManager(), &frame_sink_binding, |
| + enable_surface_synchronization); |
| + frame_sink->SetSurfaceChangedCallback( |
| + 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.
|
| + AttachCompositorFrameSink(std::move(frame_sink_binding)); |
| + return std::move(frame_sink); |
| } |
| cc::SurfaceId WindowPortMus::GetSurfaceId() const { |
| - // TODO(penghuang): Implement it for Mus. |
| + // This method is only used by exo unittests which are not running against |
| + // mus, so don't implement it now. |
| return cc::SurfaceId(); |
| } |
| void WindowPortMus::UpdatePrimarySurfaceInfo() { |
| bool embeds_surface = window_mus_type() == WindowMusType::TOP_LEVEL_IN_WM || |
| window_mus_type() == WindowMusType::EMBED_IN_OWNER; |
| - if (!embeds_surface || !window_tree_client_->enable_surface_synchronization_) |
| + 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.
|
| return; |
| if (!frame_sink_id_.is_valid() || !local_surface_id_.is_valid()) |
| @@ -534,4 +590,12 @@ void WindowPortMus::UpdateClientSurfaceEmbedder() { |
| client_surface_embedder_->SetFallbackSurfaceInfo(fallback_surface_info_); |
| } |
| +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.
|
| + const gfx::Size& surface_size) { |
| + DCHECK_EQ(window_mus_type(), WindowMusType::LOCAL); |
| + local_surface_id_ = local_surface_id; |
| + last_surface_size_ = surface_size; |
| + UpdatePrimarySurfaceInfo(); |
| +} |
| + |
| } // namespace aura |