Flutter Engine
The Flutter Engine
Classes | Namespaces | Functions
PathOpsExtendedTest.h File Reference
#include "include/core/SkBitmap.h"
#include "include/pathops/SkPathOps.h"
#include <cstddef>

Go to the source code of this file.

Classes

struct  TestDesc
 

Namespaces

namespace  skiatest
 

Functions

int comparePaths (skiatest::Reporter *reporter, const char *filename, const SkPath &one, const SkPath &two, SkBitmap &bitmap)
 
int comparePaths (skiatest::Reporter *reporter, const char *filename, const SkPath &one, const SkPath &two)
 
bool drawAsciiPaths (const SkPath &one, const SkPath &two, bool drawPaths)
 
void markTestFlakyForPathKit ()
 
void showOp (const SkPathOp op)
 
bool testPathOp (skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp, const char *testName)
 
bool testPathOpCheck (skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp, const char *testName, bool checkFail)
 
bool testPathOpFail (skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp, const char *testName)
 
bool testPathOpFuzz (skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp, const char *testName)
 
bool testSimplify (SkPath &path, bool useXor, SkPath &out, PathOpsThreadState &state, const char *pathStr)
 
bool testSimplify (skiatest::Reporter *reporter, const SkPath &path, const char *filename)
 
bool testSimplifyCheck (skiatest::Reporter *reporter, const SkPath &path, const char *filename, bool checkFail)
 
bool testSimplifyFail (skiatest::Reporter *reporter, const SkPath &path, const char *filename)
 
bool testSimplifyFuzz (skiatest::Reporter *reporter, const SkPath &path, const char *filename)
 
void initializeTests (skiatest::Reporter *reporter, const char *testName)
 
void RunTestSet (skiatest::Reporter *reporter, TestDesc tests[], size_t count, void(*firstTest)(skiatest::Reporter *, const char *filename), void(*skipTest)(skiatest::Reporter *, const char *filename), void(*stopTest)(skiatest::Reporter *, const char *filename), bool reverse)
 
void ShowFunctionHeader (const char *name)
 
void ShowPath (const SkPath &path, const char *pathName)
 
void ShowOp (SkPathOp op, const char *pathOne, const char *pathTwo)
 

Function Documentation

◆ comparePaths() [1/2]

int comparePaths ( skiatest::Reporter reporter,
const char *  filename,
const SkPath one,
const SkPath two 
)
inline

Definition at line 28 of file PathOpsExtendedTest.h.

29 {
31 return comparePaths(reporter, filename, one, two, bitmap);
32}
reporter
Definition: FontMgrTest.cpp:39
int comparePaths(skiatest::Reporter *reporter, const char *filename, const SkPath &one, const SkPath &two, SkBitmap &bitmap)
Definition: bitmap.py:1

◆ comparePaths() [2/2]

int comparePaths ( skiatest::Reporter reporter,
const char *  filename,
const SkPath one,
const SkPath two,
SkBitmap bitmap 
)

Definition at line 252 of file PathOpsExtendedTest.cpp.

253 {
254 int errors2x2;
255 SkPath scaledOne, scaledTwo;
256 (void) pathsDrawTheSame(one, two, bitmap, scaledOne, scaledTwo, errors2x2);
257 if (errors2x2 == 0) {
258 return 0;
259 }
260 const int MAX_ERRORS = 9;
261 return errors2x2 > MAX_ERRORS ? errors2x2 : 0;
262}
static int pathsDrawTheSame(SkBitmap &bits, const SkPath &scaledOne, const SkPath &scaledTwo, int &error2x2)
Definition: SkPath.h:59

◆ drawAsciiPaths()

bool drawAsciiPaths ( const SkPath one,
const SkPath two,
bool  drawPaths 
)

Definition at line 205 of file PathOpsExtendedTest.cpp.

