Flutter Engine
The Flutter Engine
geometry.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
6#define FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
7
14
15namespace impeller {
16
17class Tessellator;
18
20 enum class Mode {
21 /// The geometry has no overlapping triangles.
22 kNormal,
23 /// The geometry may have overlapping triangles. The geometry should be
24 /// stenciled with the NonZero fill rule.
26 /// The geometry may have overlapping triangles. The geometry should be
27 /// stenciled with the EvenOdd fill rule.
29 /// The geometry may have overlapping triangles, but they should not
30 /// overdraw or cancel each other out. This is a special case for stroke
31 /// geometry.
32 kPreventOverdraw,
33 };
34
39};
40
43 {
45 },
46};
47
48class Geometry {
49 public:
50 static std::shared_ptr<Geometry> MakeFillPath(
51 const Path& path,
52 std::optional<Rect> inner_rect = std::nullopt);
53
54 static std::shared_ptr<Geometry> MakeStrokePath(
55 const Path& path,
56 Scalar stroke_width = 0.0,
57 Scalar miter_limit = 4.0,
58 Cap stroke_cap = Cap::kButt,
59 Join stroke_join = Join::kMiter);
60
61 static std::shared_ptr<Geometry> MakeCover();
62
63 static std::shared_ptr<Geometry> MakeRect(const Rect& rect);
64
65 static std::shared_ptr<Geometry> MakeOval(const Rect& rect);
66
67 static std::shared_ptr<Geometry> MakeLine(const Point& p0,
68 const Point& p1,
70 Cap cap);
71
72 static std::shared_ptr<Geometry> MakeCircle(const Point& center,
73 Scalar radius);
74
75 static std::shared_ptr<Geometry> MakeStrokedCircle(const Point& center,
76 Scalar radius,
78
79 static std::shared_ptr<Geometry> MakeRoundRect(const Rect& rect,
80 const Size& radii);
81
82 static std::shared_ptr<Geometry> MakePointField(std::vector<Point> points,
83 Scalar radius,
84 bool round);
85
87 const Entity& entity,
88 RenderPass& pass) const = 0;
89
90 virtual GeometryResult::Mode GetResultMode() const;
91
92 virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
93
94 /// @brief Determines if this geometry, transformed by the given
95 /// `transform`, will completely cover all surface area of the given
96 /// `rect`.
97 ///
98 /// This is a conservative estimate useful for certain
99 /// optimizations.
100 ///
101 /// @returns `true` if the transformed geometry is guaranteed to cover the
102 /// given `rect`. May return `false` in many undetected cases where
103 /// the transformed geometry does in fact cover the `rect`.
104 virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
105
106 virtual bool IsAxisAlignedRect() const;
107
108 virtual bool CanApplyMaskFilter() const;
109
110 virtual Scalar ComputeAlphaCoverage(const Entity& entitys) const {
111 return 1.0;
112 }
113
114 protected:
117 const Tessellator::VertexGenerator& generator,
118 const Entity& entity,
119 RenderPass& pass);
120};
121
122} // namespace impeller
123
124#endif // FLUTTER_IMPELLER_ENTITY_GEOMETRY_GEOMETRY_H_
static void round(SkPoint *p)
static const int points[]
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
virtual Scalar ComputeAlphaCoverage(const Entity &entitys) const
Definition: geometry.h:110
static std::shared_ptr< Geometry > MakeCover()
Definition: geometry.cc:85
virtual GeometryResult::Mode GetResultMode() const
Definition: geometry.cc:56
static std::shared_ptr< Geometry > MakeOval(const Rect &rect)
Definition: geometry.cc:93
static std::shared_ptr< Geometry > MakeLine(const Point &p0, const Point &p1, Scalar width, Cap cap)
Definition: geometry.cc:97
static std::shared_ptr< Geometry > MakeCircle(const Point &center, Scalar radius)
Definition: geometry.cc:104
static std::shared_ptr< Geometry > MakeRect(const Rect &rect)
Definition: geometry.cc:89
static std::shared_ptr< Geometry > MakePointField(std::vector< Point > points, Scalar radius, bool round)
Definition: geometry.cc:66
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const =0
static std::shared_ptr< Geometry > MakeRoundRect(const Rect &rect, const Size &radii)
Definition: geometry.cc:115
virtual bool CanApplyMaskFilter() const
Definition: geometry.cc:128
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:24
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)
Definition: geometry.cc:72
static std::shared_ptr< Geometry > MakeStrokedCircle(const Point &center, Scalar radius, Scalar stroke_width)
Definition: geometry.cc:109
virtual bool CoversArea(const Matrix &transform, const Rect &rect) const
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Definition: geometry.cc:120
static std::shared_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:60
virtual bool IsAxisAlignedRect() const
Definition: geometry.cc:124
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:52
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:33
An object which produces a list of vertices as |Point|s that tessellate a previously provided shape a...
Definition: tessellator.h:91
@ kNormal
Default priority level.
Definition: embedder.h:262
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition: switches.h:57
@ kNone
Does not use the index buffer.
Join
Definition: path.h:24
PrimitiveType
Decides how backend draws pixels based on input vertices.
Definition: formats.h:352
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:18
static const GeometryResult kEmptyResult
Definition: geometry.h:41
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
int32_t width
const Scalar stroke_width
PrimitiveType type
Definition: geometry.h:35
@ kNormal
The geometry has no overlapping triangles.
VertexBuffer vertex_buffer
Definition: geometry.h:36
A 4x4 matrix using column-major storage.
Definition: matrix.h:37