Home | History | Annotate | Download | only in core
      1 #ifndef SkPictureRecord_DEFINED
      2 #define SkPictureRecord_DEFINED
      3 
      4 #include "SkCanvas.h"
      5 #include "SkFlattenable.h"
      6 #include "SkPathHeap.h"
      7 #include "SkPicture.h"
      8 #include "SkPictureFlat.h"
      9 #include "SkTemplates.h"
     10 #include "SkWriter32.h"
     11 
     12 class SkPictureRecord : public SkCanvas {
     13 public:
     14     SkPictureRecord(uint32_t recordFlags);
     15     virtual ~SkPictureRecord();
     16 
     17     // overrides from SkCanvas
     18     virtual int save(SaveFlags);
     19     virtual int saveLayer(const SkRect* bounds, const SkPaint*, SaveFlags);
     20     virtual void restore();
     21     virtual bool translate(SkScalar dx, SkScalar dy);
     22     virtual bool scale(SkScalar sx, SkScalar sy);
     23     virtual bool rotate(SkScalar degrees);
     24     virtual bool skew(SkScalar sx, SkScalar sy);
     25     virtual bool concat(const SkMatrix& matrix);
     26     virtual void setMatrix(const SkMatrix& matrix);
     27     virtual bool clipRect(const SkRect& rect, SkRegion::Op op);
     28     virtual bool clipPath(const SkPath& path, SkRegion::Op op);
     29     virtual bool clipRegion(const SkRegion& region, SkRegion::Op op);
     30     virtual void drawPaint(const SkPaint& paint);
     31     virtual void drawPoints(PointMode, size_t count, const SkPoint pts[],
     32                             const SkPaint&);
     33     virtual void drawRect(const SkRect& rect, const SkPaint&);
     34     virtual void drawPath(const SkPath& path, const SkPaint&);
     35     virtual void drawBitmap(const SkBitmap&, SkScalar left, SkScalar top,
     36                             const SkPaint*);
     37     virtual void drawBitmapRect(const SkBitmap&, const SkIRect* src,
     38                                 const SkRect& dst, const SkPaint*);
     39     virtual void drawBitmapMatrix(const SkBitmap&, const SkMatrix&,
     40                                   const SkPaint*);
     41     virtual void drawSprite(const SkBitmap&, int left, int top,
     42                             const SkPaint*);
     43     virtual void drawText(const void* text, size_t byteLength, SkScalar x,
     44                           SkScalar y, const SkPaint&);
     45     virtual void drawPosText(const void* text, size_t byteLength,
     46                              const SkPoint pos[], const SkPaint&);
     47     virtual void drawPosTextH(const void* text, size_t byteLength,
     48                       const SkScalar xpos[], SkScalar constY, const SkPaint&);
     49     virtual void drawTextOnPath(const void* text, size_t byteLength,
     50                             const SkPath& path, const SkMatrix* matrix,
     51                                 const SkPaint&);
     52     virtual void drawPicture(SkPicture& picture);
     53     virtual void drawShape(SkShape*);
     54     virtual void drawVertices(VertexMode, int vertexCount,
     55                           const SkPoint vertices[], const SkPoint texs[],
     56                           const SkColor colors[], SkXfermode*,
     57                           const uint16_t indices[], int indexCount,
     58                               const SkPaint&);
     59     virtual void drawData(const void*, size_t);
     60 
     61     void addFontMetricsTopBottom(const SkPaint& paint, SkScalar baselineY);
     62 
     63     const SkTDArray<const SkFlatBitmap* >& getBitmaps() const {
     64         return fBitmaps;
     65     }
     66     const SkTDArray<const SkFlatMatrix* >& getMatrices() const {
     67         return fMatrices;
     68     }
     69     const SkTDArray<const SkFlatPaint* >& getPaints() const {
     70         return fPaints;
     71     }
     72     const SkTDArray<SkPicture* >& getPictureRefs() const {
     73         return fPictureRefs;
     74     }
     75     const SkTDArray<SkShape* >& getShapes() const {
     76         return fShapes;
     77     }
     78     const SkTDArray<const SkFlatRegion* >& getRegions() const {
     79         return fRegions;
     80     }
     81 
     82     void reset();
     83 
     84     const SkWriter32& writeStream() const {
     85         return fWriter;
     86     }
     87 
     88 private:
     89     SkTDArray<uint32_t> fRestoreOffsetStack;
     90 
     91     void addDraw(DrawType drawType) {
     92 #ifdef SK_DEBUG_TRACE
     93         SkDebugf("add %s\n", DrawTypeToString(drawType));
     94 #endif
     95         fWriter.writeInt(drawType);
     96     }
     97     void addInt(int value) {
     98         fWriter.writeInt(value);
     99     }
    100     void addScalar(SkScalar scalar) {
    101         fWriter.writeScalar(scalar);
    102     }
    103 
    104     void addBitmap(const SkBitmap& bitmap);
    105     void addMatrix(const SkMatrix& matrix);
    106     void addMatrixPtr(const SkMatrix* matrix);
    107     void addPaint(const SkPaint& paint);
    108     void addPaintPtr(const SkPaint* paint);
    109     void addPath(const SkPath& path);
    110     void addPicture(SkPicture& picture);
    111     void addPoint(const SkPoint& point);
    112     void addPoints(const SkPoint pts[], int count);
    113     void addRect(const SkRect& rect);
    114     void addRectPtr(const SkRect* rect);
    115     void addIRectPtr(const SkIRect* rect);
    116     void addRegion(const SkRegion& region);
    117     void addText(const void* text, size_t byteLength);
    118 
    119     int find(SkTDArray<const SkFlatBitmap* >& bitmaps,
    120                    const SkBitmap& bitmap);
    121     int find(SkTDArray<const SkFlatMatrix* >& matrices,
    122                    const SkMatrix* matrix);
    123     int find(SkTDArray<const SkFlatPaint* >& paints, const SkPaint* paint);
    124     int find(SkTDArray<const SkFlatRegion* >& regions, const SkRegion& region);
    125 
    126 #ifdef SK_DEBUG_DUMP
    127 public:
    128     void dumpMatrices();
    129     void dumpPaints();
    130 #endif
    131 
    132 #ifdef SK_DEBUG_SIZE
    133 public:
    134     size_t size() const;
    135     int bitmaps(size_t* size) const;
    136     int matrices(size_t* size) const;
    137     int paints(size_t* size) const;
    138     int paths(size_t* size) const;
    139     int regions(size_t* size) const;
    140     size_t streamlen() const;
    141 
    142     size_t fPointBytes, fRectBytes, fTextBytes;
    143     int fPointWrites, fRectWrites, fTextWrites;
    144 #endif
    145 
    146 #ifdef SK_DEBUG_VALIDATE
    147 public:
    148     void validate() const;
    149 private:
    150     void validateBitmaps() const;
    151     void validateMatrices() const;
    152     void validatePaints() const;
    153     void validatePaths() const;
    154     void validateRegions() const;
    155 #else
    156 public:
    157     void validate() const {}
    158 #endif
    159 
    160 private:
    161     SkChunkAlloc fHeap;
    162     int fBitmapIndex;
    163     SkTDArray<const SkFlatBitmap* > fBitmaps;
    164     int fMatrixIndex;
    165     SkTDArray<const SkFlatMatrix* > fMatrices;
    166     int fPaintIndex;
    167     SkTDArray<const SkFlatPaint* > fPaints;
    168     int fRegionIndex;
    169     SkTDArray<const SkFlatRegion* > fRegions;
    170     SkPathHeap* fPathHeap;  // reference counted
    171     SkWriter32 fWriter;
    172 
    173     // we ref each item in these arrays
    174     SkTDArray<SkPicture*> fPictureRefs;
    175     SkTDArray<SkShape*> fShapes;
    176 
    177     SkRefCntRecorder fRCRecorder;
    178     SkRefCntRecorder fTFRecorder;
    179 
    180     uint32_t fRecordFlags;
    181 
    182     friend class SkPicturePlayback;
    183 
    184     typedef SkCanvas INHERITED;
    185 };
    186 
    187 #endif
    188