205 {
206 if (!drawPaths) {
207 return true;
208 }
209 const SkRect& bounds1 = one.getBounds();
210 const SkRect& bounds2 = two.getBounds();
211 SkRect larger = bounds1;
212 larger.join(bounds2);
214 char out[256];
215 int bitWidth = SkScalarCeilToInt(larger.width()) + 2;
216 if (bitWidth * 2 + 1 >= (int) sizeof(out)) {
217 return false;
218 }
219 int bitHeight = SkScalarCeilToInt(larger.height()) + 2;
220 if (bitHeight >= (int) sizeof(out)) {
221 return false;
222 }
223 bits.allocN32Pixels(bitWidth * 2, bitHeight);
224 SkCanvas canvas(bits);
225 canvas.drawColor(SK_ColorWHITE);
227 canvas.save();
228 canvas.translate(-bounds1.fLeft + 1, -bounds1.fTop + 1);
229 canvas.drawPath(one, paint);
230 canvas.restore();
231 canvas.save();
232 canvas.translate(-bounds1.fLeft + 1 + bitWidth, -bounds1.fTop + 1);
233 canvas.drawPath(two, paint);
234 canvas.restore();
235 for (int y = 0; y < bitHeight; ++y) {
236 uint32_t* addr1 = bits.getAddr32(0, y);
237 int x;
238 char* outPtr = out;
239 for (x = 0; x < bitWidth; ++x) {
240 *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
241 }
242 *outPtr++ = '|';
243 for (x = bitWidth; x < bitWidth * 2; ++x) {
244 *outPtr++ = addr1[x] == (uint32_t) -1 ? '_' : 'x';
245 }
246 *outPtr++ = '\0';
247 SkDebugf("%s\n", out);
248 }
249 return true;
250}
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
#define SkScalarCeilToInt(x)
Definition: SkScalar.h:36
const SkRect & getBounds() const
Definition: SkPath.cpp:430
const Paint & paint
Definition: color_source.cc:38
double y
double x
SkScalar fLeft
smaller x-axis bounds
Definition: extension.cpp:14
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
void join(const SkRect &r)
Definition: SkRect.cpp:126
SkScalar fTop
smaller y-axis bounds
Definition: extension.cpp:15

◆ initializeTests()

void initializeTests ( skiatest::Reporter reporter,
const char *  testName 
)

Definition at line 650 of file PathOpsExtendedTest.cpp.

650 {
651 static SkMutex& mu = *(new SkMutex);
652 if (reporter->verbose()) {
653 SkAutoMutexExclusive lock(mu);
654 sTestName = test;
655 size_t testNameSize = strlen(test);
656 SkFILEStream inFile("../../experimental/Intersection/op.htm");
657 if (inFile.isValid()) {
658 SkTDArray<char> inData;
659 inData.resize((int) inFile.getLength());
660 size_t inLen = inData.size();
661 inFile.read(inData.begin(), inLen);
662 inFile.close();
663 char* insert = strstr(inData.begin(), marker);
664 if (insert) {
665 insert += sizeof(marker) - 1;
666 const char* numLoc = insert + 4 /* indent spaces */ + testNameSize - 1;
667 sTestNumber = atoi(numLoc) + 1;
668 }
669 }
670 }
671}
#define test(name)
static const char marker[]
static int sTestNumber
static const char * sTestName
int size() const
Definition: SkTDArray.h:138
T * begin()
Definition: SkTDArray.h:150
void resize(int count)
Definition: SkTDArray.h:183

◆ markTestFlakyForPathKit()

void markTestFlakyForPathKit ( )

Definition at line 369 of file PathOpsExtendedTest.cpp.

369 {
373 }
374}
#define SkASSERT(cond)
Definition: SkAssert.h:116
static bool gJson
Definition: PathOpsDebug.h:15
static bool gMarkJsonFlaky
Definition: PathOpsDebug.h:16

◆ RunTestSet()

