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/core/SkColor.h"
13#include "include/core/SkM44.h"
14#include "include/core/SkRefCnt.h"
15#include "include/core/SkSamplingOptions.h"
16#include "include/core/SkScalar.h"
17#include "include/private/base/SkNoncopyable.h"
18#include "include/private/base/SkTDArray.h"
19#include "include/utils/SkNoDrawCanvas.h"
20#include "src/core/SkBigPicture.h"
21
22#include <cstddef>
23#include <memory>
24#include <utility>
25
26class SkBlender;
27class SkData;
28class SkDrawable;
29class SkImage;
30class SkMatrix;
31class SkMesh;
32class SkPaint;
33class SkPath;
34class SkPicture;
35class SkRRect;
36class SkRecord;
37class SkRegion;
38class SkShader;
39class SkSurface;
40class SkSurfaceProps;
41class SkTextBlob;
42class SkVertices;
43enum class SkBlendMode;
44enum class SkClipOp;
45struct SkDrawShadowRec;
46struct SkImageInfo;
47struct SkPoint;
48struct SkRSXform;
49struct SkRect;
50
51namespace sktext {
52 class GlyphRunList;
53 namespace gpu { class Slug; }
54}
55
56class SkDrawableList : SkNoncopyable {
57public:
58 SkDrawableList() {}
59 ~SkDrawableList();
60
61 int count() const { return fArray.size(); }
62 SkDrawable* const* begin() const { return fArray.begin(); }
63 SkDrawable* const* end() const { return fArray.end(); }
64
65 void append(SkDrawable* drawable);
66
67 // Return a new or ref'd array of pictures that were snapped from our drawables.
68 SkBigPicture::SnapshotArray* newDrawableSnapshot();
69
70private:
71 SkTDArray<SkDrawable*> fArray;
72};
73
74// SkRecorder provides an SkCanvas interface for recording into an SkRecord.
75
76class SkRecorder final : public SkCanvasVirtualEnforcer<SkNoDrawCanvas> {
77public:
78 // Does not take ownership of the SkRecord.
79 SkRecorder(SkRecord*, int width, int height); // TODO: remove
80 SkRecorder(SkRecord*, const SkRect& bounds);
81
82 void reset(SkRecord*, const SkRect& bounds);
83
84 size_t approxBytesUsedBySubPictures() const { return fApproxBytesUsedBySubPictures; }
85
86 SkDrawableList* getDrawableList() const { return fDrawableList.get(); }
87 std::unique_ptr<SkDrawableList> detachDrawableList() { return std::move(fDrawableList); }
88
89 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
90 void forgetRecord();
91
92 void willSave() override;
93 SaveLayerStrategy getSaveLayerStrategy(const SaveLayerRec&) override;
94 bool onDoSaveBehind(const SkRect*) override;
95 void willRestore() override {}
96 void didRestore() override;
97
98 void didConcat44(const SkM44&) override;
99 void didSetM44(const SkM44&) override;
100 void didScale(SkScalar, SkScalar) override;
101 void didTranslate(SkScalar, SkScalar) override;
102
103 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
104 void onDrawDrawable(SkDrawable*, const SkMatrix*) override;
105 void onDrawTextBlob(const SkTextBlob* blob,
106 SkScalar x,
107 SkScalar y,
108 const SkPaint& paint) override;
109 void onDrawSlug(const sktext::gpu::Slug* slug) override;
110 void onDrawGlyphRunList(
111 const sktext::GlyphRunList& glyphRunList, const SkPaint& paint) override;
112 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
113 const SkPoint texCoords[4], SkBlendMode,
114 const SkPaint& paint) override;
115
116 void onDrawPaint(const SkPaint&) override;
117 void onDrawBehind(const SkPaint&) override;
118 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
119 void onDrawRect(const SkRect&, const SkPaint&) override;
120 void onDrawRegion(const SkRegion&, const SkPaint&) override;
121 void onDrawOval(const SkRect&, const SkPaint&) override;
122 void onDrawArc(const SkRect&, SkScalar, SkScalar, bool, const SkPaint&) override;
123 void onDrawRRect(const SkRRect&, const SkPaint&) override;
124 void onDrawPath(const SkPath&, const SkPaint&) override;
125
126 void onDrawImage2(const SkImage*, SkScalar, SkScalar, const SkSamplingOptions&,
127 const SkPaint*) override;
128 void onDrawImageRect2(const SkImage*, const SkRect&, const SkRect&, const SkSamplingOptions&,
129 const SkPaint*, SrcRectConstraint) override;
130 void onDrawImageLattice2(const SkImage*, const Lattice&, const SkRect&, SkFilterMode,
131 const SkPaint*) override;
132 void onDrawAtlas2(const SkImage*, const SkRSXform[], const SkRect[], const SkColor[], int,
133 SkBlendMode, const SkSamplingOptions&, const SkRect*, const SkPaint*) override;
134
135 void onDrawVerticesObject(const SkVertices*, SkBlendMode, const SkPaint&) override;
136#ifdef SK_ENABLE_SKSL
137 void onDrawMesh(const SkMesh&, sk_sp<SkBlender>, const SkPaint&) override;
138#endif
139 void onDrawShadowRec(const SkPath&, const SkDrawShadowRec&) override;
140
141 void onClipRect(const SkRect& rect, SkClipOp, ClipEdgeStyle) override;
142 void onClipRRect(const SkRRect& rrect, SkClipOp, ClipEdgeStyle) override;
143 void onClipPath(const SkPath& path, SkClipOp, ClipEdgeStyle) override;
144 void onClipShader(sk_sp<SkShader>, SkClipOp) override;
145 void onClipRegion(const SkRegion& deviceRgn, SkClipOp) override;
146 void onResetClip() override;
147
148 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
149
150 void onDrawAnnotation(const SkRect&, const char[], SkData*) override;
151
152 void onDrawEdgeAAQuad(const SkRect&, const SkPoint[4], QuadAAFlags, const SkColor4f&,
153 SkBlendMode) override;
154 void onDrawEdgeAAImageSet2(const ImageSetEntry[], int count, const SkPoint[], const SkMatrix[],
155 const SkSamplingOptions&, const SkPaint*,
156 SrcRectConstraint) override;
157
158 sk_sp<SkSurface> onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override;
159
160private:
161 template <typename T>
162 T* copy(const T*);
163
164 template <typename T>
165 T* copy(const T[], size_t count);
166
167 template<typename T, typename... Args>
168 void append(Args&&...);
169
170 size_t fApproxBytesUsedBySubPictures;
171 SkRecord* fRecord;
172 std::unique_ptr<SkDrawableList> fDrawableList;
173};
174
175#endif//SkRecorder_DEFINED
176

source code of flutter_engine/third_party/skia/src/core/SkRecorder.h