#include "SkTemplates.h"
#include "SkWriter32.h"
-class SkPictureStateTree;
class SkBBoxHierarchy;
+class SkPictureStateTree;
// These macros help with packing and unpacking a single byte value and
// a 3 byte value into/out of a uint32_t
class SkPictureRecord : public SkCanvas {
public:
- SkPictureRecord(uint32_t recordFlags, SkBaseDevice*);
+ SkPictureRecord(SkPicture* picture, const SkISize& dimensions, uint32_t recordFlags);
virtual ~SkPictureRecord();
- virtual SkBaseDevice* setDevice(SkBaseDevice* device) SK_OVERRIDE;
-
- virtual int save(SaveFlags) SK_OVERRIDE;
- virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags) SK_OVERRIDE;
- virtual void restore() SK_OVERRIDE;
- virtual bool translate(SkScalar dx, SkScalar dy) SK_OVERRIDE;
- virtual bool scale(SkScalar sx, SkScalar sy) SK_OVERRIDE;
- virtual bool rotate(SkScalar degrees) SK_OVERRIDE;
- virtual bool skew(SkScalar sx, SkScalar sy) SK_OVERRIDE;
- virtual bool concat(const SkMatrix& matrix) SK_OVERRIDE;
- virtual void setMatrix(const SkMatrix& matrix) SK_OVERRIDE;
- virtual bool clipRect(const SkRect&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipRRect(const SkRRect&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipPath(const SkPath&, SkRegion::Op, bool) SK_OVERRIDE;
- virtual bool clipRegion(const SkRegion& region, SkRegion::Op op) SK_OVERRIDE;
virtual void clear(SkColor) SK_OVERRIDE;
virtual void drawPaint(const SkPaint& paint) SK_OVERRIDE;
virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
const SkRect& dst, const SkPaint*) SK_OVERRIDE;
virtual void drawSprite(const SkBitmap&, int left, int top,
const SkPaint*) SK_OVERRIDE;
- virtual void drawText(const void* text, size_t byteLength, SkScalar x,
- SkScalar y, const SkPaint&) SK_OVERRIDE;
- virtual void drawPosText(const void* text, size_t byteLength,
- const SkPoint pos[], const SkPaint&) SK_OVERRIDE;
- virtual void drawPosTextH(const void* text, size_t byteLength,
- const SkScalar xpos[], SkScalar constY, const SkPaint&) SK_OVERRIDE;
- virtual void drawTextOnPath(const void* text, size_t byteLength,
- const SkPath& path, const SkMatrix* matrix,
- const SkPaint&) SK_OVERRIDE;
virtual void drawPicture(SkPicture& picture) SK_OVERRIDE;
virtual void drawVertices(VertexMode, int vertexCount,
const SkPoint vertices[], const SkPoint texs[],
void beginRecording();
void endRecording();
+ void internalOnly_EnableOpts(bool optsEnabled) {
+ fOptsEnabled = optsEnabled;
+ }
+
private:
void handleOptimization(int opt);
- int recordRestoreOffsetPlaceholder(SkRegion::Op);
+ size_t recordRestoreOffsetPlaceholder(SkRegion::Op);
void fillRestoreOffsetPlaceholdersForCurrentStackLevel(uint32_t restoreOffset);
#ifndef SK_COLLAPSE_MATRIX_CLIP_STATE
};
#endif
+ SkTDArray<uint32_t> fCullOffsetStack;
+
/*
* Write the 'drawType' operation and chunk size to the skp. 'size'
* can potentially be increased if the chunk size needs its own storage
* end of blocks could go unused). Possibly add a second addDraw that
* operates in this manner.
*/
- size_t addDraw(DrawType drawType, uint32_t* size) {
+ size_t addDraw(DrawType drawType, size_t* size) {
size_t offset = fWriter.bytesWritten();
this->predrawNotify();
if (0 != (*size & ~MASK_24) || *size == MASK_24) {
fWriter.writeInt(PACK_8_24(drawType, MASK_24));
*size += 1;
- fWriter.writeInt(*size);
+ fWriter.writeInt(SkToU32(*size));
} else {
- fWriter.writeInt(PACK_8_24(drawType, *size));
+ fWriter.writeInt(PACK_8_24(drawType, SkToU32(*size)));
}
return offset;
fWriter.writeScalar(scalar);
}
- void addBitmap(const SkBitmap& bitmap);
+ // The command at 'offset' in the skp uses the specified bitmap
+ int addBitmap(const SkBitmap& bitmap);
void addMatrix(const SkMatrix& matrix);
const SkFlatData* addPaint(const SkPaint& paint) { return this->addPaintPtr(&paint); }
const SkFlatData* addPaintPtr(const SkPaint* paint);
void validateRegions() const;
#else
public:
- void validate(size_t initialOffset, uint32_t size) const {
+ void validate(size_t initialOffset, size_t size) const {
SkASSERT(fWriter.bytesWritten() == initialOffset + size);
}
#endif
return NULL;
}
+ virtual void willSave(SaveFlags) SK_OVERRIDE;
+ virtual SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SaveFlags) SK_OVERRIDE;
+ virtual void willRestore() SK_OVERRIDE;
+
+ virtual void didConcat(const SkMatrix&) SK_OVERRIDE;
+ virtual void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
+
+ virtual void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
+ virtual void onPushCull(const SkRect&) SK_OVERRIDE;
+ virtual void onPopCull() SK_OVERRIDE;
+
+ virtual void onDrawText(const void* text, size_t byteLength, SkScalar x, SkScalar y,
+ const SkPaint&) SK_OVERRIDE;
+ virtual void onDrawPosText(const void* text, size_t byteLength, const SkPoint pos[],
+ const SkPaint&) SK_OVERRIDE;
+ virtual void onDrawPosTextH(const void* text, size_t byteLength, const SkScalar xpos[],
+ SkScalar constY, const SkPaint&) SK_OVERRIDE;
+ virtual void onDrawTextOnPath(const void* text, size_t byteLength, const SkPath& path,
+ const SkMatrix* matrix, const SkPaint&) SK_OVERRIDE;
+
+ virtual void onClipRect(const SkRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRRect(const SkRRect&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipPath(const SkPath&, SkRegion::Op, ClipEdgeStyle) SK_OVERRIDE;
+ virtual void onClipRegion(const SkRegion&, SkRegion::Op) SK_OVERRIDE;
+
// Return fontmetrics.fTop,fBottom in topbot[0,1], after they have been
// tweaked by paint.computeFastBounds().
static void ComputeFontMetricsTopBottom(const SkPaint& paint, SkScalar topbot[2]);
// restores to be deferred (e.g., if the MC state is being collapsed and
// only written out as needed).
void recordConcat(const SkMatrix& matrix);
- int recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA);
- int recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
- int recordClipPath(int pathID, SkRegion::Op op, bool doAA);
- int recordClipRegion(const SkRegion& region, SkRegion::Op op);
+ void recordTranslate(const SkMatrix& matrix);
+ void recordScale(const SkMatrix& matrix);
+ size_t recordClipRect(const SkRect& rect, SkRegion::Op op, bool doAA);
+ size_t recordClipRRect(const SkRRect& rrect, SkRegion::Op op, bool doAA);
+ size_t recordClipPath(int pathID, SkRegion::Op op, bool doAA);
+ size_t recordClipRegion(const SkRegion& region, SkRegion::Op op);
void recordSave(SaveFlags flags);
void recordSaveLayer(const SkRect* bounds, const SkPaint* paint, SaveFlags flags);
void recordRestore(bool fillInSkips = true);
SkBitmapHeap* fBitmapHeap;
private:
+ // The owning SkPicture
+ SkPicture* fPicture;
+
friend class MatrixClipState; // for access to *Impl methods
friend class SkMatrixClipStateMgr; // for access to *Impl methods
SkPaintDictionary fPaints;
- SkPathHeap* fPathHeap; // reference counted
SkWriter32 fWriter;
// we ref each item in these arrays
SkTDArray<SkPicture*> fPictureRefs;
uint32_t fRecordFlags;
- int fInitialSaveCount;
+ bool fOptsEnabled;
+ int fInitialSaveCount;
friend class SkPicturePlayback;
friend class SkPictureTester; // for unit testing