diff options
author | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-06-26 20:22:26 +0000 |
---|---|---|
committer | reed@android.com <reed@android.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2009-06-26 20:22:26 +0000 |
commit | 09b84a00f79979142fbcfd691ccaeb5e5600922d (patch) | |
tree | 216574508368bdb12ff070d608709aabff856c68 /src | |
parent | 0baf19375466cfc24c96532df406e7c5b1d1aae8 (diff) |
add shape recording to pictuures (sans serialization)
git-svn-id: http://skia.googlecode.com/svn/trunk@240 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkPictureFlat.h | 1 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.cpp | 39 | ||||
-rw-r--r-- | src/core/SkPicturePlayback.h | 13 | ||||
-rw-r--r-- | src/core/SkPictureRecord.cpp | 15 | ||||
-rw-r--r-- | src/core/SkPictureRecord.h | 7 |
5 files changed, 69 insertions, 6 deletions
diff --git a/src/core/SkPictureFlat.h b/src/core/SkPictureFlat.h index aad1dcdd77..86a161d144 100644 --- a/src/core/SkPictureFlat.h +++ b/src/core/SkPictureFlat.h @@ -26,6 +26,7 @@ enum DrawType { DRAW_POS_TEXT_H, DRAW_POS_TEXT_H_TOP_BOTTOM, // fast variant of DRAW_POS_TEXT_H DRAW_RECT, + DRAW_SHAPE, DRAW_SPRITE, DRAW_TEXT, DRAW_TEXT_ON_PATH, diff --git a/src/core/SkPicturePlayback.cpp b/src/core/SkPicturePlayback.cpp index 421d5c21da..24fcd8e57d 100644 --- a/src/core/SkPicturePlayback.cpp +++ b/src/core/SkPicturePlayback.cpp @@ -119,7 +119,17 @@ SkPicturePlayback::SkPicturePlayback(const SkPictureRecord& record) { fPictureRefs[i]->ref(); } } - + + const SkTDArray<SkShape* >& shapes = record.getShapes(); + fShapeCount = shapes.count(); + if (fShapeCount > 0) { + fShapes = SkNEW_ARRAY(SkShape*, fShapeCount); + for (int i = 0; i < fShapeCount; i++) { + fShapes[i] = shapes[i]; + fShapes[i]->ref(); + } + } + const SkTDArray<const SkFlatRegion* >& regions = record.getRegions(); fRegionCount = regions.count(); if (fRegionCount > 0) { @@ -192,6 +202,13 @@ SkPicturePlayback::SkPicturePlayback(const SkPicturePlayback& src) { fPictureRefs[i]->ref(); } + fShapeCount = src.fShapeCount; + fShapes = SkNEW_ARRAY(SkShape*, fShapeCount); + for (int i = 0; i < fShapeCount; i++) { + fShapes[i] = src.fShapes[i]; + fShapes[i]->ref(); + } + fRegionCount = src.fRegionCount; fRegions = SkNEW_ARRAY(SkRegion, fRegionCount); for (i = 0; i < fRegionCount; i++) { @@ -205,6 +222,7 @@ void SkPicturePlayback::init() { fPaints = NULL; fPathHeap = NULL; fPictureRefs = NULL; + fShapes = NULL; fRegions = NULL; fBitmapCount = fMatrixCount = fPaintCount = fPictureCount = fRegionCount = 0; @@ -221,12 +239,17 @@ SkPicturePlayback::~SkPicturePlayback() { SkDELETE_ARRAY(fRegions); fPathHeap->safeUnref(); - + for (int i = 0; i < fPictureCount; i++) { fPictureRefs[i]->unref(); } SkDELETE_ARRAY(fPictureRefs); + for (int i = 0; i < fShapeCount; i++) { + fShapes[i]->unref(); + } + SkDELETE_ARRAY(fShapes); + SkDELETE(fFactoryPlayback); } @@ -362,7 +385,14 @@ void SkPicturePlayback::serialize(SkWStream* stream) const { for (i = 0; i < fPictureCount; i++) { fPictureRefs[i]->serialize(stream); } - + +#if 0 + writeTagSize(stream, PICT_SHAPE_TAG, fShapeCount); + for (i = 0; i < fShapeCount; i++) { + fShapes[i]->serialize(stream); + } +#endif + writeTagSize(stream, PICT_ARRAYS_TAG, buffer.size()); buffer.writeToStream(stream); } @@ -603,6 +633,9 @@ void SkPicturePlayback::draw(SkCanvas& canvas) { const SkPaint& paint = *getPaint(); canvas.drawRect(*fReader.skipRect(), paint); } break; + case DRAW_SHAPE: + canvas.drawShape(getShape()); + break; case DRAW_SPRITE: { const SkPaint* paint = getPaint(); const SkBitmap& bitmap = getBitmap(); diff --git a/src/core/SkPicturePlayback.h b/src/core/SkPicturePlayback.h index b4e69cac46..ae9641a189 100644 --- a/src/core/SkPicturePlayback.h +++ b/src/core/SkPicturePlayback.h @@ -11,6 +11,7 @@ #include "SkPathHeap.h" #include "SkRegion.h" #include "SkPictureFlat.h" +#include "SkShape.h" class SkPictureRecord; class SkStream; @@ -72,7 +73,13 @@ private: SkASSERT(index > 0 && index <= fPictureCount); return *fPictureRefs[index - 1]; } - + + SkShape* getShape() { + int index = getInt(); + SkASSERT(index > 0 && index <= fShapeCount); + return fShapes[index - 1]; + } + const SkPaint* getPaint() { int index = getInt(); if (index == 0) { @@ -159,7 +166,9 @@ private: SkPicture** fPictureRefs; int fPictureCount; - + SkShape** fShapes; + int fShapeCount; + SkRefCntPlayback fRCPlayback; SkTypefacePlayback fTFPlayback; SkFactoryPlayback* fFactoryPlayback; diff --git a/src/core/SkPictureRecord.cpp b/src/core/SkPictureRecord.cpp index 77756a9746..f0f3402790 100644 --- a/src/core/SkPictureRecord.cpp +++ b/src/core/SkPictureRecord.cpp @@ -1,4 +1,5 @@ #include "SkPictureRecord.h" +#include "SkShape.h" #include "SkTSearch.h" #define MIN_WRITER_SIZE 16384 @@ -353,6 +354,20 @@ void SkPictureRecord::drawPicture(SkPicture& picture) { validate(); } +void SkPictureRecord::drawShape(SkShape* shape) { + addDraw(DRAW_SHAPE); + + int index = fShapes.find(shape); + if (index < 0) { // not found + index = fShapes.count(); + *fShapes.append() = shape; + shape->ref(); + } + // follow the convention of recording a 1-based index + addInt(index + 1); + validate(); +} + void SkPictureRecord::drawVertices(VertexMode vmode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode*, diff --git a/src/core/SkPictureRecord.h b/src/core/SkPictureRecord.h index 5325e1e386..05761afd0b 100644 --- a/src/core/SkPictureRecord.h +++ b/src/core/SkPictureRecord.h @@ -50,6 +50,7 @@ public: const SkPath& path, const SkMatrix* matrix, const SkPaint&); virtual void drawPicture(SkPicture& picture); + virtual void drawShape(SkShape*); virtual void drawVertices(VertexMode, int vertexCount, const SkPoint vertices[], const SkPoint texs[], const SkColor colors[], SkXfermode*, @@ -70,6 +71,9 @@ public: const SkTDArray<SkPicture* >& getPictureRefs() const { return fPictureRefs; } + const SkTDArray<SkShape* >& getShapes() const { + return fShapes; + } const SkTDArray<const SkFlatRegion* >& getRegions() const { return fRegions; } @@ -165,8 +169,9 @@ private: SkPathHeap* fPathHeap; // reference counted SkWriter32 fWriter; - // we ref each item in this array + // we ref each item in these arrays SkTDArray<SkPicture*> fPictureRefs; + SkTDArray<SkShape*> fShapes; SkRefCntRecorder fRCRecorder; SkRefCntRecorder fTFRecorder; |