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

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

Issue 585523003: Simplify a little in SkRecords.h: (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: safe ref Created 6 years, 3 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/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2014 Google Inc. 2 * Copyright 2014 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkRecords_DEFINED 8 #ifndef SkRecords_DEFINED
9 #define SkRecords_DEFINED 9 #define SkRecords_DEFINED
10 10
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 }; 111 };
112 112
113 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \ 113 #define RECORD5(T, A, a, B, b, C, c, D, d, E, e) \
114 struct T { \ 114 struct T { \
115 static const Type kType = T##_Type; \ 115 static const Type kType = T##_Type; \
116 template <typename Z, typename Y, typename X, typename W, typename V> \ 116 template <typename Z, typename Y, typename X, typename W, typename V> \
117 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ 117 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \
118 A a; B b; C c; D d; E e; \ 118 A a; B b; C c; D d; E e; \
119 }; 119 };
120 120
121 #define ACT_AS_PTR(ptr) \ 121 #define ACT_AS_PTR(ptr) \
122 operator T*() { return ptr; } \ 122 operator T*() const { return ptr; } \
tfarina 2014/09/18 17:35:43 why not keep non-const and const versions? it see
mtklein 2014/09/18 17:52:38 Mostly this is because it is inconvenient to use t
123 operator const T*() const { return ptr; } \ 123 T* operator->() const { return ptr; }
124 T* operator->() { return ptr; } \
125 const T* operator->() const { return ptr; }
126 124
127 template <typename T> 125 template <typename T>
128 class RefBox : SkNoncopyable { 126 class RefBox : SkNoncopyable {
129 public: 127 public:
130 RefBox(T* obj) : fObj(SkRef(obj)) {} 128 RefBox(T* obj) : fObj(SkSafeRef(obj)) {}
131 ~RefBox() { fObj->unref(); } 129 ~RefBox() { SkSafeUnref(fObj); }
132 130
133 ACT_AS_PTR(fObj); 131 ACT_AS_PTR(fObj);
134 132
135 private: 133 private:
136 T* fObj; 134 T* fObj;
137 }; 135 };
138 136
139 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD data. 137 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD data.
140 template <typename T> 138 template <typename T>
141 class Optional : SkNoncopyable { 139 class Optional : SkNoncopyable {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 SkRect, dst); 230 SkRect, dst);
233 RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint, 231 RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint,
234 ImmutableBitmap, bitmap, 232 ImmutableBitmap, bitmap,
235 Optional<SkRect>, src, 233 Optional<SkRect>, src,
236 SkRect, dst, 234 SkRect, dst,
237 SkCanvas::DrawBitmapRectFlags, flags); 235 SkCanvas::DrawBitmapRectFlags, flags);
238 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner); 236 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner);
239 RECORD2(DrawOval, SkPaint, paint, SkRect, oval); 237 RECORD2(DrawOval, SkPaint, paint, SkRect, oval);
240 RECORD1(DrawPaint, SkPaint, paint); 238 RECORD1(DrawPaint, SkPaint, paint);
241 RECORD2(DrawPath, SkPaint, paint, SkPath, path); 239 RECORD2(DrawPath, SkPaint, paint, SkPath, path);
242 //RECORD2(DrawPatch, SkPaint, paint, SkPatch, patch);
243 RECORD3(DrawPicture, Optional<SkPaint>, paint, 240 RECORD3(DrawPicture, Optional<SkPaint>, paint,
244 RefBox<const SkPicture>, picture, 241 RefBox<const SkPicture>, picture,
245 Optional<SkMatrix>, matrix); 242 Optional<SkMatrix>, matrix);
246 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, Sk Point*, pts); 243 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, Sk Point*, pts);
247 RECORD4(DrawPosText, SkPaint, paint, 244 RECORD4(DrawPosText, SkPaint, paint,
248 PODArray<char>, text, 245 PODArray<char>, text,
249 size_t, byteLength, 246 size_t, byteLength,
250 PODArray<SkPoint>, pos); 247 PODArray<SkPoint>, pos);
251 RECORD5(DrawPosTextH, SkPaint, paint, 248 RECORD5(DrawPosTextH, SkPaint, paint,
252 PODArray<char>, text, 249 PODArray<char>, text,
(...skipping 13 matching lines...) Expand all
266 SkScalar, x, 263 SkScalar, x,
267 SkScalar, y); 264 SkScalar, y);
268 RECORD5(DrawTextOnPath, SkPaint, paint, 265 RECORD5(DrawTextOnPath, SkPaint, paint,
269 PODArray<char>, text, 266 PODArray<char>, text,
270 size_t, byteLength, 267 size_t, byteLength,
271 SkPath, path, 268 SkPath, path,
272 Optional<SkMatrix>, matrix); 269 Optional<SkMatrix>, matrix);
273 270
274 RECORD2(DrawData, PODArray<char>, data, size_t, length); 271 RECORD2(DrawData, PODArray<char>, data, size_t, length);
275 272
273 RECORD5(DrawPatch, SkPaint, paint,
274 PODArray<SkPoint>, cubics,
275 PODArray<SkColor>, colors,
276 PODArray<SkPoint>, texCoords,
277 RefBox<SkXfermode>, xmode);
278
276 // This guy is so ugly we just write it manually. 279 // This guy is so ugly we just write it manually.
277 struct DrawVertices { 280 struct DrawVertices {
278 static const Type kType = DrawVertices_Type; 281 static const Type kType = DrawVertices_Type;
279 282
280 DrawVertices(const SkPaint& paint, 283 DrawVertices(const SkPaint& paint,
281 SkCanvas::VertexMode vmode, 284 SkCanvas::VertexMode vmode,
282 int vertexCount, 285 int vertexCount,
283 SkPoint* vertices, 286 SkPoint* vertices,
284 SkPoint* texs, 287 SkPoint* texs,
285 SkColor* colors, 288 SkColor* colors,
(...skipping 14 matching lines...) Expand all
300 SkCanvas::VertexMode vmode; 303 SkCanvas::VertexMode vmode;
301 int vertexCount; 304 int vertexCount;
302 PODArray<SkPoint> vertices; 305 PODArray<SkPoint> vertices;
303 PODArray<SkPoint> texs; 306 PODArray<SkPoint> texs;
304 PODArray<SkColor> colors; 307 PODArray<SkColor> colors;
305 SkAutoTUnref<SkXfermode> xmode; 308 SkAutoTUnref<SkXfermode> xmode;
306 PODArray<uint16_t> indices; 309 PODArray<uint16_t> indices;
307 int indexCount; 310 int indexCount;
308 }; 311 };
309 312
310 struct DrawPatch {
311 static const Type kType = DrawPatch_Type;
312
313 DrawPatch(const SkPaint& paint, SkPoint cubics[12], SkColor colors[4],
314 SkPoint texCoords[4], SkXfermode* xmode)
315 : paint(paint)
316 , cubics(cubics)
317 , colors(colors)
318 , texCoords(texCoords)
319 , xmode(SkSafeRef(xmode)) { }
320
321 SkPaint paint;
322 PODArray<SkPoint> cubics;
323 PODArray<SkColor> colors;
324 PODArray<SkPoint> texCoords;
325 SkAutoTUnref<SkXfermode> xmode;
326 };
327
328 #undef RECORD0 313 #undef RECORD0
329 #undef RECORD1 314 #undef RECORD1
330 #undef RECORD2 315 #undef RECORD2
331 #undef RECORD3 316 #undef RECORD3
332 #undef RECORD4 317 #undef RECORD4
333 #undef RECORD5 318 #undef RECORD5
334 319
335 } // namespace SkRecords 320 } // namespace SkRecords
336 321
337 #endif//SkRecords_DEFINED 322 #endif//SkRecords_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698