From 9dbf3d72f8aa0b3334cd5e5e18eea49a33b11609 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Wed, 3 Feb 2016 14:07:35 -0800 Subject: [PATCH] Include child scenes when uploading to Mozart Previously we just dropped child scenes on the floor. Now we upload them to Mozart. However, we just draw them on top of all the other content and don't apply any clips or blends. --- engine/src/flutter/flow/BUILD.gn | 3 ++- .../flutter/flow/layers/child_scene_layer.cc | 27 +++++++++++++++++++ .../flutter/flow/layers/child_scene_layer.h | 4 +++ .../flutter/flow/layers/container_layer.cc | 6 +++++ .../src/flutter/flow/layers/container_layer.h | 3 +++ engine/src/flutter/flow/layers/layer.cc | 4 +++ engine/src/flutter/flow/layers/layer.h | 6 ++++- engine/src/flutter/flow/layers/layer_tree.cc | 10 +++++-- engine/src/flutter/flow/layers/layer_tree.h | 6 +++++ 9 files changed, 65 insertions(+), 4 deletions(-) diff --git a/engine/src/flutter/flow/BUILD.gn b/engine/src/flutter/flow/BUILD.gn index c21db2930c..7bd885cff2 100644 --- a/engine/src/flutter/flow/BUILD.gn +++ b/engine/src/flutter/flow/BUILD.gn @@ -42,7 +42,8 @@ source_set("flow") { deps = [ "//base", - "//skia", "//mojo/services/gfx/composition/interfaces", + "//mojo/skia", + "//skia", ] } diff --git a/engine/src/flutter/flow/layers/child_scene_layer.cc b/engine/src/flutter/flow/layers/child_scene_layer.cc index 5f808e59f3..0a6db85ee0 100644 --- a/engine/src/flutter/flow/layers/child_scene_layer.cc +++ b/engine/src/flutter/flow/layers/child_scene_layer.cc @@ -4,15 +4,42 @@ #include "flow/layers/child_scene_layer.h" +#include "mojo/skia/type_converters.h" + namespace flow { +// TODO(abarth): We need to figure out how to allocate these ids sensibly. +static uint32_t next_id = 10; + ChildSceneLayer::ChildSceneLayer() { } ChildSceneLayer::~ChildSceneLayer() { } +void ChildSceneLayer::Preroll(PrerollContext* context, const SkMatrix& matrix) { + transform_ = matrix; +} + void ChildSceneLayer::Paint(PaintContext::ScopedFrame& frame) { } +void ChildSceneLayer::UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) { + uint32_t id = next_id++; + + auto child_resource = mojo::gfx::composition::Resource::New(); + child_resource->set_scene(mojo::gfx::composition::SceneResource::New()); + child_resource->get_scene()->scene_token = scene_token_.Clone(); + update->resources.insert(id, child_resource.Pass()); + + auto child_node = mojo::gfx::composition::Node::New(); + child_node->op = mojo::gfx::composition::NodeOp::New(); + child_node->op->set_scene(mojo::gfx::composition::SceneNodeOp::New()); + child_node->op->get_scene()->scene_resource_id = id; + child_node->content_transform = mojo::Transform::From(transform_); + update->nodes.insert(id, child_node.Pass()); + container->child_node_ids.push_back(id); +} + } // namespace flow diff --git a/engine/src/flutter/flow/layers/child_scene_layer.h b/engine/src/flutter/flow/layers/child_scene_layer.h index 4f7c196cc3..3ebaa8ad95 100644 --- a/engine/src/flutter/flow/layers/child_scene_layer.h +++ b/engine/src/flutter/flow/layers/child_scene_layer.h @@ -25,12 +25,16 @@ class ChildSceneLayer : public Layer { scene_token_ = scene_token.Pass(); } + void Preroll(PrerollContext* context, const SkMatrix& matrix) override; void Paint(PaintContext::ScopedFrame& frame) override; + void UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) override; private: SkPoint offset_; SkISize physical_size_; mojo::gfx::composition::SceneTokenPtr scene_token_; + SkMatrix transform_; DISALLOW_COPY_AND_ASSIGN(ChildSceneLayer); }; diff --git a/engine/src/flutter/flow/layers/container_layer.cc b/engine/src/flutter/flow/layers/container_layer.cc index 533c8bebfb..a6427ecabb 100644 --- a/engine/src/flutter/flow/layers/container_layer.cc +++ b/engine/src/flutter/flow/layers/container_layer.cc @@ -37,4 +37,10 @@ void ContainerLayer::PaintChildren(PaintContext::ScopedFrame& frame) const { layer->Paint(frame); } +void ContainerLayer::UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) { + for (auto& layer : layers_) + layer->UpdateScene(update, container); +} + } // namespace flow diff --git a/engine/src/flutter/flow/layers/container_layer.h b/engine/src/flutter/flow/layers/container_layer.h index c5b6b588c3..12a6412cef 100644 --- a/engine/src/flutter/flow/layers/container_layer.h +++ b/engine/src/flutter/flow/layers/container_layer.h @@ -22,6 +22,9 @@ class ContainerLayer : public Layer { void PaintChildren(PaintContext::ScopedFrame& frame) const; + void UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) override; + const std::vector>& layers() const { return layers_; } private: diff --git a/engine/src/flutter/flow/layers/layer.cc b/engine/src/flutter/flow/layers/layer.cc index d4fc13e25b..49139525fa 100644 --- a/engine/src/flutter/flow/layers/layer.cc +++ b/engine/src/flutter/flow/layers/layer.cc @@ -20,4 +20,8 @@ Layer::~Layer() { void Layer::Preroll(PrerollContext* context, const SkMatrix& matrix) { } +void Layer::UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) { +} + } // namespace flow diff --git a/engine/src/flutter/flow/layers/layer.h b/engine/src/flutter/flow/layers/layer.h index 9484047974..27c20e9977 100644 --- a/engine/src/flutter/flow/layers/layer.h +++ b/engine/src/flutter/flow/layers/layer.h @@ -10,8 +10,9 @@ #include "base/logging.h" #include "base/macros.h" -#include "skia/ext/refptr.h" #include "flow/paint_context.h" +#include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" +#include "skia/ext/refptr.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColorFilter.h" @@ -38,6 +39,9 @@ class Layer { virtual void Preroll(PrerollContext* context, const SkMatrix& matrix); virtual void Paint(PaintContext::ScopedFrame& frame) = 0; + virtual void UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container); + ContainerLayer* parent() const { return parent_; } void set_parent(ContainerLayer* parent) { parent_ = parent; } diff --git a/engine/src/flutter/flow/layers/layer_tree.cc b/engine/src/flutter/flow/layers/layer_tree.cc index 20c2ff952e..e1fa655d25 100644 --- a/engine/src/flutter/flow/layers/layer_tree.cc +++ b/engine/src/flutter/flow/layers/layer_tree.cc @@ -17,15 +17,21 @@ LayerTree::~LayerTree() { void LayerTree::Raster(PaintContext::ScopedFrame& frame) { { - TRACE_EVENT0("flutter", "LayerTree::Preroll") + TRACE_EVENT0("flutter", "LayerTree::Preroll"); Layer::PrerollContext context = { frame, SkRect::MakeEmpty() }; root_layer_->Preroll(&context, SkMatrix()); } { - TRACE_EVENT0("flutter", "LayerTree::Paint") + TRACE_EVENT0("flutter", "LayerTree::Paint"); root_layer_->Paint(frame); } } +void LayerTree::UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container) { + TRACE_EVENT0("flutter", "LayerTree::UpdateScene"); + root_layer_->UpdateScene(update, container); +} + } // namespace flow diff --git a/engine/src/flutter/flow/layers/layer_tree.h b/engine/src/flutter/flow/layers/layer_tree.h index a74f7abd03..e4ecc98e01 100644 --- a/engine/src/flutter/flow/layers/layer_tree.h +++ b/engine/src/flutter/flow/layers/layer_tree.h @@ -22,6 +22,12 @@ class LayerTree { void Raster(PaintContext::ScopedFrame& frame); + // TODO(abarth): Integrate scene updates with the rasterization pass so that + // we can draw on top of child scenes (and so that we can apply clips and + // blending operations to child scene). + void UpdateScene(mojo::gfx::composition::SceneUpdate* update, + mojo::gfx::composition::Node* container); + Layer* root_layer() const { return root_layer_.get(); } void set_root_layer(std::unique_ptr root_layer) {