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
2 changes: 2 additions & 0 deletions impeller/aiks/aiks_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include "impeller/entity/contents/conical_gradient_contents.h"
#include "impeller/entity/contents/filters/inputs/filter_input.h"
#include "impeller/entity/contents/linear_gradient_contents.h"
#include "impeller/entity/contents/radial_gradient_contents.h"
#include "impeller/entity/contents/solid_color_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/contents/tiled_texture_contents.h"
#include "impeller/geometry/color.h"
#include "impeller/geometry/constants.h"
Expand Down
8 changes: 4 additions & 4 deletions impeller/aiks/canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ void Canvas::ClipRect(const Rect& rect, Entity::ClipOperation clip_op) {
return; // This clip will do nothing, so skip it.
}

ClipGeometry(std::move(geometry), clip_op);
ClipGeometry(geometry, clip_op);
switch (clip_op) {
case Entity::ClipOperation::kIntersect:
IntersectCulling(rect);
Expand Down Expand Up @@ -365,7 +365,7 @@ void Canvas::ClipRRect(const Rect& rect,
return; // This clip will do nothing, so skip it.
}

ClipGeometry(std::move(geometry), clip_op);
ClipGeometry(geometry, clip_op);
switch (clip_op) {
case Entity::ClipOperation::kIntersect:
IntersectCulling(rect);
Expand All @@ -390,10 +390,10 @@ void Canvas::ClipRRect(const Rect& rect,
}
}

void Canvas::ClipGeometry(std::unique_ptr<Geometry> geometry,
void Canvas::ClipGeometry(const std::shared_ptr<Geometry>& geometry,
Entity::ClipOperation clip_op) {
auto contents = std::make_shared<ClipContents>();
contents->SetGeometry(std::move(geometry));
contents->SetGeometry(geometry);
contents->SetClipOperation(clip_op);

Entity entity;
Expand Down
4 changes: 1 addition & 3 deletions impeller/aiks/canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <optional>
#include <vector>

#include "flutter/fml/macros.h"
#include "impeller/aiks/image.h"
#include "impeller/aiks/image_filter.h"
#include "impeller/aiks/paint.h"
Expand All @@ -23,7 +22,6 @@
#include "impeller/geometry/path.h"
#include "impeller/geometry/point.h"
#include "impeller/geometry/vector.h"
#include "impeller/typographer/glyph_atlas.h"
#include "impeller/typographer/text_frame.h"

namespace impeller {
Expand Down Expand Up @@ -175,7 +173,7 @@ class Canvas {

size_t GetClipDepth() const;

void ClipGeometry(std::unique_ptr<Geometry> geometry,
void ClipGeometry(const std::shared_ptr<Geometry>& geometry,
Entity::ClipOperation clip_op);

void IntersectCulling(Rect clip_bounds);
Expand Down
8 changes: 4 additions & 4 deletions impeller/aiks/paint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ constexpr ColorMatrix kColorInversion = {

std::shared_ptr<Contents> Paint::CreateContentsForEntity(const Path& path,
bool cover) const {
std::unique_ptr<Geometry> geometry;
std::shared_ptr<Geometry> geometry;
switch (style) {
case Style::kFill:
geometry = cover ? Geometry::MakeCover() : Geometry::MakeFillPath(path);
Expand All @@ -40,11 +40,11 @@ std::shared_ptr<Contents> Paint::CreateContentsForEntity(const Path& path,
stroke_cap, stroke_join);
break;
}
return CreateContentsForGeometry(std::move(geometry));
return CreateContentsForGeometry(geometry);
}

std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
std::shared_ptr<Geometry> geometry) const {
const std::shared_ptr<Geometry>& geometry) const {
auto contents = color_source.GetContents(*this);

// Attempt to apply the color filter on the CPU first.
Expand All @@ -57,7 +57,7 @@ std::shared_ptr<Contents> Paint::CreateContentsForGeometry(
needs_color_filter = false;
}

contents->SetGeometry(std::move(geometry));
contents->SetGeometry(geometry);
if (mask_blur_descriptor.has_value()) {
// If there's a mask blur and we need to apply the color filter on the GPU,
// we need to be careful to only apply the color filter to the source
Expand Down
6 changes: 1 addition & 5 deletions impeller/aiks/paint.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@

#include <memory>

#include "flutter/fml/macros.h"
#include "impeller/aiks/color_filter.h"
#include "impeller/aiks/color_source.h"
#include "impeller/aiks/image_filter.h"
#include "impeller/entity/contents/contents.h"
#include "impeller/entity/contents/filters/color_filter_contents.h"
#include "impeller/entity/contents/filters/filter_contents.h"
#include "impeller/entity/contents/linear_gradient_contents.h"
#include "impeller/entity/contents/radial_gradient_contents.h"
#include "impeller/entity/contents/sweep_gradient_contents.h"
#include "impeller/entity/entity.h"
#include "impeller/entity/geometry/geometry.h"
#include "impeller/geometry/color.h"
Expand Down Expand Up @@ -92,7 +88,7 @@ struct Paint {
bool cover = false) const;

std::shared_ptr<Contents> CreateContentsForGeometry(
std::shared_ptr<Geometry> geometry) const;
const std::shared_ptr<Geometry>& geometry) const;

/// @brief Whether this paint has a color filter that can apply opacity
bool HasColorFilter() const;
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ ClipContents::ClipContents() = default;

ClipContents::~ClipContents() = default;

void ClipContents::SetGeometry(std::unique_ptr<Geometry> geometry) {
geometry_ = std::move(geometry);
void ClipContents::SetGeometry(const std::shared_ptr<Geometry>& geometry) {
geometry_ = geometry;
}

void ClipContents::SetClipOperation(Entity::ClipOperation clip_op) {
Expand Down
4 changes: 2 additions & 2 deletions impeller/entity/contents/clip_contents.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClipContents final : public Contents {

~ClipContents();

void SetGeometry(std::unique_ptr<Geometry> geometry);
void SetGeometry(const std::shared_ptr<Geometry>& geometry);

void SetClipOperation(Entity::ClipOperation clip_op);

Expand All @@ -48,7 +48,7 @@ class ClipContents final : public Contents {
void SetInheritedOpacity(Scalar opacity) override;

private:
std::unique_ptr<Geometry> geometry_;
std::shared_ptr<Geometry> geometry_;
Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect;

ClipContents(const ClipContents&) = delete;
Expand Down
6 changes: 2 additions & 4 deletions impeller/entity/geometry/cover_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ namespace impeller {

CoverGeometry::CoverGeometry() = default;

CoverGeometry::~CoverGeometry() = default;

GeometryResult CoverGeometry::GetPositionBuffer(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
RenderPass& pass) const {
auto rect = Rect::MakeSize(pass.GetRenderTargetSize());
constexpr uint16_t kRectIndicies[4] = {0, 1, 2, 3};
auto& host_buffer = pass.GetTransientsBuffer();
Expand Down Expand Up @@ -43,7 +41,7 @@ GeometryResult CoverGeometry::GetPositionUVBuffer(
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
RenderPass& pass) const {
auto rect = Rect::MakeSize(pass.GetRenderTargetSize());
return ComputeUVGeometryForRect(rect, texture_coverage, effect_transform,
renderer, entity, pass);
Expand Down
10 changes: 6 additions & 4 deletions impeller/entity/geometry/cover_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ namespace impeller {

/// @brief A geometry that implements "drawPaint" like behavior by covering
/// the entire render pass area.
class CoverGeometry : public Geometry {
class CoverGeometry final : public Geometry {
public:
CoverGeometry();

~CoverGeometry();
~CoverGeometry() = default;

// |Geometry|
bool CoversArea(const Matrix& transform, const Rect& rect) const override;
Expand All @@ -23,7 +23,7 @@ class CoverGeometry : public Geometry {
// |Geometry|
GeometryResult GetPositionBuffer(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) override;
RenderPass& pass) const override;

// |Geometry|
GeometryVertexType GetVertexType() const override;
Expand All @@ -36,11 +36,13 @@ class CoverGeometry : public Geometry {
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) override;
RenderPass& pass) const override;

CoverGeometry(const CoverGeometry&) = delete;

CoverGeometry& operator=(const CoverGeometry&) = delete;
};

static_assert(std::is_trivially_destructible<CoverGeometry>::value);

} // namespace impeller
6 changes: 2 additions & 4 deletions impeller/entity/geometry/fill_path_geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ FillPathGeometry::FillPathGeometry(const Path& path,
std::optional<Rect> inner_rect)
: path_(path), inner_rect_(inner_rect) {}

FillPathGeometry::~FillPathGeometry() = default;

GeometryResult FillPathGeometry::GetPositionBuffer(
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
RenderPass& pass) const {
auto& host_buffer = pass.GetTransientsBuffer();
VertexBuffer vertex_buffer;

Expand Down Expand Up @@ -76,7 +74,7 @@ GeometryResult FillPathGeometry::GetPositionUVBuffer(
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
RenderPass& pass) const {
using VS = TextureFillVertexShader;

auto uv_transform =
Expand Down
8 changes: 4 additions & 4 deletions impeller/entity/geometry/fill_path_geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
namespace impeller {

/// @brief A geometry that is created from a filled path object.
class FillPathGeometry : public Geometry {
class FillPathGeometry final : public Geometry {
public:
explicit FillPathGeometry(const Path& path,
std::optional<Rect> inner_rect = std::nullopt);

~FillPathGeometry();
~FillPathGeometry() = default;

// |Geometry|
bool CoversArea(const Matrix& transform, const Rect& rect) const override;
Expand All @@ -26,7 +26,7 @@ class FillPathGeometry : public Geometry {
// |Geometry|
GeometryResult GetPositionBuffer(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) override;
RenderPass& pass) const override;

// |Geometry|
GeometryVertexType GetVertexType() const override;
Expand All @@ -39,7 +39,7 @@ class FillPathGeometry : public Geometry {
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) override;
RenderPass& pass) const override;

Path path_;
std::optional<Rect> inner_rect_;
Expand Down
31 changes: 14 additions & 17 deletions impeller/entity/geometry/geometry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "impeller/entity/geometry/geometry.h"

#include <memory>
#include <optional>

#include "impeller/entity/geometry/cover_geometry.h"
Expand Down Expand Up @@ -69,31 +70,27 @@ GeometryResult ComputeUVGeometryForRect(Rect source_rect,
};
}

Geometry::Geometry() = default;

Geometry::~Geometry() = default;

GeometryResult Geometry::GetPositionUVBuffer(Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) {
RenderPass& pass) const {
return {};
}

std::unique_ptr<Geometry> Geometry::MakeFillPath(
std::shared_ptr<Geometry> Geometry::MakeFillPath(
const Path& path,
std::optional<Rect> inner_rect) {
return std::make_unique<FillPathGeometry>(path, inner_rect);
return std::make_shared<FillPathGeometry>(path, inner_rect);
}

std::unique_ptr<Geometry> Geometry::MakePointField(std::vector<Point> points,
std::shared_ptr<Geometry> Geometry::MakePointField(std::vector<Point> points,
Scalar radius,
bool round) {
return std::make_unique<PointFieldGeometry>(std::move(points), radius, round);
return std::make_shared<PointFieldGeometry>(std::move(points), radius, round);
}

std::unique_ptr<Geometry> Geometry::MakeStrokePath(const Path& path,
std::shared_ptr<Geometry> Geometry::MakeStrokePath(const Path& path,
Scalar stroke_width,
Scalar miter_limit,
Cap stroke_cap,
Expand All @@ -102,23 +99,23 @@ std::unique_ptr<Geometry> Geometry::MakeStrokePath(const Path& path,
if (miter_limit < 0) {
miter_limit = 4.0;
}
return std::make_unique<StrokePathGeometry>(path, stroke_width, miter_limit,
return std::make_shared<StrokePathGeometry>(path, stroke_width, miter_limit,
stroke_cap, stroke_join);
}

std::unique_ptr<Geometry> Geometry::MakeCover() {
return std::make_unique<CoverGeometry>();
std::shared_ptr<Geometry> Geometry::MakeCover() {
return std::make_shared<CoverGeometry>();
}

std::unique_ptr<Geometry> Geometry::MakeRect(Rect rect) {
return std::make_unique<RectGeometry>(rect);
std::shared_ptr<Geometry> Geometry::MakeRect(Rect rect) {
return std::make_shared<RectGeometry>(rect);
}

std::unique_ptr<Geometry> Geometry::MakeLine(Point p0,
std::shared_ptr<Geometry> Geometry::MakeLine(Point p0,
Point p1,
Scalar width,
Cap cap) {
return std::make_unique<LineGeometry>(p0, p1, width, cap);
return std::make_shared<LineGeometry>(p0, p1, width, cap);
}

bool Geometry::CoversArea(const Matrix& transform, const Rect& rect) const {
Expand Down
20 changes: 8 additions & 12 deletions impeller/entity/geometry/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,43 +48,39 @@ GeometryResult ComputeUVGeometryForRect(Rect source_rect,

class Geometry {
public:
Geometry();

virtual ~Geometry();

static std::unique_ptr<Geometry> MakeFillPath(
static std::shared_ptr<Geometry> MakeFillPath(
const Path& path,
std::optional<Rect> inner_rect = std::nullopt);

static std::unique_ptr<Geometry> MakeStrokePath(
static std::shared_ptr<Geometry> MakeStrokePath(
const Path& path,
Scalar stroke_width = 0.0,
Scalar miter_limit = 4.0,
Cap stroke_cap = Cap::kButt,
Join stroke_join = Join::kMiter);

static std::unique_ptr<Geometry> MakeCover();
static std::shared_ptr<Geometry> MakeCover();

static std::unique_ptr<Geometry> MakeRect(Rect rect);
static std::shared_ptr<Geometry> MakeRect(Rect rect);

static std::unique_ptr<Geometry> MakeLine(Point p0,
static std::shared_ptr<Geometry> MakeLine(Point p0,
Point p1,
Scalar width,
Cap cap);

static std::unique_ptr<Geometry> MakePointField(std::vector<Point> points,
static std::shared_ptr<Geometry> MakePointField(std::vector<Point> points,
Scalar radius,
bool round);

virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
const Entity& entity,
RenderPass& pass) = 0;
RenderPass& pass) const = 0;

virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage,
Matrix effect_transform,
const ContentContext& renderer,
const Entity& entity,
RenderPass& pass);
RenderPass& pass) const = 0;

virtual GeometryVertexType GetVertexType() const = 0;

Expand Down
Loading