2 * Copyright 2013 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
7 #include "PathOpsExtendedTest.h"
8 #include "PathOpsThreadedCommon.h"
15 static void testTightBoundsLines(PathOpsThreadState* data) {
17 for (int index = 0; index < 1000; ++index) {
19 int contourCount = ran.nextRangeU(1, 10);
20 for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
21 int lineCount = ran.nextRangeU(1, 10);
22 path.moveTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
23 for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
24 path.lineTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
30 SkRect classicBounds = path.getBounds();
32 REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
33 REPORTER_ASSERT(data->fReporter, classicBounds == tightBounds);
37 DEF_TEST(PathOpsTightBoundsLines, reporter) {
38 int threadCount = initializeTests(reporter, "tightBoundsLines");
39 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
40 int outerCount = reporter->allowExtendedTest() ? 100 : 1;
41 for (int index = 0; index < outerCount; ++index) {
42 for (int idx2 = 0; idx2 < 10; ++idx2) {
43 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
44 (&testTightBoundsLines, 0, 0, 0, 0, &testRunner));
50 static void testTightBoundsQuads(PathOpsThreadState* data) {
52 const int bitWidth = 32;
53 const int bitHeight = 32;
54 const float pathMin = 1;
55 const float pathMax = (float) (bitHeight - 2);
56 SkBitmap& bits = *data->fBitmap;
57 if (bits.width() == 0) {
58 bits.allocN32Pixels(bitWidth, bitHeight);
60 SkCanvas canvas(bits);
62 for (int index = 0; index < 100; ++index) {
64 int contourCount = ran.nextRangeU(1, 10);
65 for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
66 int lineCount = ran.nextRangeU(1, 10);
67 path.moveTo(ran.nextRangeF(1, pathMax), ran.nextRangeF(pathMin, pathMax));
68 for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
70 path.lineTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
72 path.quadTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax),
73 ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
80 SkRect classicBounds = path.getBounds();
82 REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
83 REPORTER_ASSERT(data->fReporter, classicBounds.contains(tightBounds));
84 canvas.drawColor(SK_ColorWHITE);
85 canvas.drawPath(path, paint);
86 SkIRect bitsWritten = {31, 31, 0, 0};
87 for (int y = 0; y < bitHeight; ++y) {
88 uint32_t* addr1 = data->fBitmap->getAddr32(0, y);
89 bool lineWritten = false;
90 for (int x = 0; x < bitWidth; ++x) {
91 if (addr1[x] == (uint32_t) -1) {
95 bitsWritten.fLeft = SkTMin(bitsWritten.fLeft, x);
96 bitsWritten.fRight = SkTMax(bitsWritten.fRight, x);
101 bitsWritten.fTop = SkTMin(bitsWritten.fTop, y);
102 bitsWritten.fBottom = SkTMax(bitsWritten.fBottom, y);
104 if (!bitsWritten.isEmpty()) {
106 tightBounds.roundOut(&tightOut);
107 REPORTER_ASSERT(data->fReporter, tightOut.contains(bitsWritten));
112 DEF_TEST(PathOpsTightBoundsQuads, reporter) {
113 int threadCount = initializeTests(reporter, "tightBoundsQuads");
114 PathOpsThreadedTestRunner testRunner(reporter, threadCount);
115 int outerCount = reporter->allowExtendedTest() ? 100 : 1;
116 for (int index = 0; index < outerCount; ++index) {
117 for (int idx2 = 0; idx2 < 10; ++idx2) {
118 *testRunner.fRunnables.append() = SkNEW_ARGS(PathOpsThreadedRunnable,
119 (&testTightBoundsQuads, 0, 0, 0, 0, &testRunner));