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 #include "SkBigPicture.h" | 8 #include "SkBigPicture.h" |
9 #include "SkCanvasPriv.h" | 9 #include "SkCanvasPriv.h" |
10 #include "SkPatchUtils.h" | 10 #include "SkPatchUtils.h" |
11 #include "SkPicture.h" | 11 #include "SkPicture.h" |
12 #include "SkPictureUtils.h" | 12 #include "SkPictureUtils.h" |
13 #include "SkRecorder.h" | 13 #include "SkRecorder.h" |
14 | 14 |
15 //#define WRAP_BITMAP_AS_IMAGE | 15 //#define WRAP_BITMAP_AS_IMAGE |
16 | 16 |
17 SkDrawableList::~SkDrawableList() { | 17 SkDrawableList::~SkDrawableList() { |
18 fArray.unrefAll(); | 18 fArray.unrefAll(); |
19 } | 19 } |
20 | 20 |
21 SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { | 21 SkBigPicture::SnapshotArray* SkDrawableList::newDrawableSnapshot() { |
22 const int count = fArray.count(); | 22 const int count = fArray.count(); |
23 if (0 == count) { | 23 if (0 == count) { |
24 return NULL; | 24 return nullptr; |
25 } | 25 } |
26 SkAutoTMalloc<const SkPicture*> pics(count); | 26 SkAutoTMalloc<const SkPicture*> pics(count); |
27 for (int i = 0; i < count; ++i) { | 27 for (int i = 0; i < count; ++i) { |
28 pics[i] = fArray[i]->newPictureSnapshot(); | 28 pics[i] = fArray[i]->newPictureSnapshot(); |
29 } | 29 } |
30 return new SkBigPicture::SnapshotArray(pics.detach(), count); | 30 return new SkBigPicture::SnapshotArray(pics.detach(), count); |
31 } | 31 } |
32 | 32 |
33 void SkDrawableList::append(SkDrawable* drawable) { | 33 void SkDrawableList::append(SkDrawable* drawable) { |
34 *fArray.append() = SkRef(drawable); | 34 *fArray.append() = SkRef(drawable); |
(...skipping 18 matching lines...) Expand all Loading... |
53 void SkRecorder::reset(SkRecord* record, const SkRect& bounds, | 53 void SkRecorder::reset(SkRecord* record, const SkRect& bounds, |
54 DrawPictureMode dpm, SkMiniRecorder* mr) { | 54 DrawPictureMode dpm, SkMiniRecorder* mr) { |
55 this->forgetRecord(); | 55 this->forgetRecord(); |
56 fDrawPictureMode = dpm; | 56 fDrawPictureMode = dpm; |
57 fRecord = record; | 57 fRecord = record; |
58 this->resetForNextPicture(bounds.roundOut()); | 58 this->resetForNextPicture(bounds.roundOut()); |
59 fMiniRecorder = mr; | 59 fMiniRecorder = mr; |
60 } | 60 } |
61 | 61 |
62 void SkRecorder::forgetRecord() { | 62 void SkRecorder::forgetRecord() { |
63 fDrawableList.reset(NULL); | 63 fDrawableList.reset(nullptr); |
64 fApproxBytesUsedBySubPictures = 0; | 64 fApproxBytesUsedBySubPictures = 0; |
65 fRecord = NULL; | 65 fRecord = nullptr; |
66 } | 66 } |
67 | 67 |
68 // To make appending to fRecord a little less verbose. | 68 // To make appending to fRecord a little less verbose. |
69 #define APPEND(T, ...) \ | 69 #define APPEND(T, ...) \ |
70 if (fMiniRecorder) { \ | 70 if (fMiniRecorder) { \ |
71 this->flushMiniRecorder(); \ | 71 this->flushMiniRecorder(); \ |
72 } \ | 72 } \ |
73 new (fRecord->append<SkRecords::T>()) SkRecords::T(__VA_ARGS__) | 73 new (fRecord->append<SkRecords::T>()) SkRecords::T(__VA_ARGS__) |
74 | 74 |
75 #define TRY_MINIRECORDER(method, ...) \ | 75 #define TRY_MINIRECORDER(method, ...) \ |
76 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; } | 76 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; } |
77 | 77 |
78 // For methods which must call back into SkCanvas. | 78 // For methods which must call back into SkCanvas. |
79 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) | 79 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) |
80 | 80 |
81 // Use copy() only for optional arguments, to be copied if present or skipped if
not. | 81 // Use copy() only for optional arguments, to be copied if present or skipped if
not. |
82 // (For most types we just pass by value and let copy constructors do their thin
g.) | 82 // (For most types we just pass by value and let copy constructors do their thin
g.) |
83 template <typename T> | 83 template <typename T> |
84 T* SkRecorder::copy(const T* src) { | 84 T* SkRecorder::copy(const T* src) { |
85 if (NULL == src) { | 85 if (nullptr == src) { |
86 return NULL; | 86 return nullptr; |
87 } | 87 } |
88 return new (fRecord->alloc<T>()) T(*src); | 88 return new (fRecord->alloc<T>()) T(*src); |
89 } | 89 } |
90 | 90 |
91 // This copy() is for arrays. | 91 // This copy() is for arrays. |
92 // It will work with POD or non-POD, though currently we only use it for POD. | 92 // It will work with POD or non-POD, though currently we only use it for POD. |
93 template <typename T> | 93 template <typename T> |
94 T* SkRecorder::copy(const T src[], size_t count) { | 94 T* SkRecorder::copy(const T src[], size_t count) { |
95 if (NULL == src) { | 95 if (nullptr == src) { |
96 return NULL; | 96 return nullptr; |
97 } | 97 } |
98 T* dst = fRecord->alloc<T>(count); | 98 T* dst = fRecord->alloc<T>(count); |
99 for (size_t i = 0; i < count; i++) { | 99 for (size_t i = 0; i < count; i++) { |
100 new (dst + i) T(src[i]); | 100 new (dst + i) T(src[i]); |
101 } | 101 } |
102 return dst; | 102 return dst; |
103 } | 103 } |
104 | 104 |
105 // Specialization for copying strings, using memcpy. | 105 // Specialization for copying strings, using memcpy. |
106 // This measured around 2x faster for copying code points, | 106 // This measured around 2x faster for copying code points, |
107 // but I found no corresponding speedup for other arrays. | 107 // but I found no corresponding speedup for other arrays. |
108 template <> | 108 template <> |
109 char* SkRecorder::copy(const char src[], size_t count) { | 109 char* SkRecorder::copy(const char src[], size_t count) { |
110 if (NULL == src) { | 110 if (nullptr == src) { |
111 return NULL; | 111 return nullptr; |
112 } | 112 } |
113 char* dst = fRecord->alloc<char>(count); | 113 char* dst = fRecord->alloc<char>(count); |
114 memcpy(dst, src, count); | 114 memcpy(dst, src, count); |
115 return dst; | 115 return dst; |
116 } | 116 } |
117 | 117 |
118 // As above, assuming and copying a terminating \0. | 118 // As above, assuming and copying a terminating \0. |
119 template <> | 119 template <> |
120 char* SkRecorder::copy(const char* src) { | 120 char* SkRecorder::copy(const char* src) { |
121 return this->copy(src, strlen(src)+1); | 121 return this->copy(src, strlen(src)+1); |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
295 | 295 |
296 void SkRecorder::onDrawVertices(VertexMode vmode, | 296 void SkRecorder::onDrawVertices(VertexMode vmode, |
297 int vertexCount, const SkPoint vertices[], | 297 int vertexCount, const SkPoint vertices[], |
298 const SkPoint texs[], const SkColor colors[], | 298 const SkPoint texs[], const SkColor colors[], |
299 SkXfermode* xmode, | 299 SkXfermode* xmode, |
300 const uint16_t indices[], int indexCount, const
SkPaint& paint) { | 300 const uint16_t indices[], int indexCount, const
SkPaint& paint) { |
301 APPEND(DrawVertices, paint, | 301 APPEND(DrawVertices, paint, |
302 vmode, | 302 vmode, |
303 vertexCount, | 303 vertexCount, |
304 this->copy(vertices, vertexCount), | 304 this->copy(vertices, vertexCount), |
305 texs ? this->copy(texs, vertexCount) : NULL, | 305 texs ? this->copy(texs, vertexCount) : nullptr, |
306 colors ? this->copy(colors, vertexCount) : NULL, | 306 colors ? this->copy(colors, vertexCount) : nullptr, |
307 xmode, | 307 xmode, |
308 this->copy(indices, indexCount), | 308 this->copy(indices, indexCount), |
309 indexCount); | 309 indexCount); |
310 } | 310 } |
311 | 311 |
312 void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], | 312 void SkRecorder::onDrawPatch(const SkPoint cubics[12], const SkColor colors[4], |
313 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { | 313 const SkPoint texCoords[4], SkXfermode* xmode, cons
t SkPaint& paint) { |
314 APPEND(DrawPatch, paint, | 314 APPEND(DrawPatch, paint, |
315 cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : NULL, | 315 cubics ? this->copy(cubics, SkPatchUtils::kNumCtrlPts) : nullptr, |
316 colors ? this->copy(colors, SkPatchUtils::kNumCorners) : NULL, | 316 colors ? this->copy(colors, SkPatchUtils::kNumCorners) : nullptr, |
317 texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : NULL, | 317 texCoords ? this->copy(texCoords, SkPatchUtils::kNumCorners) : nullpt
r, |
318 xmode); | 318 xmode); |
319 } | 319 } |
320 | 320 |
321 void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], cons
t SkRect tex[], | 321 void SkRecorder::onDrawAtlas(const SkImage* atlas, const SkRSXform xform[], cons
t SkRect tex[], |
322 const SkColor colors[], int count, SkXfermode::Mode
mode, | 322 const SkColor colors[], int count, SkXfermode::Mode
mode, |
323 const SkRect* cull, const SkPaint* paint) { | 323 const SkRect* cull, const SkPaint* paint) { |
324 APPEND(DrawAtlas, this->copy(paint), | 324 APPEND(DrawAtlas, this->copy(paint), |
325 atlas, | 325 atlas, |
326 this->copy(xform, count), | 326 this->copy(xform, count), |
327 this->copy(tex, count), | 327 this->copy(tex, count), |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 INHERITED(onClipPath, path, op, edgeStyle); | 375 INHERITED(onClipPath, path, op, edgeStyle); |
376 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); | 376 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); |
377 APPEND(ClipPath, this->devBounds(), path, opAA); | 377 APPEND(ClipPath, this->devBounds(), path, opAA); |
378 } | 378 } |
379 | 379 |
380 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { | 380 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { |
381 INHERITED(onClipRegion, deviceRgn, op); | 381 INHERITED(onClipRegion, deviceRgn, op); |
382 APPEND(ClipRegion, this->devBounds(), deviceRgn, op); | 382 APPEND(ClipRegion, this->devBounds(), deviceRgn, op); |
383 } | 383 } |
384 | 384 |
OLD | NEW |