2013-04-08 11:50:46 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkString.h"
|
|
|
|
#include "src/pathops/SkIntersections.h"
|
|
|
|
#include "src/pathops/SkPathOpsLine.h"
|
|
|
|
#include "src/pathops/SkPathOpsQuad.h"
|
|
|
|
#include "src/pathops/SkReduceOrder.h"
|
|
|
|
#include "tests/PathOpsExtendedTest.h"
|
|
|
|
#include "tests/PathOpsTestCommon.h"
|
|
|
|
#include "tests/PathOpsThreadedCommon.h"
|
2013-04-08 11:50:46 +00:00
|
|
|
|
2018-06-18 19:11:00 +00:00
|
|
|
#include <utility>
|
|
|
|
|
2013-04-08 11:50:46 +00:00
|
|
|
static int doIntersect(SkIntersections& intersections, const SkDQuad& quad, const SkDLine& line,
|
|
|
|
bool& flipped) {
|
|
|
|
int result;
|
|
|
|
flipped = false;
|
|
|
|
if (line[0].fX == line[1].fX) {
|
|
|
|
double top = line[0].fY;
|
|
|
|
double bottom = line[1].fY;
|
|
|
|
flipped = top > bottom;
|
|
|
|
if (flipped) {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
|
|
|
swap(top, bottom);
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
|
|
|
result = intersections.vertical(quad, top, bottom, line[0].fX, flipped);
|
|
|
|
} else if (line[0].fY == line[1].fY) {
|
|
|
|
double left = line[0].fX;
|
|
|
|
double right = line[1].fX;
|
|
|
|
flipped = left > right;
|
|
|
|
if (flipped) {
|
2018-06-18 19:11:00 +00:00
|
|
|
using std::swap;
|
|
|
|
swap(left, right);
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
|
|
|
result = intersections.horizontal(quad, left, right, line[0].fY, flipped);
|
|
|
|
} else {
|
|
|
|
intersections.intersect(quad, line);
|
|
|
|
result = intersections.used();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void testLineIntersect(skiatest::Reporter* reporter, const SkDQuad& quad,
|
|
|
|
const SkDLine& line, const double x, const double y) {
|
2016-10-06 18:46:25 +00:00
|
|
|
SkString pathStr;
|
|
|
|
pathStr.appendf(" path.moveTo(%1.9g, %1.9g);\n", quad[0].fX, quad[0].fY);
|
|
|
|
pathStr.appendf(" path.quadTo(%1.9g, %1.9g, %1.9g, %1.9g);\n", quad[1].fX,
|
2013-04-10 15:55:37 +00:00
|
|
|
quad[1].fY, quad[2].fX, quad[2].fY);
|
2016-10-06 18:46:25 +00:00
|
|
|
pathStr.appendf(" path.moveTo(%1.9g, %1.9g);\n", line[0].fX, line[0].fY);
|
|
|
|
pathStr.appendf(" path.lineTo(%1.9g, %1.9g);\n", line[1].fX, line[1].fY);
|
2013-04-08 11:50:46 +00:00
|
|
|
|
|
|
|
SkIntersections intersections;
|
|
|
|
bool flipped = false;
|
|
|
|
int result = doIntersect(intersections, quad, line, flipped);
|
|
|
|
bool found = false;
|
|
|
|
for (int index = 0; index < result; ++index) {
|
|
|
|
double quadT = intersections[0][index];
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint quadXY = quad.ptAtT(quadT);
|
2013-04-08 11:50:46 +00:00
|
|
|
double lineT = intersections[1][index];
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint lineXY = line.ptAtT(lineT);
|
2013-04-08 11:50:46 +00:00
|
|
|
if (quadXY.approximatelyEqual(lineXY)) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
REPORTER_ASSERT(reporter, found);
|
|
|
|
}
|
|
|
|
|
|
|
|
// find a point on a quad by choosing a t from 0 to 1
|
|
|
|
// create a vertical span above and below the point
|
|
|
|
// verify that intersecting the vertical span and the quad returns t
|
|
|
|
// verify that a vertical span starting at quad[0] intersects at t=0
|
|
|
|
// verify that a vertical span starting at quad[2] intersects at t=1
|
2013-04-10 15:55:37 +00:00
|
|
|
static void testQuadLineIntersectMain(PathOpsThreadState* data)
|
2013-04-08 11:50:46 +00:00
|
|
|
{
|
2013-04-10 15:55:37 +00:00
|
|
|
PathOpsThreadState& state = *data;
|
|
|
|
REPORTER_ASSERT(state.fReporter, data);
|
|
|
|
int ax = state.fA & 0x03;
|
|
|
|
int ay = state.fA >> 2;
|
|
|
|
int bx = state.fB & 0x03;
|
|
|
|
int by = state.fB >> 2;
|
|
|
|
int cx = state.fC & 0x03;
|
|
|
|
int cy = state.fC >> 2;
|
2016-10-20 15:32:18 +00:00
|
|
|
QuadPts q = {{{(double) ax, (double) ay}, {(double) bx, (double) by},
|
2013-04-11 12:33:23 +00:00
|
|
|
{(double) cx, (double) cy}}};
|
2016-10-20 15:32:18 +00:00
|
|
|
SkDQuad quad;
|
|
|
|
quad.debugSet(q.fPts);
|
2013-04-10 15:55:37 +00:00
|
|
|
SkReduceOrder reducer;
|
2013-11-25 14:18:21 +00:00
|
|
|
int order = reducer.reduce(quad);
|
2013-04-10 15:55:37 +00:00
|
|
|
if (order < 3) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (int tIndex = 0; tIndex <= 4; ++tIndex) {
|
2013-07-23 15:27:41 +00:00
|
|
|
SkDPoint xy = quad.ptAtT(tIndex / 4.0);
|
2013-04-10 15:55:37 +00:00
|
|
|
for (int h = -2; h <= 2; ++h) {
|
|
|
|
for (int v = -2; v <= 2; ++v) {
|
2015-08-26 12:15:46 +00:00
|
|
|
if (h == v && SkTAbs(h) != 1) {
|
2013-04-10 15:55:37 +00:00
|
|
|
continue;
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
2013-04-10 15:55:37 +00:00
|
|
|
double x = xy.fX;
|
|
|
|
double y = xy.fY;
|
|
|
|
SkDLine line = {{{x - h, y - v}, {x, y}}};
|
|
|
|
testLineIntersect(state.fReporter, quad, line, x, y);
|
|
|
|
state.fReporter->bumpTestCount();
|
|
|
|
SkDLine line2 = {{{x, y}, {x + h, y + v}}};
|
|
|
|
testLineIntersect(state.fReporter, quad, line2, x, y);
|
|
|
|
state.fReporter->bumpTestCount();
|
|
|
|
SkDLine line3 = {{{x - h, y - v}, {x + h, y + v}}};
|
|
|
|
testLineIntersect(state.fReporter, quad, line3, x, y);
|
|
|
|
state.fReporter->bumpTestCount();
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
|
|
|
}
|
2013-04-10 15:55:37 +00:00
|
|
|
}
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
|
|
|
|
2014-01-02 21:45:03 +00:00
|
|
|
DEF_TEST(PathOpsQuadLineIntersectionThreaded, 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, "testQuadLineIntersect");
|
|
|
|
PathOpsThreadedTestRunner testRunner(reporter);
|
2013-04-08 11:50:46 +00:00
|
|
|
for (int a = 0; a < 16; ++a) {
|
|
|
|
for (int b = 0 ; b < 16; ++b) {
|
|
|
|
for (int c = 0 ; c < 16; ++c) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*testRunner.fRunnables.append() = new PathOpsThreadedRunnable(
|
|
|
|
&testQuadLineIntersectMain, a, b, c, 0, &testRunner);
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
2013-04-10 15:55:37 +00:00
|
|
|
if (!reporter->allowExtendedTest()) goto finish;
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
finish:
|
2013-04-10 15:55:37 +00:00
|
|
|
testRunner.render();
|
2013-04-08 11:50:46 +00:00
|
|
|
}
|