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 "include/core/SkCanvasVirtualEnforcer.h" 12 #include "include/private/SkTDArray.h" 13 #include "include/utils/SkNoDrawCanvas.h" 14 #include "src/core/SkBigPicture.h" 15 #include "src/core/SkMiniRecorder.h" 16 #include "src/core/SkRecord.h" 17 #include "src/core/SkRecords.h" 18 19 class SkBBHFactory; 20 21 class SkDrawableList : SkNoncopyable { 22 public: SkDrawableList()23 SkDrawableList() {} 24 ~SkDrawableList(); 25 count()26 int count() const { return fArray.count(); } begin()27 SkDrawable* const* begin() const { return fArray.begin(); } 28 29 void append(SkDrawable* drawable); 30 31 // Return a new or ref'd array of pictures that were snapped from our drawables. 32 SkBigPicture::SnapshotArray* newDrawableSnapshot(); 33 34 private: 35 SkTDArray<SkDrawable*> fArray; 36 }; 37 38 // SkRecorder provides an SkCanvas interface for recording into an SkRecord. 39 40 class SkRecorder final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> { 41 public: 42 // Does not take ownership of the SkRecord. 43 SkRecorder(SkRecord*, int width, int height, SkMiniRecorder* = nullptr); // TODO: remove 44 SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr); 45 46 void reset(SkRecord*, const SkRect& bounds, 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 onFlush() override; 57 58 void willSave() override; 59 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override; 60 bool onDoSaveBehind(const SkRect*) override; willRestore()61 void willRestore() override {} 62 void didRestore() override; 63 64 void onMarkCTM(const char*) override; 65 void didConcat44(const SkM44&) override; 66 void didSetM44(const SkM44&) override; 67 void didScale(SkScalar, SkScalar) override; 68 void didTranslate(SkScalar, SkScalar) override; 69 70 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override; 71 void onDrawDrawable(SkDrawable*, const SkMatrix*) override; 72 void onDrawTextBlob(const SkTextBlob* blob, 73 SkScalar x, 74 SkScalar y, 75 const SkPaint& paint) override; 76 void onDrawGlyphRunList(const SkGlyphRunList& glyphRunList, const SkPaint& paint) override; 77 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], 78 const SkPoint texCoords[4], SkBlendMode, 79 const SkPaint& paint) override; 80 81 void onDrawPaint(const SkPaint&) override; 82 void onDrawBehind(const SkPaint&) override; 83 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override; 84 void onDrawRect(const SkRect&, const SkPaint&) override; 85 void onDrawRegion(const SkRegion&, const SkPaint&) override; 86 void onDrawOval(const SkRect&, const SkPaint&) override; 87 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override; 88 void onDrawRRect(const SkRRect&, const SkPaint&) override; 89 void onDrawPath(const SkPath&, const SkPaint&) override; 90 91 void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&, 92 const SkPaint*) override; 93 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&, 94 const SkPaint*, SrcRectConstraint) override; 95 void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode, 96 const SkPaint*) override; 97 void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int, 98 SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override; 99 100 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override; 101 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override; 102 103 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override; 104 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override; 105 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override; 106 void onClipShader(sk_sp<SkShader>, SkClipOp) override; 107 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override; 108 void onResetClip() override; 109 110 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override; 111 112 void onDrawAnnotation(const SkRect&, const char[], SkData*) override; 113 114 void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&, 115 SkBlendMode) override; 116 void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[], 117 const SkSamplingOptions&, const SkPaint*, 118 SrcRectConstraint) override; 119 120 sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override; 121 122 void flushMiniRecorder(); 123 124 private: 125 template <typename T> 126 T* copy(const T*); 127 128 template <typename T> 129 T* copy(const T[], size_t count); 130 131 template<typename T, typename... Args> 132 void append(Args&&...); 133 134 size_t fApproxBytesUsedBySubPictures; 135 SkRecord* fRecord; 136 std::unique_ptr<SkDrawableList> fDrawableList; 137 138 SkMiniRecorder* fMiniRecorder; 139 }; 140 141 #endif//SkRecorder_DEFINED 142