Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2014 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkRecorder_DEFINED
      9 #define SkRecorder_DEFINED
     10 
     11 #include "SkCanvas.h"
     12 #include "SkRecord.h"
     13 #include "SkRecords.h"
     14 #include "SkTDArray.h"
     15 
     16 // SkRecorder provides an SkCanvas interface for recording into an SkRecord.
     17 
     18 class SkRecorder : public SkCanvas {
     19 public:
     20     // Does not take ownership of the SkRecord.
     21     SkRecorder(SkRecord*, int width, int height);
     22 
     23     // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
     24     void forgetRecord();
     25 
     26     void clear(SkColor) SK_OVERRIDE;
     27     void drawPaint(const SkPaint& paint) SK_OVERRIDE;
     28     void drawPoints(PointMode mode,
     29                     size_t count,
     30                     const SkPoint pts[],
     31                     const SkPaint& paint) SK_OVERRIDE;
     32     void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
     33     void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
     34     void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
     35     void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
     36     void drawBitmap(const SkBitmap& bitmap,
     37                     SkScalar left,
     38                     SkScalar top,
     39                     const SkPaint* paint = NULL) SK_OVERRIDE;
     40     void drawBitmapRectToRect(const SkBitmap& bitmap,
     41                               const SkRect* src,
     42                               const SkRect& dst,
     43                               const SkPaint* paint = NULL,
     44                               DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) SK_OVERRIDE;
     45     void drawBitmapMatrix(const SkBitmap& bitmap,
     46                           const SkMatrix& m,
     47                           const SkPaint* paint = NULL) SK_OVERRIDE;
     48     void drawBitmapNine(const SkBitmap& bitmap,
     49                         const SkIRect& center,
     50                         const SkRect& dst,
     51                         const SkPaint* paint = NULL) SK_OVERRIDE;
     52     void drawSprite(const SkBitmap& bitmap,
     53                     int left,
     54                     int top,
     55                     const SkPaint* paint = NULL) SK_OVERRIDE;
     56     void drawVertices(VertexMode vmode,
     57                       int vertexCount,
     58                       const SkPoint vertices[],
     59                       const SkPoint texs[],
     60                       const SkColor colors[],
     61                       SkXfermode* xmode,
     62                       const uint16_t indices[],
     63                       int indexCount,
     64                       const SkPaint& paint) SK_OVERRIDE;
     65 
     66     void willSave() SK_OVERRIDE;
     67     SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
     68     void willRestore() SK_OVERRIDE {}
     69     void didRestore() SK_OVERRIDE;
     70 
     71     void didConcat(const SkMatrix&) SK_OVERRIDE;
     72     void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
     73 
     74     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
     75     void onDrawText(const void* text,
     76                     size_t byteLength,
     77                     SkScalar x,
     78                     SkScalar y,
     79                     const SkPaint& paint) SK_OVERRIDE;
     80     void onDrawPosText(const void* text,
     81                        size_t byteLength,
     82                        const SkPoint pos[],
     83                        const SkPaint& paint) SK_OVERRIDE;
     84     void onDrawPosTextH(const void* text,
     85                         size_t byteLength,
     86                         const SkScalar xpos[],
     87                         SkScalar constY,
     88                         const SkPaint& paint) SK_OVERRIDE;
     89     void onDrawTextOnPath(const void* text,
     90                           size_t byteLength,
     91                           const SkPath& path,
     92                           const SkMatrix* matrix,
     93                           const SkPaint& paint) SK_OVERRIDE;
     94     void onDrawTextBlob(const SkTextBlob* blob,
     95                         SkScalar x,
     96                         SkScalar y,
     97                         const SkPaint& paint) SK_OVERRIDE;
     98     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
     99                      const SkPoint texCoords[4], SkXfermode* xmode,
    100                      const SkPaint& paint) SK_OVERRIDE;
    101 
    102     void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
    103     void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
    104     void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
    105     void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) SK_OVERRIDE;
    106 
    107     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE;
    108 
    109     void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
    110     void onPopCull() SK_OVERRIDE;
    111 
    112     void beginCommentGroup(const char*) SK_OVERRIDE;
    113     void addComment(const char*, const char*) SK_OVERRIDE;
    114     void endCommentGroup() SK_OVERRIDE;
    115     void drawData(const void*, size_t) SK_OVERRIDE;
    116 
    117     bool isDrawingToLayer() const SK_OVERRIDE;
    118     SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE { return NULL; }
    119 
    120 private:
    121     template <typename T>
    122     T* copy(const T*);
    123 
    124     template <typename T>
    125     T* copy(const T[], size_t count);
    126 
    127     SkIRect devBounds() const {
    128         SkIRect devBounds;
    129         this->getClipDeviceBounds(&devBounds);
    130         return devBounds;
    131     }
    132 
    133     SkRecord* fRecord;
    134 
    135     int fSaveLayerCount;
    136     SkTDArray<SkBool8> fSaveIsSaveLayer;
    137 };
    138 
    139 #endif//SkRecorder_DEFINED
    140