44
55#include " flutter/flow/scene_update_context.h"
66
7+ #include < lib/ui/scenic/cpp/commands.h>
78#include < lib/ui/scenic/cpp/view_token_pair.h>
89
910#include " flutter/flow/layers/layer.h"
@@ -64,28 +65,67 @@ void SetMaterialColor(scenic::Material& material,
6465
6566} // namespace
6667
67- SceneUpdateContext::SceneUpdateContext (scenic::Session* session)
68- : session_(session) {}
68+ SceneUpdateContext::SceneUpdateContext (std::string debug_label,
69+ fuchsia::ui::views::ViewToken view_token,
70+ scenic::ViewRefPair view_ref_pair,
71+ SessionWrapper& session)
72+ : session_(session),
73+ root_view_ (session_.get(),
74+ std::move(view_token),
75+ std::move(view_ref_pair.control_ref),
76+ std::move(view_ref_pair.view_ref),
77+ debug_label),
78+ root_node_(session_.get()) {
79+ root_view_.AddChild (root_node_);
80+ root_node_.SetEventMask (fuchsia::ui::gfx::kMetricsEventMask );
81+
82+ session_.Present ();
83+ }
84+
85+ std::vector<SceneUpdateContext::PaintTask> SceneUpdateContext::GetPaintTasks () {
86+ std::vector<PaintTask> frame_paint_tasks = std::move (paint_tasks_);
87+
88+ paint_tasks_.clear ();
6989
70- void SceneUpdateContext::CreateFrame (scenic::EntityNode entity_node,
90+ return frame_paint_tasks;
91+ }
92+
93+ void SceneUpdateContext::EnableWireframe (bool enable) {
94+ session_.get ()->Enqueue (
95+ scenic::NewSetEnableDebugViewBoundsCmd (root_view_.id (), enable));
96+ }
97+
98+ void SceneUpdateContext::Reset () {
99+ paint_tasks_.clear ();
100+ top_entity_ = nullptr ;
101+ top_scale_x_ = 1 .f ;
102+ top_scale_y_ = 1 .f ;
103+ top_elevation_ = 0 .f ;
104+ next_elevation_ = 0 .f ;
105+ alpha_ = 1 .f ;
106+
107+ // We are going to be sending down a fresh node hierarchy every frame. So just
108+ // enqueue a detach op on the imported root node.
109+ session_.get ()->Enqueue (scenic::NewDetachChildrenCmd (root_node_.id ()));
110+ }
111+
112+ void SceneUpdateContext::CreateFrame (scenic::EntityNode& entity_node,
71113 const SkRRect& rrect,
72114 SkColor color,
73115 SkAlpha opacity,
74116 const SkRect& paint_bounds,
75117 std::vector<Layer*> paint_layers) {
76- FML_DCHECK (!rrect.isEmpty ());
118+ if (rrect.isEmpty ())
119+ return ;
77120
78121 // Frames always clip their children.
79122 SkRect shape_bounds = rrect.getBounds ();
80123 SetEntityNodeClipPlanes (entity_node, shape_bounds);
81124
82125 // and possibly for its texture.
83126 // TODO(SCN-137): Need to be able to express the radii as vectors.
84- scenic::ShapeNode shape_node (session ());
85- scenic::Rectangle shape (session_, // session
86- rrect.width (), // width
87- rrect.height () // height
88- );
127+ scenic::ShapeNode shape_node (session_.get ());
128+ scenic::Rectangle shape (session_.get (), rrect.width (), rrect.height ());
89129 shape_node.SetShape (shape);
90130 shape_node.SetTranslation (shape_bounds.width () * 0 .5f + shape_bounds.left (),
91131 shape_bounds.height () * 0 .5f + shape_bounds.top (),
@@ -95,7 +135,7 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
95135 if (paint_bounds.isEmpty () || !paint_bounds.intersects (shape_bounds))
96136 paint_layers.clear ();
97137
98- scenic::Material material (session ());
138+ scenic::Material material (session_. get ());
99139 shape_node.SetMaterial (material);
100140 entity_node.AddChild (shape_node);
101141
@@ -120,30 +160,24 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
120160 }
121161}
122162
123- std::vector<SceneUpdateContext::PaintTask>
124- SceneUpdateContext::ResetAndGetPaintTasks () {
125- std::vector<PaintTask> frame_paint_tasks = std::move (paint_tasks_);
126-
127- // Reset all internal state.
128- paint_tasks_.clear ();
129- top_elevation_ = 0 .0f ;
130- next_elevation_ = 0 .0f ;
131- alpha_ = 1 .0f ;
132-
133- return frame_paint_tasks;
134- }
135-
136- void SceneUpdateContext::UpdateScene (int64_t view_id,
137- const SkPoint& offset,
138- const SkSize& size) {
163+ void SceneUpdateContext::UpdateView (int64_t view_id,
164+ const SkPoint& offset,
165+ const SkSize& size,
166+ std::optional<bool > override_hit_testable) {
139167 auto * view_holder = ViewHolder::FromId (view_id);
140168 FML_DCHECK (view_holder);
141169
142- view_holder->SetProperties (size.width (), size.height (), 0 , 0 , 0 , 0 ,
143- view_holder->focusable ());
144- view_holder->UpdateScene (*this , offset, size,
145- SkScalarRoundToInt (alphaf () * 255 ),
146- view_holder->hit_testable ());
170+ if (size.width () > 0 .f && size.height () > 0 .f ) {
171+ view_holder->SetProperties (size.width (), size.height (), 0 , 0 , 0 , 0 ,
172+ view_holder->focusable ());
173+ }
174+
175+ bool hit_testable = override_hit_testable.has_value ()
176+ ? *override_hit_testable
177+ : view_holder->hit_testable ();
178+ view_holder->UpdateScene (session_.get (), top_entity_->embedder_node (), offset,
179+ size, SkScalarRoundToInt (alphaf () * 255 ),
180+ hit_testable);
147181}
148182
149183void SceneUpdateContext::CreateView (int64_t view_id,
@@ -167,13 +201,17 @@ void SceneUpdateContext::DestroyView(int64_t view_id) {
167201SceneUpdateContext::Entity::Entity (SceneUpdateContext& context)
168202 : context_(context),
169203 previous_entity_(context.top_entity_),
170- entity_node_(context.session()) {
171- if (previous_entity_)
172- previous_entity_->embedder_node ().AddChild (entity_node_);
204+ entity_node_(context.session_.get()) {
173205 context.top_entity_ = this ;
174206}
175207
176208SceneUpdateContext::Entity::~Entity () {
209+ if (previous_entity_) {
210+ previous_entity_->embedder_node ().AddChild (entity_node_);
211+ } else {
212+ context_.root_node_ .AddChild (entity_node_);
213+ }
214+
177215 FML_DCHECK (context_.top_entity_ == this );
178216 context_.top_entity_ = previous_entity_;
179217}
@@ -242,7 +280,7 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
242280 rrect_(rrect),
243281 color_(color),
244282 opacity_(opacity),
245- opacity_node_(context.session ()),
283+ opacity_node_(context.session_.get ()),
246284 paint_bounds_(SkRect::MakeEmpty()) {
247285 entity_node ().SetLabel (label);
248286 entity_node ().SetTranslation (0 .f , 0 .f ,
@@ -259,15 +297,11 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
259297}
260298
261299SceneUpdateContext::Frame::~Frame () {
262- context ().top_elevation_ = previous_elevation_;
263-
264- // We don't need a shape if the frame is zero size.
265- if (rrect_.isEmpty ())
266- return ;
267-
268300 // Add a part which represents the frame's geometry for clipping purposes
269- context ().CreateFrame (std::move (entity_node ()), rrect_, color_, opacity_,
270- paint_bounds_, std::move (paint_layers_));
301+ context ().CreateFrame (entity_node (), rrect_, color_, opacity_, paint_bounds_,
302+ std::move (paint_layers_));
303+
304+ context ().top_elevation_ = previous_elevation_;
271305}
272306
273307void SceneUpdateContext::Frame::AddPaintLayer (Layer* layer) {
0 commit comments