void RunTestSet ( skiatest::Reporter reporter,
TestDesc  tests[],
size_t  count,
void(*)(skiatest::Reporter *, const char *filename)  firstTest,
void(*)(skiatest::Reporter *, const char *filename)  skipTest,
void(*)(skiatest::Reporter *, const char *filename)  stopTest,
bool  reverse 
)

Definition at line 691 of file PathOpsExtendedTest.cpp.

694 {
695 size_t index;
696 if (firstTest) {
697 index = count - 1;
698 while (index > 0 && tests[index].fun != firstTest) {
699 --index;
700 }
701 (*tests[index].fun)(reporter, tests[index].str);
702 if (tests[index].fun == stopTest) {
703 return;
704 }
705 }
706 index = reverse ? count - 1 : 0;
707 size_t last = reverse ? 0 : count - 1;
708 bool foundSkip = !skipTest;
709 do {
710 if (tests[index].fun == skipTest) {
711 foundSkip = true;
712 }
713 if (foundSkip && tests[index].fun != firstTest) {
714 (*tests[index].fun)(reporter, tests[index].str);
715 }
716 if (tests[index].fun == stopTest || index == last) {
717 break;
718 }
719 index += reverse ? -1 : 1;
720 } while (true);
721}
static BlurTest tests[]
Definition: BlurTest.cpp:84
int count
Definition: FontMgrTest.cpp:50
static void(* stopTest)(skiatest::Reporter *, const char *filename)
static void(* firstTest)(skiatest::Reporter *, const char *filename)

◆ ShowFunctionHeader()

void ShowFunctionHeader ( const char *  name)

◆ showOp()

void showOp ( const SkPathOp  op)

Definition at line 107 of file PathOpsExtendedTest.cpp.

107 {
108 switch (op) {
110 SkDebugf("op difference\n");
111 break;
113 SkDebugf("op intersect\n");
114 break;
115 case kUnion_SkPathOp:
116 SkDebugf("op union\n");
117 break;
118 case kXOR_SkPathOp:
119 SkDebugf("op xor\n");
120 break;
122 SkDebugf("op reverse difference\n");
123 break;
124 default:
125 SkASSERT(0);
126 }
127}
@ kReverseDifference_SkPathOp
subtract the first path from the op path
Definition: SkPathOps.h:27
@ kDifference_SkPathOp
subtract the op path from the first path
Definition: SkPathOps.h:23
@ kIntersect_SkPathOp
intersect the two paths
Definition: SkPathOps.h:24
@ kUnion_SkPathOp
union (inclusive-or) the two paths
Definition: SkPathOps.h:25
@ kXOR_SkPathOp
exclusive-or the two paths
Definition: SkPathOps.h:26

◆ ShowOp()

void ShowOp ( SkPathOp  op,
const char *  pathOne,
const char *  pathTwo 
)

◆ ShowPath()

void ShowPath ( const SkPath path,
const char *  pathName 
)

◆ testPathOp()

bool testPathOp ( skiatest::Reporter reporter,
const SkPath a,
const SkPath b,
const  SkPathOp,
const char *  testName 
)

Definition at line 618 of file PathOpsExtendedTest.cpp.

619 {
622}
static bool innerPathOp(skiatest::Reporter *reporter, const SkPath &a, const SkPath &b, const SkPathOp shapeOp, const char *testName, ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMatch)
static bool b
struct MyStruct a[10]

◆ testPathOpCheck()

bool testPathOpCheck ( skiatest::Reporter reporter,
const SkPath a,
const SkPath b,
const  SkPathOp,
const char *  testName,
bool  checkFail 
)

Definition at line 624 of file PathOpsExtendedTest.cpp.

◆ testPathOpFail()

bool testPathOpFail ( skiatest::Reporter reporter,
const SkPath a,
const SkPath b,
const  SkPathOp,
const char *  testName 
)

Definition at line 636 of file PathOpsExtendedTest.cpp.

