Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 37 additions & 35 deletions flow/scene_update_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: const?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ultimately, that EntityNode is moved from so it can't be const

const SkRect& bounds) {
const float top = bounds.top();
const float bottom = bounds.bottom();
Expand Down Expand Up @@ -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,
Expand All @@ -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())
Expand All @@ -85,18 +84,18 @@ 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))
paint_layers.clear();

// Check whether a solid color will suffice.
if (paint_layers.empty()) {
SetShapeColor(*shape_node, color);
SetShapeColor(shape_node, color);
return;
}

Expand All @@ -105,20 +104,20 @@ 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,
SkScalar scale_y,
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));
Expand Down Expand Up @@ -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;
Expand All @@ -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 "
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -287,14 +284,19 @@ 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,
float local_elevation,
float world_elevation,
float depth,
Layer* layer)
: Entity(context),
: Shape(context),
rrect_(rrect),
color_(color),
paint_bounds_(SkRect::MakeEmpty()),
Expand All @@ -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) {
Expand All @@ -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
70 changes: 35 additions & 35 deletions flow/scene_update_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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);

Expand Down Expand Up @@ -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;
Expand Down