blob: 9eb68319cb502db0b6e773c3daeb499aba29cc97 [file] [log] [blame]
commit-bot@chromium.orgc4b21e62014-04-11 18:33:31 +00001/*
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
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +00008#ifndef SkRecorder_DEFINED
9#define SkRecorder_DEFINED
10
11#include "SkCanvas.h"
12#include "SkRecord.h"
13#include "SkRecords.h"
mtklein29dfaa82014-09-04 14:12:44 -070014#include "SkTDArray.h"
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000015
16// SkRecorder provides an SkCanvas interface for recording into an SkRecord.
17
18class SkRecorder : public SkCanvas {
19public:
20 // Does not take ownership of the SkRecord.
commit-bot@chromium.orga0950412014-05-29 16:52:40 +000021 SkRecorder(SkRecord*, int width, int height);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000022
commit-bot@chromium.org732bd662014-04-24 15:22:55 +000023 // Make SkRecorder forget entirely about its SkRecord*; all calls to SkRecorder will fail.
24 void forgetRecord();
25
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000026 void clear(SkColor) SK_OVERRIDE;
27 void drawPaint(const SkPaint& paint) SK_OVERRIDE;
28 void drawPoints(PointMode mode,
29 size_t count,
30 const SkPoint pts[],
31 const SkPaint& paint) SK_OVERRIDE;
32 void drawRect(const SkRect& rect, const SkPaint& paint) SK_OVERRIDE;
33 void drawOval(const SkRect& oval, const SkPaint&) SK_OVERRIDE;
34 void drawRRect(const SkRRect& rrect, const SkPaint& paint) SK_OVERRIDE;
35 void drawPath(const SkPath& path, const SkPaint& paint) SK_OVERRIDE;
36 void drawBitmap(const SkBitmap& bitmap,
37 SkScalar left,
38 SkScalar top,
39 const SkPaint* paint = NULL) SK_OVERRIDE;
40 void drawBitmapRectToRect(const SkBitmap& bitmap,
41 const SkRect* src,
42 const SkRect& dst,
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000043 const SkPaint* paint = NULL,
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000044 DrawBitmapRectFlags flags = kNone_DrawBitmapRectFlag) SK_OVERRIDE;
45 void drawBitmapMatrix(const SkBitmap& bitmap,
46 const SkMatrix& m,
47 const SkPaint* paint = NULL) SK_OVERRIDE;
48 void drawBitmapNine(const SkBitmap& bitmap,
49 const SkIRect& center,
50 const SkRect& dst,
51 const SkPaint* paint = NULL) SK_OVERRIDE;
52 void drawSprite(const SkBitmap& bitmap,
53 int left,
54 int top,
55 const SkPaint* paint = NULL) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000056 void drawVertices(VertexMode vmode,
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000057 int vertexCount,
58 const SkPoint vertices[],
59 const SkPoint texs[],
60 const SkColor colors[],
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000061 SkXfermode* xmode,
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000062 const uint16_t indices[],
63 int indexCount,
64 const SkPaint& paint) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000065
Florin Malita5f6102d2014-06-30 10:13:28 -040066 void willSave() SK_OVERRIDE;
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000067 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
mtklein29dfaa82014-09-04 14:12:44 -070068 void willRestore() SK_OVERRIDE {}
mtklein6cfa73a2014-08-13 13:33:49 -070069 void didRestore() SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000070
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000071 void didConcat(const SkMatrix&) SK_OVERRIDE;
72 void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000073
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000074 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
reed@google.come0d9ce82014-04-23 04:00:17 +000075 void onDrawText(const void* text,
76 size_t byteLength,
77 SkScalar x,
78 SkScalar y,
79 const SkPaint& paint) SK_OVERRIDE;
80 void onDrawPosText(const void* text,
81 size_t byteLength,
82 const SkPoint pos[],
83 const SkPaint& paint) SK_OVERRIDE;
84 void onDrawPosTextH(const void* text,
85 size_t byteLength,
86 const SkScalar xpos[],
87 SkScalar constY,
88 const SkPaint& paint) SK_OVERRIDE;
89 void onDrawTextOnPath(const void* text,
90 size_t byteLength,
91 const SkPath& path,
92 const SkMatrix* matrix,
93 const SkPaint& paint) SK_OVERRIDE;
fmalita00d5c2c2014-08-21 08:53:26 -070094 void onDrawTextBlob(const SkTextBlob* blob,
95 SkScalar x,
96 SkScalar y,
fmalitab7425172014-08-26 07:56:44 -070097 const SkPaint& paint) SK_OVERRIDE;
dandovb3c9d1c2014-08-12 08:34:29 -070098 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
99 const SkPoint texCoords[4], SkXfermode* xmode,
100 const SkPaint& paint) SK_OVERRIDE;
mtklein6cfa73a2014-08-13 13:33:49 -0700101
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +0000102 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;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000106
reedd5fa1a42014-08-09 11:08:05 -0700107 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE;
robertphillips9b14f262014-06-04 05:40:44 -0700108
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +0000109 void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
110 void onPopCull() SK_OVERRIDE;
commit-bot@chromium.org03a99b82014-04-08 15:17:17 +0000111
mtklein5f0e8222014-08-22 11:44:26 -0700112 void beginCommentGroup(const char*) SK_OVERRIDE;
113 void addComment(const char*, const char*) SK_OVERRIDE;
114 void endCommentGroup() SK_OVERRIDE;
mtklein29dfaa82014-09-04 14:12:44 -0700115 void drawData(const void*, size_t) SK_OVERRIDE;
116
117 bool isDrawingToLayer() const SK_OVERRIDE;
reed3716fd02014-09-21 09:39:55 -0700118 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE { return NULL; }
mtklein5f0e8222014-08-22 11:44:26 -0700119
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000120private:
121 template <typename T>
122 T* copy(const T*);
123
124 template <typename T>
reed2347b622014-08-07 12:19:50 -0700125 T* copy(const T[], size_t count);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000126
mtkleina723b572014-08-15 11:49:49 -0700127 SkIRect devBounds() const {
128 SkIRect devBounds;
129 this->getClipDeviceBounds(&devBounds);
130 return devBounds;
131 }
132
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000133 SkRecord* fRecord;
mtklein29dfaa82014-09-04 14:12:44 -0700134
135 int fSaveLayerCount;
136 SkTDArray<SkBool8> fSaveIsSaveLayer;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000137};
138
139#endif//SkRecorder_DEFINED