OLD | NEW |
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 |
11 #include "SkCanvas.h" | 11 #include "SkCanvas.h" |
12 #include "SkPicture.h" | 12 #include "SkPicture.h" |
13 #include "SkTextBlob.h" | 13 #include "SkTextBlob.h" |
14 | 14 |
15 namespace SkRecords { | 15 namespace SkRecords { |
16 | 16 |
17 template <typename T> | |
18 class RefBox : SkNoncopyable { | |
19 public: | |
20 RefBox(const T* obj) : fObj(SkRef(obj)) {} | |
21 ~RefBox() { fObj->unref(); } | |
22 | |
23 operator const T*() const { return fObj; } | |
24 | |
25 private: | |
26 const T* fObj; | |
27 }; | |
28 | |
29 // A list of all the types of canvas calls we can record. | 17 // A list of all the types of canvas calls we can record. |
30 // Each of these is reified into a struct below. | 18 // Each of these is reified into a struct below. |
31 // | 19 // |
32 // (We're using the macro-of-macro trick here to do several different things wit
h the same list.) | 20 // (We're using the macro-of-macro trick here to do several different things wit
h the same list.) |
33 // | 21 // |
34 // We leave this SK_RECORD_TYPES macro defined for use by code that wants to ope
rate on SkRecords | 22 // We leave this SK_RECORD_TYPES macro defined for use by code that wants to ope
rate on SkRecords |
35 // types polymorphically. (See SkRecord::Record::{visit,mutate} for an example.
) | 23 // types polymorphically. (See SkRecord::Record::{visit,mutate} for an example.
) |
36 // | 24 // |
37 // Order doesn't technically matter here, but the compiler can generally generat
e better code if | 25 // Order doesn't technically matter here, but the compiler can generally generat
e better code if |
38 // you keep them semantically grouped, especially the Draws. It's also nice to
leave NoOp at 0. | 26 // you keep them semantically grouped, especially the Draws. It's also nice to
leave NoOp at 0. |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ | 113 T(Z a, Y b, X c, W d, V e) : a(a), b(b), c(c), d(d), e(e) {} \ |
126 A a; B b; C c; D d; E e; \ | 114 A a; B b; C c; D d; E e; \ |
127 }; | 115 }; |
128 | 116 |
129 #define ACT_AS_PTR(ptr) \ | 117 #define ACT_AS_PTR(ptr) \ |
130 operator T*() { return ptr; } \ | 118 operator T*() { return ptr; } \ |
131 operator const T*() const { return ptr; } \ | 119 operator const T*() const { return ptr; } \ |
132 T* operator->() { return ptr; } \ | 120 T* operator->() { return ptr; } \ |
133 const T* operator->() const { return ptr; } | 121 const T* operator->() const { return ptr; } |
134 | 122 |
| 123 template <typename T> |
| 124 class RefBox : SkNoncopyable { |
| 125 public: |
| 126 RefBox(T* obj) : fObj(SkRef(obj)) {} |
| 127 ~RefBox() { fObj->unref(); } |
| 128 |
| 129 ACT_AS_PTR(fObj); |
| 130 |
| 131 private: |
| 132 T* fObj; |
| 133 }; |
| 134 |
135 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD
data. | 135 // An Optional doesn't own the pointer's memory, but may need to destroy non-POD
data. |
136 template <typename T> | 136 template <typename T> |
137 class Optional : SkNoncopyable { | 137 class Optional : SkNoncopyable { |
138 public: | 138 public: |
139 Optional(T* ptr) : fPtr(ptr) {} | 139 Optional(T* ptr) : fPtr(ptr) {} |
140 ~Optional() { if (fPtr) fPtr->~T(); } | 140 ~Optional() { if (fPtr) fPtr->~T(); } |
141 | 141 |
142 ACT_AS_PTR(fPtr); | 142 ACT_AS_PTR(fPtr); |
143 private: | 143 private: |
144 T* fPtr; | 144 T* fPtr; |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint, | 224 RECORD5(DrawBitmapRectToRect, Optional<SkPaint>, paint, |
225 ImmutableBitmap, bitmap, | 225 ImmutableBitmap, bitmap, |
226 Optional<SkRect>, src, | 226 Optional<SkRect>, src, |
227 SkRect, dst, | 227 SkRect, dst, |
228 SkCanvas::DrawBitmapRectFlags, flags); | 228 SkCanvas::DrawBitmapRectFlags, flags); |
229 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner); | 229 RECORD3(DrawDRRect, SkPaint, paint, SkRRect, outer, SkRRect, inner); |
230 RECORD2(DrawOval, SkPaint, paint, SkRect, oval); | 230 RECORD2(DrawOval, SkPaint, paint, SkRect, oval); |
231 RECORD1(DrawPaint, SkPaint, paint); | 231 RECORD1(DrawPaint, SkPaint, paint); |
232 RECORD2(DrawPath, SkPaint, paint, SkPath, path); | 232 RECORD2(DrawPath, SkPaint, paint, SkPath, path); |
233 //RECORD2(DrawPatch, SkPaint, paint, SkPatch, patch); | 233 //RECORD2(DrawPatch, SkPaint, paint, SkPatch, patch); |
234 RECORD3(DrawPicture, Optional<SkPaint>, paint, RefBox<SkPicture>, picture, Optio
nal<SkMatrix>, matrix); | 234 RECORD3(DrawPicture, Optional<SkPaint>, paint, |
| 235 RefBox<const SkPicture>, picture, |
| 236 Optional<SkMatrix>, matrix); |
235 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, Sk
Point*, pts); | 237 RECORD4(DrawPoints, SkPaint, paint, SkCanvas::PointMode, mode, size_t, count, Sk
Point*, pts); |
236 RECORD4(DrawPosText, SkPaint, paint, | 238 RECORD4(DrawPosText, SkPaint, paint, |
237 PODArray<char>, text, | 239 PODArray<char>, text, |
238 size_t, byteLength, | 240 size_t, byteLength, |
239 PODArray<SkPoint>, pos); | 241 PODArray<SkPoint>, pos); |
240 RECORD5(DrawPosTextH, SkPaint, paint, | 242 RECORD5(DrawPosTextH, SkPaint, paint, |
241 PODArray<char>, text, | 243 PODArray<char>, text, |
242 size_t, byteLength, | 244 size_t, byteLength, |
243 PODArray<SkScalar>, xpos, | 245 PODArray<SkScalar>, xpos, |
244 SkScalar, y); | 246 SkScalar, y); |
245 RECORD2(DrawRRect, SkPaint, paint, SkRRect, rrect); | 247 RECORD2(DrawRRect, SkPaint, paint, SkRRect, rrect); |
246 RECORD2(DrawRect, SkPaint, paint, SkRect, rect); | 248 RECORD2(DrawRect, SkPaint, paint, SkRect, rect); |
247 RECORD4(DrawSprite, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, int, left
, int, top); | 249 RECORD4(DrawSprite, Optional<SkPaint>, paint, ImmutableBitmap, bitmap, int, left
, int, top); |
248 RECORD5(DrawText, SkPaint, paint, | 250 RECORD5(DrawText, SkPaint, paint, |
249 PODArray<char>, text, | 251 PODArray<char>, text, |
250 size_t, byteLength, | 252 size_t, byteLength, |
251 SkScalar, x, | 253 SkScalar, x, |
252 SkScalar, y); | 254 SkScalar, y); |
253 RECORD4(DrawTextBlob, SkPaint, paint, | 255 RECORD4(DrawTextBlob, SkPaint, paint, |
254 RefBox<SkTextBlob>, blob, | 256 RefBox<const SkTextBlob>, blob, |
255 SkScalar, x, | 257 SkScalar, x, |
256 SkScalar, y); | 258 SkScalar, y); |
257 RECORD5(DrawTextOnPath, SkPaint, paint, | 259 RECORD5(DrawTextOnPath, SkPaint, paint, |
258 PODArray<char>, text, | 260 PODArray<char>, text, |
259 size_t, byteLength, | 261 size_t, byteLength, |
260 SkPath, path, | 262 SkPath, path, |
261 Optional<SkMatrix>, matrix); | 263 Optional<SkMatrix>, matrix); |
262 | 264 |
263 // This guy is so ugly we just write it manually. | 265 // This guy is so ugly we just write it manually. |
264 struct DrawVertices { | 266 struct DrawVertices { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 #undef RECORD0 | 317 #undef RECORD0 |
316 #undef RECORD1 | 318 #undef RECORD1 |
317 #undef RECORD2 | 319 #undef RECORD2 |
318 #undef RECORD3 | 320 #undef RECORD3 |
319 #undef RECORD4 | 321 #undef RECORD4 |
320 #undef RECORD5 | 322 #undef RECORD5 |
321 | 323 |
322 } // namespace SkRecords | 324 } // namespace SkRecords |
323 | 325 |
324 #endif//SkRecords_DEFINED | 326 #endif//SkRecords_DEFINED |
OLD | NEW |