remove SkMemoryWStream -- unused externally
authorMike Reed <reed@google.com>
Sat, 7 Jan 2017 16:16:28 +0000 (11:16 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Sun, 8 Jan 2017 03:06:06 +0000 (03:06 +0000)
BUG=skia:

Change-Id: Idbc9af4e703238871f56f623cd616fb7a5e686d3
Reviewed-on: https://skia-review.googlesource.com/6727
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Mike Reed <reed@google.com>

15 files changed:
include/core/SkStream.h
src/core/SkStream.cpp
tests/PathOpsExtendedTest.cpp
tests/PathOpsExtendedTest.h
tests/PathOpsOpCircleThreadedTest.cpp
tests/PathOpsOpCubicThreadedTest.cpp
tests/PathOpsOpLoopThreadedTest.cpp
tests/PathOpsOpRectThreadedTest.cpp
tests/PathOpsSimplifyDegenerateThreadedTest.cpp
tests/PathOpsSimplifyQuadThreadedTest.cpp
tests/PathOpsSimplifyQuadralateralsThreadedTest.cpp
tests/PathOpsSimplifyRectThreadedTest.cpp
tests/PathOpsSimplifyTrianglesThreadedTest.cpp
tests/PathOpsThreadedCommon.h
tests/StreamTest.cpp

index f3c99b7..419ef7b 100644 (file)
@@ -366,20 +366,6 @@ private:
     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();
index 202762a..db9caee 100644 (file)
@@ -431,23 +431,6 @@ void SkFILEWStream::fsync()
 
 ////////////////////////////////////////////////////////////////////////
 
-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);
index 9b08ba9..abc1770 100644 (file)
@@ -370,17 +370,16 @@ static int comparePaths(skiatest::Reporter* reporter, const char* testName, cons
 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);
@@ -396,20 +395,17 @@ static void outputToStream(const char* pathStr, const char* pathPrefix, const ch
     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);
@@ -423,7 +419,6 @@ static void outputToStream(const char* pathStr, const char* pathPrefix, const ch
     writeTestName(nameSuffix, outFile);
     outFile.writeText("),\n");
 #endif
-    outFile.flush();
 }
 
 SK_DECLARE_STATIC_MUTEX(simplifyDebugOut);
@@ -444,9 +439,7 @@ bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& st
     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) {
@@ -454,8 +447,8 @@ bool testSimplify(SkPath& path, bool useXor, SkPath& out, PathOpsThreadState& st
             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();
@@ -633,7 +626,7 @@ void initializeTests(skiatest::Reporter* reporter, const char* test) {
     }
 }
 
-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;
@@ -641,16 +634,14 @@ void outputProgress(char* ramStr, const char* pathStr, SkPath::FillType pathFill
         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,
index 35c14e7..9f8b0ae 100644 (file)
@@ -49,8 +49,6 @@ extern bool testSimplifyFuzz(skiatest::Reporter* reporter, const SkPath& path,
                                        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),
index 40a02c1..7711dd0 100644 (file)
@@ -45,7 +45,7 @@ static void testOpCirclesMain(PathOpsThreadState* data) {
                 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()) {
index e76eb06..0bb8c19 100644 (file)
@@ -56,7 +56,7 @@ static void testOpCubicsMain(PathOpsThreadState* data) {
                 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()) {
index 3854f90..04caac9 100644 (file)
@@ -76,7 +76,7 @@ static void testOpLoopsMain(PathOpsThreadState* data) {
             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");
                 }
index 5761572..e904a8d 100644 (file)
@@ -64,7 +64,7 @@ static void testPathOpsRectsMain(PathOpsThreadState* data)
                 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()) {
index 71933df..3f49718 100644 (file)
@@ -50,12 +50,12 @@ static void testSimplifyDegeneratesMain(PathOpsThreadState* data) {
                     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());
             }
index bca8d5a..55dc07b 100644 (file)
@@ -61,12 +61,12 @@ static void testSimplifyQuadsMain(PathOpsThreadState* data)
                         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());
                 }
index 1ea55e2..6133042 100644 (file)
@@ -63,12 +63,12 @@ static void testSimplifyQuadralateralsMain(PathOpsThreadState* data)
                         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());
                 }
index 4ddc6f7..384d1b0 100644 (file)
@@ -166,11 +166,11 @@ static void testSimplify4x4RectsMain(PathOpsThreadState* data)
         }
         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());
     }
index 671616c..372b667 100644 (file)
@@ -53,13 +53,13 @@ static void testSimplifyTrianglesMain(PathOpsThreadState* data) {
                     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());
index 54586d9..8fe573f 100644 (file)
@@ -8,6 +8,8 @@
 #define PathOpsThreadedCommon_DEFINED
 
 #include "SkGraphics.h"
+#include "SkPath.h"
+#include "SkString.h"
 #include "SkTDArray.h"
 
 #define PATH_STR_SIZE 512
@@ -23,11 +25,14 @@ struct PathOpsThreadState {
     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 {
index 4b8923f..4c1b3df 100644 (file)
@@ -146,18 +146,16 @@ static void TestPackedUInt(skiatest::Reporter* reporter) {
 
 
     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);
         }