Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Macros | Functions | Variables
PathCoverageTest.cpp File Reference
#include "include/core/SkPoint.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTypes.h"
#include "include/private/base/SkSafe32.h"
#include "src/base/SkMathPriv.h"
#include "src/core/SkPointPriv.h"
#include "tests/Test.h"
#include <algorithm>
#include <array>
#include <cstdint>

Go to the source code of this file.

Macros

#define MAX_COEFF_SHIFT   6
 

Functions

static int cheap_distance (SkScalar dx, SkScalar dy)
 
static int estimate_distance (const SkPoint points[])
 
static SkScalar compute_distance (const SkPoint points[])
 
static uint32_t estimate_pointCount (int distance)
 
static uint32_t compute_pointCount (SkScalar d, SkScalar tol)
 
static uint32_t quadraticPointCount_EE (const SkPoint points[])
 
static uint32_t quadraticPointCount_EC (const SkPoint points[], SkScalar tol)
 
static uint32_t quadraticPointCount_CE (const SkPoint points[])
 
static uint32_t quadraticPointCount_CC (const SkPoint points[], SkScalar tol)
 
static bool one_d_pe (const int *array, const unsigned int count, skiatest::Reporter *reporter)
 
static void TestQuadPointCount (skiatest::Reporter *reporter)
 
 DEF_TEST (PathCoverage, reporter)
 

Variables

static const uint32_t MAX_POINTS_PER_CURVE = 1 << MAX_COEFF_SHIFT
 
static const int gXY []
 
static const int gSawtooth []
 
static const int gOvalish []
 
static const int gSharpSawtooth []
 
static const int gRibbon []
 

Macro Definition Documentation

◆ MAX_COEFF_SHIFT

#define MAX_COEFF_SHIFT   6

Definition at line 27 of file PathCoverageTest.cpp.

Function Documentation

◆ cheap_distance()

static int cheap_distance ( SkScalar  dx,
SkScalar  dy 
)
inlinestatic

Definition at line 35 of file PathCoverageTest.cpp.

35 {
36 int idx = SkAbs32(SkScalarRoundToInt(dx));
37 int idy = SkAbs32(SkScalarRoundToInt(dy));
38 if (idx > idy) {
39 idx += idy >> 1;
40 } else {
41 idx = idy + (idx >> 1);
42 }
43 return idx;
44}
static int32_t SkAbs32(int32_t value)
Definition SkSafe32.h:41
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37

◆ compute_distance()

static SkScalar compute_distance ( const SkPoint  points[])
inlinestatic

Definition at line 51 of file PathCoverageTest.cpp.

51 {
53}
static const int points[]
static SkScalar DistanceToLineSegmentBetween(const SkPoint &pt, const SkPoint &a, const SkPoint &b)
Definition SkPointPriv.h:43

◆ compute_pointCount()

static uint32_t compute_pointCount ( SkScalar  d,
SkScalar  tol 
)
inlinestatic

Definition at line 66 of file PathCoverageTest.cpp.

66 {
67 if (d < tol) {
68 return 1;
69 } else {
70 int temp = SkScalarCeilToInt(SkScalarSqrt(d / tol));
71 uint32_t count = std::min<uint32_t>(SkNextPow2(temp), MAX_POINTS_PER_CURVE);
72 return count;
73 }
74}
int count
static const uint32_t MAX_POINTS_PER_CURVE
static int SkNextPow2(int value)
Definition SkMathPriv.h:272
#define SkScalarCeilToInt(x)
Definition SkScalar.h:36
#define SkScalarSqrt(x)
Definition SkScalar.h:42
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19

◆ DEF_TEST()

DEF_TEST ( PathCoverage  ,
reporter   
)

Definition at line 165 of file PathCoverageTest.cpp.

165 {
167
168}
reporter
static void TestQuadPointCount(skiatest::Reporter *reporter)

◆ estimate_distance()

static int estimate_distance ( const SkPoint  points[])
inlinestatic

Definition at line 46 of file PathCoverageTest.cpp.

46 {
47 return cheap_distance(points[1].fX * 2 - points[2].fX - points[0].fX,
48 points[1].fY * 2 - points[2].fY - points[0].fY);
49}
static int cheap_distance(SkScalar dx, SkScalar dy)

◆ estimate_pointCount()

static uint32_t estimate_pointCount ( int  distance)
inlinestatic

Definition at line 55 of file PathCoverageTest.cpp.

55 {
56 // Includes -2 bias because this estimator runs 4x high?
57 int shift = 30 - SkCLZ(distance);
58 // Clamp to zero if above subtraction went negative.
59 shift &= ~(shift>>31);
60 if (shift > MAX_COEFF_SHIFT) {
61 shift = MAX_COEFF_SHIFT;
62 }
63 return 1 << shift;
64}
#define MAX_COEFF_SHIFT
static int SkCLZ(uint32_t mask)
Definition SkMathPriv.h:186

◆ one_d_pe()

static bool one_d_pe ( const int array,
const unsigned int  count,
skiatest::Reporter reporter 
)
static

Definition at line 118 of file PathCoverageTest.cpp.

