2014-04-25 12:59:11 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
2018-08-08 13:48:09 +00:00
|
|
|
#include "PathOpsDebug.h"
|
2014-04-25 12:59:11 +00:00
|
|
|
#include "PathOpsExtendedTest.h"
|
|
|
|
#include "PathOpsThreadedCommon.h"
|
2016-10-06 18:46:25 +00:00
|
|
|
#include "SkString.h"
|
2018-08-09 03:22:37 +00:00
|
|
|
#include <atomic>
|
2014-04-25 12:59:11 +00:00
|
|
|
|
2016-10-06 18:46:25 +00:00
|
|
|
static int loopNo = 17;
|
|
|
|
|
|
|
|
static void add_point(SkString* str, SkScalar x, SkScalar y) {
|
2015-03-26 14:52:43 +00:00
|
|
|
int asInt = SkScalarRoundToInt(x);
|
|
|
|
if (SkIntToScalar(asInt) == x) {
|
2016-10-06 18:46:25 +00:00
|
|
|
str->appendf("%d", asInt);
|
2015-03-26 14:52:43 +00:00
|
|
|
} else {
|
2016-10-06 18:46:25 +00:00
|
|
|
str->appendf("%1.9gf", x);
|
2015-03-26 14:52:43 +00:00
|
|
|
}
|
2016-10-06 18:46:25 +00:00
|
|
|
str->appendf(",");
|
2015-03-26 14:52:43 +00:00
|
|
|
asInt = SkScalarRoundToInt(y);
|
|
|
|
if (SkIntToScalar(asInt) == y) {
|
2016-10-06 18:46:25 +00:00
|
|
|
str->appendf("%d", asInt);
|
2015-03-26 14:52:43 +00:00
|
|
|
} else {
|
2016-10-06 18:46:25 +00:00
|
|
|
str->appendf("%1.9gf", y);
|
2015-03-26 14:52:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-09 03:22:37 +00:00
|
|
|
static std::atomic<int> gLoopsTestNo{0};
|
2018-08-08 13:48:09 +00:00
|
|
|
|
2014-04-25 12:59:11 +00:00
|
|
|
static void testOpLoopsMain(PathOpsThreadState* data) {
|
|
|
|
#if DEBUG_SHOW_TEST_NAME
|
|
|
|
strncpy(DEBUG_FILENAME_STRING, "", DEBUG_FILENAME_STRING_LENGTH);
|
|
|
|
#endif
|
|
|
|
SkASSERT(data);
|
|
|
|
PathOpsThreadState& state = *data;
|
2016-10-06 18:46:25 +00:00
|
|
|
SkString pathStr;
|
2014-04-25 12:59:11 +00:00
|
|
|
for (int a = 0 ; a < 6; ++a) {
|
|
|
|
for (int b = a + 1 ; b < 7; ++b) {
|
|
|
|
for (int c = 0 ; c < 6; ++c) {
|
|
|
|
for (int d = c + 1 ; d < 7; ++d) {
|
|
|
|
// define 4 points that form two lines that often cross; one line is (a, b) (c, d)
|
|
|
|
SkVector v = {SkIntToScalar(a - c), SkIntToScalar(b - d)};
|
|
|
|
SkPoint midA = { SkIntToScalar(a * state.fA + c * (6 - state.fA)) / 6,
|
|
|
|
SkIntToScalar(b * state.fA + d * (6 - state.fA)) / 6 };
|
|
|
|
SkPoint midB = { SkIntToScalar(a * state.fB + c * (6 - state.fB)) / 6,
|
|
|
|
SkIntToScalar(b * state.fB + d * (6 - state.fB)) / 6 };
|
|
|
|
SkPoint endC = { midA.fX + v.fY * state.fC / 3,
|
|
|
|
midA.fY + v.fX * state.fC / 3 };
|
|
|
|
SkPoint endD = { midB.fX - v.fY * state.fD / 3,
|
|
|
|
midB.fY + v.fX * state.fD / 3 };
|
|
|
|
SkPath pathA, pathB;
|
|
|
|
pathA.moveTo(SkIntToScalar(a), SkIntToScalar(b));
|
|
|
|
pathA.cubicTo(SkIntToScalar(c), SkIntToScalar(d), endC.fX, endC.fY, endD.fX, endD.fY);
|
|
|
|
pathA.close();
|
|
|
|
pathB.moveTo(SkIntToScalar(c), SkIntToScalar(d));
|
|
|
|
pathB.cubicTo(endC.fX, endC.fY, endD.fX, endD.fY, SkIntToScalar(a), SkIntToScalar(b));
|
|
|
|
pathB.close();
|
|
|
|
// SkDebugf("%s\n", pathStr);
|
2016-10-06 18:46:25 +00:00
|
|
|
if (state.fReporter->verbose()) {
|
|
|
|
pathStr.printf("static void loop%d(skiatest::Reporter* reporter,"
|
|
|
|
" const char* filename) {\n", loopNo);
|
|
|
|
pathStr.appendf(" SkPath path, pathB;\n");
|
|
|
|
pathStr.appendf(" path.moveTo(%d,%d);\n", a, b);
|
|
|
|
pathStr.appendf(" path.cubicTo(%d,%d, ", c, d);
|
|
|
|
add_point(&pathStr, endC.fX, endC.fY);
|
|
|
|
pathStr.appendf(", ");
|
|
|
|
add_point(&pathStr, endD.fX, endD.fY);
|
|
|
|
pathStr.appendf(");\n");
|
|
|
|
pathStr.appendf(" path.close();\n");
|
|
|
|
pathStr.appendf(" pathB.moveTo(%d,%d);\n", c, d);
|
|
|
|
pathStr.appendf(" pathB.cubicTo(");
|
|
|
|
add_point(&pathStr, endC.fX, endC.fY);
|
|
|
|
pathStr.appendf(", ");
|
|
|
|
add_point(&pathStr, endD.fX, endD.fY);
|
|
|
|
pathStr.appendf(", %d,%d);\n", a, b);
|
|
|
|
pathStr.appendf(" pathB.close();\n");
|
|
|
|
pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
|
|
|
|
" filename);\n");
|
|
|
|
pathStr.appendf("}\n");
|
2017-01-07 16:16:28 +00:00
|
|
|
state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
|
2014-04-25 12:59:11 +00:00
|
|
|
}
|
2018-08-08 13:48:09 +00:00
|
|
|
SkString testName;
|
|
|
|
testName.printf("thread_loops%d", ++gLoopsTestNo);
|
|
|
|
testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, testName.c_str());
|
|
|
|
if (PathOpsDebug::gCheckForDuplicateNames) return;
|
2014-04-25 12:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_TEST(PathOpsOpLoopsThreaded, reporter) {
|
2015-04-20 15:31:59 +00:00
|
|
|
initializeTests(reporter, "loopOp");
|
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
|
|
|
PathOpsThreadedTestRunner testRunner(reporter);
|
2014-04-25 12:59:11 +00:00
|
|
|
for (int a = 0; a < 6; ++a) { // outermost
|
|
|
|
for (int b = a + 1; b < 7; ++b) {
|
|
|
|
for (int c = 0 ; c < 6; ++c) {
|
|
|
|
for (int d = c + 1; d < 7; ++d) {
|
2015-08-26 20:07:48 +00:00
|
|
|
*testRunner.fRunnables.append() =
|
|
|
|
new PathOpsThreadedRunnable(&testOpLoopsMain, a, b, c, d, &testRunner);
|
2014-04-25 12:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!reporter->allowExtendedTest()) goto finish;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
finish:
|
|
|
|
testRunner.render();
|
|
|
|
}
|