blob: 6ac8a564756815402550dc359445c5a600f392ec [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;
piotaixr65151752014-10-16 11:58:39 -070052 virtual void drawImage(const SkImage* image, SkScalar left, SkScalar top,
53 const SkPaint* paint = NULL) SK_OVERRIDE;
54 virtual void drawImageRect(const SkImage* image, const SkRect* src,
55 const SkRect& dst,
56 const SkPaint* paint = NULL) SK_OVERRIDE;
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000057 void drawSprite(const SkBitmap& bitmap,
58 int left,
59 int top,
60 const SkPaint* paint = NULL) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000061 void drawVertices(VertexMode vmode,
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000062 int vertexCount,
63 const SkPoint vertices[],
64 const SkPoint texs[],
65 const SkColor colors[],
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000066 SkXfermode* xmode,
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000067 const uint16_t indices[],
68 int indexCount,
69 const SkPaint& paint) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000070
Florin Malita5f6102d2014-06-30 10:13:28 -040071 void willSave() SK_OVERRIDE;
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000072 SaveLayerStrategy willSaveLayer(const SkRect*, const SkPaint*, SkCanvas::SaveFlags) SK_OVERRIDE;
mtklein29dfaa82014-09-04 14:12:44 -070073 void willRestore() SK_OVERRIDE {}
mtklein6cfa73a2014-08-13 13:33:49 -070074 void didRestore() SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000075
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000076 void didConcat(const SkMatrix&) SK_OVERRIDE;
77 void didSetMatrix(const SkMatrix&) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +000078
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +000079 void onDrawDRRect(const SkRRect&, const SkRRect&, const SkPaint&) SK_OVERRIDE;
reed@google.come0d9ce82014-04-23 04:00:17 +000080 void onDrawText(const void* text,
81 size_t byteLength,
82 SkScalar x,
83 SkScalar y,
84 const SkPaint& paint) SK_OVERRIDE;
85 void onDrawPosText(const void* text,
86 size_t byteLength,
87 const SkPoint pos[],
88 const SkPaint& paint) SK_OVERRIDE;
89 void onDrawPosTextH(const void* text,
90 size_t byteLength,
91 const SkScalar xpos[],
92 SkScalar constY,
93 const SkPaint& paint) SK_OVERRIDE;
94 void onDrawTextOnPath(const void* text,
95 size_t byteLength,
96 const SkPath& path,
97 const SkMatrix* matrix,
98 const SkPaint& paint) SK_OVERRIDE;
fmalita00d5c2c2014-08-21 08:53:26 -070099 void onDrawTextBlob(const SkTextBlob* blob,
100 SkScalar x,
101 SkScalar y,
fmalitab7425172014-08-26 07:56:44 -0700102 const SkPaint& paint) SK_OVERRIDE;
dandovb3c9d1c2014-08-12 08:34:29 -0700103 void onDrawPatch(const SkPoint cubics[12], const SkColor colors[4],
104 const SkPoint texCoords[4], SkXfermode* xmode,
105 const SkPaint& paint) SK_OVERRIDE;
mtklein6cfa73a2014-08-13 13:33:49 -0700106
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +0000107 void onClipRect(const SkRect& rect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
108 void onClipRRect(const SkRRect& rrect, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
109 void onClipPath(const SkPath& path, SkRegion::Op op, ClipEdgeStyle edgeStyle) SK_OVERRIDE;
110 void onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) SK_OVERRIDE;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000111
reedd5fa1a42014-08-09 11:08:05 -0700112 void onDrawPicture(const SkPicture*, const SkMatrix*, const SkPaint*) SK_OVERRIDE;
robertphillips9b14f262014-06-04 05:40:44 -0700113
commit-bot@chromium.org066a28d2014-04-08 17:31:08 +0000114 void onPushCull(const SkRect& cullRect) SK_OVERRIDE;
115 void onPopCull() SK_OVERRIDE;
commit-bot@chromium.org03a99b82014-04-08 15:17:17 +0000116
mtklein5f0e8222014-08-22 11:44:26 -0700117 void beginCommentGroup(const char*) SK_OVERRIDE;
118 void addComment(const char*, const char*) SK_OVERRIDE;
119 void endCommentGroup() SK_OVERRIDE;
mtklein29dfaa82014-09-04 14:12:44 -0700120 void drawData(const void*, size_t) SK_OVERRIDE;
121
122 bool isDrawingToLayer() const SK_OVERRIDE;
reed4a8126e2014-09-22 07:29:03 -0700123 SkSurface* onNewSurface(const SkImageInfo&, const SkSurfaceProps&) SK_OVERRIDE { return NULL; }
mtklein5f0e8222014-08-22 11:44:26 -0700124
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000125private:
126 template <typename T>
127 T* copy(const T*);
128
129 template <typename T>
reed2347b622014-08-07 12:19:50 -0700130 T* copy(const T[], size_t count);
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000131
mtkleina723b572014-08-15 11:49:49 -0700132 SkIRect devBounds() const {
133 SkIRect devBounds;
134 this->getClipDeviceBounds(&devBounds);
135 return devBounds;
136 }
137
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000138 SkRecord* fRecord;
mtklein29dfaa82014-09-04 14:12:44 -0700139
140 int fSaveLayerCount;
141 SkTDArray<SkBool8> fSaveIsSaveLayer;
commit-bot@chromium.orge3ff5582014-04-01 16:24:06 +0000142};
143
144#endif//SkRecorder_DEFINED