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.
This commit is contained in:
Adam Barth
2016-02-03 14:07:35 -08:00
parent b16c7cd87d
commit 9dbf3d72f8
9 changed files with 65 additions and 4 deletions

View File

@@ -42,7 +42,8 @@ source_set("flow") {
deps = [
"//base",
"//skia",
"//mojo/services/gfx/composition/interfaces",
"//mojo/skia",
"//skia",
]
}

View File

@@ -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

View File

@@ -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);
};

View File

@@ -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

View File

@@ -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<std::unique_ptr<Layer>>& layers() const { return layers_; }
private:

View File

@@ -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

View File

@@ -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; }

View File

@@ -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

View File

@@ -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<Layer> root_layer) {