[fuchsia] Remove extraneous ShapeNodes (#10150)

Test: Ran test programs on Fuchsia and dumped Scenic scene graph using
`fx shell cat /hub/c/scenic.cmx/*/out/debug/dump-scenes`
Inspected scene graph to confirm removal of ShapeNodes.
FL-284 #done
This commit is contained in:
David Worsham 2019-07-31 02:22:01 -07:00 committed by GitHub
parent 8ef792f6c5
commit a29ef66013
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 70 deletions

View File

@ -11,7 +11,7 @@
namespace flutter {
// Helper function to generate clip planes for a scenic::EntityNode.
static void SetEntityNodeClipPlanes(scenic::EntityNode* entity_node,
static void SetEntityNodeClipPlanes(scenic::EntityNode& entity_node,
const SkRect& bounds) {
const float top = bounds.top();
const float bottom = bounds.bottom();
@ -46,7 +46,7 @@ static void SetEntityNodeClipPlanes(scenic::EntityNode* entity_node,
clip_planes[3].dir.y = 0.f;
clip_planes[3].dir.z = 0.f;
entity_node->SetClipPlanes(std::move(clip_planes));
entity_node.SetClipPlanes(std::move(clip_planes));
}
SceneUpdateContext::SceneUpdateContext(scenic::Session* session,
@ -55,18 +55,17 @@ SceneUpdateContext::SceneUpdateContext(scenic::Session* session,
FML_DCHECK(surface_producer_ != nullptr);
}
void SceneUpdateContext::CreateFrame(
std::unique_ptr<scenic::EntityNode> entity_node,
std::unique_ptr<scenic::ShapeNode> shape_node,
const SkRRect& rrect,
SkColor color,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer) {
void SceneUpdateContext::CreateFrame(scenic::EntityNode entity_node,
scenic::ShapeNode shape_node,
const SkRRect& rrect,
SkColor color,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer) {
// Frames always clip their children.
SetEntityNodeClipPlanes(entity_node.get(), rrect.getBounds());
SetEntityNodeClipPlanes(entity_node, rrect.getBounds());
// TODO(SCN-1274): AddPart() and SetClip() will be deleted.
entity_node->SetClip(0u, true /* clip to self */);
entity_node.SetClip(0u, true /* clip to self */);
// We don't need a shape if the frame is zero size.
if (rrect.isEmpty())
@ -85,10 +84,10 @@ void SceneUpdateContext::CreateFrame(
rrect.radii(SkRRect::kLowerRight_Corner).x(), // bottom_right_radius
rrect.radii(SkRRect::kLowerLeft_Corner).x() // bottom_left_radius
);
shape_node->SetShape(shape);
shape_node->SetTranslation(shape_bounds.width() * 0.5f + shape_bounds.left(),
shape_bounds.height() * 0.5f + shape_bounds.top(),
0.f);
shape_node.SetShape(shape);
shape_node.SetTranslation(shape_bounds.width() * 0.5f + shape_bounds.left(),
shape_bounds.height() * 0.5f + shape_bounds.top(),
0.f);
// Check whether the painted layers will be visible.
if (paint_bounds.isEmpty() || !paint_bounds.intersects(shape_bounds))
@ -96,7 +95,7 @@ void SceneUpdateContext::CreateFrame(
// Check whether a solid color will suffice.
if (paint_layers.empty()) {
SetShapeColor(*shape_node, color);
SetShapeColor(shape_node, color);
return;
}
@ -105,12 +104,12 @@ void SceneUpdateContext::CreateFrame(
const float scale_y = ScaleY();
// Apply a texture to the whole shape.
SetShapeTextureOrColor(*shape_node, color, scale_x, scale_y, shape_bounds,
std::move(paint_layers), layer,
std::move(entity_node));
SetShapeTextureAndColor(shape_node, color, scale_x, scale_y, shape_bounds,
std::move(paint_layers), layer,
std::move(entity_node));
}
void SceneUpdateContext::SetShapeTextureOrColor(
void SceneUpdateContext::SetShapeTextureAndColor(
scenic::ShapeNode& shape_node,
SkColor color,
SkScalar scale_x,
@ -118,7 +117,7 @@ void SceneUpdateContext::SetShapeTextureOrColor(
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
std::unique_ptr<scenic::EntityNode> entity_node) {
scenic::EntityNode entity_node) {
scenic::Image* image = GenerateImageIfNeeded(
color, scale_x, scale_y, paint_bounds, std::move(paint_layers), layer,
std::move(entity_node));
@ -150,7 +149,7 @@ scenic::Image* SceneUpdateContext::GenerateImageIfNeeded(
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
std::unique_ptr<scenic::EntityNode> entity_node) {
scenic::EntityNode entity_node) {
// Bail if there's nothing to paint.
if (paint_layers.empty())
return nullptr;
@ -168,7 +167,7 @@ scenic::Image* SceneUpdateContext::GenerateImageIfNeeded(
LayerRasterCacheKey(
// Root frame has a nullptr layer
layer ? layer->unique_id() : 0, Matrix()),
std::move(entity_node));
std::make_unique<scenic::EntityNode>(std::move(entity_node)));
if (!surface) {
FML_LOG(ERROR) << "Could not acquire a surface from the surface producer "
@ -222,13 +221,11 @@ SceneUpdateContext::ExecutePaintTasks(CompositorContext::ScopedFrame& frame) {
}
SceneUpdateContext::Entity::Entity(SceneUpdateContext& context)
: context_(context), previous_entity_(context.top_entity_) {
entity_node_ptr_ = std::make_unique<scenic::EntityNode>(context.session());
shape_node_ptr_ = std::make_unique<scenic::ShapeNode>(context.session());
// TODO(SCN-1274): AddPart() and SetClip() will be deleted.
entity_node_ptr_->AddPart(*shape_node_ptr_);
: context_(context),
previous_entity_(context.top_entity_),
entity_node_(context.session()) {
if (previous_entity_)
previous_entity_->entity_node_ptr_->AddChild(*entity_node_ptr_);
previous_entity_->embedder_node().AddChild(entity_node_);
context.top_entity_ = this;
}
@ -287,6 +284,11 @@ SceneUpdateContext::Transform::~Transform() {
context().top_scale_y_ = previous_scale_y_;
}
SceneUpdateContext::Shape::Shape(SceneUpdateContext& context)
: Entity(context), shape_node_(context.session()) {
entity_node().AddPart(shape_node_);
}
SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
const SkRRect& rrect,
SkColor color,
@ -294,7 +296,7 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
float world_elevation,
float depth,
Layer* layer)
: Entity(context),
: Shape(context),
rrect_(rrect),
color_(color),
paint_bounds_(SkRect::MakeEmpty()),
@ -316,9 +318,9 @@ SceneUpdateContext::Frame::Frame(SceneUpdateContext& context,
}
SceneUpdateContext::Frame::~Frame() {
context().CreateFrame(std::move(entity_node_ptr()),
std::move(shape_node_ptr()), rrect_, color_,
paint_bounds_, std::move(paint_layers_), layer_);
context().CreateFrame(std::move(entity_node()), std::move(shape_node()),
rrect_, color_, paint_bounds_, std::move(paint_layers_),
layer_);
}
void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) {
@ -330,7 +332,7 @@ void SceneUpdateContext::Frame::AddPaintLayer(Layer* layer) {
SceneUpdateContext::Clip::Clip(SceneUpdateContext& context,
const SkRect& shape_bounds)
: Entity(context) {
SetEntityNodeClipPlanes(&entity_node(), shape_bounds);
SetEntityNodeClipPlanes(entity_node(), shape_bounds);
}
} // namespace flutter

View File

@ -69,26 +69,17 @@ class SceneUpdateContext {
class Entity {
public:
Entity(SceneUpdateContext& context);
~Entity();
virtual ~Entity();
SceneUpdateContext& context() { return context_; }
scenic::EntityNode& entity_node() { return *entity_node_ptr_; }
std::unique_ptr<scenic::EntityNode>& entity_node_ptr() {
return entity_node_ptr_;
}
protected:
scenic::ShapeNode& shape_node() { return *shape_node_ptr_; }
std::unique_ptr<scenic::ShapeNode>& shape_node_ptr() {
return shape_node_ptr_;
}
scenic::EntityNode& entity_node() { return entity_node_; }
virtual scenic::ContainerNode& embedder_node() { return entity_node_; }
private:
SceneUpdateContext& context_;
Entity* const previous_entity_;
std::unique_ptr<scenic::EntityNode> entity_node_ptr_;
std::unique_ptr<scenic::ShapeNode> shape_node_ptr_;
scenic::EntityNode entity_node_;
};
class Transform : public Entity {
@ -98,14 +89,25 @@ class SceneUpdateContext {
float scale_x,
float scale_y,
float scale_z);
~Transform();
virtual ~Transform();
private:
float const previous_scale_x_;
float const previous_scale_y_;
};
class Frame : public Entity {
class Shape : public Entity {
public:
Shape(SceneUpdateContext& context);
virtual ~Shape() = default;
scenic::ShapeNode& shape_node() { return shape_node_; }
private:
scenic::ShapeNode shape_node_;
};
class Frame : public Shape {
public:
// When layer is not nullptr, the frame is associated with a layer subtree
// rooted with that layer. The frame may then create a surface that will be
@ -117,8 +119,7 @@ class SceneUpdateContext {
float parent_elevation = 0.0f,
float depth = 0.0f,
Layer* layer = nullptr);
~Frame();
virtual ~Frame();
void AddPaintLayer(Layer* layer);
@ -192,30 +193,29 @@ class SceneUpdateContext {
// own the associated entity_node. If the layer pointer isn't nullptr, the
// surface (and thus the entity_node) will be retained for that layer to
// improve the performance.
void CreateFrame(std::unique_ptr<scenic::EntityNode> entity_node,
std::unique_ptr<scenic::ShapeNode> shape_node,
void CreateFrame(scenic::EntityNode entity_node,
scenic::ShapeNode shape_node,
const SkRRect& rrect,
SkColor color,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer);
void SetShapeTextureOrColor(scenic::ShapeNode& shape_node,
SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
std::unique_ptr<scenic::EntityNode> entity_node);
void SetShapeTextureAndColor(scenic::ShapeNode& shape_node,
SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
scenic::EntityNode entity_node);
void SetShapeColor(scenic::ShapeNode& shape_node, SkColor color);
scenic::Image* GenerateImageIfNeeded(
SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
std::unique_ptr<scenic::EntityNode> entity_node);
scenic::Image* GenerateImageIfNeeded(SkColor color,
SkScalar scale_x,
SkScalar scale_y,
const SkRect& paint_bounds,
std::vector<Layer*> paint_layers,
Layer* layer,
scenic::EntityNode entity_node);
Entity* top_entity_ = nullptr;
float top_scale_x_ = 1.f;