637 {
638 SkPath orig;
639 orig.lineTo(54, 43);
640 SkPath out = orig;
641 if (Op(a, b, shapeOp, &out) ) {
642 SkDebugf("%s test is expected to fail\n", __FUNCTION__);
644 return false;
645 }
646 SkASSERT(out == orig);
647 return true;
648}
#define REPORTER_ASSERT(r, cond,...)
Definition: Test.h:286
SkPath & lineTo(SkScalar x, SkScalar y)
Definition: SkPath.cpp:728

◆ testPathOpFuzz()

bool testPathOpFuzz ( skiatest::Reporter reporter,
const SkPath a,
const SkPath b,
const  SkPathOp,
const char *  testName 
)

◆ testSimplify() [1/2]

bool testSimplify ( skiatest::Reporter reporter,
const SkPath path,
const char *  filename 
)

Definition at line 526 of file PathOpsExtendedTest.cpp.

526 {
529}
static bool inner_simplify(skiatest::Reporter *reporter, const SkPath &path, const char *filename, ExpectSuccess expectSuccess, SkipAssert skipAssert, ExpectMatch expectMatch)
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

◆ testSimplify() [2/2]

bool testSimplify ( SkPath path,
bool  useXor,
SkPath out,
PathOpsThreadState state,
const char *  pathStr 
)

Definition at line 376 of file PathOpsExtendedTest.cpp.

377 {
378 static SkMutex& simplifyDebugOut = *(new SkMutex);
380 path.setFillType(fillType);
381 state.fReporter->bumpTestCount();
382 if (!Simplify(path, &out)) {
383 SkDebugf("%s did not expect failure\n", __FUNCTION__);
384 REPORTER_ASSERT(state.fReporter, 0);
385 return false;
386 }
387 if (!state.fReporter->verbose()) {
388 return true;
389 }
390 int result = comparePaths(state.fReporter, nullptr, path, out, *state.fBitmap);
391 if (result) {
392 SkAutoMutexExclusive autoM(simplifyDebugOut);
393 std::string str;
394 const char* pathPrefix = nullptr;
395 const char* nameSuffix = nullptr;
396 if (fillType == SkPathFillType::kEvenOdd) {
397 pathPrefix = " path.setFillType(SkPathFillType::kEvenOdd);\n";
398 nameSuffix = "x";
399 }
400 const char testFunction[] = "testSimplify(reporter, path);";
401 appendTest(pathStr, pathPrefix, nameSuffix, testFunction, false, str);
402 SkDebugf("%s", str.c_str());
403 REPORTER_ASSERT(state.fReporter, 0);
404 }
405 state.fReporter->bumpTestCount();
406 return result == 0;
407}
int comparePaths(skiatest::Reporter *reporter, const char *filename, const SkPath &one, const SkPath &two, SkBitmap &bitmap)
static void appendTest(const char *pathStr, const char *pathPrefix, const char *nameSuffix, const char *testFunction, bool twoPaths, std::string &out)
bool SK_API Simplify(const SkPath &path, SkPath *result)
SkPathFillType
Definition: SkPathTypes.h:11
AtkStateType state
GAsyncResult * result
static int testFunction(int x)

◆ testSimplifyCheck()

bool testSimplifyCheck ( skiatest::Reporter reporter,
const SkPath path,
const char *  filename,
bool  checkFail 
)

Definition at line 536 of file PathOpsExtendedTest.cpp.

537 {
538 return inner_simplify(reporter, path, filename, checkFail ?
540}

◆ testSimplifyFail()

bool testSimplifyFail ( skiatest::Reporter reporter,
const SkPath path,
const char *  filename 
)

Definition at line 542 of file PathOpsExtendedTest.cpp.

◆ testSimplifyFuzz()

bool testSimplifyFuzz ( skiatest::Reporter reporter,
const SkPath path,
const char *  filename 
)

Definition at line 531 of file PathOpsExtendedTest.cpp.