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 8f7aa82d3847ae808b091b13292475694ff6680e..5dfe1a3a07b3e80dc5a0969b60d9f69099e1c704 100644 |
--- a/ui/aura/mus/window_port_mus.cc |
+++ b/ui/aura/mus/window_port_mus.cc |
@@ -4,6 +4,7 @@ |
#include "ui/aura/mus/window_port_mus.h" |
+#include "cc/surfaces/surface_reference_factory.h" |
#include "ui/aura/client/aura_constants.h" |
#include "ui/aura/client/transient_window_client.h" |
#include "ui/aura/mus/property_converter.h" |
@@ -16,6 +17,113 @@ |
#include "ui/aura/window_property.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 |
+ |
+// Used by WindowPortMus when it is embedding a client. Responsible for setting |
sky
2017/01/03 21:53:07
Can you move this into it's own .h/.cc?
mfomitchev
2017/01/03 22:28:50
Done.
|
+// up layers containing content from the client, parenting them to the window's |
+// layer, and updating them when the client submits new surfaces. |
+class EmbeddedContent { |
+ public: |
+ EmbeddedContent(Window* window); |
sky
2017/01/03 21:53:07
explicit
mfomitchev
2017/01/03 22:28:50
Done.
|
+ virtual ~EmbeddedContent(); |
sky
2017/01/03 21:53:07
Do you really need virtual?
mfomitchev
2017/01/03 22:28:50
Nope. Removed, thanks.
|
+ |
+ // Updates the surface layer and the clip layer based on the surface info. |
+ void UpdateSurface(const SurfaceInfo& surface_info); |
+ |
+ private: |
+ // The window which embeds the client. |
+ Window* window_; |
+ |
+ // Contains the client's content. |
+ std::unique_ptr<ui::Layer> surface_layer_; |
+ |
+ // Used for clipping the surface layer to the window bounds. |
+ std::unique_ptr<ui::Layer> clip_layer_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(EmbeddedContent); |
+}; |
+ |
+EmbeddedContent::EmbeddedContent(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); |
+} |
+ |
+EmbeddedContent::~EmbeddedContent() { |
+ window_->layer()->Remove(clip_layer_.get()); |
+} |
+ |
+void EmbeddedContent::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, |
+ surface_info.device_scale_factor, frame_size); |
+ |
+ surface_layer_->SetShowSurface( |
+ cc_surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); |
+} |
WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
@@ -255,10 +363,22 @@ void WindowPortMus::SetSurfaceIdFromServer( |
} |
} |
WindowPortMus* parent = Get(window_->parent()); |
+ // TODO(mfomitchev): This is unused. We probably don't need this. |
if (parent && parent->surface_id_handler_) { |
parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, |
&surface_info); |
} |
+ |
+ // The fact that SetSurfaceIdFromServer was called means that this window |
+ // corresponds to an embedded client. |
+ if (!embedded_content_ && surface_info) |
+ embedded_content_ = base::MakeUnique<EmbeddedContent>(window_); |
+ |
+ if (surface_info) |
+ embedded_content_->UpdateSurface(*surface_info.get()); |
+ else |
+ embedded_content_.reset(); |
+ |
surface_info_ = std::move(surface_info); |
} |