From e05fb33e41d880e99af0325876a69e3369e58a22 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 17 Nov 2023 08:14:54 -0800 Subject: [PATCH] [Impeller] Cleanups to geometry interfaces. --- impeller/aiks/aiks_unittests.cc | 2 ++ impeller/aiks/canvas.cc | 8 ++--- impeller/aiks/canvas.h | 4 +-- impeller/aiks/paint.cc | 8 ++--- impeller/aiks/paint.h | 6 +--- impeller/entity/contents/clip_contents.cc | 4 +-- impeller/entity/contents/clip_contents.h | 4 +-- impeller/entity/geometry/cover_geometry.cc | 6 ++-- impeller/entity/geometry/cover_geometry.h | 10 +++--- .../entity/geometry/fill_path_geometry.cc | 6 ++-- impeller/entity/geometry/fill_path_geometry.h | 8 ++--- impeller/entity/geometry/geometry.cc | 31 +++++++++---------- impeller/entity/geometry/geometry.h | 20 +++++------- impeller/entity/geometry/line_geometry.cc | 6 ++-- impeller/entity/geometry/line_geometry.h | 11 ++++--- .../entity/geometry/point_field_geometry.cc | 10 +++--- .../entity/geometry/point_field_geometry.h | 12 +++---- impeller/entity/geometry/rect_geometry.cc | 6 ++-- impeller/entity/geometry/rect_geometry.h | 10 +++--- .../entity/geometry/stroke_path_geometry.cc | 4 +-- .../entity/geometry/stroke_path_geometry.h | 6 ++-- impeller/entity/geometry/vertices_geometry.cc | 6 ++-- impeller/entity/geometry/vertices_geometry.h | 8 ++--- 23 files changed, 90 insertions(+), 106 deletions(-) diff --git a/impeller/aiks/aiks_unittests.cc b/impeller/aiks/aiks_unittests.cc index e65b1c06c4877..91b6aa6e83a24 100644 --- a/impeller/aiks/aiks_unittests.cc +++ b/impeller/aiks/aiks_unittests.cc @@ -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" diff --git a/impeller/aiks/canvas.cc b/impeller/aiks/canvas.cc index 0bcb16580d2f2..488ba29e518b8 100644 --- a/impeller/aiks/canvas.cc +++ b/impeller/aiks/canvas.cc @@ -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); @@ -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); @@ -390,10 +390,10 @@ void Canvas::ClipRRect(const Rect& rect, } } -void Canvas::ClipGeometry(std::unique_ptr geometry, +void Canvas::ClipGeometry(const std::shared_ptr& geometry, Entity::ClipOperation clip_op) { auto contents = std::make_shared(); - contents->SetGeometry(std::move(geometry)); + contents->SetGeometry(geometry); contents->SetClipOperation(clip_op); Entity entity; diff --git a/impeller/aiks/canvas.h b/impeller/aiks/canvas.h index 1bee70b25f587..6e2cc344026a6 100644 --- a/impeller/aiks/canvas.h +++ b/impeller/aiks/canvas.h @@ -10,7 +10,6 @@ #include #include -#include "flutter/fml/macros.h" #include "impeller/aiks/image.h" #include "impeller/aiks/image_filter.h" #include "impeller/aiks/paint.h" @@ -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 { @@ -175,7 +173,7 @@ class Canvas { size_t GetClipDepth() const; - void ClipGeometry(std::unique_ptr geometry, + void ClipGeometry(const std::shared_ptr& geometry, Entity::ClipOperation clip_op); void IntersectCulling(Rect clip_bounds); diff --git a/impeller/aiks/paint.cc b/impeller/aiks/paint.cc index 708c8782f36ba..65a6015351239 100644 --- a/impeller/aiks/paint.cc +++ b/impeller/aiks/paint.cc @@ -28,7 +28,7 @@ constexpr ColorMatrix kColorInversion = { std::shared_ptr Paint::CreateContentsForEntity(const Path& path, bool cover) const { - std::unique_ptr geometry; + std::shared_ptr geometry; switch (style) { case Style::kFill: geometry = cover ? Geometry::MakeCover() : Geometry::MakeFillPath(path); @@ -40,11 +40,11 @@ std::shared_ptr Paint::CreateContentsForEntity(const Path& path, stroke_cap, stroke_join); break; } - return CreateContentsForGeometry(std::move(geometry)); + return CreateContentsForGeometry(geometry); } std::shared_ptr Paint::CreateContentsForGeometry( - std::shared_ptr geometry) const { + const std::shared_ptr& geometry) const { auto contents = color_source.GetContents(*this); // Attempt to apply the color filter on the CPU first. @@ -57,7 +57,7 @@ std::shared_ptr 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 diff --git a/impeller/aiks/paint.h b/impeller/aiks/paint.h index bf96842b783c9..9538b8acc3d04 100644 --- a/impeller/aiks/paint.h +++ b/impeller/aiks/paint.h @@ -6,16 +6,12 @@ #include -#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" @@ -92,7 +88,7 @@ struct Paint { bool cover = false) const; std::shared_ptr CreateContentsForGeometry( - std::shared_ptr geometry) const; + const std::shared_ptr& geometry) const; /// @brief Whether this paint has a color filter that can apply opacity bool HasColorFilter() const; diff --git a/impeller/entity/contents/clip_contents.cc b/impeller/entity/contents/clip_contents.cc index c6c173171f3b1..a67b72ce34353 100644 --- a/impeller/entity/contents/clip_contents.cc +++ b/impeller/entity/contents/clip_contents.cc @@ -22,8 +22,8 @@ ClipContents::ClipContents() = default; ClipContents::~ClipContents() = default; -void ClipContents::SetGeometry(std::unique_ptr geometry) { - geometry_ = std::move(geometry); +void ClipContents::SetGeometry(const std::shared_ptr& geometry) { + geometry_ = geometry; } void ClipContents::SetClipOperation(Entity::ClipOperation clip_op) { diff --git a/impeller/entity/contents/clip_contents.h b/impeller/entity/contents/clip_contents.h index cb1ea1bf85cfe..48e479f387344 100644 --- a/impeller/entity/contents/clip_contents.h +++ b/impeller/entity/contents/clip_contents.h @@ -21,7 +21,7 @@ class ClipContents final : public Contents { ~ClipContents(); - void SetGeometry(std::unique_ptr geometry); + void SetGeometry(const std::shared_ptr& geometry); void SetClipOperation(Entity::ClipOperation clip_op); @@ -48,7 +48,7 @@ class ClipContents final : public Contents { void SetInheritedOpacity(Scalar opacity) override; private: - std::unique_ptr geometry_; + std::shared_ptr geometry_; Entity::ClipOperation clip_op_ = Entity::ClipOperation::kIntersect; ClipContents(const ClipContents&) = delete; diff --git a/impeller/entity/geometry/cover_geometry.cc b/impeller/entity/geometry/cover_geometry.cc index cc7793a0ec40b..9922897a8f39c 100644 --- a/impeller/entity/geometry/cover_geometry.cc +++ b/impeller/entity/geometry/cover_geometry.cc @@ -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(); @@ -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); diff --git a/impeller/entity/geometry/cover_geometry.h b/impeller/entity/geometry/cover_geometry.h index 83d65f1727f60..653b0c5f9769f 100644 --- a/impeller/entity/geometry/cover_geometry.h +++ b/impeller/entity/geometry/cover_geometry.h @@ -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; @@ -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; @@ -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::value); + } // namespace impeller diff --git a/impeller/entity/geometry/fill_path_geometry.cc b/impeller/entity/geometry/fill_path_geometry.cc index 1e721cc645e30..63a4902860dc7 100644 --- a/impeller/entity/geometry/fill_path_geometry.cc +++ b/impeller/entity/geometry/fill_path_geometry.cc @@ -11,12 +11,10 @@ FillPathGeometry::FillPathGeometry(const Path& path, std::optional 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; @@ -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 = diff --git a/impeller/entity/geometry/fill_path_geometry.h b/impeller/entity/geometry/fill_path_geometry.h index cf9d51cbef6a4..c46e13aa6c0bc 100644 --- a/impeller/entity/geometry/fill_path_geometry.h +++ b/impeller/entity/geometry/fill_path_geometry.h @@ -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 inner_rect = std::nullopt); - ~FillPathGeometry(); + ~FillPathGeometry() = default; // |Geometry| bool CoversArea(const Matrix& transform, const Rect& rect) const override; @@ -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; @@ -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 inner_rect_; diff --git a/impeller/entity/geometry/geometry.cc b/impeller/entity/geometry/geometry.cc index 250022dd6384e..d028aa635b019 100644 --- a/impeller/entity/geometry/geometry.cc +++ b/impeller/entity/geometry/geometry.cc @@ -4,6 +4,7 @@ #include "impeller/entity/geometry/geometry.h" +#include #include #include "impeller/entity/geometry/cover_geometry.h" @@ -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::MakeFillPath( +std::shared_ptr Geometry::MakeFillPath( const Path& path, std::optional inner_rect) { - return std::make_unique(path, inner_rect); + return std::make_shared(path, inner_rect); } -std::unique_ptr Geometry::MakePointField(std::vector points, +std::shared_ptr Geometry::MakePointField(std::vector points, Scalar radius, bool round) { - return std::make_unique(std::move(points), radius, round); + return std::make_shared(std::move(points), radius, round); } -std::unique_ptr Geometry::MakeStrokePath(const Path& path, +std::shared_ptr Geometry::MakeStrokePath(const Path& path, Scalar stroke_width, Scalar miter_limit, Cap stroke_cap, @@ -102,23 +99,23 @@ std::unique_ptr Geometry::MakeStrokePath(const Path& path, if (miter_limit < 0) { miter_limit = 4.0; } - return std::make_unique(path, stroke_width, miter_limit, + return std::make_shared(path, stroke_width, miter_limit, stroke_cap, stroke_join); } -std::unique_ptr Geometry::MakeCover() { - return std::make_unique(); +std::shared_ptr Geometry::MakeCover() { + return std::make_shared(); } -std::unique_ptr Geometry::MakeRect(Rect rect) { - return std::make_unique(rect); +std::shared_ptr Geometry::MakeRect(Rect rect) { + return std::make_shared(rect); } -std::unique_ptr Geometry::MakeLine(Point p0, +std::shared_ptr Geometry::MakeLine(Point p0, Point p1, Scalar width, Cap cap) { - return std::make_unique(p0, p1, width, cap); + return std::make_shared(p0, p1, width, cap); } bool Geometry::CoversArea(const Matrix& transform, const Rect& rect) const { diff --git a/impeller/entity/geometry/geometry.h b/impeller/entity/geometry/geometry.h index 0c76cae845aa3..307ce315d1af7 100644 --- a/impeller/entity/geometry/geometry.h +++ b/impeller/entity/geometry/geometry.h @@ -48,43 +48,39 @@ GeometryResult ComputeUVGeometryForRect(Rect source_rect, class Geometry { public: - Geometry(); - - virtual ~Geometry(); - - static std::unique_ptr MakeFillPath( + static std::shared_ptr MakeFillPath( const Path& path, std::optional inner_rect = std::nullopt); - static std::unique_ptr MakeStrokePath( + static std::shared_ptr 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 MakeCover(); + static std::shared_ptr MakeCover(); - static std::unique_ptr MakeRect(Rect rect); + static std::shared_ptr MakeRect(Rect rect); - static std::unique_ptr MakeLine(Point p0, + static std::shared_ptr MakeLine(Point p0, Point p1, Scalar width, Cap cap); - static std::unique_ptr MakePointField(std::vector points, + static std::shared_ptr MakePointField(std::vector 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; diff --git a/impeller/entity/geometry/line_geometry.cc b/impeller/entity/geometry/line_geometry.cc index c7984eb7aab7a..b81d3e6e8519a 100644 --- a/impeller/entity/geometry/line_geometry.cc +++ b/impeller/entity/geometry/line_geometry.cc @@ -15,8 +15,6 @@ LineGeometry::LineGeometry(Point p0, Point p1, Scalar width, Cap cap) FML_DCHECK(cap != Cap::kRound); } -LineGeometry::~LineGeometry() = default; - bool LineGeometry::ComputeCorners(Point corners[4], const Matrix& transform, bool extend_endpoints) const { @@ -55,7 +53,7 @@ bool LineGeometry::ComputeCorners(Point corners[4], GeometryResult LineGeometry::GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { auto& host_buffer = pass.GetTransientsBuffer(); Point corners[4]; @@ -84,7 +82,7 @@ GeometryResult LineGeometry::GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { auto& host_buffer = pass.GetTransientsBuffer(); auto uv_transform = diff --git a/impeller/entity/geometry/line_geometry.h b/impeller/entity/geometry/line_geometry.h index b7e99b428e03d..fe37de6a62f56 100644 --- a/impeller/entity/geometry/line_geometry.h +++ b/impeller/entity/geometry/line_geometry.h @@ -4,15 +4,16 @@ #pragma once +#include #include "impeller/entity/geometry/geometry.h" namespace impeller { -class LineGeometry : public Geometry { +class LineGeometry final : public Geometry { public: explicit LineGeometry(Point p0, Point p1, Scalar width, Cap cap); - ~LineGeometry(); + ~LineGeometry() = default; // |Geometry| bool CoversArea(const Matrix& transform, const Rect& rect) const override; @@ -42,7 +43,7 @@ class LineGeometry : public Geometry { // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryVertexType GetVertexType() const override; @@ -55,7 +56,7 @@ class LineGeometry : public Geometry { Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; Point p0_; Point p1_; @@ -67,4 +68,6 @@ class LineGeometry : public Geometry { LineGeometry& operator=(const LineGeometry&) = delete; }; +static_assert(std::is_trivially_destructible::value); + } // namespace impeller diff --git a/impeller/entity/geometry/point_field_geometry.cc b/impeller/entity/geometry/point_field_geometry.cc index 9821bad91ad7b..3a75e03621caa 100644 --- a/impeller/entity/geometry/point_field_geometry.cc +++ b/impeller/entity/geometry/point_field_geometry.cc @@ -14,12 +14,10 @@ PointFieldGeometry::PointFieldGeometry(std::vector points, bool round) : points_(std::move(points)), radius_(radius), round_(round) {} -PointFieldGeometry::~PointFieldGeometry() = default; - GeometryResult PointFieldGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { if (renderer.GetDeviceCapabilities().SupportsCompute()) { return GetPositionBufferGPU(renderer, entity, pass); } @@ -43,7 +41,7 @@ GeometryResult PointFieldGeometry::GetPositionUVBuffer( Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { if (renderer.GetDeviceCapabilities().SupportsCompute()) { return GetPositionBufferGPU(renderer, entity, pass, texture_coverage, effect_transform); @@ -69,7 +67,7 @@ GeometryResult PointFieldGeometry::GetPositionUVBuffer( std::optional> PointFieldGeometry::GetPositionBufferCPU(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { if (radius_ < 0.0) { return std::nullopt; } @@ -127,7 +125,7 @@ GeometryResult PointFieldGeometry::GetPositionBufferGPU( const Entity& entity, RenderPass& pass, std::optional texture_coverage, - std::optional effect_transform) { + std::optional effect_transform) const { FML_DCHECK(renderer.GetDeviceCapabilities().SupportsCompute()); if (radius_ < 0.0) { return {}; diff --git a/impeller/entity/geometry/point_field_geometry.h b/impeller/entity/geometry/point_field_geometry.h index 30ccdaa01a369..944db2df960b6 100644 --- a/impeller/entity/geometry/point_field_geometry.h +++ b/impeller/entity/geometry/point_field_geometry.h @@ -8,11 +8,11 @@ namespace impeller { -class PointFieldGeometry : public Geometry { +class PointFieldGeometry final : public Geometry { public: PointFieldGeometry(std::vector points, Scalar radius, bool round); - ~PointFieldGeometry(); + ~PointFieldGeometry() = default; static size_t ComputeCircleDivisions(Scalar scaled_radius, bool round); @@ -20,14 +20,14 @@ class PointFieldGeometry : public Geometry { // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryResult GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryVertexType GetVertexType() const override; @@ -40,12 +40,12 @@ class PointFieldGeometry : public Geometry { const Entity& entity, RenderPass& pass, std::optional texture_coverage = std::nullopt, - std::optional effect_transform = std::nullopt); + std::optional effect_transform = std::nullopt) const; std::optional> GetPositionBufferCPU(const ContentContext& renderer, const Entity& entity, - RenderPass& pass); + RenderPass& pass) const; std::vector points_; Scalar radius_; diff --git a/impeller/entity/geometry/rect_geometry.cc b/impeller/entity/geometry/rect_geometry.cc index 7ea0476699876..856b0a5252376 100644 --- a/impeller/entity/geometry/rect_geometry.cc +++ b/impeller/entity/geometry/rect_geometry.cc @@ -8,11 +8,9 @@ namespace impeller { RectGeometry::RectGeometry(Rect rect) : rect_(rect) {} -RectGeometry::~RectGeometry() = default; - GeometryResult RectGeometry::GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { auto& host_buffer = pass.GetTransientsBuffer(); return GeometryResult{ .type = PrimitiveType::kTriangleStrip, @@ -34,7 +32,7 @@ GeometryResult RectGeometry::GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { return ComputeUVGeometryForRect(rect_, texture_coverage, effect_transform, renderer, entity, pass); } diff --git a/impeller/entity/geometry/rect_geometry.h b/impeller/entity/geometry/rect_geometry.h index 37364981a71c9..35f1762ed2a11 100644 --- a/impeller/entity/geometry/rect_geometry.h +++ b/impeller/entity/geometry/rect_geometry.h @@ -8,11 +8,11 @@ namespace impeller { -class RectGeometry : public Geometry { +class RectGeometry final : public Geometry { public: explicit RectGeometry(Rect rect); - ~RectGeometry(); + ~RectGeometry() = default; // |Geometry| bool CoversArea(const Matrix& transform, const Rect& rect) const override; @@ -24,7 +24,7 @@ class RectGeometry : public Geometry { // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryVertexType GetVertexType() const override; @@ -37,7 +37,7 @@ class RectGeometry : public Geometry { Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; Rect rect_; @@ -46,4 +46,6 @@ class RectGeometry : public Geometry { RectGeometry& operator=(const RectGeometry&) = delete; }; +static_assert(std::is_trivially_destructible::value); + } // namespace impeller diff --git a/impeller/entity/geometry/stroke_path_geometry.cc b/impeller/entity/geometry/stroke_path_geometry.cc index 48eebb6a9286a..a42ef7749f7e3 100644 --- a/impeller/entity/geometry/stroke_path_geometry.cc +++ b/impeller/entity/geometry/stroke_path_geometry.cc @@ -439,7 +439,7 @@ StrokePathGeometry::CreateSolidStrokeVertices( GeometryResult StrokePathGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { if (stroke_width_ < 0.0) { return {}; } @@ -471,7 +471,7 @@ GeometryResult StrokePathGeometry::GetPositionUVBuffer( Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { if (stroke_width_ < 0.0) { return {}; } diff --git a/impeller/entity/geometry/stroke_path_geometry.h b/impeller/entity/geometry/stroke_path_geometry.h index 69b7511d9a7e9..ae9817974af22 100644 --- a/impeller/entity/geometry/stroke_path_geometry.h +++ b/impeller/entity/geometry/stroke_path_geometry.h @@ -9,7 +9,7 @@ namespace impeller { /// @brief A geometry that is created from a stroked path object. -class StrokePathGeometry : public Geometry { +class StrokePathGeometry final : public Geometry { public: StrokePathGeometry(const Path& path, Scalar stroke_width, @@ -47,14 +47,14 @@ class StrokePathGeometry : public Geometry { // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryResult GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryVertexType GetVertexType() const override; diff --git a/impeller/entity/geometry/vertices_geometry.cc b/impeller/entity/geometry/vertices_geometry.cc index 42af1e49c0a46..a21c274a6ac33 100644 --- a/impeller/entity/geometry/vertices_geometry.cc +++ b/impeller/entity/geometry/vertices_geometry.cc @@ -67,8 +67,6 @@ VerticesGeometry::VerticesGeometry(std::vector vertices, NormalizeIndices(); } -VerticesGeometry::~VerticesGeometry() = default; - PrimitiveType VerticesGeometry::GetPrimitiveType() const { switch (vertex_mode_) { case VerticesGeometry::VertexMode::kTriangleFan: @@ -113,7 +111,7 @@ std::optional VerticesGeometry::GetTextureCoordinateCoverge() const { GeometryResult VerticesGeometry::GetPositionBuffer( const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { auto index_count = indices_.size(); auto vertex_count = vertices_.size(); @@ -222,7 +220,7 @@ GeometryResult VerticesGeometry::GetPositionUVBuffer( Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) { + RenderPass& pass) const { using VS = TexturePipeline::VertexShader; auto index_count = indices_.size(); diff --git a/impeller/entity/geometry/vertices_geometry.h b/impeller/entity/geometry/vertices_geometry.h index 93ab83679b1e3..1e32961fd5eb5 100644 --- a/impeller/entity/geometry/vertices_geometry.h +++ b/impeller/entity/geometry/vertices_geometry.h @@ -9,7 +9,7 @@ namespace impeller { /// @brief A geometry that is created from a vertices object. -class VerticesGeometry : public Geometry { +class VerticesGeometry final : public Geometry { public: enum class VertexMode { kTriangles, @@ -24,7 +24,7 @@ class VerticesGeometry : public Geometry { Rect bounds, VerticesGeometry::VertexMode vertex_mode); - ~VerticesGeometry(); + ~VerticesGeometry() = default; GeometryResult GetPositionColorBuffer(const ContentContext& renderer, const Entity& entity, @@ -35,12 +35,12 @@ class VerticesGeometry : public Geometry { Matrix effect_transform, const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| GeometryResult GetPositionBuffer(const ContentContext& renderer, const Entity& entity, - RenderPass& pass) override; + RenderPass& pass) const override; // |Geometry| std::optional GetCoverage(const Matrix& transform) const override;