23static std::vector<uint16_t> fromFanIndices(
size_t vertex_count,
25 const uint16_t* indices) {
26 std::vector<uint16_t> unrolled_indices;
29 if (index_count > 0u) {
30 if (index_count < 3u) {
34 auto center_point = indices[0];
35 for (
auto i = 1u;
i < index_count - 1;
i++) {
36 unrolled_indices.push_back(center_point);
37 unrolled_indices.push_back(indices[
i]);
38 unrolled_indices.push_back(indices[
i + 1]);
41 if (vertex_count < 3u) {
47 for (
auto i = 1u;
i < vertex_count - 1;
i++) {
48 unrolled_indices.push_back(0);
49 unrolled_indices.push_back(
i);
50 unrolled_indices.push_back(
i + 1);
53 return unrolled_indices;
61 const std::shared_ptr<const flutter::DlVertices>& vertices,
63 : vertices_(vertices) {
64 performed_normalization_ = MaybePerformIndexNormalization(renderer);
65 bounds_ = vertices_->GetBounds();
69 switch (vertices_->mode()) {
72 if (performed_normalization_) {
84 return vertices_->colors() !=
nullptr;
88 return vertices_->texture_coordinate_data() !=
nullptr;
95 auto vertex_count = vertices_->vertex_count();
96 if (vertex_count == 0) {
100 auto first = vertices_->texture_coordinate_data();
101 auto left = first->x;
103 auto right = first->x;
104 auto bottom = first->y;
106 for (
auto it = first + 1;
i < vertex_count; ++it,
i++) {
107 left = std::min(left, it->x);
108 top = std::min(top, it->y);
109 right = std::max(right, it->x);
110 bottom = std::max(bottom, it->y);
119 int vertex_count = vertices_->vertex_count();
121 vertices_->vertex_data(), vertex_count *
sizeof(
Point),
alignof(
Point));
125 performed_normalization_ ? indices_.size() : vertices_->index_count();
126 const uint16_t* indices_data =
127 performed_normalization_ ? indices_.data() : vertices_->indices();
130 indices_data, index_count *
sizeof(uint16_t),
alignof(uint16_t));
134 .
type = GetPrimitiveType(),
137 .vertex_buffer = vertex_buffer,
138 .index_buffer = index_buffer,
139 .vertex_count = index_count > 0 ? index_count : vertex_count,
148 Rect texture_coverage,
153 using VS = PorterDuffBlendPipeline::VertexShader;
155 int vertex_count = vertices_->vertex_count();
161 const Point* coordinates = has_texture_coordinates
162 ? vertices_->texture_coordinate_data()
163 : vertices_->vertex_data();
165 vertex_count *
sizeof(VS::PerVertexData),
alignof(VS::PerVertexData),
167 VS::PerVertexData* vtx_contents =
168 reinterpret_cast<VS::PerVertexData*
>(
data);
169 const Point* vertex_points = vertices_->vertex_data();
170 for (
auto i = 0;
i < vertex_count;
i++) {
171 Point texture_coord = coordinates[
i];
172 Point uv = uv_transform * texture_coord;
173 Color color = has_colors
177 VS::PerVertexData vertex_data = {.vertices = vertex_points[
i],
178 .texture_coords = uv,
180 vtx_contents[
i] = vertex_data;
186 performed_normalization_ ? indices_.size() : vertices_->index_count();
187 const uint16_t* indices_data =
188 performed_normalization_ ? indices_.data() : vertices_->indices();
191 indices_data, index_count *
sizeof(uint16_t),
alignof(uint16_t));
195 .
type = GetPrimitiveType(),
198 .vertex_buffer = vertex_buffer,
199 .index_buffer = index_buffer,
200 .vertex_count = index_count > 0 ? index_count : vertex_count,
213bool DlVerticesGeometry::MaybePerformIndexNormalization(
217 indices_ = fromFanIndices(vertices_->vertex_count(),
218 vertices_->index_count(), vertices_->indices());
virtual bool SupportsTriangleFan() const =0
Whether the primitive type TriangleFan is supported by the backend.
HostBuffer & GetTransientsDataBuffer() const
Retrieve the current host buffer for transient storage of other non-index data.
const Capabilities & GetDeviceCapabilities() const
HostBuffer & GetTransientsIndexesBuffer() const
Retrieve the current host buffer for transient storage of indexes used for indexed draws.
bool HasTextureCoordinates() const override
std::optional< Rect > GetCoverage(const Matrix &transform) const override
bool CanApplyMaskFilter() const override
DlVerticesGeometry(const std::shared_ptr< const flutter::DlVertices > &vertices, const ContentContext &renderer)
std::optional< Rect > GetTextureCoordinateCoverage() const override
GeometryResult GetPositionUVColorBuffer(Rect texture_coverage, Matrix effect_transform, const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
GeometryResult GetPositionBuffer(const ContentContext &renderer, const Entity &entity, RenderPass &pass) const override
bool HasVertexColors() const override
Matrix GetShaderTransform(const RenderPass &pass) const
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
Render passes encode render commands directed as one specific render target into an underlying comman...
@ kTriangles
The vertices are taken 3 at a time to form a triangle.
Color ToColor(const flutter::DlColor &color)
PrimitiveType
Decides how backend draws pixels based on input vertices.
@ kNone
Does not use the index buffer.
LinePipeline::VertexShader VS
static constexpr Color BlackTransparent()
constexpr Color Premultiply() const
A 4x4 matrix using column-major storage.
constexpr TRect TransformBounds(const Matrix &transform) const
Creates a new bounding box that contains this transformed rectangle.
constexpr Matrix GetNormalizingTransform() const
Constructs a Matrix that will map all points in the coordinate space of the rectangle into a new norm...
static constexpr TRect MakeLTRB(Type left, Type top, Type right, Type bottom)
std::shared_ptr< const fml::Mapping > data