Flutter Engine
The Flutter Engine
Classes | Functions | Variables
GraphitePrimitivesSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkM44.h"
#include "include/core/SkPaint.h"
#include "include/core/SkRRect.h"
#include "include/core/SkVertices.h"
#include "include/private/base/SkTPin.h"
#include "tools/viewer/ClickHandlerSlide.h"
#include <unordered_set>

Go to the source code of this file.

Classes

struct  LocalCornerVert
 
class  GraphitePrimitivesSlide
 
class  GraphitePrimitivesSlide::Click
 

Functions

static SkPaint paint (SkColor color, float strokeWidth=-1.f, SkPaint::Join join=SkPaint::kMiter_Join)
 
static std::pair< float, float > singular_values (float a, float b, float c, float d)
 
static float local_aa_radius (const SkM44 &matrix, const SkV2 &p)
 
static void compute_corner (SkV3 devPts[19], const SkM44 &m, const SkV4 &cornerMapping, const SkV2 &cornerPt, const SkV2 &cornerRadii, const SkV4 &center, float centerWeight, float localAARadius, float strokeRadius, SkPaint::Join join)
 
static void compute_vertices (SkV3 devPts[kVertexCount], const SkM44 &m, const SkRRect &rrect, float strokeRadius, SkPaint::Join join)
 

Variables

static constexpr float kAARadius = 10.f
 
static constexpr float kMiterScale = 1.f
 
static constexpr float kBevelScale = 0.0f
 
static constexpr float kRoundScale = SK_FloatSqrt2 - 1.f
 
static constexpr float kHR2 = SK_ScalarRoot2Over2
 
static constexpr LocalCornerVert kCornerTemplate [19]
 
static const uint16_t kBR = 0*std::size(kCornerTemplate)
 
static const uint16_t kTR = 1*std::size(kCornerTemplate)
 
static const uint16_t kTL = 2*std::size(kCornerTemplate)
 
static const uint16_t kBL = 3*std::size(kCornerTemplate)
 
static const size_t kVertexCount = 4*std::size(kCornerTemplate)
 
static const uint16_t kIndices []
 
static const uint16_t kOuterCornerIndices []
 
static const uint16_t kInnerCornerIndices []
 
static const uint16_t kInteriorIndices []
 
static const uint16_t kEdgeIndices []
 

Function Documentation

◆ compute_corner()

static void compute_corner ( SkV3  devPts[19],
const SkM44 m,
const SkV4 cornerMapping,
const SkV2 cornerPt,
const SkV2 cornerRadii,
const SkV4 center,
float  centerWeight,
float  localAARadius,
float  strokeRadius,
SkPaint::Join  join 
)
static

Definition at line 254 of file GraphitePrimitivesSlide.cpp.

257 {
258 float joinScale;
259
260 // TODO: checking against localAARadius can snap to rect corner unexpectedly under high skew
261 // because localAARadius gets so big, but would be nice to be fuzzy here.
262 if (cornerRadii.x <= 0.f || cornerRadii.y <= 0.f) {
263 // Effectively a rectangular corner
264 joinScale = kMiterScale; // default for rect corners
265 if (strokeRadius > 0.f) {
266 // Non-hairline strokes need to adjust the join scale factor to match style.
267 if (join == SkPaint::kBevel_Join) {
268 joinScale = kBevelScale;
269 } else if (join == SkPaint::kRound_Join) {
270 joinScale = kRoundScale;
271 }
272 }
273 } else {
274 // Rounded filled corner vertices are always positioned for a round join since the
275 // underlying geometry has no real tangent discontinuity.
276 joinScale = kRoundScale;
277 }
278
279 for (size_t i = 0; i < std::size(kCornerTemplate); ++i) {
280 devPts[i] = kCornerTemplate[i].transform(m, cornerMapping, cornerPt, cornerRadii,
281 center, centerWeight, strokeRadius, joinScale,
282 localAARadius);
283 }
284}
static constexpr float kMiterScale
static constexpr float kBevelScale
static constexpr LocalCornerVert kCornerTemplate[19]
static constexpr float kRoundScale
static SkScalar center(float pos0, float pos1)
@ kRound_Join
adds circle
Definition: SkPaint.h:360
@ kBevel_Join
connects outside edges
Definition: SkPaint.h:361
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
static SkString join(const CommandLineFlags::StringArray &)
Definition: skpbench.cpp:741
SkV3 transform(const SkM44 &m, const SkV4 &cornerMapping, const SkV2 &cornerPt, const SkV2 &cornerRadii, const SkV4 &devCenter, float centerWeight, float strokeRadius, float joinScale, float localAARadius) const
float x
Definition: SkM44.h:20
float y
Definition: SkM44.h:20

