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 "SkBigPicture.h" 12 #include "SkCanvas.h" 13 #include "SkMiniRecorder.h" 14 #include "SkRecord.h" 15 #include "SkRecords.h" 16 #include "SkTDArray.h" 17 18 class SkBBHFactory; 19 20 class SkDrawableList : SkNoncopyable { 21 public: SkDrawableList()22 SkDrawableList() {} 23 ~SkDrawableList(); 24 count()25 int count() const { return fArray.count(); } begin()26 SkDrawable* const* begin() const { return fArray.begin(); } 27 28 void append(SkDrawable* drawable); 29 30 // Return a new or ref'd array of pictures that were snapped from our drawables. 31 SkBigPicture::SnapshotArray* newDrawableSnapshot(); 32 33 private: 34 SkTDArray<SkDrawable*> fArray; 35 }; 36 37 // SkRecorder provides an SkCanvas interface for recording into an SkRecord. 38 39 class SkRecorder : public SkCanvas { 40 public: 41 // Does not take ownership of the SkRecord. 42 SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // legacy version 43 SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); 44 45 enum DrawPictureMode { Record_DrawPictureMode, Playback_DrawPictureMode }; 46 void reset(SkRecord*, const SkRect& bounds, DrawPictureMode, SkMiniRecorder* = nullptr); 47 approxBytesUsedBySubPictures()48 size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; } 49 getDrawableList()50 SkDrawableList* getDrawableList() const { return fDrawableList.get(); } detachDrawableList()51 SkDrawableList* detachDrawableList() { return fDrawableList.detach(); } 52 53 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail. 54 void forgetRecord(); 55 56 void willSave() override; 57 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; willRestore()58 void willRestore() override {} 59 void didRestore() override; 60 61 void didConcat(const SkMatrix&) override; 62 void didSetMatrix(const SkMatrix&) override; 63 64 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 65 void onDrawDrawable(SkDrawable*, const SkMatrix*) override; 66 void onDrawText(const void* text, 67 size_t byteLength, 68 SkScalar x, 69 SkScalar y, 70 const SkPaint& paint) override; 71 void onDrawPosText(const void* text, 72 size_t byteLength, 73 const SkPoint pos[], 74 const SkPaint& paint) override; 75 void onDrawPosTextH(const void* text, 76 size_t byteLength, 77 const SkScalar xpos[], 78 SkScalar constY, 79 const SkPaint& paint) override; 80 void onDrawTextOnPath(const void* text, 81 size_t byteLength, 82 const SkPath& path, 83 const SkMatrix* matrix, 84 const SkPaint& paint) override; 85 void onDrawTextBlob(const SkTextBlob* blob, 86 SkScalar x, 87 SkScalar y, 88 const SkPaint& paint) override; 89 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 90 const SkPoint texCoords[4], SkXfermode* xmode, 91 const SkPaint& paint) override; 92 93 void onDrawPaint(const SkPaint&) override; 94 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; 95 void onDrawRect(const SkRect&, const SkPaint&) override; 96 void onDrawOval(const SkRect&, const SkPaint&) override; 97 void onDrawRRect(const SkRRect&, const SkPaint&) override; 98 void onDrawPath(const SkPath&, const SkPaint&) override; 99 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; 100 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, 101 SrcRectConstraint) override; 102 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; 103 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 104 const SkPaint*, SrcRectConstraint) override; 105 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, 106 const SkPaint*) override; 107 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 108 const SkPaint*) override; 109 void onDrawVertices(VertexMode vmode, int vertexCount, 110 const SkPoint vertices[], const SkPoint texs[], 111 const SkColor colors[], SkXfermode* xmode, 112 const uint16_t indices[], int indexCount, 113 const SkPaint&) override; 114 void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], 115 int count, SkXfermode::Mode, const SkRect* cull, const SkPaint*) override; 116 117 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 118 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 119 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) override; 120 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override; 121 122 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 123 onNewSurface(const SkImageInfo &,const SkSurfaceProps &)124 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override { return nullptr; } 125 126 void flushMiniRecorder(); 127 128 private: 129 template <typename T> 130 T* copy(const T*); 131 132 template <typename T> 133 T* copy(const T[], size_t count); 134 devBounds()135 SkIRect devBounds() const { 136 SkIRect devBounds; 137 this->getClipDeviceBounds(&devBounds); 138 return devBounds; 139 } 140 141 DrawPictureMode fDrawPictureMode; 142 size_t fApproxBytesUsedBySubPictures; 143 SkRecord* fRecord; 144 SkAutoTDelete<SkDrawableList> fDrawableList; 145 146 SkMiniRecorder* fMiniRecorder; 147 }; 148 149 #endif//SkRecorder_DEFINED 150