Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
StrokeTest.cpp File Reference
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathUtils.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkScalar.h"
#include "include/core/SkStrokeRec.h"
#include "src/base/SkFloatBits.h"
#include "src/core/SkPathPriv.h"
#include "tests/Test.h"
#include <array>
#include <cstddef>
#include <cstdint>

Go to the source code of this file.

Functions

static bool equal (const SkRect &a, const SkRect &b)
 
static void test_strokecubic (skiatest::Reporter *reporter)
 
static void test_strokerect (skiatest::Reporter *reporter)
 
static void test_strokerec_equality (skiatest::Reporter *reporter)
 
static void test_big_stroke (skiatest::Reporter *reporter)
 
 DEF_TEST (Stroke, reporter)
 

Function Documentation

◆ DEF_TEST()

DEF_TEST ( Stroke  ,
reporter   
)

Definition at line 189 of file StrokeTest.cpp.

189 {
194}
reporter
static void test_strokerect(skiatest::Reporter *reporter)
static void test_strokecubic(skiatest::Reporter *reporter)
static void test_big_stroke(skiatest::Reporter *reporter)
static void test_strokerec_equality(skiatest::Reporter *reporter)

◆ equal()

static bool equal ( const SkRect a,
const SkRect b 
)
static

Definition at line 23 of file StrokeTest.cpp.

23 {
24 return SkScalarNearlyEqual(a.left(), b.left()) &&
25 SkScalarNearlyEqual(a.top(), b.top()) &&
26 SkScalarNearlyEqual(a.right(), b.right()) &&
27 SkScalarNearlyEqual(a.bottom(), b.bottom());
28}
static bool SkScalarNearlyEqual(SkScalar x, SkScalar y, SkScalar tolerance=SK_ScalarNearlyZero)
Definition SkScalar.h:107
static bool b
struct MyStruct a[10]

◆ test_big_stroke()

static void test_big_stroke ( skiatest::Reporter reporter)
static

Definition at line 172 of file StrokeTest.cpp.

172 {
175 paint.setStrokeWidth(1.49679073e+10f);
176
177 SkPath path;
178 path.moveTo(SkBits2Float(0x46380000), SkBits2Float(0xc6380000)); // 11776, -11776
179 path.lineTo(SkBits2Float(0x46a00000), SkBits2Float(0xc6a00000)); // 20480, -20480
180 path.lineTo(SkBits2Float(0x468c0000), SkBits2Float(0xc68c0000)); // 17920, -17920
181 path.lineTo(SkBits2Float(0x46100000), SkBits2Float(0xc6100000)); // 9216, -9216
182 path.lineTo(SkBits2Float(0x46380000), SkBits2Float(0xc6380000)); // 11776, -11776
183 path.close();
184
185 SkPath strokeAndFillPath;
186 skpathutils::FillPathWithPaint(path, paint, &strokeAndFillPath);
187}
static float SkBits2Float(uint32_t bits)
Definition SkFloatBits.h:48
@ kStrokeAndFill_Style
sets to stroke and fill geometry
Definition SkPaint.h:195
const Paint & paint
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
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)

◆ test_strokecubic()

static void test_strokecubic ( skiatest::Reporter reporter)
static

Definition at line 30 of file StrokeTest.cpp.

30 {
31 uint32_t hexCubicVals[] = {
32 0x424c1086, 0x44bcf0cb, // fX=51.0161362 fY=1511.52478
33 0x424c107c, 0x44bcf0cb, // fX=51.0160980 fY=1511.52478
34 0x424c10c2, 0x44bcf0cb, // fX=51.0163651 fY=1511.52478
35 0x424c1119, 0x44bcf0ca, // fX=51.0166969 fY=1511.52466
36 };
37 SkPoint cubicVals[] = {
38 {51.0161362f, 1511.52478f },
39 {51.0160980f, 1511.52478f },
40 {51.0163651f, 1511.52478f },
41 {51.0166969f, 1511.52466f },
42 };
44
46 paint.setStrokeWidth(0.394537568f);
47 SkPath path, fillPath;
48 path.moveTo(cubicVals[0]);
49 path.cubicTo(cubicVals[1], cubicVals[2], cubicVals[3]);
50 skpathutils::FillPathWithPaint(path, paint, &fillPath);
51 path.reset();
52 path.moveTo(SkBits2Float(hexCubicVals[0]), SkBits2Float(hexCubicVals[1]));
53 path.cubicTo(SkBits2Float(hexCubicVals[2]), SkBits2Float(hexCubicVals[3]),
54 SkBits2Float(hexCubicVals[4]), SkBits2Float(hexCubicVals[5]),
55 SkBits2Float(hexCubicVals[6]), SkBits2Float(hexCubicVals[7]));
56 skpathutils::FillPathWithPaint(path, paint, &fillPath);
57}
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194

