Chromium Code Reviews| Index: ui/aura/mus/client_surface_embedder.cc |
| diff --git a/ui/aura/mus/client_surface_embedder.cc b/ui/aura/mus/client_surface_embedder.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..a37bad468c3bf0f1e618a800964befedd353928f |
| --- /dev/null |
| +++ b/ui/aura/mus/client_surface_embedder.cc |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ui/aura/mus/client_surface_embedder.h" |
| + |
| +#include "cc/surfaces/surface_reference_factory.h" |
| +#include "ui/aura/mus/surface_id_handler.h" |
| +#include "ui/aura/window.h" |
| + |
| +namespace aura { |
| +namespace { |
| + |
| +// TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference |
| +// work is complete. |
| +class StubSurfaceReference : public cc::SurfaceReferenceBase { |
| + public: |
| + StubSurfaceReference(scoped_refptr<const cc::SurfaceReferenceFactory> factory) |
| + : cc::SurfaceReferenceBase(factory) {} |
| + |
| + ~StubSurfaceReference() override { Destroy(); } |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(StubSurfaceReference); |
| +}; |
| + |
| +class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { |
| + public: |
| + StubSurfaceReferenceFactory() = default; |
| + |
| + // cc::SurfaceReferenceFactory: |
| + std::unique_ptr<cc::SurfaceReferenceBase> CreateReference( |
| + cc::SurfaceReferenceOwner* owner, |
| + const cc::SurfaceId& surface_id) const override { |
| + return base::MakeUnique<StubSurfaceReference>(make_scoped_refptr(this)); |
| + } |
| + |
| + protected: |
| + ~StubSurfaceReferenceFactory() override = default; |
| + |
| + private: |
| + // cc::SurfaceReferenceFactory: |
| + void DestroyReference(cc::SurfaceReferenceBase* surface_ref) const override {} |
| + |
| + DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); |
| +}; |
| +} // namespace |
| + |
| +ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window) : window_(window) { |
| + surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); |
| + surface_layer_->SetVisible(true); |
| + // The frame provided by the parent window->layer() needs to show through |
| + // the surface layer. |
| + surface_layer_->SetFillsBoundsOpaquely(false); |
| + |
| + clip_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_NOT_DRAWN); |
| + clip_layer_->SetFillsBoundsOpaquely(false); |
| + |
| + clip_layer_->Add(surface_layer_.get()); |
| + window_->layer()->Add(clip_layer_.get()); |
| + |
| + // Window's layer may contain content from this client (the embedder), e.g. |
| + // this is the case with window decorations provided by Window Manager. |
| + // This content should appear underneath the content of the embedded client. |
| + window_->layer()->StackAtTop(clip_layer_.get()); |
| + |
| + // We can't set this on window's layer, because that would clip the window |
| + // shadow. |
| + clip_layer_->SetMasksToBounds(true); |
| +} |
| + |
| +ClientSurfaceEmbedder::~ClientSurfaceEmbedder() { |
| + window_->layer()->Remove(clip_layer_.get()); |
|
sky
2017/01/03 23:25:05
I believe the destruction order is:
~Window
De
mfomitchev
2017/01/03 23:41:12
Would it be okay to do port_owner_.reset() before
|
| +} |
| + |
| +void ClientSurfaceEmbedder::UpdateSurface(const SurfaceInfo& surface_info) { |
| + // TODO(mfomitchev): Currently the frame size may not match the window size. |
| + // In the future the surface id will be created by Ash (and used with the |
| + // surface layer) when the window resize happens, which will ensure that the |
| + // surface size matches the window size (unless a timeout occurs). |
| + gfx::Size frame_size = surface_info.frame_size; |
| + surface_layer_->SetBounds( |
| + gfx::Rect(0, 0, frame_size.width(), frame_size.height())); |
| + // Clip to window bounds. |
| + clip_layer_->SetBounds( |
| + gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); |
| + |
| + // TODO(mfomitchev, samans): Get rid of Aura's SurfaceInfo. |
| + cc::SurfaceInfo cc_surface_info(surface_info.surface_id, |
|
Fady Samuel
2017/01/04 12:34:18
This should be fixed now. Please rebase.
mfomitchev
2017/01/04 20:45:30
Done.
|
| + surface_info.device_scale_factor, frame_size); |
| + |
| + surface_layer_->SetShowSurface( |
| + cc_surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); |
| +} |
| + |
| +} // namespace aura |