• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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);   // legacy version
44     SkRecorder(SkRecord*, const SkRect& bounds, SkMiniRecorder* = nullptr);
45 
46     enum DrawPictureMode { Record_DrawPictureMode, Playback_DrawPictureMode };
47     void reset(SkRecord*, const SkRect& bounds, DrawPictureMode, SkMiniRecorder* = nullptr);
48 
approxBytesUsedBySubPictures()49     size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; }
50 
getDrawableList()51     SkDrawableList* getDrawableList() const { return fDrawableList.get(); }
detachDrawableList()52     std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); }
53 
54     // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
55     void forgetRecord();
56 
57     void onFlush() override;
58 
59     void willSave() override;
60     SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
61     bool onDoSaveBehind(const SkRect*) override;
willRestore()62     void willRestore() override {}
63     void didRestore() override;
64 
65     void didConcat(const SkMatrix&) override;
66     void didSetMatrix(const SkMatrix&) override;
67     void didTranslate(SkScalar, SkScalar) override;
68 
69     void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
70     void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
71     void onDrawTextBlob(const SkTextBlob* blob,
72                         SkScalar x,
73                         SkScalar y,
74                         const SkPaint& paint) override;
75     void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
76                      const SkPoint texCoords[4], SkBlendMode,
77                      const SkPaint& paint) override;
78 
79     void onDrawPaint(const SkPaint&) override;
80     void onDrawBehind(const SkPaint&) override;
81     void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
82     void onDrawRect(const SkRect&, const SkPaint&) override;
83     void onDrawRegion(const SkRegion&, const SkPaint&) override;
84     void onDrawOval(const SkRect&, const SkPaint&) override;
85     void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
86     void onDrawRRect(const SkRRect&, const SkPaint&) override;
87     void onDrawPath(const SkPath&, const SkPaint&) override;
88     void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
89     void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
90                           SrcRectConstraint) override;
91     void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
92     void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
93                          const SkPaint*, SrcRectConstraint) override;
94     void onDrawImageNine(const SkImage*, const SkIRect& center, const SkRect& dst,
95                          const SkPaint*) override;
96     void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
97                           const SkPaint*) override;
98     void onDrawImageLattice(const SkImage*, const Lattice& lattice, const SkRect& dst,
99                             const SkPaint*) override;
100     void onDrawBitmapLattice(const SkBitmap&, const Lattice& lattice, const SkRect& dst,
101                              const SkPaint*) override;
102     void onDrawVerticesObject(const SkVertices*, const SkVertices::Bone bones[], int boneCount,
103                               SkBlendMode, const SkPaint&) override;
104     void onDrawAtlas(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[],
105                      int count, SkBlendMode, const SkRect* cull, const SkPaint*) override;
106     void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
107 
108     void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override;
109     void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override;
110     void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override;
111     void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
112 
113     void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
114 
115     void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
116 
117     void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, SkColor,
118                           SkBlendMode) override;
119     void onDrawEdgeAAImageSet(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
120                               const SkPaint*, SrcRectConstraint) override;
121 
122     sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
123 
124     void flushMiniRecorder();
125 
126 private:
127     template <typename T>
128     T* copy(const T*);
129 
130     template <typename T>
131     T* copy(const T[], size_t count);
132 
133     template<typename T, typename... Args>
134     void append(Args&&...);
135 
136     DrawPictureMode fDrawPictureMode;
137     size_t fApproxBytesUsedBySubPictures;
138     SkRecord* fRecord;
139     std::unique_ptr<SkDrawableList> fDrawableList;
140 
141     SkMiniRecorder* fMiniRecorder;
142 };
143 
144 #endif//SkRecorder_DEFINED
145