| Flutter Impeller |

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 #pragma once
6
7 #include "impeller/core/formats.h"
8 #include "impeller/core/vertex_buffer.h"
9 #include "impeller/entity/contents/content_context.h"
10 #include "impeller/entity/entity.h"
11 #include "impeller/entity/texture_fill.vert.h"
12 #include "impeller/renderer/render_pass.h"
13
14 namespace impeller {
15
16 class Tessellator;
17
18 struct GeometryResult {
19 PrimitiveType type;
20 VertexBuffer vertex_buffer;
21 Matrix transform;
22 bool prevent_overdraw;
23 };
24
25 enum GeometryVertexType {
26 kPosition,
27 kColor,
28 kUV,
29 };
30
31 /// @brief Compute UV geometry for a VBB that contains only position geometry.
32 ///
33 /// texture_origin should be set to 0, 0 for stroke and stroke based geometry,
34 /// like the point field.
35 VertexBufferBuilder<TextureFillVertexShader::PerVertexData>
36 ComputeUVGeometryCPU(
37 VertexBufferBuilder<SolidFillVertexShader::PerVertexData>& input,
38 Point texture_origin,
39 Size texture_coverage,
40 Matrix effect_transform);
41
42 GeometryResult ComputeUVGeometryForRect(Rect source_rect,
43 Rect texture_coverage,
44 Matrix effect_transform,
45 const ContentContext& renderer,
46 const Entity& entity,
47 RenderPass& pass);
48
49 /// @brief Given a polyline created from a convex filled path, perform a
50 /// tessellation.
51 std::pair<std::vector<Point>, std::vector<uint16_t>> TessellateConvex(
52 Path::Polyline polyline);
53
54 class Geometry {
55 public:
56 Geometry();
57
58 virtual ~Geometry();
59
60 static std::unique_ptr<Geometry> MakeFillPath(
61 const Path& path,
62 std::optional<Rect> inner_rect = std::nullopt);
63
64 static std::unique_ptr<Geometry> MakeStrokePath(
65 const Path& path,
66 Scalar stroke_width = 0.0,
67 Scalar miter_limit = 4.0,
68 Cap stroke_cap = Cap::kButt,
69 Join stroke_join = Join::kMiter);
70
71 static std::unique_ptr<Geometry> MakeCover();
72
73 static std::unique_ptr<Geometry> MakeRect(Rect rect);
74
75 static std::unique_ptr<Geometry> MakePointField(std::vector<Point> points,
76 Scalar radius,
77 bool round);
78
79 virtual GeometryResult GetPositionBuffer(const ContentContext& renderer,
80 const Entity& entity,
81 RenderPass& pass) = 0;
82
83 virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage,
84 Matrix effect_transform,
85 const ContentContext& renderer,
86 const Entity& entity,
87 RenderPass& pass);
88
89 virtual GeometryVertexType GetVertexType() const = 0;
90
91 virtual std::optional<Rect> GetCoverage(const Matrix& transform) const = 0;
92
93 /// @brief Determines if this geometry, transformed by the given
94 /// `transform`, will completely cover all surface area of the given
95 /// `rect`.
96 ///
97 /// This is a conservative estimate useful for certain
98 /// optimizations.
99 ///
100 /// @returns `true` if the transformed geometry is guaranteed to cover the
101 /// given `rect`. May return `false` in many undetected cases where
102 /// the transformed geometry does in fact cover the `rect`.
103 virtual bool CoversArea(const Matrix& transform, const Rect& rect) const;
104 };
105
106 } // namespace impeller
impeller::PrimitiveType
PrimitiveType
Definition: formats.h:328
impeller::Scalar
float Scalar
Definition: scalar.h:15
vertex_buffer.h
entity.h
impeller::Geometry::~Geometry
virtual ~Geometry()
impeller::Geometry::GetCoverage
virtual std::optional< Rect > GetCoverage(const Matrix &transform) const =0
impeller::VertexBuffer
Definition: vertex_buffer.h:12
formats.h
impeller::Geometry::MakeRect
static std::unique_ptr< Geometry > MakeRect(Rect rect)
Definition: geometry.cc:142
impeller::TessellateConvex
std::pair< std::vector< Point >, std::vector< uint16_t > > TessellateConvex(Path::Polyline polyline)
Given a convex polyline, create a triangle fan structure.
Definition: geometry.cc:19
impeller::Size
TSize< Scalar > Size
Definition: size.h:135
impeller::Geometry::CoversArea
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:146
impeller::Cap::kButt
@ kButt
impeller::ComputeUVGeometryCPU
VertexBufferBuilder< TextureFillVertexShader::PerVertexData > ComputeUVGeometryCPU(VertexBufferBuilder< SolidFillVertexShader::PerVertexData > &input, Point texture_origin, Size texture_coverage, Matrix effect_transform)
Compute UV geometry for a VBB that contains only position geometry.
Definition: geometry.cc:50
impeller::GeometryVertexType
GeometryVertexType
Definition: geometry.h:25
impeller::Join::kMiter
@ kMiter
impeller::GeometryResult::prevent_overdraw
bool prevent_overdraw
Definition: geometry.h:22
impeller::kColor
@ kColor
Definition: geometry.h:27
impeller::Entity
Definition: entity.h:21
impeller::Point
TPoint< Scalar > Point
Definition: point.h:306
render_pass.h
impeller::GeometryResult::type
PrimitiveType type
Definition: geometry.h:19
impeller::Path
Paths are lightweight objects that describe a collection of linear, quadratic, or cubic segments....
Definition: path.h:54
impeller::Geometry::MakeStrokePath
static std::unique_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:125
impeller::Geometry::Geometry
Geometry()
impeller::GeometryResult
Definition: geometry.h:18
impeller::Rect
TRect< Scalar > Rect
Definition: rect.h:306
impeller::Geometry::GetVertexType
virtual GeometryVertexType GetVertexType() const =0
impeller::Geometry::MakeCover
static std::unique_ptr< Geometry > MakeCover()
Definition: geometry.cc:138
impeller::Geometry::GetPositionUVBuffer
virtual GeometryResult GetPositionUVBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:105
impeller::kUV
@ kUV
Definition: geometry.h:28
impeller::RenderPass
Render passes encode render commands directed as one specific render target into an underlying comman...
Definition: render_pass.h:27
impeller::GeometryResult::transform
Matrix transform
Definition: geometry.h:21
impeller::Geometry::GetPositionBuffer
virtual GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass)=0
content_context.h
impeller::Geometry
Definition: geometry.h:54
impeller::Geometry::MakePointField
static std::unique_ptr< Geometry > MakePointField(std::vector< Point > points, Scalar radius, bool round)
Definition: geometry.cc:119
impeller::Join
Join
Definition: path.h:23
impeller::Geometry::MakeFillPath
static std::unique_ptr< Geometry > MakeFillPath(const Path &path, std::optional< Rect > inner_rect=std::nullopt)
Definition: geometry.cc:113
impeller::GeometryResult::vertex_buffer
VertexBuffer vertex_buffer
Definition: geometry.h:20
impeller::ComputeUVGeometryForRect
GeometryResult ComputeUVGeometryForRect(Rect source_rect, Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass)
Definition: geometry.cc:70
impeller
Definition: aiks_context.cc:10
impeller::kPosition
@ kPosition
Definition: geometry.h:26
impeller::ContentContext
Definition: content_context.h:344
impeller::TRect< Scalar >
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition: matrix.h:36
impeller::Cap
Cap
Definition: path.h:17