11 : p0_(p0), p1_(p1), width_(width), cap_(cap) {
12 FML_DCHECK(width >= 0);
25 return std::max(width, min_size) * 0.5f;
29 bool allow_zero_length)
const {
35 auto along = p1_ - p0_;
36 Scalar length = along.GetLength();
38 if (!allow_zero_length) {
42 return {stroke_half_width, 0};
44 return along * stroke_half_width / length;
48 bool LineGeometry::ComputeCorners(
Point corners[4],
50 bool extend_endpoints)
const {
51 auto along = ComputeAlongVector(
transform, extend_endpoints);
56 auto across =
Vector2(along.y, -along.x);
57 corners[0] = p0_ - across;
58 corners[1] = p1_ - across;
59 corners[2] = p0_ + across;
60 corners[3] = p1_ + across;
61 if (extend_endpoints) {
77 using VT = SolidFillVertexShader::PerVertexData;
96 BufferView vertex_buffer = host_buffer.
Emplace(
97 count *
sizeof(VT),
alignof(VT), [&corners](uint8_t* buffer) {
98 auto vertices =
reinterpret_cast<VT*
>(buffer);
99 for (
auto& corner : corners) {
106 return GeometryResult{
110 .vertex_buffer = vertex_buffer,
111 .vertex_count = count,
118 std::optional<Rect> LineGeometry::GetCoverage(
const Matrix&
transform)
const {
125 for (
int i = 0; i < 4; i++) {
136 return coverage.has_value() ? coverage->Contains(rect) :
false;
140 return cap_ !=
Cap::kRound && (p0_.x == p1_.
x || p0_.y == p1_.
y);
HostBuffer & GetTransientsBuffer() const
Retrieve the currnent host buffer for transient storage.
Tessellator & GetTessellator() const
Matrix GetShaderTransform(const RenderPass &pass) const
Get the vertex shader transform used for drawing this Entity.
const Matrix & GetTransform() const
Get the global transform matrix for this Entity.
static Scalar ComputeStrokeAlphaCoverage(const Matrix &entity, Scalar stroke_width)
Compute an alpha value to simulate lower coverage of fractional pixel strokes.
static GeometryResult ComputePositionGeometry(const ContentContext &renderer, const Tessellator::VertexGenerator &generator, const Entity &entity, RenderPass &pass)
BufferView Emplace(const BufferType &buffer, size_t alignment=0)
Emplace non-uniform data (like contiguous vertices) onto the host buffer.
LineGeometry(Point p0, Point p1, Scalar width, Cap cap)
static Scalar ComputePixelHalfWidth(const Matrix &transform, Scalar width)
bool IsAxisAlignedRect() const override
Scalar ComputeAlphaCoverage(const Matrix &transform) const override
bool CoversArea(const Matrix &transform, const Rect &rect) const override
Determines if this geometry, transformed by the given transform, will completely cover all surface ar...
Render passes encode render commands directed as one specific render target into an underlying comman...
EllipticalVertexGenerator RoundCapLine(const Matrix &view_transform, const Point &p0, const Point &p1, Scalar radius)
Create a |VertexGenerator| that can produce vertices for a line with round end caps of the given radi...
@ kNone
Does not use the index buffer.
constexpr float kEhCloseEnough
static const GeometryResult kEmptyResult
static constexpr Scalar kMinStrokeSize
A 4x4 matrix using column-major storage.
constexpr static std::optional< TRect > MakePointBounds(const U &value)