Make the GM tool run GMs through an SkGPipe.
authorscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 4 Jun 2012 17:17:36 +0000 (17:17 +0000)
committerscroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>
Mon, 4 Jun 2012 17:17:36 +0000 (17:17 +0000)
Add pipe to core gyp project.

Do not run samplerstress through the pipe, since its
custom MaskFilter will not draw correctly.

Fix an assert in SkGPipeWrite when writing a typeface.
Review URL: https://codereview.appspot.com/6276044

git-svn-id: http://skia.googlecode.com/svn/trunk@4139 2bbb7eff-a529-9590-31e7-b0007b416f81

gm/gm.h
gm/gmmain.cpp
gm/samplerstress.cpp
gyp/SampleApp.gyp
gyp/core.gyp
gyp/gm.gyp
src/pipe/SkGPipeWrite.cpp

diff --git a/gm/gm.h b/gm/gm.h
index 97b21d97b817ae04db3e2b62f31316dbd6c7819a..4072f102956143a3208cef8d4692c44ab06d89b3 100644 (file)
--- a/gm/gm.h
+++ b/gm/gm.h
@@ -31,7 +31,8 @@ namespace skiagm {
                 
         enum Flags {
             kSkipPDF_Flag       = 1 << 0,
-            kSkipPicture_Flag   = 1 << 1
+            kSkipPicture_Flag   = 1 << 1,
+            kSkipPipe_Flag      = 1 << 2
         };
 
         void draw(SkCanvas*);
index 61a085938d7c3f9abc35d278cad9d60d5eb413b4..760262cb406b82662bb58b5da7b7f1c0f577aabf 100644 (file)
@@ -13,6 +13,7 @@
 #include "SkData.h"
 #include "SkDeferredCanvas.h"
 #include "SkDevice.h"
+#include "SkGPipe.h"
 #include "SkGpuCanvas.h"
 #include "SkGpuDevice.h"
 #include "SkGraphics.h"
@@ -615,6 +616,67 @@ static ErrorBitfield test_picture_serialization(GM* gm,
     }
 }
 
