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"
15 // SkRecorder provides an SkCanvas interface for recording into an SkRecord.
17 class SkRecorder : public SkCanvas {
19 // SkRecorder can work in two modes:
20 // write-only: only a core subset of SkCanvas operations (save/restore, clip, transform, draw)
21 // are supported, and all of the readback methods on SkCanvas will probably fail or lie.
23 // read-write: all methods should behave with similar semantics to SkCanvas.
25 // Write-only averages 10-20% faster, but you can't sensibly inspect the canvas while recording.
26 enum Mode { kWriteOnly_Mode, kReadWrite_Mode };
28 // Does not take ownership of the SkRecord.
29 SkRecorder(Mode mode, SkRecord*, int width, int height);
31 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
34 void clear(SkColor) SK_OVERRIDE;
35 void drawPaint(const SkPaint& paint) SK_OVERRIDE;
36 void drawPoints(PointMode mode,
39 const SkPaint& paint) SK_OVERRIDE;
40 void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
41 void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
42 void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
43 void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
44 void drawBitmap(const SkBitmap& bitmap,
47 const SkPaint* paint = NULL) SK_OVERRIDE;
48 void drawBitmapRectToRect(const SkBitmap& bitmap,
51 const SkPaint* paint = NULL,
52 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) SK_OVERRIDE;
53 void drawBitmapMatrix(const SkBitmap& bitmap,
55 const SkPaint* paint = NULL) SK_OVERRIDE;
56 void drawBitmapNine(const SkBitmap& bitmap,
57 const SkIRect& center,
59 const SkPaint* paint = NULL) SK_OVERRIDE;
60 void drawSprite(const SkBitmap& bitmap,
63 const SkPaint* paint = NULL) SK_OVERRIDE;
64 void drawPicture(SkPicture& picture) SK_OVERRIDE;
65 void drawVertices(VertexMode vmode,
67 const SkPoint vertices[],
69 const SkColor colors[],
71 const uint16_t indices[],
73 const SkPaint& paint) SK_OVERRIDE;
75 void willSave(SkCanvas::SaveFlags) SK_OVERRIDE;
76 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
77 void willRestore() SK_OVERRIDE;
79 void didConcat(const SkMatrix&) SK_OVERRIDE;
80 void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
82 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
83 void onDrawText(const void* text,
87 const SkPaint& paint) SK_OVERRIDE;
88 void onDrawPosText(const void* text,
91 const SkPaint& paint) SK_OVERRIDE;
92 void onDrawPosTextH(const void* text,
94 const SkScalar xpos[],
96 const SkPaint& paint) SK_OVERRIDE;
97 void onDrawTextOnPath(const void* text,
100 const SkMatrix* matrix,
101 const SkPaint& paint) SK_OVERRIDE;
102 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
103 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
104 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
105 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) SK_OVERRIDE;
107 void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
108 void onPopCull() SK_OVERRIDE;
111 template <typename T>
114 template <typename T>
115 T* copy(const T[], unsigned count);
121 #endif//SkRecorder_DEFINED