2014-06-24 14:55:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
#include "PathOpsExtendedTest.h"
|
|
|
|
#include "PathOpsThreadedCommon.h"
|
|
|
|
#include "SkCanvas.h"
|
|
|
|
#include "SkRandom.h"
|
|
|
|
#include "SkTSort.h"
|
|
|
|
#include "Test.h"
|
|
|
|
|
|
|
|
static void testTightBoundsLines(PathOpsThreadState* data) {
|
|
|
|
SkRandom ran;
|
|
|
|
for (int index = 0; index < 1000; ++index) {
|
|
|
|
SkPath path;
|
|
|
|
int contourCount = ran.nextRangeU(1, 10);
|
|
|
|
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
|
|
|
|
int lineCount = ran.nextRangeU(1, 10);
|
|
|
|
path.moveTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
|
|
|
|
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
|
|
|
|
path.lineTo(ran.nextRangeF(-1000, 1000), ran.nextRangeF(-1000, 1000));
|
|
|
|
}
|
|
|
|
if (ran.nextBool()) {
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkRect classicBounds = path.getBounds();
|
|
|
|
SkRect tightBounds;
|
|
|
|
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
|
|
|
|
REPORTER_ASSERT(data->fReporter, classicBounds == tightBounds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsLines, reporter) {
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
initializeTests(reporter, "tightBoundsLines");
|
|
|
|
PathOpsThreadedTestRunner testRunner(reporter);
|
2014-06-24 14:55:11 +00:00
|
|
|
int outerCount = reporter->allowExtendedTest() ? 100 : 1;
|
|
|
|
for (int index = 0; index < outerCount; ++index) {
|
|
|
|
for (int idx2 = 0; idx2 < 10; ++idx2) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*testRunner.fRunnables.append() =
|
|
|
|
new PathOpsThreadedRunnable(&testTightBoundsLines, 0, 0, 0, 0, &testRunner);
|
2014-06-24 14:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
testRunner.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testTightBoundsQuads(PathOpsThreadState* data) {
|
|
|
|
SkRandom ran;
|
|
|
|
const int bitWidth = 32;
|
|
|
|
const int bitHeight = 32;
|
|
|
|
const float pathMin = 1;
|
|
|
|
const float pathMax = (float) (bitHeight - 2);
|
|
|
|
SkBitmap& bits = *data->fBitmap;
|
|
|
|
if (bits.width() == 0) {
|
|
|
|
bits.allocN32Pixels(bitWidth, bitHeight);
|
|
|
|
}
|
|
|
|
SkCanvas canvas(bits);
|
|
|
|
SkPaint paint;
|
|
|
|
for (int index = 0; index < 100; ++index) {
|
|
|
|
SkPath path;
|
|
|
|
int contourCount = ran.nextRangeU(1, 10);
|
|
|
|
for (int cIndex = 0; cIndex < contourCount; ++cIndex) {
|
|
|
|
int lineCount = ran.nextRangeU(1, 10);
|
|
|
|
path.moveTo(ran.nextRangeF(1, pathMax), ran.nextRangeF(pathMin, pathMax));
|
|
|
|
for (int lIndex = 0; lIndex < lineCount; ++lIndex) {
|
|
|
|
if (ran.nextBool()) {
|
|
|
|
path.lineTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
|
|
|
|
} else {
|
|
|
|
path.quadTo(ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax),
|
|
|
|
ran.nextRangeF(pathMin, pathMax), ran.nextRangeF(pathMin, pathMax));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (ran.nextBool()) {
|
|
|
|
path.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SkRect classicBounds = path.getBounds();
|
|
|
|
SkRect tightBounds;
|
|
|
|
REPORTER_ASSERT(data->fReporter, TightBounds(path, &tightBounds));
|
|
|
|
REPORTER_ASSERT(data->fReporter, classicBounds.contains(tightBounds));
|
|
|
|
canvas.drawColor(SK_ColorWHITE);
|
|
|
|
canvas.drawPath(path, paint);
|
|
|
|
SkIRect bitsWritten = {31, 31, 0, 0};
|
|
|
|
for (int y = 0; y < bitHeight; ++y) {
|
|
|
|
uint32_t* addr1 = data->fBitmap->getAddr32(0, y);
|
|
|
|
bool lineWritten = false;
|
|
|
|
for (int x = 0; x < bitWidth; ++x) {
|
|
|
|
if (addr1[x] == (uint32_t) -1) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
lineWritten = true;
|
|
|
|
bitsWritten.fLeft = SkTMin(bitsWritten.fLeft, x);
|
|
|
|
bitsWritten.fRight = SkTMax(bitsWritten.fRight, x);
|
|
|
|
}
|
|
|
|
if (!lineWritten) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
bitsWritten.fTop = SkTMin(bitsWritten.fTop, y);
|
|
|
|
bitsWritten.fBottom = SkTMax(bitsWritten.fBottom, y);
|
|
|
|
}
|
|
|
|
if (!bitsWritten.isEmpty()) {
|
|
|
|
SkIRect tightOut;
|
|
|
|
tightBounds.roundOut(&tightOut);
|
|
|
|
REPORTER_ASSERT(data->fReporter, tightOut.contains(bitsWritten));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsQuads, reporter) {
|
SkThreadPool ~~> SkTaskGroup
SkTaskGroup is like SkThreadPool except the threads stay in
one global pool. Each SkTaskGroup itself is tiny (4 bytes)
and its wait() method applies only to tasks add()ed to that
instance, not the whole thread pool.
This means we don't need to bring up new thread pools when
tests themselves want to use multithreading (e.g. pathops,
quilt). We just create a new SkTaskGroup and wait for that
to complete. This should be more efficient, and allow us
to expand where we use threads to really latency sensitive
places. E.g. we can probably now use these in nanobench
for CPU .skp rendering.
Now that all threads are sharing the same pool, I think we
can remove most of the custom mechanism pathops tests use
to control threading. They'll just ride on the global pool
with all other tests now.
This (temporarily?) removes the GPU multithreading feature
from DM, which we don't use.
On my desktop, DM runs a little faster (57s -> 55s) in
Debug, and a lot faster in Release (36s -> 24s). The bots
show speedups of similar proportions, cutting more than a
minute off the N4/Release and Win7/Debug runtimes.
BUG=skia:
Committed: https://skia.googlesource.com/skia/+/9c7207b5dc71dc5a96a2eb107d401133333d5b6f
R=caryclark@google.com, bsalomon@google.com, bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/531653002
2014-09-03 22:34:37 +00:00
|
|
|
initializeTests(reporter, "tightBoundsQuads");
|
|
|
|
PathOpsThreadedTestRunner testRunner(reporter);
|
2014-06-24 14:55:11 +00:00
|
|
|
int outerCount = reporter->allowExtendedTest() ? 100 : 1;
|
|
|
|
for (int index = 0; index < outerCount; ++index) {
|
|
|
|
for (int idx2 = 0; idx2 < 10; ++idx2) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*testRunner.fRunnables.append() =
|
|
|
|
new PathOpsThreadedRunnable(&testTightBoundsQuads, 0, 0, 0, 0, &testRunner);
|
2014-06-24 14:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
testRunner.render();
|
|
|
|
}
|
2016-10-05 20:23:00 +00:00
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsMove, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(10, 10);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
path.lineTo(20, 20);
|
|
|
|
path.close();
|
|
|
|
path.moveTo(15, 15);
|
|
|
|
path.lineTo(15, 15);
|
|
|
|
path.close();
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds == tight);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsMoveOne, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds == tight);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsMoveTwo, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(20, 20);
|
|
|
|
path.moveTo(40, 40);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds == tight);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsTiny, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(1, 1);
|
|
|
|
path.quadTo(1.000001f, 1, 1, 1);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
SkRect moveBounds = {1, 1, 1, 1};
|
|
|
|
REPORTER_ASSERT(reporter, bounds != tight);
|
|
|
|
REPORTER_ASSERT(reporter, moveBounds == tight);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsWellBehaved, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(1, 1);
|
|
|
|
path.quadTo(2, 3, 4, 5);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds == tight);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsTightBoundsIllBehaved, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(1, 1);
|
|
|
|
path.quadTo(4, 3, 2, 2);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds != tight);
|
|
|
|
}
|
|
|
|
|
2017-01-04 12:31:47 +00:00
|
|
|
DEF_TEST(PathOpsTightBoundsIllBehavedScaled, reporter) {
|
|
|
|
SkPath path;
|
|
|
|
path.moveTo(0, 0);
|
|
|
|
path.quadTo(1048578, 1048577, 1048576, 1048576);
|
|
|
|
const SkRect& bounds = path.getBounds();
|
|
|
|
SkRect tight;
|
|
|
|
REPORTER_ASSERT(reporter, TightBounds(path, &tight));
|
|
|
|
REPORTER_ASSERT(reporter, bounds != tight);
|
|
|
|
REPORTER_ASSERT(reporter, tight.right() == 1048576);
|
|
|
|
REPORTER_ASSERT(reporter, tight.bottom() == 1048576);
|
|
|
|
}
|