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 "SkMiniRecorder.h" 13 #include "SkNoDrawCanvas.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 final : public SkNoDrawCanvas { 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 std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); } 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 void didTranslate(SkScalar, SkScalar) override; 64 65 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 66 void onDrawDrawable(SkDrawable*, const SkMatrix*) override; 67 void onDrawText(const void* text, 68 size_t byteLength, 69 SkScalar x, 70 SkScalar y, 71 const SkPaint& paint) override; 72 void onDrawPosText(const void* text, 73 size_t byteLength, 74 const SkPoint pos[], 75 const SkPaint& paint) override; 76 void onDrawPosTextH(const void* text, 77 size_t byteLength, 78 const SkScalar xpos[], 79 SkScalar constY, 80 const SkPaint& paint) override; 81 void onDrawTextOnPath(const void* text, 82 size_t byteLength, 83 const SkPath& path, 84 const SkMatrix* matrix, 85 const SkPaint& paint) override; 86 void onDrawTextRSXform(const void* text, 87 size_t byteLength, 88 const SkRSXform[], 89 const SkRect* cull, 90 const SkPaint& paint) override; 91 void onDrawTextBlob(const SkTextBlob* blob, 92 SkScalar x, 93 SkScalar y, 94 const SkPaint& paint) override; 95 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 96 const SkPoint texCoords[4], SkBlendMode, 97 const SkPaint& paint) override; 98 99 void onDrawPaint(const SkPaint&) override; 100 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; 101 void onDrawRect(const SkRect&, const SkPaint&) override; 102 void onDrawRegion(const SkRegion&, const SkPaint&) override; 103 void onDrawOval(const SkRect&, const SkPaint&) override; 104 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; 105 void onDrawRRect(const SkRRect&, const SkPaint&) override; 106 void onDrawPath(const SkPath&, const SkPaint&) override; 107 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override; 108 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*, 109 SrcRectConstraint) override; 110 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override; 111 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst, 112 const SkPaint*, SrcRectConstraint) override; 113 void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst, 114 const SkPaint*) override; 115 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst, 116 const SkPaint*) override; 117 void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst, 118 const SkPaint*) override; 119 void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst, 120 const SkPaint*) override; 121 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; 122 void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], 123 int count, SkBlendMode, const SkRect* cull, const SkPaint*) override; 124 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; 125 126 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override; 127 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override; 128 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override; 129 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override; 130 131 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 132 133 void onDrawAnnotation(const SkRect&, const char[], SkData*) override; 134 135 sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; 136 137 void flushMiniRecorder(); 138 139 private: 140 template <typename T> 141 T* copy(const T*); 142 143 template <typename T> 144 T* copy(const T[], size_t count); 145 146 DrawPictureMode fDrawPictureMode; 147 size_t fApproxBytesUsedBySubPictures; 148 SkRecord* fRecord; 149 std::unique_ptr<SkDrawableList> fDrawableList; 150 151 SkMiniRecorder* fMiniRecorder; 152 }; 153 154 #endif//SkRecorder_DEFINED 155