diff options
-rw-r--r-- | include/core/SkCanvas.h | 8 | ||||
-rw-r--r-- | include/utils/SkDumpCanvas.h | 4 | ||||
-rw-r--r-- | include/utils/SkProxyCanvas.h | 3 | ||||
-rw-r--r-- | samplecode/SamplePicture.cpp | 14 | ||||
-rw-r--r-- | src/core/SkCanvas.cpp | 4 | ||||
-rw-r--r-- | src/core/SkPictureFlat.h | 1 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 5 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 6 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 1 | ||||
-rw-r--r-- | src/utils/SkDumpCanvas.cpp | 6 | ||||
-rw-r--r-- | src/utils/SkProxyCanvas.cpp | 4 |
11 files changed, 53 insertions, 3 deletions
diff --git a/include/core/SkCanvas.h b/include/core/SkCanvas.h index 8fba6cf49d..40b5c56171 100644 --- a/include/core/SkCanvas.h +++ b/include/core/SkCanvas.h @@ -626,6 +626,14 @@ public: const uint16_t indices[], int indexCount, const SkPaint& paint); + /** Send a blob of data to the canvas. + For canvases that draw, this call is effectively a no-op, as the data + is not parsed, but just ignored. However, this call exists for + subclasses like SkPicture's recording canvas, that can store the data + and then play it back later (via another call to drawData). + */ + virtual void drawData(const void* data, size_t length); + ////////////////////////////////////////////////////////////////////////// /** Get the current bounder object. diff --git a/include/utils/SkDumpCanvas.h b/include/utils/SkDumpCanvas.h index 6f16c92faf..3731bef822 100644 --- a/include/utils/SkDumpCanvas.h +++ b/include/utils/SkDumpCanvas.h @@ -34,7 +34,8 @@ public: kDrawText_Verb, kDrawPicture_Verb, kDrawShape_Verb, - kDrawVertices_Verb + kDrawVertices_Verb, + kDrawData_Verb }; /** Subclasses of this are installed on the DumpCanvas, and then called for @@ -102,6 +103,7 @@ public: const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint); + virtual void drawData(const void*, size_t); private: Dumper* fDumper; diff --git a/include/utils/SkProxyCanvas.h b/include/utils/SkProxyCanvas.h index f2e57abf84..082e0fdee8 100644 --- a/include/utils/SkProxyCanvas.h +++ b/include/utils/SkProxyCanvas.h @@ -75,7 +75,8 @@ public: const SkColor colors[], SkXfermode* xmode, const uint16_t indices[], int indexCount, const SkPaint& paint); - + virtual void drawData(const void* data, size_t length); + virtual SkBounder* setBounder(SkBounder* bounder); virtual SkDrawFilter* setDrawFilter(SkDrawFilter* filter); diff --git a/samplecode/SamplePicture.cpp b/samplecode/SamplePicture.cpp index e1b05ad66b..e232a50409 100644 --- a/samplecode/SamplePicture.cpp +++ b/samplecode/SamplePicture.cpp @@ -1,11 +1,11 @@ #include "SampleCode.h" +#include "SkDumpCanvas.h" #include "SkView.h" #include "SkCanvas.h" #include "Sk64.h" #include "SkGradientShader.h" #include "SkGraphics.h" #include "SkImageDecoder.h" -#include "SkKernel33MaskFilter.h" #include "SkPath.h" #include "SkPicture.h" #include "SkRandom.h" @@ -103,15 +103,21 @@ protected: canvas->drawBitmap(fBitmap, 0, 0, NULL); canvas->restore(); + const char beforeStr[] = "before circle"; + const char afterStr[] = "after circle"; + paint.setAntiAlias(true); paint.setColor(SK_ColorRED); + canvas->drawData(beforeStr, sizeof(beforeStr)); canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), SkIntToScalar(40), paint); + canvas->drawData(afterStr, sizeof(afterStr)); paint.setColor(SK_ColorBLACK); paint.setTextSize(SkIntToScalar(40)); canvas->drawText("Picture", 7, SkIntToScalar(50), SkIntToScalar(62), paint); + } virtual void onDraw(SkCanvas* canvas) { @@ -145,6 +151,12 @@ protected: canvas->translate(-SkIntToScalar(100), 0); canvas->drawPicture(*pict); canvas->restore(); + + if (false) { + SkDebugfDumper dumper; + SkDumpCanvas dumpCanvas(&dumper); + dumpCanvas.drawPicture(*pict); + } // test that we can re-record a subpicture, and see the results diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 0bf0614264..a5529af633 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1239,6 +1239,10 @@ void SkCanvas::drawVertices(VertexMode vmode, int vertexCount, ITER_END } +void SkCanvas::drawData(const void* data, size_t length) { + // do nothing. Subclasses may do something with the data +} + ////////////////////////////////////////////////////////////////////////////// // These methods are NOT virtual, and therefore must call back into virtual // methods, rather than actually drawing themselves. diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index 86a161d144..2c0af5a2ec 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -18,6 +18,7 @@ enum DrawType { DRAW_BITMAP, DRAW_BITMAP_MATRIX, DRAW_BITMAP_RECT, + DRAW_DATA, DRAW_PAINT, DRAW_PATH, DRAW_PICTURE, diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 03cdc1681c..f488565b41 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -589,6 +589,11 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { const SkMatrix* matrix = getMatrix(); canvas.drawBitmapMatrix(bitmap, *matrix, paint); } break; + case DRAW_DATA: { + size_t length = getInt(); + canvas.drawData(fReader.skip(length), length); + // skip handles padding the read out to a multiple of 4 + } break; case DRAW_PAINT: canvas.drawPaint(*getPaint()); break; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index b565fc11a8..9844a480cd 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -410,6 +410,12 @@ void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, } } +void SkPictureRecord::drawData(const void* data, size_t length) { + addDraw(DRAW_DATA); + addInt(length); + fWriter.writePad(data, length); +} + /////////////////////////////////////////////////////////////////////////////// void SkPictureRecord::reset() { diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 05761afd0b..f9c967d32f 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -56,6 +56,7 @@ public: const SkColor colors[], SkXfermode*, const uint16_t indices[], int indexCount, const SkPaint&); + virtual void drawData(const void*, size_t); void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY); diff --git a/src/utils/SkDumpCanvas.cpp b/src/utils/SkDumpCanvas.cpp index 215113300c..4ff7a50fc8 100644 --- a/src/utils/SkDumpCanvas.cpp +++ b/src/utils/SkDumpCanvas.cpp @@ -379,6 +379,12 @@ void SkDumpCanvas::drawVertices(VertexMode vmode, int vertexCount, SkScalarToFloat(vertices[0].fY)); } +void SkDumpCanvas::drawData(const void* data, size_t length) { +// this->dump(kDrawData_Verb, NULL, "drawData(%d)", length); + this->dump(kDrawData_Verb, NULL, "drawData(%d) %.*s", length, + SkMin32(length, 64), data); +} + /////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////// diff --git a/src/utils/SkProxyCanvas.cpp b/src/utils/SkProxyCanvas.cpp index cb0d44a88a..c643c8277e 100644 --- a/src/utils/SkProxyCanvas.cpp +++ b/src/utils/SkProxyCanvas.cpp @@ -151,6 +151,10 @@ void SkProxyCanvas::drawVertices(VertexMode vmode, int vertexCount, xmode, indices, indexCount, paint); } +void SkProxyCanvas::drawData(const void* data, size_t length) { + fProxy->drawData(data, length); +} + SkBounder* SkProxyCanvas::setBounder(SkBounder* bounder) { return fProxy->setBounder(bounder); } |