Flutter Engine
The Flutter Engine
GrPathUtils.h
Go to the documentation of this file.
1/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef GrPathUtils_DEFINED
9#define GrPathUtils_DEFINED
10
14
15#include <cstddef>
16#include <cstdint>
17
18class SkMatrix;
19enum class SkPathFirstDirection;
20struct SkRect;
21
22/**
23 * Utilities for evaluating paths.
24 */
25namespace GrPathUtils {
26
27// When tessellating curved paths into linear segments, this defines the maximum distance in screen
28// space which a segment may deviate from the mathematically correct value. Above this value, the
29// segment will be subdivided.
30// This value was chosen to approximate the supersampling accuracy of the raster path (16 samples,
31// or one quarter pixel).
33
34// We guarantee that no quad or cubic will ever produce more than this many points
35static const int kMaxPointsPerCurve = 1 << 10;
36
37// Very small tolerances will be increased to a minimum threshold value, to avoid division problems
38// in subsequent math.
40 const SkMatrix& viewM,
41 const SkRect& pathBounds);
42
43// Returns the maximum number of vertices required when using a recursive chopping algorithm to
44// linearize the quadratic Bezier (e.g. generateQuadraticPoints below) to the given error tolerance.
45// This is a power of two and will not exceed kMaxPointsPerCurve.
46uint32_t quadraticPointCount(const SkPoint points[], SkScalar tol);
47
48// Returns the number of points actually written to 'points', will be <= to 'pointsLeft'
49uint32_t generateQuadraticPoints(const SkPoint& p0,
50 const SkPoint& p1,
51 const SkPoint& p2,
52 SkScalar tolSqd,
54 uint32_t pointsLeft);
55
56// Returns the maximum number of vertices required when using a recursive chopping algorithm to
57// linearize the cubic Bezier (e.g. generateQuadraticPoints below) to the given error tolerance.
58// This is a power of two and will not exceed kMaxPointsPerCurve.
59uint32_t cubicPointCount(const SkPoint points[], SkScalar tol);
60
61// Returns the number of points actually written to 'points', will be <= to 'pointsLeft'
62uint32_t generateCubicPoints(const SkPoint& p0,
63 const SkPoint& p1,
64 const SkPoint& p2,
65 const SkPoint& p3,
66 SkScalar tolSqd,
68 uint32_t pointsLeft);
69
70// A 2x3 matrix that goes from the 2d space coordinates to UV space where u^2-v = 0 specifies the
71// quad. The matrix is determined by the control points of the quadratic.
73public:
75 // Initialize the matrix from the control pts
76 QuadUVMatrix(const SkPoint controlPts[3]) { this->set(controlPts); }
77 void set(const SkPoint controlPts[3]);
78
79 /**
80 * Applies the matrix to vertex positions to compute UV coords.
81 *
82 * vertices is a pointer to the first vertex.
83 * vertexCount is the number of vertices.
84 * stride is the size of each vertex.
85 * uvOffset is the offset of the UV values within each vertex.
86 */
87 void apply(void* vertices, int vertexCount, size_t stride, size_t uvOffset) const {
88 intptr_t xyPtr = reinterpret_cast<intptr_t>(vertices);
89 intptr_t uvPtr = reinterpret_cast<intptr_t>(vertices) + uvOffset;
90 float sx = fM[0];
91 float kx = fM[1];
92 float tx = fM[2];
93 float ky = fM[3];
94 float sy = fM[4];
95 float ty = fM[5];
96 for (int i = 0; i < vertexCount; ++i) {
97 const SkPoint* xy = reinterpret_cast<const SkPoint*>(xyPtr);
98 SkPoint* uv = reinterpret_cast<SkPoint*>(uvPtr);
99 uv->fX = sx * xy->fX + kx * xy->fY + tx;
100 uv->fY = ky * xy->fX + sy * xy->fY + ty;
101 xyPtr += stride;
102 uvPtr += stride;
103 }
104 }
105private:
106 float fM[6];
107};
108
109// Input is 3 control points and a weight for a bezier conic. Calculates the three linear
110// functionals (K,L,M) that represent the implicit equation of the conic, k^2 - lm.
111//
112// Output: klm holds the linear functionals K,L,M as row vectors:
113//
114// | ..K.. | | x | | k |
115// | ..L.. | * | y | == | l |
116// | ..M.. | | 1 | | m |
117//
118void getConicKLM(const SkPoint p[3], const SkScalar weight, SkMatrix* klm);
119
120// Converts a cubic into a sequence of quads. If working in device space use tolScale = 1, otherwise
121// set based on stretchiness of the matrix. The result is sets of 3 points in quads. This will
122// preserve the starting and ending tangent vectors (modulo FP precision).
123void convertCubicToQuads(const SkPoint p[4],
124 SkScalar tolScale,
126
127// When we approximate a cubic {a,b,c,d} with a quadratic we may have to ensure that the new control
128// point lies between the lines ab and cd. The convex path renderer requires this. It starts with a
129// path where all the control points taken together form a convex polygon. It relies on this
130// property and the quadratic approximation of cubics step cannot alter it. This variation enforces
131// this constraint. The cubic must be simple and dir must specify the orientation of the contour
132// containing the cubic.
134 SkScalar tolScale,
137
138} // namespace GrPathUtils
139
140#endif
static const int points[]
SkPathFirstDirection
Definition: SkPathEnums.h:19
#define SkDoubleToScalar(x)
Definition: SkScalar.h:64
void apply(void *vertices, int vertexCount, size_t stride, size_t uvOffset) const
Definition: GrPathUtils.h:87
void set(const SkPoint controlPts[3])
QuadUVMatrix(const SkPoint controlPts[3])
Definition: GrPathUtils.h:76
float SkScalar
Definition: extension.cpp:12
void convertCubicToQuads(const SkPoint p[4], SkScalar tolScale, skia_private::TArray< SkPoint, true > *quads)
uint32_t generateCubicPoints(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, const SkPoint &p3, SkScalar tolSqd, SkPoint **points, uint32_t pointsLeft)
uint32_t quadraticPointCount(const SkPoint points[], SkScalar tol)
Definition: GrPathUtils.cpp:73
static const SkScalar kDefaultTolerance
Definition: GrPathUtils.h:32
uint32_t cubicPointCount(const SkPoint points[], SkScalar tol)
SkScalar scaleToleranceToSrc(SkScalar devTol, const SkMatrix &viewM, const SkRect &pathBounds)
Definition: GrPathUtils.cpp:41
void convertCubicToQuadsConstrainToTangents(const SkPoint p[4], SkScalar tolScale, SkPathFirstDirection dir, skia_private::TArray< SkPoint, true > *quads)
void getConicKLM(const SkPoint p[3], const SkScalar weight, SkMatrix *klm)
static const int kMaxPointsPerCurve
Definition: GrPathUtils.h:35
uint32_t generateQuadraticPoints(const SkPoint &p0, const SkPoint &p1, const SkPoint &p2, SkScalar tolSqd, SkPoint **points, uint32_t pointsLeft)
Definition: GrPathUtils.cpp:78
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
Definition: switches.h:145
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165