Commit a86d0169 authored by mfomitchev's avatar mfomitchev Committed by Commit bot

Mustash: Ensure surfaces submitted to Mus by WM and embedders contain Surfaces...

Mustash: Ensure surfaces submitted to Mus by WM and embedders contain Surfaces with embeded content.

- Use SurfaceLayers in embedders and Window Manager to properly position the
  embedded content in the layer tree.

- WM no longer uses underlay surfaces for window decorations. Instead they are
  submitted to Mus as part of the WM's surface.

- FrameGenerator now only creates SurfaceDrawQuad for the top-level window
  rather than recursively creating SurfaceDrawQuad for all windows in the
  window tree, since all surfaces are now part of the tree rooted at the
  surface of the top-level window.

BUG=672943,669964

Review-Url: https://codereview.chromium.org/2580063002
Cr-Commit-Position: refs/heads/master@{#441492}
parent 86dfcea3
...@@ -271,6 +271,13 @@ ServerWindow* Display::GetRootWindow() { ...@@ -271,6 +271,13 @@ ServerWindow* Display::GetRootWindow() {
return root_.get(); return root_.get();
} }
ServerWindow* Display::GetActiveRootWindow() {
WindowManagerDisplayRoot* display_root = GetActiveWindowManagerDisplayRoot();
if (display_root)
return display_root->root();
return nullptr;
}
void Display::OnAcceleratedWidgetAvailable() { void Display::OnAcceleratedWidgetAvailable() {
display_manager()->OnDisplayAcceleratedWidgetAvailable(this); display_manager()->OnDisplayAcceleratedWidgetAvailable(this);
InitWindowManagerDisplayRoots(); InitWindowManagerDisplayRoots();
......
...@@ -166,6 +166,7 @@ class Display : public PlatformDisplayDelegate, ...@@ -166,6 +166,7 @@ class Display : public PlatformDisplayDelegate,
// PlatformDisplayDelegate: // PlatformDisplayDelegate:
display::Display GetDisplay() override; display::Display GetDisplay() override;
ServerWindow* GetRootWindow() override; ServerWindow* GetRootWindow() override;
ServerWindow* GetActiveRootWindow() override;
void OnAcceleratedWidgetAvailable() override; void OnAcceleratedWidgetAvailable() override;
bool IsInHighContrastMode() override; bool IsInHighContrastMode() override;
void OnEvent(const ui::Event& event) override; void OnEvent(const ui::Event& event) override;
......
...@@ -130,7 +130,7 @@ cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( ...@@ -130,7 +130,7 @@ cc::CompositorFrame FrameGenerator::GenerateCompositorFrame(
render_pass->SetNew(render_pass_id, output_rect, output_rect, render_pass->SetNew(render_pass_id, output_rect, output_rect,
gfx::Transform()); gfx::Transform());
DrawWindowTree(render_pass.get(), root_window_, gfx::Vector2d(), 1.0f); DrawWindow(render_pass.get(), delegate_->GetActiveRootWindow());
cc::CompositorFrame frame; cc::CompositorFrame frame;
frame.render_pass_list.push_back(std::move(render_pass)); frame.render_pass_list.push_back(std::move(render_pass));
...@@ -155,41 +155,24 @@ cc::CompositorFrame FrameGenerator::GenerateCompositorFrame( ...@@ -155,41 +155,24 @@ cc::CompositorFrame FrameGenerator::GenerateCompositorFrame(
return frame; return frame;
} }
void FrameGenerator::DrawWindowTree( void FrameGenerator::DrawWindow(cc::RenderPass* pass, ServerWindow* window) {
cc::RenderPass* pass,
ServerWindow* window,
const gfx::Vector2d& parent_to_root_origin_offset,
float opacity) {
if (!window->visible()) if (!window->visible())
return; return;
const gfx::Rect absolute_bounds =
window->bounds() + parent_to_root_origin_offset;
const ServerWindow::Windows& children = window->children();
const float combined_opacity = opacity * window->opacity();
for (ServerWindow* child : base::Reversed(children)) {
DrawWindowTree(pass, child, absolute_bounds.OffsetFromOrigin(),
combined_opacity);
}
if (!window->compositor_frame_sink_manager() || if (!window->compositor_frame_sink_manager() ||
!window->compositor_frame_sink_manager()->ShouldDraw()) !window->compositor_frame_sink_manager()->ShouldDraw())
return; return;
cc::SurfaceId underlay_surface_id =
window->compositor_frame_sink_manager()->GetLatestSurfaceId(
mojom::CompositorFrameSinkType::UNDERLAY);
cc::SurfaceId default_surface_id = cc::SurfaceId default_surface_id =
window->compositor_frame_sink_manager()->GetLatestSurfaceId( window->compositor_frame_sink_manager()->GetLatestSurfaceId(
mojom::CompositorFrameSinkType::DEFAULT); mojom::CompositorFrameSinkType::DEFAULT);
if (!underlay_surface_id.is_valid() && !default_surface_id.is_valid()) if (!default_surface_id.is_valid())
return; return;
if (default_surface_id.is_valid()) {
gfx::Transform quad_to_target_transform; gfx::Transform quad_to_target_transform;
quad_to_target_transform.Translate(absolute_bounds.x(), quad_to_target_transform.Translate(window->bounds().x(),
absolute_bounds.y()); window->bounds().y());
cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState(); cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
...@@ -200,35 +183,12 @@ void FrameGenerator::DrawWindowTree( ...@@ -200,35 +183,12 @@ void FrameGenerator::DrawWindowTree(
quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */, quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */,
bounds_at_origin /* visible_layer_bounds */, bounds_at_origin /* visible_layer_bounds */,
bounds_at_origin /* clip_rect */, false /* is_clipped */, bounds_at_origin /* clip_rect */, false /* is_clipped */,
combined_opacity, SkBlendMode::kSrcOver, 0 /* sorting-context_id */); 1.0f /* opacity */, SkBlendMode::kSrcOver, 0 /* sorting-context_id */);
auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>(); auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
quad->SetAll(sqs, bounds_at_origin /* rect */, quad->SetAll(sqs, bounds_at_origin /* rect */,
gfx::Rect() /* opaque_rect */, gfx::Rect() /* opaque_rect */,
bounds_at_origin /* visible_rect */, true /* needs_blending*/, bounds_at_origin /* visible_rect */, true /* needs_blending*/,
default_surface_id); default_surface_id);
}
if (underlay_surface_id.is_valid()) {
const gfx::Rect underlay_absolute_bounds =
absolute_bounds - window->underlay_offset();
gfx::Transform quad_to_target_transform;
quad_to_target_transform.Translate(underlay_absolute_bounds.x(),
underlay_absolute_bounds.y());
cc::SharedQuadState* sqs = pass->CreateAndAppendSharedQuadState();
const gfx::Rect bounds_at_origin(
window->compositor_frame_sink_manager()->GetLatestFrameSize(
mojom::CompositorFrameSinkType::UNDERLAY));
sqs->SetAll(
quad_to_target_transform, bounds_at_origin.size() /* layer_bounds */,
bounds_at_origin /* visible_layer_bounds */,
bounds_at_origin /* clip_rect */, false /* is_clipped */,
combined_opacity, SkBlendMode::kSrcOver, 0 /* sorting-context_id */);
auto* quad = pass->CreateAndAppendDrawQuad<cc::SurfaceDrawQuad>();
quad->SetAll(sqs, bounds_at_origin /* rect */,
gfx::Rect() /* opaque_rect */,
bounds_at_origin /* visible_rect */, true /* needs_blending*/,
underlay_surface_id);
}
} }
cc::SurfaceId FrameGenerator::FindParentSurfaceId(ServerWindow* window) { cc::SurfaceId FrameGenerator::FindParentSurfaceId(ServerWindow* window) {
......
...@@ -80,12 +80,9 @@ class FrameGenerator : public ServerWindowTracker, ...@@ -80,12 +80,9 @@ class FrameGenerator : public ServerWindowTracker,
// Generates the CompositorFrame. // Generates the CompositorFrame.
cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect); cc::CompositorFrame GenerateCompositorFrame(const gfx::Rect& output_rect);
// DrawWindowTree recursively visits ServerWindows, creating a SurfaceDrawQuad // DrawWindow creates SurfaceDrawQuad for the provided ServerWindow and
// for each that lacks one. // appends it to the provided cc::RenderPass.
void DrawWindowTree(cc::RenderPass* pass, void DrawWindow(cc::RenderPass* pass, ServerWindow* window);
ServerWindow* window,
const gfx::Vector2d& parent_to_root_origin_offset,
float opacity);
// Finds the parent surface id for |window|. // Finds the parent surface id for |window|.
cc::SurfaceId FindParentSurfaceId(ServerWindow* window); cc::SurfaceId FindParentSurfaceId(ServerWindow* window);
......
...@@ -10,6 +10,8 @@ namespace ws { ...@@ -10,6 +10,8 @@ namespace ws {
class FrameGeneratorDelegate { class FrameGeneratorDelegate {
public: public:
// Returns the root window of the active user.
virtual ServerWindow* GetActiveRootWindow() = 0;
virtual bool IsInHighContrastMode() = 0; virtual bool IsInHighContrastMode() = 0;
protected: protected:
......
...@@ -52,8 +52,8 @@ class FrameGeneratorTest : public testing::Test { ...@@ -52,8 +52,8 @@ class FrameGeneratorTest : public testing::Test {
kRootDisplayId)) {} kRootDisplayId)) {}
~FrameGeneratorTest() override {} ~FrameGeneratorTest() override {}
// Calls DrawWindowTree() on |frame_generator_| // Calls DrawWindow() on |frame_generator_|
void DrawWindowTree(cc::RenderPass* pass); void DrawWindow(cc::RenderPass* pass);
ServerWindow* root_window() { return root_window_.get(); } ServerWindow* root_window() { return root_window_.get(); }
...@@ -75,14 +75,14 @@ class FrameGeneratorTest : public testing::Test { ...@@ -75,14 +75,14 @@ class FrameGeneratorTest : public testing::Test {
DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest); DISALLOW_COPY_AND_ASSIGN(FrameGeneratorTest);
}; };
void FrameGeneratorTest::DrawWindowTree(cc::RenderPass* pass) { void FrameGeneratorTest::DrawWindow(cc::RenderPass* pass) {
frame_generator_->DrawWindowTree(pass, root_window_.get(), gfx::Vector2d(), frame_generator_->DrawWindow(pass, root_window_.get());
1.0f);
} }
void FrameGeneratorTest::SetUp() { void FrameGeneratorTest::SetUp() {
testing::Test::SetUp(); testing::Test::SetUp();
frame_generator_delegate_ = base::MakeUnique<TestFrameGeneratorDelegate>(); frame_generator_delegate_ =
base::MakeUnique<TestFrameGeneratorDelegate>(root_window_.get());
PlatformDisplayInitParams init_params; PlatformDisplayInitParams init_params;
frame_generator_ = base::MakeUnique<FrameGenerator>( frame_generator_ = base::MakeUnique<FrameGenerator>(
frame_generator_delegate_.get(), root_window_.get()); frame_generator_delegate_.get(), root_window_.get());
...@@ -97,51 +97,23 @@ void FrameGeneratorTest::TearDown() { ...@@ -97,51 +97,23 @@ void FrameGeneratorTest::TearDown() {
} }
// Tests correctness of the SharedQuadStateList generated by // Tests correctness of the SharedQuadStateList generated by
// FrameGenerator::DrawWindowTree(). // FrameGenerator::DrawWindow().
TEST_F(FrameGeneratorTest, DrawWindowTree) { TEST_F(FrameGeneratorTest, DrawWindow) {
ServerWindow child_window(test_window_delegate(), WindowId(1, 1)); ServerWindow child_window(test_window_delegate(), WindowId(1, 1));
root_window()->Add(&child_window); root_window()->Add(&child_window);
InitWindow(&child_window); InitWindow(&child_window);
const float root_opacity = .5f;
const float child_opacity = .4f; const float child_opacity = .4f;
root_window()->SetOpacity(root_opacity);
child_window.SetOpacity(child_opacity); child_window.SetOpacity(child_opacity);
std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create(); std::unique_ptr<cc::RenderPass> render_pass = cc::RenderPass::Create();
DrawWindowTree(render_pass.get()); DrawWindow(render_pass.get());
cc::SharedQuadStateList* quad_state_list = cc::SharedQuadStateList* quad_state_list =
&render_pass->shared_quad_state_list; &render_pass->shared_quad_state_list;
// Both child and root have a DEFAULT Surface and no underlay Surfaces, so EXPECT_EQ(1u, quad_state_list->size());
// there should be two SharedQuadStates in the list.
EXPECT_EQ(2u, quad_state_list->size());
cc::SharedQuadState* root_sqs = quad_state_list->back(); cc::SharedQuadState* root_sqs = quad_state_list->back();
cc::SharedQuadState* child_sqs = quad_state_list->front(); // Opacity should always be 1.
EXPECT_EQ(root_opacity, root_sqs->opacity); EXPECT_EQ(1.0f, root_sqs->opacity);
// Child's SharedQuadState contains the effective opacity of the child layer,
// which should be a product of the child and the parent opacity.
EXPECT_EQ(child_opacity * root_opacity, child_sqs->opacity);
// Pretend to create the UNDERLAY Surface for the child window, and confirm
// that this creates an extra SharedQuadState in the CompositorFrame.
child_window.GetOrCreateCompositorFrameSinkManager()->SetLatestSurfaceInfo(
mojom::CompositorFrameSinkType::UNDERLAY,
cc::SurfaceInfo(
cc::SurfaceId(
cc::FrameSinkId(WindowIdToTransportId(child_window.id()),
static_cast<uint32_t>(
mojom::CompositorFrameSinkType::UNDERLAY)),
cc::LocalFrameId(1u, kArbitraryToken)),
1.0f, gfx::Size(100, 100)));
render_pass = cc::RenderPass::Create();
DrawWindowTree(render_pass.get());
quad_state_list = &render_pass->shared_quad_state_list;
EXPECT_EQ(3u, quad_state_list->size());
auto it = quad_state_list->begin();
EXPECT_EQ(child_opacity * root_opacity, (*it)->opacity);
EXPECT_EQ(child_opacity * root_opacity, (*++it)->opacity);
EXPECT_EQ(root_opacity, (*++it)->opacity);
} }
} // namespace test } // namespace test
......
...@@ -248,6 +248,10 @@ void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() { ...@@ -248,6 +248,10 @@ void PlatformDisplayDefault::OnAcceleratedWidgetDestroyed() {
void PlatformDisplayDefault::OnActivationChanged(bool active) {} void PlatformDisplayDefault::OnActivationChanged(bool active) {}
ServerWindow* PlatformDisplayDefault::GetActiveRootWindow() {
return delegate_->GetActiveRootWindow();
}
bool PlatformDisplayDefault::IsInHighContrastMode() { bool PlatformDisplayDefault::IsInHighContrastMode() {
return delegate_ ? delegate_->IsInHighContrastMode() : false; return delegate_ ? delegate_->IsInHighContrastMode() : false;
} }
......
...@@ -68,6 +68,7 @@ class PlatformDisplayDefault : public PlatformDisplay, ...@@ -68,6 +68,7 @@ class PlatformDisplayDefault : public PlatformDisplay,
void OnActivationChanged(bool active) override; void OnActivationChanged(bool active) override;
// FrameGeneratorDelegate: // FrameGeneratorDelegate:
ServerWindow* GetActiveRootWindow() override;
bool IsInHighContrastMode() override; bool IsInHighContrastMode() override;
const int64_t display_id_; const int64_t display_id_;
......
...@@ -28,6 +28,9 @@ class PlatformDisplayDelegate { ...@@ -28,6 +28,9 @@ class PlatformDisplayDelegate {
// Returns the root window of this display. // Returns the root window of this display.
virtual ServerWindow* GetRootWindow() = 0; virtual ServerWindow* GetRootWindow() = 0;
// Returns the root window of the active user.
virtual ServerWindow* GetActiveRootWindow() = 0;
// Called once when the AcceleratedWidget is available for drawing. // Called once when the AcceleratedWidget is available for drawing.
virtual void OnAcceleratedWidgetAvailable() = 0; virtual void OnAcceleratedWidgetAvailable() = 0;
......
...@@ -29,9 +29,7 @@ bool ServerWindowCompositorFrameSinkManager::ShouldDraw() { ...@@ -29,9 +29,7 @@ bool ServerWindowCompositorFrameSinkManager::ShouldDraw() {
return true; return true;
waiting_for_initial_frames_ = !IsCompositorFrameSinkReadyAndNonEmpty( waiting_for_initial_frames_ = !IsCompositorFrameSinkReadyAndNonEmpty(
mojom::CompositorFrameSinkType::DEFAULT) || mojom::CompositorFrameSinkType::DEFAULT);
!IsCompositorFrameSinkReadyAndNonEmpty(
mojom::CompositorFrameSinkType::UNDERLAY);
return !waiting_for_initial_frames_; return !waiting_for_initial_frames_;
} }
......
...@@ -109,6 +109,8 @@ class ServerWindowCompositorFrameSinkManager { ...@@ -109,6 +109,8 @@ class ServerWindowCompositorFrameSinkManager {
TypeToCompositorFrameSinkMap type_to_compositor_frame_sink_map_; TypeToCompositorFrameSinkMap type_to_compositor_frame_sink_map_;
// TODO(mfomitchev): This is currently always false. Confirm if we still need
// this.
// While true the window is not drawn. This is initially true if the window // While true the window is not drawn. This is initially true if the window
// has the property |kWaitForUnderlay_Property|. This is set to false once // has the property |kWaitForUnderlay_Property|. This is set to false once
// the underlay and default surface have been set *and* their size is at // the underlay and default surface have been set *and* their size is at
......
...@@ -151,10 +151,16 @@ TestPlatformDisplayFactory::CreatePlatformDisplay( ...@@ -151,10 +151,16 @@ TestPlatformDisplayFactory::CreatePlatformDisplay(
// TestFrameGeneratorDelegate ------------------------------------------------- // TestFrameGeneratorDelegate -------------------------------------------------
TestFrameGeneratorDelegate::TestFrameGeneratorDelegate() {} TestFrameGeneratorDelegate::TestFrameGeneratorDelegate(
ServerWindow* root_window)
: root_window_(root_window) {}
TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {} TestFrameGeneratorDelegate::~TestFrameGeneratorDelegate() {}
ServerWindow* TestFrameGeneratorDelegate::GetActiveRootWindow() {
return root_window_;
}
bool TestFrameGeneratorDelegate::IsInHighContrastMode() { bool TestFrameGeneratorDelegate::IsInHighContrastMode() {
return false; return false;
} }
......
...@@ -285,13 +285,16 @@ class TestPlatformDisplayFactory : public PlatformDisplayFactory { ...@@ -285,13 +285,16 @@ class TestPlatformDisplayFactory : public PlatformDisplayFactory {
// A stub implementation of FrameGeneratorDelegate. // A stub implementation of FrameGeneratorDelegate.
class TestFrameGeneratorDelegate : public FrameGeneratorDelegate { class TestFrameGeneratorDelegate : public FrameGeneratorDelegate {
public: public:
TestFrameGeneratorDelegate(); TestFrameGeneratorDelegate(ServerWindow* root_window);
~TestFrameGeneratorDelegate() override; ~TestFrameGeneratorDelegate() override;
// FrameGeneratorDelegate: // FrameGeneratorDelegate:
ServerWindow* GetActiveRootWindow() override;
bool IsInHighContrastMode() override; bool IsInHighContrastMode() override;
private: private:
ServerWindow* root_window_;
DISALLOW_COPY_AND_ASSIGN(TestFrameGeneratorDelegate); DISALLOW_COPY_AND_ASSIGN(TestFrameGeneratorDelegate);
}; };
......
...@@ -71,6 +71,8 @@ component("aura") { ...@@ -71,6 +71,8 @@ component("aura") {
"mus/capture_synchronizer.cc", "mus/capture_synchronizer.cc",
"mus/capture_synchronizer.h", "mus/capture_synchronizer.h",
"mus/capture_synchronizer_delegate.h", "mus/capture_synchronizer_delegate.h",
"mus/client_surface_embedder.cc",
"mus/client_surface_embedder.h",
"mus/drag_drop_controller_host.h", "mus/drag_drop_controller_host.h",
"mus/drag_drop_controller_mus.cc", "mus/drag_drop_controller_mus.cc",
"mus/drag_drop_controller_mus.h", "mus/drag_drop_controller_mus.h",
......
...@@ -6,6 +6,7 @@ include_rules = [ ...@@ -6,6 +6,7 @@ include_rules = [
"+cc/surfaces/surface_id_allocator.h", "+cc/surfaces/surface_id_allocator.h",
"+cc/surfaces/surface_info.h", "+cc/surfaces/surface_info.h",
"+cc/surfaces/surface_manager.h", "+cc/surfaces/surface_manager.h",
"+cc/surfaces/surface_reference_factory.h",
"+gpu/command_buffer/client/gpu_memory_buffer_manager.h", "+gpu/command_buffer/client/gpu_memory_buffer_manager.h",
"+gpu/ipc/client/gpu_channel_host.h", "+gpu/ipc/client/gpu_channel_host.h",
"+mojo/public/cpp/system/buffer.h", "+mojo/public/cpp/system/buffer.h",
......
// 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() = default;
void ClientSurfaceEmbedder::UpdateSurface(const cc::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.size_in_pixels();
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()));
surface_layer_->SetShowSurface(
surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory));
}
} // namespace aura
// 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 <memory>
#include "base/macros.h"
namespace cc {
class SurfaceInfo;
}
namespace ui {
class Layer;
}
namespace aura {
class Window;
// Used by WindowPortMus when it is embedding a client. Responsible for setting
// up layers containing content from the client, parenting them to the window's
// layer, and updating them when the client submits new surfaces.
class ClientSurfaceEmbedder {
public:
explicit ClientSurfaceEmbedder(Window* window);
~ClientSurfaceEmbedder();
// Updates the surface layer and the clip layer based on the surface info.
void UpdateSurface(const cc::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(ClientSurfaceEmbedder);
};
} // namespace aura
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "ui/aura/client/aura_constants.h" #include "ui/aura/client/aura_constants.h"
#include "ui/aura/client/transient_window_client.h" #include "ui/aura/client/transient_window_client.h"
#include "ui/aura/mus/client_surface_embedder.h"
#include "ui/aura/mus/property_converter.h" #include "ui/aura/mus/property_converter.h"
#include "ui/aura/mus/surface_id_handler.h" #include "ui/aura/mus/surface_id_handler.h"
#include "ui/aura/mus/window_tree_client.h" #include "ui/aura/mus/window_tree_client.h"
...@@ -255,10 +256,22 @@ void WindowPortMus::SetSurfaceInfoFromServer( ...@@ -255,10 +256,22 @@ void WindowPortMus::SetSurfaceInfoFromServer(
} }
} }
WindowPortMus* parent = Get(window_->parent()); WindowPortMus* parent = Get(window_->parent());
// TODO(mfomitchev): This is unused. We probably don't need this.
if (parent && parent->surface_id_handler_) { if (parent && parent->surface_id_handler_) {
parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_,
surface_info); surface_info);
} }
// The fact that SetSurfaceIdFromServer was called means that this window
// corresponds to an embedded client.
if (!client_surface_embedder && surface_info.id().is_valid())
client_surface_embedder = base::MakeUnique<ClientSurfaceEmbedder>(window_);
if (surface_info.id().is_valid())
client_surface_embedder->UpdateSurface(surface_info);
else
client_surface_embedder.reset();
surface_info_ = surface_info; surface_info_ = surface_info;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
namespace aura { namespace aura {
class ClientSurfaceEmbedder;
class PropertyConverter; class PropertyConverter;
class SurfaceIdHandler; class SurfaceIdHandler;
class Window; class Window;
...@@ -243,6 +244,9 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus { ...@@ -243,6 +244,9 @@ class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
Window* window_ = nullptr; Window* window_ = nullptr;
// Used when this window is embedding a client.
std::unique_ptr<ClientSurfaceEmbedder> client_surface_embedder;
ServerChangeIdType next_server_change_id_ = 0; ServerChangeIdType next_server_change_id_ = 0;
ServerChanges server_changes_; ServerChanges server_changes_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment