Flutter Engine
The Flutter Engine
geometry.cc
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
6
7#include <memory>
8#include <optional>
9
21
22namespace impeller {
23
26 const Tessellator::VertexGenerator& generator,
27 const Entity& entity,
28 RenderPass& pass) {
29 using VT = SolidFillVertexShader::PerVertexData;
30
31 size_t count = generator.GetVertexCount();
32
33 return GeometryResult{
34 .type = generator.GetTriangleType(),
35 .vertex_buffer =
36 {
37 .vertex_buffer = renderer.GetTransientsBuffer().Emplace(
38 count * sizeof(VT), alignof(VT),
39 [&generator](uint8_t* buffer) {
40 auto vertices = reinterpret_cast<VT*>(buffer);
41 generator.GenerateVertices([&vertices](const Point& p) {
42 *vertices++ = {
43 .position = p,
44 };
45 });
46 FML_DCHECK(vertices == reinterpret_cast<VT*>(buffer) +
47 generator.GetVertexCount());
48 }),
49 .vertex_count = count,
50 .index_type = IndexType::kNone,
51 },
52 .transform = entity.GetShaderTransform(pass),
53 };
54}
55
58}
59
60std::shared_ptr<Geometry> Geometry::MakeFillPath(
61 const Path& path,
62 std::optional<Rect> inner_rect) {
63 return std::make_shared<FillPathGeometry>(path, inner_rect);
64}
65
66std::shared_ptr<Geometry> Geometry::MakePointField(std::vector<Point> points,
67 Scalar radius,
68 bool round) {
69 return std::make_shared<PointFieldGeometry>(std::move(points), radius, round);
70}
71
72std::shared_ptr<Geometry> Geometry::MakeStrokePath(const Path& path,
74 Scalar miter_limit,
75 Cap stroke_cap,
76 Join stroke_join) {
77 // Skia behaves like this.
78 if (miter_limit < 0) {
79 miter_limit = 4.0;
80 }
81 return std::make_shared<StrokePathGeometry>(path, stroke_width, miter_limit,
82 stroke_cap, stroke_join);
83}
84
85std::shared_ptr<Geometry> Geometry::MakeCover() {
86 return std::make_shared<CoverGeometry>();
87}
88
89std::shared_ptr<Geometry> Geometry::MakeRect(const Rect& rect) {
90 return std::make_shared<RectGeometry>(rect);
91}
92
93std::shared_ptr<Geometry> Geometry::MakeOval(const Rect& rect) {
94 return std::make_shared<EllipseGeometry>(rect);
95}
96
97std::shared_ptr<Geometry> Geometry::MakeLine(const Point& p0,
98 const Point& p1,
100 Cap cap) {
101 return std::make_shared<LineGeometry>(p0, p1, width, cap);
102}
103
104std::shared_ptr<Geometry> Geometry::MakeCircle(const Point& center,
105 Scalar radius) {
106 return std::make_shared<CircleGeometry>(center, radius);
107}
108
109std::shared_ptr<Geometry> Geometry::MakeStrokedCircle(const Point& center,
110 Scalar radius,
112 return std::make_shared<CircleGeometry>(center, radius, stroke_width);
113}
114
115std::shared_ptr<Geometry> Geometry::MakeRoundRect(const Rect& rect,
116 const Size& radii) {
117 return std::make_shared<RoundRectGeometry>(rect, radii);
118}
119
120bool Geometry::CoversArea(const Matrix& transform, const Rect& rect) const {
121 return false;
122}
123
125 return false;
126}
127
129 return true;
130}
131
132} // namespace impeller
int count
Definition: FontMgrTest.cpp:50
static void round(SkPoint *p)
static const int points[]
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
Definition: entity.cc:50
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
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
virtual size_t GetVertexCount() const =0
Returns the number of vertices that the generator plans to produce, if known.
virtual PrimitiveType GetTriangleType() const =0
Returns the |PrimitiveType| that describes the relationship among the list of vertices produced by th...
virtual void GenerateVertices(const TessellatedVertexProc &proc) const =0
Generate the vertices and deliver them in the necessary order (as required by the PrimitiveType) to t...
#define FML_DCHECK(condition)
Definition: logging.h:103
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
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 to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Definition: switches.h:126
@ kNone
Does not use the index buffer.
Join
Definition: path.h:24
float Scalar
Definition: scalar.h:18
Cap
Definition: path.h:18
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.
A 4x4 matrix using column-major storage.
Definition: matrix.h:37