2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkRecorder_DEFINED
9 #define SkRecorder_DEFINED
13 #include "SkRecords.h"
14 #include "SkTDArray.h"
18 class SkDrawableList : SkNoncopyable {
22 int count() const { return fArray.count(); }
23 SkDrawable* const* begin() const { return fArray.begin(); }
25 void append(SkDrawable* drawable);
27 // Return a new or ref'd array of pictures that were snapped from our drawables.
28 SkPicture::SnapshotArray* newDrawableSnapshot();
31 SkTDArray<SkDrawable*> fArray;
34 // SkRecorder provides an SkCanvas interface for recording into an SkRecord.
36 class SkRecorder : public SkCanvas {
38 // Does not take ownership of the SkRecord.
39 SkRecorder(SkRecord*, int width, int height); // legacy version
40 SkRecorder(SkRecord*, const SkRect& bounds);
42 SkDrawableList* getDrawableList() const { return fDrawableList.get(); }
43 SkDrawableList* detachDrawableList() { return fDrawableList.detach(); }
45 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
48 void willSave() override;
49 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) override;
50 void willRestore() override {}
51 void didRestore() override;
53 void didConcat(const SkMatrix&) override;
54 void didSetMatrix(const SkMatrix&) override;
56 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) override;
57 void onDrawDrawable(SkDrawable*) override;
58 void onDrawText(const void* text,
62 const SkPaint& paint) override;
63 void onDrawPosText(const void* text,
66 const SkPaint& paint) override;
67 void onDrawPosTextH(const void* text,
69 const SkScalar xpos[],
71 const SkPaint& paint) override;
72 void onDrawTextOnPath(const void* text,
75 const SkMatrix* matrix,
76 const SkPaint& paint) override;
77 void onDrawTextBlob(const SkTextBlob* blob,
80 const SkPaint& paint) override;
81 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
82 const SkPoint texCoords[4], SkXfermode* xmode,
83 const SkPaint& paint) override;
85 void onDrawPaint(const SkPaint&) override;
86 void onDrawPoints(PointMode, size_t count, const SkPoint pts[], const SkPaint&) override;
87 void onDrawRect(const SkRect&, const SkPaint&) override;
88 void onDrawOval(const SkRect&, const SkPaint&) override;
89 void onDrawRRect(const SkRRect&, const SkPaint&) override;
90 void onDrawPath(const SkPath&, const SkPaint&) override;
91 void onDrawBitmap(const SkBitmap&, SkScalar left, SkScalar top, const SkPaint*) override;
92 void onDrawBitmapRect(const SkBitmap&, const SkRect* src, const SkRect& dst, const SkPaint*,
93 DrawBitmapRectFlags flags) override;
94 void onDrawImage(const SkImage*, SkScalar left, SkScalar top, const SkPaint*) override;
95 void onDrawImageRect(const SkImage*, const SkRect* src, const SkRect& dst,
96 const SkPaint*) override;
97 void onDrawBitmapNine(const SkBitmap&, const SkIRect& center, const SkRect& dst,
98 const SkPaint*) override;
99 void onDrawSprite(const SkBitmap&, int left, int top, const SkPaint*) override;
100 void onDrawVertices(VertexMode vmode, int vertexCount,
101 const SkPoint vertices[], const SkPoint texs[],
102 const SkColor colors[], SkXfermode* xmode,
103 const uint16_t indices[], int indexCount,
104 const SkPaint&) override;
106 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
107 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
108 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) override;
109 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) override;
111 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) override;
113 void beginCommentGroup(const char*) override;
114 void addComment(const char*, const char*) override;
115 void endCommentGroup() override;
117 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) override { return NULL; }
120 template <typename T>
123 template <typename T>
124 T* copy(const T[], size_t count);
126 SkIRect devBounds() const {
128 this->getClipDeviceBounds(&devBounds);
134 SkAutoTDelete<SkDrawableList> fDrawableList;
137 #endif//SkRecorder_DEFINED