+class PipeController : public SkGPipeController {
+public:
+    PipeController(SkCanvas* target);
+    ~PipeController();
+    virtual void* requestBlock(size_t minRequest, size_t* actual);
+    virtual void notifyWritten(size_t bytes);
+private:
+    SkGPipeReader fReader;
+    void* fBlock;
+    size_t fBlockSize;
+    size_t fBytesWritten;
+    SkGPipeReader::Status fStatus;
+};
+
+PipeController::PipeController(SkCanvas* target)
+:fReader(target) {
+    fBlock = NULL;
+    fBlockSize = fBytesWritten = 0;
+}
+
+PipeController::~PipeController() {
+    sk_free(fBlock);
+}
+
+void* PipeController::requestBlock(size_t minRequest, size_t *actual) {
+    sk_free(fBlock);
+    fBlockSize = minRequest * 4;
+    fBlock = sk_malloc_throw(fBlockSize);
+    fBytesWritten = 0;
+    *actual = fBlockSize;
+    return fBlock;
+}
+
+void PipeController::notifyWritten(size_t bytes) {
+    fStatus = fReader.playback((const char*)fBlock + fBytesWritten, bytes);
+    SkASSERT(SkGPipeReader::kError_Status != fStatus);
+    fBytesWritten += bytes;
+}
+
+static ErrorBitfield test_pipe_playback(GM* gm,
+                                        const ConfigData& gRec,
+                                        const SkBitmap& comparisonBitmap,
+                                        const char readPath [],
+                                        const char diffPath []) {
+    if (kRaster_Backend != gRec.fBackend) {
+        return ERROR_NONE;
+    }
+    SkBitmap bitmap;
+    SkISize size = gm->getISize();
+    setup_bitmap(gRec, size, &bitmap);
+    SkCanvas canvas(bitmap);
+    PipeController pipeController(&canvas);
+    SkGPipeWriter writer;
+    SkCanvas* pipeCanvas = writer.startRecording(&pipeController,
+            SkGPipeWriter::kCrossProcess_Flag);
+    invokeGM(gm, pipeCanvas);
+    writer.endRecording();
+    return handle_test_results(gm, gRec, NULL, NULL, diffPath,
+                               "-pipe", bitmap, NULL, &comparisonBitmap);
+}
+
 static void write_picture_serialization(GM* gm, const ConfigData& rec,
                                         const char writePicturePath[]) {
     // only do this once, so we pick raster
@@ -635,7 +697,7 @@ static void write_picture_serialization(GM* gm, const ConfigData& rec,
 static void usage(const char * argv0) {
     SkDebugf(
         "%s [-w writePath] [-r readPath] [-d diffPath] [-i resourcePath]\n"
-        "    [--noreplay] [--serialize] [--forceBWtext] [--nopdf] \n"
+        "    [--noreplay] [--nopipe] [--serialize] [--forceBWtext] [--nopdf] \n"
         "    [--nodeferred] [--match substring] [--notexturecache]\n"
         , argv0);
     SkDebugf("    writePath: directory to write rendered images in.\n");
@@ -645,6 +707,7 @@ static void usage(const char * argv0) {
     SkDebugf("    diffPath: directory to write difference images in.\n");
     SkDebugf("    resourcePath: directory that stores image resources.\n");
     SkDebugf("    --noreplay: do not exercise SkPicture replay.\n");
+    SkDebugf("    --nopipe: Skip SkGPipe replay.\n");
     SkDebugf(
 "    --serialize: exercise SkPicture serialization & deserialization.\n");
     SkDebugf("    --forceBWtext: disable text anti-aliasing.\n");
@@ -755,6 +818,7 @@ int main(int argc, char * const argv[]) {
 
     bool doPDF = true;
     bool doReplay = true;
+    bool doPipe = true;
     bool doSerialize = false;
     bool useDebugGL = false;
     bool doDeferred = true;
@@ -792,6 +856,8 @@ int main(int argc, char * const argv[]) {
             }
         } else if (strcmp(*argv, "--forceBWtext") == 0) {
             gForceBWtext = true;
+        } else if (strcmp(*argv, "--nopipe") == 0) {
+            doPipe = false;
         } else if (strcmp(*argv, "--noreplay") == 0) {
             doReplay = false;
         } else if (strcmp(*argv, "--nopdf") == 0) {
@@ -931,6 +997,13 @@ int main(int argc, char * const argv[]) {
                                                     readPath, diffPath);
             }
 
+            if ((ERROR_NONE == testErrors) && doPipe &&
+                !(gmFlags & GM::kSkipPipe_Flag)) {
+                testErrors |= test_pipe_playback(gm, gRec[i],
+                                                 forwardRenderedBitmap,
+                                                 readPath, diffPath);
+            }
+
             if ((ERROR_NONE == testErrors) && doSerialize  &&
                 !(gmFlags & GM::kSkipPicture_Flag)) {
                 testErrors |= test_picture_serialization(gm, gRec[i],
index 687c6363dd2e8774bc5d9634610e94ddb2bb2c40..b5c006902ac862128b1788bb9d3b9d4a98ead92f 100644 (file)
@@ -105,6 +105,12 @@ protected:
         return make_isize(640, 480);
     }
 
+    virtual uint32_t onGetFlags() const SK_OVERRIDE {
+        // Skip Pipe playback since we use a custom MaskFilter that will not be
+        // flattened correctly
+        return this->INHERITED::onGetFlags() | GM::kSkipPipe_Flag;
+    }
+
     /**
      * Create a red & green stripes on black texture
      */
index 0c370ab0ce740028634a6399ab916090f7ed8e2e..c426508ebc3f0912aaf8d1ddb39576452458dbfa 100644 (file)
@@ -8,7 +8,6 @@
       'include_dirs' : [
         '../src/core', # needed to get SkConcaveToTriangle, maybe this should be moved to include dir?
         '../gm',       # needed to pull gm.h
-        '../include/pipe', # To pull in SkGPipe.h for pipe reader/writer
         '../samplecode', # To pull SampleApp.h and SampleCode.h
         '../src/gpu', # To pull gl/GrGLUtil.h
       ],
         '../samplecode/SampleXfermodes.cpp',
         '../samplecode/SampleXfermodesBlur.cpp',
         '../samplecode/TransitionView.cpp',
-        
-        # Dependencies for the pipe code in SampleApp
-        '../src/pipe/SkGPipeRead.cpp',
-        '../src/pipe/SkGPipeWrite.cpp',
-        
+     
         # DrawingBoard
         #'../experimental/DrawingBoard/SkColorPalette.h',
         #'../experimental/DrawingBoard/SkColorPalette.cpp',
index 6d5cd13113f8b62ac6ba9f8fad1d6d77e44e1f8c..aea2a739f256494e62c970d1083fd1649cfd01d0 100644 (file)
         '../src/core/SkUtils.cpp',
         '../src/core/SkWriter32.cpp',
         '../src/core/SkXfermode.cpp',
+        '../src/pipe/SkGPipeRead.cpp',
+        '../src/pipe/SkGPipeWrite.cpp',
 
         '../include/core/Sk64.h',
         '../include/core/SkAdvancedTypefaceMetrics.h',
       'include_dirs': [
         '../include/config',
         '../include/core',
+        '../include/pipe',
         '../include/ports',
         '../include/xml',
         '../src/core',
           'config',
           '../include/config',
           '../include/core',
+          '../include/pipe',
           'ext',
         ],
       },
index b33313010f7a1f8ec8bd03ef5fdd245f2f3192bc..980c199bdc0841eea7e03b707f2f75d3eda8ed8e 100644 (file)
@@ -24,8 +24,8 @@
         'gpu.gyp:gr',
         'gpu.gyp:skgr',
         'images.gyp:images',
-        'ports.gyp:ports',
         'pdf.gyp:pdf',
+        'ports.gyp:ports',
         'utils.gyp:utils',        
       ],
       'conditions': [
index 08c6f49a399f213c1dfa50885b9d3f8bd82f2661..5d359889a2702f242f3d69235faebfb364c0f169 100644 (file)
@@ -67,9 +67,9 @@ static size_t writeTypeface(SkWriter32* writer, SkTypeface* typeface) {
     if (writer) {
         writer->write32(size);
         SkAutoDataUnref data(stream.copyToData());
-        writer->write(data.data(), size);
+        writer->writePad(data.data(), size);
     }
-    return 4 + size;
+    return 4 + SkAlign4(size);
 }
 
 ///////////////////////////////////////////////////////////////////////////////