◆ test_strokerec_equality()

static void test_strokerec_equality ( skiatest::Reporter reporter)
static

Definition at line 96 of file StrokeTest.cpp.

96 {
97 {
100 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
101
102 // Test that style mismatch is detected.
103 s2.setHairlineStyle();
104 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
105
106 s1.setHairlineStyle();
107 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
108
109 // ResScale is not part of equality.
110 s1.setResScale(2.1f);
111 s2.setResScale(1.2f);
112 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
113 s1.setFillStyle();
114 s2.setFillStyle();
115 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
116 s1.setStrokeStyle(1.0f, false);
117 s2.setStrokeStyle(1.0f, false);
118 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
119 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
120 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
121 }
122
123 // Stroke parameters on fill or hairline style are not part of equality.
124 {
127 for (int i = 0; i < 2; ++i) {
128 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
129 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f);
130 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
131 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f);
132 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
133 s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f);
134 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
135 s1.setHairlineStyle();
136 s2.setHairlineStyle();
137 }
138 }
139
140 // Stroke parameters on stroke style are part of equality.
141 {
144 s1.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
145 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.9f);
146 s1.setStrokeStyle(1.0f, false);
147
148 s2.setStrokeStyle(1.0f, true);
149 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
150
151 s2.setStrokeStyle(2.1f, false);
152 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
153
154 s2.setStrokeStyle(1.0f, false);
155 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
156
157 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kRound_Join, 2.1f);
158 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2)); // Miter limit not relevant to butt caps.
159 s2.setStrokeParams(SkPaint::kButt_Cap, SkPaint::kBevel_Join, 2.9f);
160 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
161 s2.setStrokeParams(SkPaint::kRound_Cap, SkPaint::kRound_Join, 2.9f);
162 REPORTER_ASSERT(reporter, !s1.hasEqualEffect(s2));
163
164 // Sets fill.
165 s1.setStrokeStyle(0.0f, true);
166 s2.setStrokeStyle(0.0f, true);
167 REPORTER_ASSERT(reporter, s1.hasEqualEffect(s2));
168 }
169}
#define REPORTER_ASSERT(r, cond,...)
Definition Test.h:286
@ kRound_Cap
adds circle
Definition SkPaint.h:335
@ kButt_Cap
no stroke extension
Definition SkPaint.h:334
@ kRound_Join
adds circle
Definition SkPaint.h:360
@ kBevel_Join
connects outside edges
Definition SkPaint.h:361

◆ test_strokerect()

static void test_strokerect ( skiatest::Reporter reporter)
static

Definition at line 59 of file StrokeTest.cpp.

59 {
60 const SkScalar width = SkIntToScalar(10);
62
64 paint.setStrokeWidth(width);
65
66 SkRect r = { 0, 0, SkIntToScalar(200), SkIntToScalar(100) };
67
68 SkRect outer(r);
69 outer.outset(width/2, width/2);
70
71 static const SkPaint::Join joins[] = {
73 };
74
75 for (size_t i = 0; i < std::size(joins); ++i) {
76 paint.setStrokeJoin(joins[i]);
77
78 SkPath path, fillPath;
79 path.addRect(r);
80 skpathutils::FillPathWithPaint(path, paint, &fillPath);
81
82 REPORTER_ASSERT(reporter, equal(outer, fillPath.getBounds()));
83
84 bool isMiter = SkPaint::kMiter_Join == joins[i];
85 SkRect nested[2];
86 REPORTER_ASSERT(reporter, SkPathPriv::IsNestedFillRects(fillPath, nested) == isMiter);
87 if (isMiter) {
88 SkRect inner(r);
89 inner.inset(width/2, width/2);
90 REPORTER_ASSERT(reporter, equal(nested[0], outer));
91 REPORTER_ASSERT(reporter, equal(nested[1], inner));
92 }
93 }
94}
#define SkIntToScalar(x)
Definition SkScalar.h:57
static bool equal(const SkRect &a, const SkRect &b)
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
static bool IsNestedFillRects(const SkPath &, SkRect rect[2], SkPathDirection dirs[2]=nullptr)
Definition SkPath.cpp:3712
const SkRect & getBounds() const
Definition SkPath.cpp:420
float SkScalar
Definition extension.cpp:12
int32_t width