Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(742)

Side by Side Diff: src/record/SkRecords.h

Issue 206313003: SkRecord strawman (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: IsSmall -> IsLarge: pithier Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/record/SkRecorder.cpp ('k') | tools/bench_record.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #ifndef SkRecords_DEFINED
2 #define SkRecords_DEFINED
3
4 #include "SkCanvas.h"
5
6 namespace SkRecords {
7
8 // A list of all the types of canvas calls we can record.
9 // Each of these is reified into a struct below.
10 //
11 // (We're using the macro-of-macro trick here to do several different things wit h the same list.)
12 //
13 // We leave this SK_RECORD_TYPES macro defined for use by code that wants to ope rate on SkRecords
14 // types polymorphically. (See SkRecord::Record::{visit,mutate} for an example. )
15 #define SK_RECORD_TYPES(M) \
16 M(Restore) \
17 M(Save) \
18 M(SaveLayer) \
19 M(Concat) \
20 M(SetMatrix) \
21 M(ClipPath) \
22 M(ClipRRect) \
23 M(ClipRect) \
24 M(ClipRegion) \
25 M(Clear) \
26 M(DrawBitmap) \
27 M(DrawBitmapMatrix) \
28 M(DrawBitmapNine) \
29 M(DrawBitmapRectToRect) \
30 M(DrawDRRect) \
31 M(DrawOval) \
32 M(DrawPaint) \
33 M(DrawPath) \
34 M(DrawPoints) \
35 M(DrawPosText) \
36 M(DrawPosTextH) \
37 M(DrawRRect) \
38 M(DrawRect) \
39 M(DrawSprite) \
40 M(DrawText) \
41 M(DrawTextOnPath) \
42 M(DrawVertices)
43
44 // Defines SkRecords::Type, an enum of all record types.
45 #define ENUM(T) T##_Type,
46 enum Type { SK_RECORD_TYPES(ENUM) };
47 #undef ENUM
48
49 // Macros to make it easier to define a record for a draw call with 0 args, 1 ar gs, 2 args, etc.
50 // These should be clearer when you look at their use below.
51 #define RECORD0(T) \
52 struct T { \
53 static const Type kType = T##_Type; \
54 T() {} \
55 };
56
57 // We try to be flexible about the types the constructors take. Instead of requ ring the exact type
58 // A here, we take any type Z which implicitly casts to A. This allows the dela y_copy() trick to
59 // work, allowing the caller to decide whether to pass by value or by const&.
60
61 #define RECORD1(T, A, a) \
62 struct T { \
63 static const Type kType = T##_Type; \
64 template <typename Z> \
65 T(Z a) : a(a) {} \
66 A a; \
67 };
68
69 #define RECORD2(T, A, a, B, b) \
70 struct T { \
71 static const Type kType = T##_Type; \
72 template <typename Z, typename Y> \
73 T(Z a, Y b) : a(a), b(b) {} \
74 A a; B b; \
75 };
76
77 #define RECORD3(T, A, a, B, b, C, c) \
78 struct T { \
79 static const Type kType = T##_Type; \
80 template <typename Z, typename Y, typename X> \
81 T(Z a, Y b, X c) : a(a), b(b), c(c) {} \
82 A a; B b; C c; \
83 };
84
85 #define RECORD4(T, A, a, B, b, C, c, D, d) \
86 struct T { \
87 static const Type kType = T##_Type; \
88 template <typename Z, typename Y, typename X, typename W> \
89 T(Z a, Y b, X c, W d) : a(a), b(b), c(c), d(d) {} \
90 A a; B b; C c; D d; \
91 };
92
93 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \
94 struct T { \
95 static const Type kType = T##_Type; \
96 template <typename Z, typename Y, typename X, typename W, typename V> \
97 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \
98 A a; B b; C c; D d; E e; \
99 };
100
101 // Like SkBitmap, but deep copies pixels if they're not immutable.
102 // Using this, we guarantee the immutability of all bitmaps we record.
103 class ImmutableBitmap {
104 public:
105 explicit ImmutableBitmap(const SkBitmap& bitmap) {
106 if (bitmap.isImmutable()) {
107 fBitmap = bitmap;
108 } else {
109 bitmap.copyTo(&fBitmap);
110 }
111 fBitmap.setImmutable();
112 }
113
114 operator const SkBitmap& () const { return fBitmap; }
115
116 private:
117 SkBitmap fBitmap;
118 };
119
120 // Pointers here represent either an optional value or an array if accompanied b y a count.
121 // None of these records manages the lifetimes of pointers, except for DrawVerti ces handling its
122 // Xfermode specially.
123
124 RECORD0(Restore);
125 RECORD1(Save, SkCanvas::SaveFlags, flags);
126 RECORD3(SaveLayer, SkRect*, bounds, SkPaint*, paint, SkCanvas::SaveFlags, flags) ;
127
128 RECORD1(Concat, SkMatrix, matrix);
129 RECORD1(SetMatrix, SkMatrix, matrix);
130
131 RECORD3(ClipPath, SkPath, path, SkRegion::Op, op, bool, doAA);
132 RECORD3(ClipRRect, SkRRect, rrect, SkRegion::Op, op, bool, doAA);
133 RECORD3(ClipRect, SkRect, rect, SkRegion::Op, op, bool, doAA);
134 RECORD2(ClipRegion, SkRegion, region, SkRegion::Op, op);
135
136 RECORD1(Clear, SkColor, color);
137 RECORD4(DrawBitmap, ImmutableBitmap, bitmap, SkScalar, left, SkScalar, top, SkPa int*, paint);
138 RECORD3(DrawBitmapMatrix, ImmutableBitmap, bitmap, SkMatrix, matrix, SkPaint*, p aint);
139 RECORD4(DrawBitmapNine, ImmutableBitmap, bitmap, SkIRect, center, SkRect, dst, S kPaint*, paint);
140 RECORD5(DrawBitmapRectToRect, ImmutableBitmap, bitmap,
141 SkRect*, src,
142 SkRect, dst,
143 SkPaint*, paint,
144 SkCanvas::DrawBitmapRectFlags, flags);
145 RECORD3(DrawDRRect, SkRRect, outer, SkRRect, inner, SkPaint, paint);
146 RECORD2(DrawOval, SkRect, oval, SkPaint, paint);
147 RECORD1(DrawPaint, SkPaint, paint);
148 RECORD2(DrawPath, SkPath, path, SkPaint, paint);
149 RECORD4(DrawPoints, SkCanvas::PointMode, mode, size_t, count, SkPoint*, pts, SkP aint, paint);
150 RECORD4(DrawPosText, char*, text, size_t, byteLength, SkPoint*, pos, SkPaint, pa int);
151 RECORD5(DrawPosTextH, char*, text,
152 size_t, byteLength,
153 SkScalar*, xpos,
154 SkScalar, y,
155 SkPaint, paint);
156 RECORD2(DrawRRect, SkRRect, rrect, SkPaint, paint);
157 RECORD2(DrawRect, SkRect, rect, SkPaint, paint);
158 RECORD4(DrawSprite, ImmutableBitmap, bitmap, int, left, int, top, SkPaint*, pain t);
159 RECORD5(DrawText, char*, text, size_t, byteLength, SkScalar, x, SkScalar, y, SkP aint, paint);
160 RECORD5(DrawTextOnPath, char*, text,
161 size_t, byteLength,
162 SkPath, path,
163 SkMatrix*, matrix,
164 SkPaint, paint);
165
166 // This guy is so ugly we just write it manually.
167 struct DrawVertices {
168 static const Type kType = DrawVertices_Type;
169
170 DrawVertices(SkCanvas::VertexMode vmode,
171 int vertexCount,
172 SkPoint* vertices,
173 SkPoint* texs,
174 SkColor* colors,
175 SkXfermode* xmode,
176 uint16_t* indices,
177 int indexCount,
178 const SkPaint& paint)
179 : vmode(vmode)
180 , vertexCount(vertexCount)
181 , vertices(vertices)
182 , texs(texs)
183 , colors(colors)
184 , xmode(SkSafeRef(xmode))
185 , indices(indices)
186 , indexCount(indexCount)
187 , paint(paint) {}
188
189 SkCanvas::VertexMode vmode;
190 int vertexCount;
191 SkPoint* vertices;
192 SkPoint* texs;
193 SkColor* colors;
194 SkAutoTUnref<SkXfermode> xmode;
195 uint16_t* indices;
196 int indexCount;
197 SkPaint paint;
198 };
199
200 #undef RECORD0
201 #undef RECORD1
202 #undef RECORD2
203 #undef RECORD3
204 #undef RECORD4
205 #undef RECORD5
206
207 } // namespace SkRecords
208
209 #endif//SkRecords_DEFINED
OLDNEW
« no previous file with comments | « src/record/SkRecorder.cpp ('k') | tools/bench_record.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698