◆ compute_vertices()

static void compute_vertices ( SkV3  devPts[kVertexCount],
const SkM44 m,
const SkRRect rrect,
float  strokeRadius,
SkPaint::Join  join 
)
static

Definition at line 291 of file GraphitePrimitivesSlide.cpp.

295 {
296 SkV4 devCenter = m.map(rrect.getBounds().centerX(), rrect.getBounds().centerY(), 0.f, 1.f);
297
298 float localAARadius = std::max({
303 });
304
305 float centerWeight = 0.f; // No center snapping
306 if (strokeRadius < 0.f) {
307 // A fill, so inner vertices need to snap to the center and then adjust the stroke radius
308 // to 0 for later math to work out nicely.
309 strokeRadius = 0.f;
310 centerWeight = 1.f;
311 }
312
313 // Check if the inset amount (max stroke-radius + local-aa-radius) would interfere with the
314 // opposite edge's inset or interfere with the adjacent corner's curve. When this happens, snap
315 // all the interior vertices to the center and let the fragment shader work through it.
316 // TODO: Could force centerWeight = 2 for filled rects and quads for simplicity around non
317 // orthogonal inset overlap calculations.
318 float maxInset = strokeRadius + localAARadius;
319 if (maxInset >= rrect.width() - maxInset || // L/R stroke insets would cross over
320 maxInset >= rrect.height() - maxInset || // T/B stroke insets would cross over
321 maxInset >= rrect.width() - rrect.radii(SkRRect::kLowerLeft_Corner).fX || // X corner cross
325 maxInset >= rrect.height() - rrect.radii(SkRRect::kLowerLeft_Corner).fY || // Y corner cross
329 // All interior vertices need to snap to the center
330 centerWeight = 2.f;
331 }
332
333 // The normalized corner template is defined relative to the quarter circle with positive X
334 // and positive Y, with a counter clockwise winding (if +Y points down). This corresponds to
335 // the bottom-right corner.
336 static constexpr SkV4 kBRBasis = { 1.f, 0.f, 0.f, 1.f};
337 static constexpr SkV4 kTRBasis = { 0.f, 1.f, -1.f, 0.f};
338 static constexpr SkV4 kTLBasis = {-1.f, 0.f, 0.f, -1.f};
339 static constexpr SkV4 kBLBasis = { 0.f, -1.f, 1.f, 0.f};
340
341 compute_corner(devPts + kBR, m, kBRBasis,
342 {rrect.getBounds().fRight,
346 devCenter, centerWeight, localAARadius, strokeRadius, join);
347 compute_corner(devPts + kTR, m, kTRBasis,
348 {rrect.getBounds().fRight,
352 devCenter, centerWeight, localAARadius,strokeRadius, join);
353 compute_corner(devPts + kTL, m, kTLBasis,
354 {rrect.getBounds().fLeft,
358 devCenter, centerWeight, localAARadius,strokeRadius, join);
359 compute_corner(devPts + kBL, m, kBLBasis,
360 {rrect.getBounds().fLeft,
364 devCenter, centerWeight, localAARadius,strokeRadius, join);
365}
static const uint16_t kTL
static const uint16_t kBL
static const uint16_t kBR
static const uint16_t kTR
static float local_aa_radius(const SkM44 &matrix, const SkV2 &p)
static void compute_corner(SkV3 devPts[19], const SkM44 &m, const SkV4 &cornerMapping, const SkV2 &cornerPt, const SkV2 &cornerRadii, const SkV4 &center, float centerWeight, float localAARadius, float strokeRadius, SkPaint::Join join)
SkVector radii(Corner corner) const
Definition: SkRRect.h:271
@ kUpperLeft_Corner
index of top-left corner radii
Definition: SkRRect.h:252
@ kLowerRight_Corner
index of bottom-right corner radii
Definition: SkRRect.h:254
@ kUpperRight_Corner
index of top-right corner radii
Definition: SkRRect.h:253
@ kLowerLeft_Corner
index of bottom-left corner radii
Definition: SkRRect.h:255
SkScalar width() const
Definition: SkRRect.h:95
SkScalar height() const
Definition: SkRRect.h:102
const SkRect & getBounds() const
Definition: SkRRect.h:279
static float max(float r, float g, float b)
Definition: hsl.cpp:49
SkRRect rrect
Definition: SkRecords.h:232
float fX
x-axis value
Definition: SkPoint_impl.h:164
float fY
y-axis value
Definition: SkPoint_impl.h:165
SkScalar fBottom
larger y-axis bounds
Definition: extension.cpp:17
constexpr float centerX() const
Definition: SkRect.h:776
constexpr float centerY() const
Definition: SkRect.h:785
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15
Definition: SkM44.h:98

◆ local_aa_radius()

static float local_aa_radius ( const SkM44 matrix,
const SkV2 p 
)
static

Definition at line 73 of file GraphitePrimitivesSlide.cpp.

73 {
74 SkV4 devP = matrix.map(p.x, p.y, 0.f, 1.f);
75
76 const float dxdu = matrix.rc(0,0);
77 const float dxdv = matrix.rc(0,1);
78 const float dydu = matrix.rc(1,0);
79 const float dydv = matrix.rc(1,1);
80 const float dwdu = matrix.rc(3,0);
81 const float dwdv = matrix.rc(3,1);
82
83 float invW2 = 1.f / (devP.w * devP.w);
84 // non-persp has invW2 = 1, devP.w = 1, dwdu = 0, dwdv = 0
85 float dfdu = (devP.w*dxdu - devP.x*dwdu) * invW2; // non-persp -> dxdu -> m00
86 float dfdv = (devP.w*dxdv - devP.x*dwdv) * invW2; // non-persp -> dxdv -> m01
87 float dgdu = (devP.w*dydu - devP.y*dwdu) * invW2; // non-persp -> dydu -> m10
88 float dgdv = (devP.w*dydv - devP.y*dwdv) * invW2; // non-persp -> dydv -> m11
89
90 // no-persp, this is the singular values of [m00,m01][m10,m11], which is just the upper 2x2
91 // and equivalent to SkMatrix::getMinmaxScales().
92 auto [sv1, sv2] = singular_values(dfdu, dfdv, dgdu, dgdv);
93
94 // The minimum and maximum singular values of the above matrix represent the min and maximum
95 // scale factors that could be applied by the 'matrix'. So if 'p' is moved 1px locally it will
96 // move between [min, max]px after transformation. Thus, moving 1/min px locally will move
97 // between [1, max/min]px after transformation, ensuring the device-space offset exceeds the
98 // minimum AA offset for analytic AA.
99 float minScale = std::min(sv1, sv2);
100 return kAARadius / minScale;
101}
static constexpr float kAARadius
static std::pair< float, float > singular_values(float a, float b, float c, float d)
static float min(float r, float g, float b)
Definition: hsl.cpp:48
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
float w
Definition: SkM44.h:99
float y
Definition: SkM44.h:99
float x
Definition: SkM44.h:99

◆ paint()

static SkPaint paint ( SkColor  color,
float  strokeWidth = -1.f,
SkPaint::Join  join = SkPaint::kMiter_Join 
)
static

Definition at line 18 of file GraphitePrimitivesSlide.cpp.

20 {
23 paint.setAntiAlias(true);
24 if (strokeWidth >= 0.f) {
28 }
29 return paint;
30}
static const int strokeWidth
Definition: BlurTest.cpp:60
static SkPaint paint(SkColor color, float strokeWidth=-1.f, SkPaint::Join join=SkPaint::kMiter_Join)
void setStyle(Style style)
Definition: SkPaint.cpp:105
void setColor(SkColor color)
Definition: SkPaint.cpp:119
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194
void setStrokeJoin(Join join)
Definition: SkPaint.cpp:189
void setStrokeWidth(SkScalar width)
Definition: SkPaint.cpp:159
DlColor color

◆ singular_values()

static std::pair< float, float > singular_values ( float  a,
float  b,
float  c,
float  d 
)
static

Definition at line 33 of file GraphitePrimitivesSlide.cpp.

33 {
34 float s1 = a*a + b*b + c*c + d*d;
35
36 float e = a*a + b*b - c*c - d*d;
37 float f = a*c + b*d;
38 float s2 = SkScalarSqrt(e*e + 4*f*f);
39
40 float singular1 = SkScalarSqrt(0.5f * (s1 + s2));
41 float singular2 = SkScalarSqrt(0.5f * (s1 - s2));
42
43 return {singular1, singular2};
44}
#define SkScalarSqrt(x)
Definition: SkScalar.h:42
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition: main.cc:19
static bool b
struct MyStruct a[10]

Variable Documentation

◆ kAARadius

constexpr float kAARadius = 10.f
staticconstexpr

Definition at line 46 of file GraphitePrimitivesSlide.cpp.

◆ kBevelScale

constexpr float kBevelScale = 0.0f
staticconstexpr

Definition at line 104 of file GraphitePrimitivesSlide.cpp.

◆ kBL

const uint16_t kBL = 3*std::size(kCornerTemplate)
static

Definition at line 289 of file GraphitePrimitivesSlide.cpp.

◆ kBR

const uint16_t kBR = 0*std::size(kCornerTemplate)
static

Definition at line 286 of file GraphitePrimitivesSlide.cpp.

◆ kCornerTemplate

constexpr LocalCornerVert kCornerTemplate[19]
staticconstexpr

Definition at line 216 of file GraphitePrimitivesSlide.cpp.

◆ kEdgeIndices

const uint16_t kEdgeIndices[]
static
Initial value:
= {
kBR+5, kBR+5,kBR+9,kTR+0,kTR+6, kTR+6,
kBR+9, kBR+9,kBR+13,kTR+6,kTR+10, kTR+10,
kBR+13, kBR+13,kBR+16,kTR+10,kTR+14, kTR+14,
kTR+5, kTR+5,kTR+9,kTL+0,kTL+6, kTL+6,
kTR+9, kTR+9,kTR+13,kTL+6,kTL+10, kTL+10,
kTR+13, kTR+13,kTR+16,kTL+10,kTL+14, kTL+14,
kTL+5, kTL+5,kTL+9,kBL+0,kBL+6, kBL+6,
kTL+9, kTL+9,kTL+13,kBL+6,kBL+10, kBL+10,
kTL+13, kTL+13,kTL+16,kBL+10,kBL+14, kBL+14,
kBL+5, kBL+5,kBL+9,kBR+0,kBR+6, kBR+6,
kBL+9, kBL+9,kBL+13,kBR+6,kBR+10, kBR+10,
kBL+13, kBL+13,kBL+16,kBR+10,kBR+14, kBR+14,
}

Definition at line 422 of file GraphitePrimitivesSlide.cpp.

◆ kHR2

constexpr float kHR2 = SK_ScalarRoot2Over2
staticconstexpr

Definition at line 214 of file GraphitePrimitivesSlide.cpp.

◆ kIndices

const uint16_t kIndices[]
static
Initial value:
= {
kBR+0,kBR+6,kBR+1,kBR+7,kBR+2,kBR+8,kBR+3,kBR+8,kBR+4,kBR+9,kBR+5,kBR+9,
kTR+0,kTR+6,kTR+1,kTR+7,kTR+2,kTR+8,kTR+3,kTR+8,kTR+4,kTR+9,kTR+5,kTR+9,
kTL+0,kTL+6,kTL+1,kTL+7,kTL+2,kTL+8,kTL+3,kTL+8,kTL+4,kTL+9,kTL+5,kTL+9,
kBL+0,kBL+6,kBL+1,kBL+7,kBL+2,kBL+8,kBL+3,kBL+8,kBL+4,kBL+9,kBL+5,kBL+9,
kBR+0,kBR+6,kBR+6,
kBR+6,kBR+10,kBR+7,kBR+11,kBR+8,kBR+12,kBR+9,kBR+13,
kTR+6,kTR+10,kTR+7,kTR+11,kTR+8,kTR+12,kTR+9,kTR+13,
kTL+6,kTL+10,kTL+7,kTL+11,kTL+8,kTL+12,kTL+9,kTL+13,
kBL+6,kBL+10,kBL+7,kBL+11,kBL+8,kBL+12,kBL+9,kBL+13,
kBR+6,kBR+10,kBR+10,
kBR+10,kBR+14,kBR+11,kBR+15,kBR+12,kBR+16,kBR+13,kBR+16,
kTR+10,kTR+14,kTR+11,kTR+15,kTR+12,kTR+16,kTR+13,kTR+16,
kTL+10,kTL+14,kTL+11,kTL+15,kTL+12,kTL+16,kTL+13,kTL+16,
kBL+10,kBL+14,kBL+11,kBL+15,kBL+12,kBL+16,kBL+13,kBL+16,
kBR+10,kBR+14,kBR+14,
kBR+14,kBR+17,kBR+15,kBR+17,kBR+16,kBR+16,kBR+18,kTR+14,
kTR+14,kTR+17,kTR+15,kTR+17,kTR+16,kTR+16,kTR+18,kTL+14,
kTL+14,kTL+17,kTL+15,kTL+17,kTL+16,kTL+16,kTL+18,kBL+14,
kBL+14,kBL+17,kBL+15,kBL+17,kBL+16,kBL+16,kBL+18,kBR+14
}

Definition at line 368 of file GraphitePrimitivesSlide.cpp.

◆ kInnerCornerIndices

const uint16_t kInnerCornerIndices[]
static
Initial value:
= {
kBR+10, kBR+10,kBR+14,kBR+11,kBR+15,kBR+12,kBR+16,kBR+13, kBR+13,
kTR+10, kTR+10,kTR+14,kTR+11,kTR+15,kTR+12,kTR+16,kTR+13, kTR+13,
kTL+10, kTL+10,kTL+14,kTL+11,kTL+15,kTL+12,kTL+16,kTL+13, kTL+13,
kBL+10, kBL+10,kBL+14,kBL+11,kBL+15,kBL+12,kBL+16,kBL+13, kBL+13,
}

Definition at line 407 of file GraphitePrimitivesSlide.cpp.

◆ kInteriorIndices

const uint16_t kInteriorIndices[]
static
Initial value:
= {
kBR+14,kBR+17,kBR+15,kBR+17,kBR+16,kBR+16,kBR+18,kTR+14,
kTR+14,kTR+17,kTR+15,kTR+17,kTR+16,kTR+16,kTR+18,kTL+14,
kTL+14,kTL+17,kTL+15,kTL+17,kTL+16,kTL+16,kTL+18,kBL+14,
kBL+14,kBL+17,kBL+15,kBL+17,kBL+16,kBL+16,kBL+18,kBR+14
}

Definition at line 414 of file GraphitePrimitivesSlide.cpp.

◆ kMiterScale

constexpr float kMiterScale = 1.f
staticconstexpr

Definition at line 103 of file GraphitePrimitivesSlide.cpp.

◆ kOuterCornerIndices

const uint16_t kOuterCornerIndices[]
static
Initial value:
= {
kBR+0, kBR+0,kBR+6,kBR+1,kBR+7,kBR+2,kBR+8,kBR+3,kBR+8,kBR+4,kBR+9,kBR+5, kBR+5,
kTR+0, kTR+0,kTR+6,kTR+1,kTR+7,kTR+2,kTR+8,kTR+3,kTR+8,kTR+4,kTR+9,kTR+5, kTR+5,
kTL+0, kTL+0,kTL+6,kTL+1,kTL+7,kTL+2,kTL+8,kTL+3,kTL+8,kTL+4,kTL+9,kTL+5, kTL+5,
kBL+0, kBL+0,kBL+6,kBL+1,kBL+7,kBL+2,kBL+8,kBL+3,kBL+8,kBL+4,kBL+9,kBL+5, kBL+5,
kBR+6, kBR+6,kBR+10,kBR+7,kBR+11,kBR+8,kBR+12,kBR+9,kBR+13, kBR+13,
kTR+6, kTR+6,kTR+10,kTR+7,kTR+11,kTR+8,kTR+12,kTR+9,kTR+13, kTR+13,
kTL+6, kTL+6,kTL+10,kTL+7,kTL+11,kTL+8,kTL+12,kTL+9,kTL+13, kTL+13,
kBL+6, kBL+6,kBL+10,kBL+7,kBL+11,kBL+8,kBL+12,kBL+9,kBL+13, kBL+13
}

Definition at line 395 of file GraphitePrimitivesSlide.cpp.

◆ kRoundScale

constexpr float kRoundScale = SK_FloatSqrt2 - 1.f
staticconstexpr

Definition at line 105 of file GraphitePrimitivesSlide.cpp.

◆ kTL

const uint16_t kTL = 2*std::size(kCornerTemplate)
static

Definition at line 288 of file GraphitePrimitivesSlide.cpp.

◆ kTR

const uint16_t kTR = 1*std::size(kCornerTemplate)
static

Definition at line 287 of file GraphitePrimitivesSlide.cpp.

◆ kVertexCount

const size_t kVertexCount = 4*std::size(kCornerTemplate)
static

Definition at line 290 of file GraphitePrimitivesSlide.cpp.