119 {
120 SkPoint path [3];
121 path[1] = SkPoint::Make(SkIntToScalar(array[0]), SkIntToScalar(array[1]));
122 path[2] = SkPoint::Make(SkIntToScalar(array[2]), SkIntToScalar(array[3]));
123 int numErrors = 0;
124 for (unsigned i = 4; i < count; i += 2) {
125 path[0] = path[1];
126 path[1] = path[2];
127 path[2] = SkPoint::Make(SkIntToScalar(array[i]),
128 SkIntToScalar(array[i+1]));
129 uint32_t computedCount =
131 uint32_t estimatedCount =
133
134 if ((false)) { // avoid bit rot, suppress warning
135 computedCount = quadraticPointCount_EC(path, SkIntToScalar(1));
136 estimatedCount = quadraticPointCount_CE(path);
137 }
138 // Allow estimated to be high by a factor of two, but no less than
139 // the computed value.
140 bool isAccurate = (estimatedCount >= computedCount) &&
141 (estimatedCount <= 2 * computedCount);
142
143 if (!isAccurate) {
144 ERRORF(reporter, "Curve from %.2f %.2f through %.2f %.2f to "
145 "%.2f %.2f computes %u, estimates %u\n",
146 path[0].fX, path[0].fY, path[1].fX, path[1].fY,
147 path[2].fX, path[2].fY, computedCount, estimatedCount);
148 numErrors++;
149 }
150 }
151
152 return (numErrors == 0);
153}
static uint32_t quadraticPointCount_EC(const SkPoint points[], SkScalar tol)
static uint32_t quadraticPointCount_CC(const SkPoint points[], SkScalar tol)
static uint32_t quadraticPointCount_EE(const SkPoint points[])
static uint32_t quadraticPointCount_CE(const SkPoint points[])
#define SkIntToScalar(x)
Definition SkScalar.h:57
#define ERRORF(r,...)
Definition Test.h:293
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
Definition switches.h:57
static constexpr SkPoint Make(float x, float y)

◆ quadraticPointCount_CC()

static uint32_t quadraticPointCount_CC ( const SkPoint  points[],
SkScalar  tol 
)
static

Definition at line 91 of file PathCoverageTest.cpp.

91 {
93 return compute_pointCount(distance, tol);
94}
static uint32_t compute_pointCount(SkScalar d, SkScalar tol)
static SkScalar compute_distance(const SkPoint points[])
float SkScalar
Definition extension.cpp:12

◆ quadraticPointCount_CE()

static uint32_t quadraticPointCount_CE ( const SkPoint  points[])
static

Definition at line 86 of file PathCoverageTest.cpp.

86 {
89}
static uint32_t estimate_pointCount(int distance)

◆ quadraticPointCount_EC()

static uint32_t quadraticPointCount_EC ( const SkPoint  points[],
SkScalar  tol 
)
static

Definition at line 81 of file PathCoverageTest.cpp.

81 {
83 return compute_pointCount(SkIntToScalar(distance), tol);
84}
static int estimate_distance(const SkPoint points[])

◆ quadraticPointCount_EE()

static uint32_t quadraticPointCount_EE ( const SkPoint  points[])
static

Definition at line 76 of file PathCoverageTest.cpp.

76 {
78 return estimate_pointCount(distance);
79}

◆ TestQuadPointCount()

static void TestQuadPointCount ( skiatest::Reporter reporter)
static

Definition at line 157 of file PathCoverageTest.cpp.

157 {
158 one_d_pe(gXY, std::size(gXY), reporter);
159 one_d_pe(gSawtooth, std::size(gSawtooth), reporter);
160 one_d_pe(gOvalish, std::size(gOvalish), reporter);
162 one_d_pe(gRibbon, std::size(gRibbon), reporter);
163}
static const int gOvalish[]
static const int gSawtooth[]
static const int gRibbon[]
static const int gXY[]
static const int gSharpSawtooth[]
static bool one_d_pe(const int *array, const unsigned int count, skiatest::Reporter *reporter)

Variable Documentation

◆ gOvalish

const int gOvalish[]
static
Initial value:
= {
0, 0, 5, 15, 20, 20, 35, 15, 40, 0
}

Definition at line 105 of file PathCoverageTest.cpp.

105 {
106 0, 0, 5, 15, 20, 20, 35, 15, 40, 0
107};

◆ gRibbon

const int gRibbon[]
static
Initial value:
= {
-4, 0, 4, 20, 0, 25, -4, 20, 4, 0
}

Definition at line 114 of file PathCoverageTest.cpp.

114 {
115 -4, 0, 4, 20, 0, 25, -4, 20, 4, 0
116};

◆ gSawtooth

const int gSawtooth[]
static
Initial value:
= {
0, 0, 10, 10, 20, 20, 30, 10, 40, 0, 50, -10, 60, -20, 70, -10, 80, 0
}

Definition at line 101 of file PathCoverageTest.cpp.

101 {
102 0, 0, 10, 10, 20, 20, 30, 10, 40, 0, 50, -10, 60, -20, 70, -10, 80, 0
103};

◆ gSharpSawtooth

const int gSharpSawtooth[]
static
Initial value:
= {
0, 0, 1, 10, 2, 0, 3, -10, 4, 0
}

Definition at line 109 of file PathCoverageTest.cpp.

109 {
110 0, 0, 1, 10, 2, 0, 3, -10, 4, 0
111};

◆ gXY

const int gXY[]
static
Initial value:
= {
4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
}

Definition at line 97 of file PathCoverageTest.cpp.

97 {
98 4, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
99};

◆ MAX_POINTS_PER_CURVE

const uint32_t MAX_POINTS_PER_CURVE = 1 << MAX_COEFF_SHIFT
static

Definition at line 28 of file PathCoverageTest.cpp.