typedef SkWStream INHERITED;
};
-class SK_API SkMemoryWStream : public SkWStream {
-public:
- SkMemoryWStream(void* buffer, size_t size);
- bool write(const void* buffer, size_t size) override;
- size_t bytesWritten() const override { return fBytesWritten; }
-
-private:
- char* fBuffer;
- size_t fMaxLength;
- size_t fBytesWritten;
-
- typedef SkWStream INHERITED;
-};
-
class SK_API SkDynamicMemoryWStream : public SkWStream {
public:
SkDynamicMemoryWStream();
////////////////////////////////////////////////////////////////////////
-SkMemoryWStream::SkMemoryWStream(void* buffer, size_t size)
- : fBuffer((char*)buffer), fMaxLength(size), fBytesWritten(0)
-{
-}
-
-bool SkMemoryWStream::write(const void* buffer, size_t size) {
- size = SkTMin(size, fMaxLength - fBytesWritten);
- if (size > 0) {
- memcpy(fBuffer + fBytesWritten, buffer, size);
- fBytesWritten += size;
- return true;
- }
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////
-
static inline void sk_memcpy_4bytes(void* dst, const void* src, size_t size) {
if (size == 4) {
memcpy(dst, src, 4);
static int testNumber = 55;
static const char* testName = "pathOpTest";
-static void writeTestName(const char* nameSuffix, SkMemoryWStream& outFile) {
- outFile.writeText(testName);
- outFile.writeDecAsText(testNumber);
+static void writeTestName(const char* nameSuffix, SkString& outFile) {
+ outFile.appendf("%s%d", testName, testNumber);
++testNumber;
if (nameSuffix) {
- outFile.writeText(nameSuffix);
+ outFile.append(nameSuffix);
}
}
static void outputToStream(const char* pathStr, const char* pathPrefix, const char* nameSuffix,
- const char* testFunction, bool twoPaths, SkMemoryWStream& outFile) {
+ const char* testFunction, bool twoPaths, SkString& outFile) {
#if 0
outFile.writeText("\n<div id=\"");
writeTestName(nameSuffix, outFile);
writeTestName(nameSuffix, outFile);
outFile.writeText(",\n\n\n");
#endif
- outFile.writeText("static void ");
+ outFile.append("static void ");
writeTestName(nameSuffix, outFile);
- outFile.writeText("(skiatest::Reporter* reporter) {\n SkPath path");
+ outFile.append("(skiatest::Reporter* reporter) {\n SkPath path");
if (twoPaths) {
- outFile.writeText(", pathB");
+ outFile.append(", pathB");
}
- outFile.writeText(";\n");
+ outFile.append(";\n");
if (pathPrefix) {
- outFile.writeText(pathPrefix);
+ outFile.append(pathPrefix);
}
- outFile.writeText(pathStr);
- outFile.writeText(" ");
- outFile.writeText(testFunction);
- outFile.writeText("\n}\n\n");
+ outFile.appendf("%s %s\n}\n\n", pathStr, testFunction);
#if 0
outFile.writeText("static void (*firstTest)() = ");
writeTestName(nameSuffix, outFile);
writeTestName(nameSuffix, outFile);
outFile.writeText("),\n");
#endif
- outFile.flush();
}
SK_DECLARE_STATIC_MUTEX(simplifyDebugOut);
int result = comparePaths(state.fReporter, nullptr, path, out, *state.fBitmap);
if (result) {
SkAutoMutexAcquire autoM(simplifyDebugOut);
- char temp[8192];
- sk_bzero(temp, sizeof(temp));
- SkMemoryWStream stream(temp, sizeof(temp));
+ SkString str;
const char* pathPrefix = nullptr;
const char* nameSuffix = nullptr;
if (fillType == SkPath::kEvenOdd_FillType) {
nameSuffix = "x";
}
const char testFunction[] = "testSimplify(reporter, path);";
- outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, stream);
- SkDebugf("%s", temp);
+ outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, str);
+ SkDebugf("%s", str.c_str());
REPORTER_ASSERT(state.fReporter, 0);
}
state.fReporter->bumpTestCount();
}
}
-void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType pathFillType) {
+void PathOpsThreadState::outputProgress(const char* pathStr, SkPath::FillType pathFillType) {
const char testFunction[] = "testSimplify(path);";
const char* pathPrefix = nullptr;
const char* nameSuffix = nullptr;
pathPrefix = " path.setFillType(SkPath::kEvenOdd_FillType);\n";
nameSuffix = "x";
}
- SkMemoryWStream rRamStream(ramStr, PATH_STR_SIZE);
- outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, rRamStream);
+ outputToStream(pathStr, pathPrefix, nameSuffix, testFunction, false, fPathStr);
}
-void outputProgress(char* ramStr, const char* pathStr, SkPathOp op) {
+void PathOpsThreadState::outputProgress(const char* pathStr, SkPathOp op) {
const char testFunction[] = "testOp(path);";
SkASSERT((size_t) op < SK_ARRAY_COUNT(opSuffixes));
const char* nameSuffix = opSuffixes[op];
- SkMemoryWStream rRamStream(ramStr, PATH_STR_SIZE);
- outputToStream(pathStr, nullptr, nameSuffix, testFunction, true, rRamStream);
+ outputToStream(pathStr, nullptr, nameSuffix, testFunction, true, fPathStr);
}
void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count,
const char* filename);
void initializeTests(skiatest::Reporter* reporter, const char* testName);
-void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType );
-void outputProgress(char* ramStr, const char* pathStr, SkPathOp op);
void RunTestSet(skiatest::Reporter* reporter, TestDesc tests[], size_t count,
void (*firstTest)(skiatest::Reporter* , const char* filename),
pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
SkPathOpsDebug::OpStr((SkPathOp) op));
pathStr.appendf("}\n");
- outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op);
+ state.outputProgress(pathStr.c_str(), (SkPathOp) op);
}
if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "circles")) {
if (state.fReporter->verbose()) {
pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
SkPathOpsDebug::OpStr((SkPathOp) op));
pathStr.appendf("}\n");
- outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op);
+ state.outputProgress(pathStr.c_str(), (SkPathOp) op);
}
if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "cubics")) {
if (state.fReporter->verbose()) {
pathStr.appendf(" testPathOp(reporter, path, pathB, kIntersect_SkPathOp,"
" filename);\n");
pathStr.appendf("}\n");
- outputProgress(state.fPathStr, pathStr.c_str(), kIntersect_SkPathOp);
+ state.outputProgress(pathStr.c_str(), kIntersect_SkPathOp);
}
testPathOp(state.fReporter, pathA, pathB, kIntersect_SkPathOp, "loops");
}
pathStr.appendf(" testPathOp(reporter, path, pathB, %s, filename);\n",
SkPathOpsDebug::OpStr((SkPathOp) op));
pathStr.appendf("}\n\n");
- outputProgress(state.fPathStr, pathStr.c_str(), (SkPathOp) op);
+ state.outputProgress(pathStr.c_str(), (SkPathOp) op);
}
if (!testPathOp(state.fReporter, pathA, pathB, (SkPathOp) op, "rects")) {
if (state.fReporter->verbose()) {
pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
pathStr.appendf(" path.close();\n");
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
}
testSimplify(path, false, out, state, pathStr.c_str());
path.setFillType(SkPath::kEvenOdd_FillType);
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
}
testSimplify(path, true, out, state, pathStr.c_str());
}
pathStr.appendf(" path.close();\n");
pathStr.appendf(" testSimplify(reporter, path, filename);\n");
pathStr.appendf("}\n");
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
}
testSimplify(path, false, out, state, pathStr.c_str());
path.setFillType(SkPath::kEvenOdd_FillType);
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
}
testSimplify(path, true, out, state, pathStr.c_str());
}
pathStr.appendf(" path.close();\n");
pathStr.appendf(" testPathSimplify(reporter, path, filename);\n");
pathStr.appendf("}\n");
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
}
testSimplify(path, false, out, state, pathStr.c_str());
path.setFillType(SkPath::kEvenOdd_FillType);
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
}
testSimplify(path, true, out, state, pathStr.c_str());
}
}
path.close();
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
}
testSimplify(path, false, out, state, pathStr.c_str());
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
}
testSimplify(path, true, out, state, pathStr.c_str());
}
pathStr.appendf(" path.lineTo(%d, %d);\n", ex, ey);
pathStr.appendf(" path.lineTo(%d, %d);\n", fx, fy);
pathStr.appendf(" path.close();\n");
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kWinding_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kWinding_FillType);
}
ShowTestName(&state, d, e, f, 0);
testSimplify(path, false, out, state, pathStr.c_str());
path.setFillType(SkPath::kEvenOdd_FillType);
if (state.fReporter->verbose()) {
- outputProgress(state.fPathStr, pathStr.c_str(), SkPath::kEvenOdd_FillType);
+ state.outputProgress(pathStr.c_str(), SkPath::kEvenOdd_FillType);
}
ShowTestName(&state, d, e, f, 1);
testSimplify(path, true, out, state, pathStr.c_str());
#define PathOpsThreadedCommon_DEFINED
#include "SkGraphics.h"
+#include "SkPath.h"
+#include "SkString.h"
#include "SkTDArray.h"
#define PATH_STR_SIZE 512
unsigned char fB;
unsigned char fC;
unsigned char fD;
- char* fPathStr;
+ SkString fPathStr;
const char* fKey;
char fSerialNo[256];
skiatest::Reporter* fReporter;
SkBitmap* fBitmap;
+
+ void outputProgress(const char* pathStr, SkPath::FillType);
+ void outputProgress(const char* pathStr, SkPathOp);
};
class PathOpsThreadedTestRunner {
size_t i;
- char buffer[sizeof(sizes) * 4];
+ SkDynamicMemoryWStream wstream;
- SkMemoryWStream wstream(buffer, sizeof(buffer));
for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) {
bool success = wstream.writePackedUInt(sizes[i]);
REPORTER_ASSERT(reporter, success);
}
- wstream.flush();
- SkMemoryStream rstream(buffer, sizeof(buffer));
+ std::unique_ptr<SkStreamAsset> rstream(wstream.detachAsStream());
for (i = 0; i < SK_ARRAY_COUNT(sizes); ++i) {
- size_t n = rstream.readPackedUInt();
+ size_t n = rstream->readPackedUInt();
if (sizes[i] != n) {
ERRORF(reporter, "sizes:%x != n:%x\n", i, sizes[i], n);
}