Home | History | Annotate | Download | only in core
      1 #ifndef SkPicturePlayback_DEFINED
      2 #define SkPicturePlayback_DEFINED
      3 
      4 #include "SkPicture.h"
      5 #include "SkReader32.h"
      6 
      7 #include "SkBitmap.h"
      8 #include "SkMatrix.h"
      9 #include "SkPaint.h"
     10 #include "SkPath.h"
     11 #include "SkPathHeap.h"
     12 #include "SkRegion.h"
     13 #include "SkPictureFlat.h"
     14 #include "SkShape.h"
     15 
     16 class SkPictureRecord;
     17 class SkStream;
     18 class SkWStream;
     19 
     20 class SkPicturePlayback {
     21 public:
     22     SkPicturePlayback();
     23     SkPicturePlayback(const SkPicturePlayback& src);
     24     explicit SkPicturePlayback(const SkPictureRecord& record);
     25     explicit SkPicturePlayback(SkStream*);
     26 
     27     virtual ~SkPicturePlayback();
     28 
     29     void draw(SkCanvas& canvas);
     30 
     31     void serialize(SkWStream*) const;
     32 
     33     void dumpSize() const;
     34 
     35     // Can be called in the middle of playback (the draw() call). WIll abort the
     36     // drawing and return from draw() after the "current" op code is done
     37     void abort();
     38 
     39 private:
     40 
     41     class TextContainer {
     42     public:
     43         size_t length() { return fByteLength; }
     44         const void* text() { return (const void*) fText; }
     45         size_t fByteLength;
     46         const char* fText;
     47     };
     48 
     49     const SkBitmap& getBitmap() {
     50         int index = getInt();
     51         SkASSERT(index > 0);
     52         return fBitmaps[index - 1];
     53     }
     54 
     55     int getIndex() { return fReader.readInt(); }
     56     int getInt() { return fReader.readInt(); }
     57 
     58     const SkMatrix* getMatrix() {
     59         int index = getInt();
     60         if (index == 0) {
     61             return NULL;
     62         }
     63         SkASSERT(index > 0 && index <= fMatrixCount);
     64         return &fMatrices[index - 1];
     65     }
     66 
     67     const SkPath& getPath() {
     68         return (*fPathHeap)[getInt() - 1];
     69     }
     70 
     71     SkPicture& getPicture() {
     72         int index = getInt();
     73         SkASSERT(index > 0 && index <= fPictureCount);
     74         return *fPictureRefs[index - 1];
     75     }
     76 
     77     SkShape* getShape() {
     78         int index = getInt();
     79         SkASSERT(index > 0 && index <= fShapeCount);
     80         return fShapes[index - 1];
     81     }
     82 
     83     const SkPaint* getPaint() {
     84         int index = getInt();
     85         if (index == 0) {
     86             return NULL;
     87         }
     88         SkASSERT(index > 0 && index <= fPaintCount);
     89         return &fPaints[index - 1];
     90     }
     91 
     92     const SkRect* getRectPtr() {
     93         if (fReader.readBool()) {
     94             return fReader.skipRect();
     95         } else {
     96             return NULL;
     97         }
     98     }
     99 
    100     const SkIRect* getIRectPtr() {
    101         if (fReader.readBool()) {
    102             return (const SkIRect*)fReader.skip(sizeof(SkIRect));
    103         } else {
    104             return NULL;
    105         }
    106     }
    107 
    108     const SkRegion& getRegion() {
    109         int index = getInt();
    110         SkASSERT(index > 0);
    111         return fRegions[index - 1];
    112     }
    113 
    114     SkScalar getScalar() { return fReader.readScalar(); }
    115 
    116     void getText(TextContainer* text) {
    117         size_t length = text->fByteLength = getInt();
    118         text->fText = (const char*)fReader.skip(length);
    119     }
    120 
    121     void init();
    122 
    123 #ifdef SK_DEBUG_SIZE
    124 public:
    125     int size(size_t* sizePtr);
    126     int bitmaps(size_t* size);
    127     int paints(size_t* size);
    128     int paths(size_t* size);
    129     int regions(size_t* size);
    130 #endif
    131 
    132 #ifdef SK_DEBUG_DUMP
    133 private:
    134     void dumpBitmap(const SkBitmap& bitmap) const;
    135     void dumpMatrix(const SkMatrix& matrix) const;
    136     void dumpPaint(const SkPaint& paint) const;
    137     void dumpPath(const SkPath& path) const;
    138     void dumpPicture(const SkPicture& picture) const;
    139     void dumpRegion(const SkRegion& region) const;
    140     int dumpDrawType(char* bufferPtr, char* buffer, DrawType drawType);
    141     int dumpInt(char* bufferPtr, char* buffer, char* name);
    142     int dumpRect(char* bufferPtr, char* buffer, char* name);
    143     int dumpPoint(char* bufferPtr, char* buffer, char* name);
    144     void dumpPointArray(char** bufferPtrPtr, char* buffer, int count);
    145     int dumpPtr(char* bufferPtr, char* buffer, char* name, void* ptr);
    146     int dumpRectPtr(char* bufferPtr, char* buffer, char* name);
    147     int dumpScalar(char* bufferPtr, char* buffer, char* name);
    148     void dumpText(char** bufferPtrPtr, char* buffer);
    149     void dumpStream();
    150 
    151 public:
    152     void dump() const;
    153 #endif
    154 
    155 private:
    156     SkPathHeap* fPathHeap;  // reference counted
    157     SkBitmap* fBitmaps;
    158     int fBitmapCount;
    159     SkMatrix* fMatrices;
    160     int fMatrixCount;
    161     SkPaint* fPaints;
    162     int fPaintCount;
    163     SkRegion* fRegions;
    164     int fRegionCount;
    165     mutable SkFlattenableReadBuffer fReader;
    166 
    167     SkPicture** fPictureRefs;
    168     int fPictureCount;
    169     SkShape** fShapes;
    170     int fShapeCount;
    171 
    172     SkRefCntPlayback fRCPlayback;
    173     SkTypefacePlayback fTFPlayback;
    174     SkFactoryPlayback*   fFactoryPlayback;
    175 };
    176 
    177 #endif
    178