forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Impeller] Directly tessellate filled ellipses (flutter#48770)
Add support for filling ellipses/ovals and greatly simplify the primitive tessellation mechanisms.
- Loading branch information
Showing
28 changed files
with
1,410 additions
and
901 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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,98 @@ | ||
// 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 <algorithm> | ||
|
||
#include "flutter/impeller/entity/geometry/circle_geometry.h" | ||
|
||
#include "flutter/impeller/entity/geometry/line_geometry.h" | ||
|
||
namespace impeller { | ||
|
||
CircleGeometry::CircleGeometry(const Point& center, Scalar radius) | ||
: center_(center), radius_(radius), stroke_width_(-1.0f) { | ||
FML_DCHECK(radius >= 0); | ||
} | ||
|
||
CircleGeometry::CircleGeometry(const Point& center, | ||
Scalar radius, | ||
Scalar stroke_width) | ||
: center_(center), | ||
radius_(radius), | ||
stroke_width_(std::max(stroke_width, 0.0f)) { | ||
FML_DCHECK(radius >= 0); | ||
FML_DCHECK(stroke_width >= 0); | ||
} | ||
|
||
GeometryResult CircleGeometry::GetPositionBuffer(const ContentContext& renderer, | ||
const Entity& entity, | ||
RenderPass& pass) const { | ||
auto& transform = entity.GetTransform(); | ||
|
||
Scalar half_width = stroke_width_ < 0 ? 0.0 | ||
: LineGeometry::ComputePixelHalfWidth( | ||
transform, stroke_width_); | ||
|
||
std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator(); | ||
|
||
// We call the StrokedCircle method which will simplify to a | ||
// FilledCircleGenerator if the inner_radius is <= 0. | ||
auto generator = | ||
tessellator->StrokedCircle(transform, center_, radius_, half_width); | ||
|
||
return ComputePositionGeometry(generator, entity, pass); | ||
} | ||
|
||
// |Geometry| | ||
GeometryResult CircleGeometry::GetPositionUVBuffer( | ||
Rect texture_coverage, | ||
Matrix effect_transform, | ||
const ContentContext& renderer, | ||
const Entity& entity, | ||
RenderPass& pass) const { | ||
auto& transform = entity.GetTransform(); | ||
auto uv_transform = | ||
texture_coverage.GetNormalizingTransform() * effect_transform; | ||
|
||
Scalar half_width = stroke_width_ < 0 ? 0.0 | ||
: LineGeometry::ComputePixelHalfWidth( | ||
transform, stroke_width_); | ||
std::shared_ptr<Tessellator> tessellator = renderer.GetTessellator(); | ||
|
||
// We call the StrokedCircle method which will simplify to a | ||
// FilledCircleGenerator if the inner_radius is <= 0. | ||
auto generator = | ||
tessellator->StrokedCircle(transform, center_, radius_, half_width); | ||
|
||
return ComputePositionUVGeometry(generator, uv_transform, entity, pass); | ||
} | ||
|
||
GeometryVertexType CircleGeometry::GetVertexType() const { | ||
return GeometryVertexType::kPosition; | ||
} | ||
|
||
std::optional<Rect> CircleGeometry::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 CircleGeometry::CoversArea(const Matrix& transform, | ||
const Rect& rect) const { | ||
return false; | ||
} | ||
|
||
bool CircleGeometry::IsAxisAlignedRect() const { | ||
return false; | ||
} | ||
|
||
} // namespace impeller |
This file contains 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,57 @@ | ||
// 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 { | ||
|
||
// Geometry class that can generate vertices (with or without texture | ||
// coordinates) for either filled or stroked circles | ||
class CircleGeometry final : public Geometry { | ||
public: | ||
explicit CircleGeometry(const Point& center, Scalar radius); | ||
|
||
explicit CircleGeometry(const Point& center, | ||
Scalar radius, | ||
Scalar stroke_width); | ||
|
||
~CircleGeometry() = default; | ||
|
||
// |Geometry| | ||
bool CoversArea(const Matrix& transform, const Rect& rect) const override; | ||
|
||
// |Geometry| | ||
bool IsAxisAlignedRect() const override; | ||
|
||
private: | ||
// |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_; | ||
Scalar stroke_width_; | ||
|
||
CircleGeometry(const CircleGeometry&) = delete; | ||
|
||
CircleGeometry& operator=(const CircleGeometry&) = delete; | ||
}; | ||
|
||
} // namespace impeller |
Oops, something went wrong.