This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[Impeller] Add direct tesselation of circles for DrawCircle and Round end caps #48103
Merged
auto-submit
merged 9 commits into
flutter:main
from
flar:impeller-direct-circle-tessellation
Nov 30, 2023
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
72d57eb
[Impeller] Add direct tesselation of circles for DrawCircle and Round…
flar 63ea32b
switch to triangle strips for circles and simplify tessellation API
flar d498124
Fix old naming typos in comments
flar cab69d8
simplify vertex accumulation
flar cfca2e1
re-enable GPU compute tessellator for PointFields
flar 4b638ba
move to direct HostBuffer emplacement of tessellation results
flar 4ccdb46
Move CircleTessellator to tessellator dir and move cache to Tessellat…
flar aeef542
document and refine circle division computation
flar 16fa52d
style feedback from review
flar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #include "impeller/entity/geometry/ellipse_geometry.h" | ||
|
|
||
| #include "flutter/impeller/tessellator/circle_tessellator.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| EllipseGeometry::EllipseGeometry(Point center, Scalar radius) | ||
| : center_(center), radius_(radius) { | ||
| FML_DCHECK(radius >= 0); | ||
| } | ||
|
|
||
| GeometryResult EllipseGeometry::GetPositionBuffer( | ||
| const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const { | ||
| auto& host_buffer = pass.GetTransientsBuffer(); | ||
| using VT = SolidFillVertexShader::PerVertexData; | ||
|
|
||
| Scalar radius = radius_; | ||
| const Point& center = center_; | ||
| std::shared_ptr<Tessellator> t = renderer.GetTessellator(); | ||
| CircleTessellator tessellator(t, entity.GetTransform(), radius_); | ||
| size_t count = tessellator.GetCircleVertexCount(); | ||
| auto vertex_buffer = | ||
| host_buffer.Emplace(count * sizeof(VT), alignof(VT), | ||
| [&tessellator, ¢er, radius](uint8_t* buffer) { | ||
| auto vertices = reinterpret_cast<VT*>(buffer); | ||
| tessellator.GenerateCircleTriangleStrip( | ||
| [&vertices](const Point& p) { // | ||
| *vertices++ = { | ||
| .position = p, | ||
| }; | ||
| }, | ||
| center, radius); | ||
| }); | ||
|
|
||
| return GeometryResult{ | ||
| .type = PrimitiveType::kTriangleStrip, | ||
| .vertex_buffer = | ||
| { | ||
| .vertex_buffer = vertex_buffer, | ||
| .vertex_count = count, | ||
| .index_type = IndexType::kNone, | ||
| }, | ||
| .transform = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * | ||
| entity.GetTransform(), | ||
| .prevent_overdraw = false, | ||
| }; | ||
| } | ||
|
|
||
| // |Geometry| | ||
| GeometryResult EllipseGeometry::GetPositionUVBuffer( | ||
| Rect texture_coverage, | ||
| Matrix effect_transform, | ||
| const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const { | ||
| auto& host_buffer = pass.GetTransientsBuffer(); | ||
| using VT = TextureFillVertexShader::PerVertexData; | ||
| auto uv_transform = | ||
| texture_coverage.GetNormalizingTransform() * effect_transform; | ||
|
|
||
| Scalar radius = radius_; | ||
| const Point& center = center_; | ||
| std::shared_ptr<Tessellator> t = renderer.GetTessellator(); | ||
| CircleTessellator tessellator(t, entity.GetTransform(), radius_); | ||
| size_t count = tessellator.GetCircleVertexCount(); | ||
| auto vertex_buffer = host_buffer.Emplace( | ||
| count * sizeof(VT), alignof(VT), | ||
| [&tessellator, &uv_transform, ¢er, radius](uint8_t* buffer) { | ||
| auto vertices = reinterpret_cast<VT*>(buffer); | ||
| tessellator.GenerateCircleTriangleStrip( | ||
| [&vertices, &uv_transform](const Point& p) { // | ||
| *vertices++ = { | ||
| .position = p, | ||
| .texture_coords = uv_transform * p, | ||
| }; | ||
| }, | ||
| center, radius); | ||
| }); | ||
|
|
||
| return GeometryResult{ | ||
| .type = PrimitiveType::kTriangleStrip, | ||
| .vertex_buffer = | ||
| { | ||
| .vertex_buffer = vertex_buffer, | ||
| .vertex_count = count, | ||
| .index_type = IndexType::kNone, | ||
| }, | ||
| // .vertex_buffer = vtx_builder.CreateVertexBuffer(host_buffer), | ||
flar marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .transform = Matrix::MakeOrthographic(pass.GetRenderTargetSize()) * | ||
| entity.GetTransform(), | ||
| .prevent_overdraw = false, | ||
| }; | ||
| } | ||
|
|
||
| GeometryVertexType EllipseGeometry::GetVertexType() const { | ||
| return GeometryVertexType::kPosition; | ||
| } | ||
|
|
||
| std::optional<Rect> EllipseGeometry::GetCoverage( | ||
| const Matrix& transform) const { | ||
| Point corners[4]{ | ||
| {center_.x, center_.y - radius_}, | ||
| {center_.x + radius_, center_.y}, | ||
| {center_.x, center_.y + radius_}, | ||
| {center_.x - radius_, center_.y}, | ||
| }; | ||
|
|
||
| for (int i = 0; i < 4; i++) { | ||
| corners[i] = transform * corners[i]; | ||
| } | ||
| return Rect::MakePointBounds(std::begin(corners), std::end(corners)); | ||
| } | ||
|
|
||
| bool EllipseGeometry::CoversArea(const Matrix& transform, | ||
| const Rect& rect) const { | ||
| return false; | ||
| } | ||
|
|
||
| bool EllipseGeometry::IsAxisAlignedRect() const { | ||
| return false; | ||
| } | ||
|
|
||
| } // namespace impeller | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "impeller/entity/geometry/geometry.h" | ||
|
|
||
| namespace impeller { | ||
|
|
||
| class EllipseGeometry final : public Geometry { | ||
| public: | ||
| explicit EllipseGeometry(Point center, Scalar radius); | ||
|
|
||
| ~EllipseGeometry() = default; | ||
|
|
||
| // |Geometry| | ||
| bool CoversArea(const Matrix& transform, const Rect& rect) const override; | ||
|
|
||
| // |Geometry| | ||
| bool IsAxisAlignedRect() const override; | ||
|
|
||
| private: | ||
| // Computes the 4 corners of a rectangle that defines the line and | ||
| // possibly extended endpoints which will be rendered under the given | ||
| // transform, and returns true if such a rectangle is defined. | ||
| // | ||
| // The coordinates will be generated in the original coordinate system | ||
| // of the line end points and the transform will only be used to determine | ||
| // the minimum line width. | ||
| // | ||
| // For kButt and kSquare end caps the ends should always be exteded as | ||
| // per that decoration, but for kRound caps the ends might be extended | ||
| // if the goal is to get a conservative bounds and might not be extended | ||
| // if the calling code is planning to draw the round caps on the ends. | ||
| // | ||
| // @return true if the transform and width were not degenerate | ||
| bool ComputeCorners(Point corners[4], | ||
| const Matrix& transform, | ||
| bool extend_endpoints) const; | ||
|
|
||
| // |Geometry| | ||
| GeometryResult GetPositionBuffer(const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const override; | ||
|
|
||
| // |Geometry| | ||
| GeometryVertexType GetVertexType() const override; | ||
|
|
||
| // |Geometry| | ||
| std::optional<Rect> GetCoverage(const Matrix& transform) const override; | ||
|
|
||
| // |Geometry| | ||
| GeometryResult GetPositionUVBuffer(Rect texture_coverage, | ||
| Matrix effect_transform, | ||
| const ContentContext& renderer, | ||
| const Entity& entity, | ||
| RenderPass& pass) const override; | ||
|
|
||
| Point center_; | ||
| Scalar radius_; | ||
|
|
||
| EllipseGeometry(const EllipseGeometry&) = delete; | ||
|
|
||
| EllipseGeometry& operator=(const EllipseGeometry&) = delete; | ||
| }; | ||
|
|
||
| } // namespace impeller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.