@@ -37,38 +37,52 @@ void Rasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree,
3737 const SkISize& frame_size = layer_tree->frame_size ();
3838 auto update = mozart::SceneUpdate::New ();
3939
40- sk_sp<SkSurface> surface;
41- if (!frame_size.isEmpty ()) {
42- // Get a surface to draw the contents.
43- mozart::ImagePtr image;
44- surface = mozart::MakeSkSurface (frame_size, buffer_producer_.get (), &image);
45- FTL_CHECK (surface);
46-
47- // Update the scene contents.
48- mozart::RectF bounds;
49- bounds.width = frame_size.width ();
50- bounds.height = frame_size.height ();
51-
52- auto content_resource = mozart::Resource::New ();
53- content_resource->set_image (mozart::ImageResource::New ());
54- content_resource->get_image ()->image = std::move (image);
55- update->resources .insert (kContentImageResourceId ,
56- std::move (content_resource));
57-
58- auto root_node = mozart::Node::New ();
59- root_node->hit_test_behavior = mozart::HitTestBehavior::New ();
60- root_node->op = mozart::NodeOp::New ();
61- root_node->op ->set_image (mozart::ImageNodeOp::New ());
62- root_node->op ->get_image ()->content_rect = bounds.Clone ();
63- root_node->op ->get_image ()->image_resource_id = kContentImageResourceId ;
64-
65- layer_tree->UpdateScene (update.get (), root_node.get ());
66-
67- update->nodes .insert (kRootNodeId , std::move (root_node));
68- } else {
40+ if (frame_size.isEmpty ()) {
6941 update->nodes .insert (kRootNodeId , mozart::Node::New ());
42+ // Publish the updated scene contents.
43+ // TODO(jeffbrown): We should set the metadata's presentation_time here too.
44+ scene_->Update (std::move (update));
45+ auto metadata = mozart::SceneMetadata::New ();
46+ metadata->version = layer_tree->scene_version ();
47+ scene_->Publish (std::move (metadata));
48+ callback ();
49+ return ;
7050 }
7151
52+ // Get a surface to draw the contents.
53+ mozart::ImagePtr image;
54+ sk_sp<SkSurface> surface =
55+ mozart::MakeSkSurface (frame_size, buffer_producer_.get (), &image);
56+
57+ FTL_CHECK (surface);
58+
59+ flow::CompositorContext::ScopedFrame frame =
60+ compositor_context_.AcquireFrame (nullptr , *surface->getCanvas ());
61+
62+ layer_tree->Preroll (frame);
63+
64+ // Update the scene contents.
65+ mozart::RectF bounds;
66+ bounds.width = frame_size.width ();
67+ bounds.height = frame_size.height ();
68+
69+ auto content_resource = mozart::Resource::New ();
70+ content_resource->set_image (mozart::ImageResource::New ());
71+ content_resource->get_image ()->image = std::move (image);
72+ update->resources .insert (kContentImageResourceId ,
73+ std::move (content_resource));
74+
75+ auto root_node = mozart::Node::New ();
76+ root_node->hit_test_behavior = mozart::HitTestBehavior::New ();
77+ root_node->op = mozart::NodeOp::New ();
78+ root_node->op ->set_image (mozart::ImageNodeOp::New ());
79+ root_node->op ->get_image ()->content_rect = bounds.Clone ();
80+ root_node->op ->get_image ()->image_resource_id = kContentImageResourceId ;
81+
82+ layer_tree->UpdateScene (update.get (), root_node.get ());
83+
84+ update->nodes .insert (kRootNodeId , std::move (root_node));
85+
7286 // Publish the updated scene contents.
7387 // TODO(jeffbrown): We should set the metadata's presentation_time here too.
7488 scene_->Update (std::move (update));
@@ -80,14 +94,10 @@ void Rasterizer::Draw(std::unique_ptr<flow::LayerTree> layer_tree,
8094 // We do this after publishing to take advantage of pipelining.
8195 // The image buffer's fence is signalled automatically when the surface
8296 // goes out of scope.
83- if (surface) {
84- SkCanvas* canvas = surface->getCanvas ();
85- flow::CompositorContext::ScopedFrame frame =
86- compositor_context_.AcquireFrame (nullptr , *canvas);
87- canvas->clear (SK_ColorBLACK);
88- layer_tree->Raster (frame);
89- canvas->flush ();
90- }
97+ SkCanvas* canvas = surface->getCanvas ();
98+ canvas->clear (SK_ColorBLACK);
99+ layer_tree->Paint (frame);
100+ canvas->flush ();
91101
92102 callback ();
93103}
0 commit comments