Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 29483bb

Browse files
committed
fuchsia: Fix elevation issues
1 parent d1e9017 commit 29483bb

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

flow/scene_update_context.cc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,12 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode& entity_node,
115115
SkAlpha opacity,
116116
const SkRect& paint_bounds,
117117
std::vector<Layer*> paint_layers) {
118-
if (rrect.isEmpty())
119-
return;
118+
FML_DCHECK(!rrect.isEmpty());
120119

121120
// Frames always clip their children.
122121
SkRect shape_bounds = rrect.getBounds();
123122
SetEntityNodeClipPlanes(entity_node, shape_bounds);
124123

125-
// and possibly for its texture.
126124
// TODO(SCN-137): Need to be able to express the radii as vectors.
127125
scenic::ShapeNode shape_node(session_.get());
128126
scenic::Rectangle shape(session_.get(), rrect.width(), rrect.height());
@@ -140,7 +138,7 @@ void SceneUpdateContext::CreateFrame(scenic::EntityNode& entity_node,
140138
entity_node.AddChild(shape_node);
141139

142140
// Check whether a solid color will suffice.
143-
if (paint_layers.empty() || shape_bounds.isEmpty()) {
141+
if (paint_layers.empty()) {
144142
SetMaterialColor(material, color, opacity);
145143
} else {
146144
// The final shape's color is material_color * texture_color. The passed in
@@ -182,6 +180,9 @@ void SceneUpdateContext::UpdateView(int64_t view_id,
182180
view_holder->UpdateScene(session_.get(), top_entity_->embedder_node(), offset,
183181
size, SkScalarRoundToInt(alphaf() * 255),
184182
hit_testable);
183+
184+
// Assume embedded views are 10 "layers" wide.
185+
next_elevation_ += 10 * kScenicZElevationBetweenLayers;
185186
}
186187

187188
void SceneUpdateContext::CreateView(int64_t view_id,
@@ -286,13 +287,17 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
286287
opacity_(opacity),
287288
opacity_node_(context.session_.get()),
288289
paint_bounds_(SkRect::MakeEmpty()) {
289-
entity_node().SetLabel(label);
290-
entity_node().SetTranslation(0.f, 0.f,
291-
context.next_elevation_ - previous_elevation_);
290+
// Increment elevation trackers before calculating any local elevation.
291+
// |UpdateView| can modify context.next_elevation_, which is why it is
292+
// neccesary to track this addtional state.
292293
context.top_elevation_ += kScenicZElevationBetweenLayers;
293294
context.next_elevation_ += kScenicZElevationBetweenLayers;
294295

296+
float local_elevation = context.next_elevation_ - previous_elevation_;
297+
entity_node().SetTranslation(0.f, 0.f, -local_elevation);
298+
entity_node().SetLabel(label);
295299
entity_node().AddChild(opacity_node_);
300+
296301
// Scenic currently lacks an API to enable rendering of alpha channel; alpha
297302
// channels are only rendered if there is a OpacityNode higher in the tree
298303
// with opacity != 1. For now, clamp to a infinitesimally smaller value than
@@ -301,11 +306,15 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
301306
}
302307

303308
SceneUpdateContext::Frame::~Frame() {
309+
context().top_elevation_ = previous_elevation_;
310+
311+
// We don't need a shape if the frame is zero size.
312+
if (rrect_.isEmpty())
313+
return;
314+
304315
// Add a part which represents the frame's geometry for clipping purposes
305316
context().CreateFrame(entity_node(), rrect_, color_, opacity_, paint_bounds_,
306317
std::move(paint_layers_));
307-
308-
context().top_elevation_ = previous_elevation_;
309318
}
310319

311320
void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) {

0 commit comments

Comments
 (0)