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

Side by Side Diff: src/core/SkRecorder.cpp

Issue 1316123003: Style Change: SkNEW->new; SkDELETE->delete (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-26 (Wednesday) 15:59:00 EDT Created 5 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') | src/core/SkResourceCache.cpp » ('j') | 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 #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 NULL;
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 SkNEW_ARGS(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);
35 } 35 }
36 36
37 //////////////////////////////////////////////////////////////////////////////// /////////////// 37 //////////////////////////////////////////////////////////////////////////////// ///////////////
38 38
39 SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr) 39 SkRecorder::SkRecorder(SkRecord* record, int width, int height, SkMiniRecorder* mr)
40 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip _InitFlag) 40 : SkCanvas(SkIRect::MakeWH(width, height), SkCanvas::kConservativeRasterClip _InitFlag)
(...skipping 18 matching lines...) Expand all
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(NULL);
64 fApproxBytesUsedBySubPictures = 0; 64 fApproxBytesUsedBySubPictures = 0;
65 fRecord = NULL; 65 fRecord = NULL;
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) { this->flushMiniRecorder(); } \ 70 if (fMiniRecorder) { \
71 SkNEW_PLACEMENT_ARGS(fRecord->append<SkRecords::T>(), SkRecords::T, (__V A_ARGS__)) 71 this->flushMiniRecorder(); \
72 } \
73 new (fRecord->append<SkRecords::T>()) SkRecords::T(__VA_ARGS__)
72 74
73 #define TRY_MINIRECORDER(method, ...) \ 75 #define TRY_MINIRECORDER(method, ...) \
74 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; } 76 if (fMiniRecorder && fMiniRecorder->method(__VA_ARGS__)) { return; }
75 77
76 // For methods which must call back into SkCanvas. 78 // For methods which must call back into SkCanvas.
77 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__) 79 #define INHERITED(method, ...) this->SkCanvas::method(__VA_ARGS__)
78 80
79 // 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.
80 // (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.)
81 template <typename T> 83 template <typename T>
82 T* SkRecorder::copy(const T* src) { 84 T* SkRecorder::copy(const T* src) {
83 if (NULL == src) { 85 if (NULL == src) {
84 return NULL; 86 return NULL;
85 } 87 }
86 return SkNEW_PLACEMENT_ARGS(fRecord->alloc<T>(), T, (*src)); 88 return new (fRecord->alloc<T>()) T(*src);
87 } 89 }
88 90
89 // This copy() is for arrays. 91 // This copy() is for arrays.
90 // 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.
91 template <typename T> 93 template <typename T>
92 T* SkRecorder::copy(const T src[], size_t count) { 94 T* SkRecorder::copy(const T src[], size_t count) {
93 if (NULL == src) { 95 if (NULL == src) {
94 return NULL; 96 return NULL;
95 } 97 }
96 T* dst = fRecord->alloc<T>(count); 98 T* dst = fRecord->alloc<T>(count);
97 for (size_t i = 0; i < count; i++) { 99 for (size_t i = 0; i < count; i++) {
98 SkNEW_PLACEMENT_ARGS(dst + i, T, (src[i])); 100 new (dst + i) T(src[i]);
99 } 101 }
100 return dst; 102 return dst;
101 } 103 }
102 104
103 // Specialization for copying strings, using memcpy. 105 // Specialization for copying strings, using memcpy.
104 // This measured around 2x faster for copying code points, 106 // This measured around 2x faster for copying code points,
105 // but I found no corresponding speedup for other arrays. 107 // but I found no corresponding speedup for other arrays.
106 template <> 108 template <>
107 char* SkRecorder::copy(const char src[], size_t count) { 109 char* SkRecorder::copy(const char src[], size_t count) {
108 if (NULL == src) { 110 if (NULL == src) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) { 152 void SkRecorder::onDrawRRect(const SkRRect& rrect, const SkPaint& paint) {
151 APPEND(DrawRRect, paint, rrect); 153 APPEND(DrawRRect, paint, rrect);
152 } 154 }
153 155
154 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) { 156 void SkRecorder::onDrawDRRect(const SkRRect& outer, const SkRRect& inner, const SkPaint& paint) {
155 APPEND(DrawDRRect, paint, outer, inner); 157 APPEND(DrawDRRect, paint, outer, inner);
156 } 158 }
157 159
158 void SkRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) { 160 void SkRecorder::onDrawDrawable(SkDrawable* drawable, const SkMatrix* matrix) {
159 if (!fDrawableList) { 161 if (!fDrawableList) {
160 fDrawableList.reset(SkNEW(SkDrawableList)); 162 fDrawableList.reset(new SkDrawableList);
161 } 163 }
162 fDrawableList->append(drawable); 164 fDrawableList->append(drawable);
163 APPEND(DrawDrawable, this->copy(matrix), drawable->getBounds(), fDrawableLis t->count() - 1); 165 APPEND(DrawDrawable, this->copy(matrix), drawable->getBounds(), fDrawableLis t->count() - 1);
164 } 166 }
165 167
166 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) { 168 void SkRecorder::onDrawPath(const SkPath& path, const SkPaint& paint) {
167 TRY_MINIRECORDER(drawPath, path, paint); 169 TRY_MINIRECORDER(drawPath, path, paint);
168 APPEND(DrawPath, paint, path); 170 APPEND(DrawPath, paint, path);
169 } 171 }
170 172
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 INHERITED(onClipPath, path, op, edgeStyle); 375 INHERITED(onClipPath, path, op, edgeStyle);
374 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle); 376 SkRecords::RegionOpAndAA opAA(op, kSoft_ClipEdgeStyle == edgeStyle);
375 APPEND(ClipPath, this->devBounds(), path, opAA); 377 APPEND(ClipPath, this->devBounds(), path, opAA);
376 } 378 }
377 379
378 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) { 380 void SkRecorder::onClipRegion(const SkRegion& deviceRgn, SkRegion::Op op) {
379 INHERITED(onClipRegion, deviceRgn, op); 381 INHERITED(onClipRegion, deviceRgn, op);
380 APPEND(ClipRegion, this->devBounds(), deviceRgn, op); 382 APPEND(ClipRegion, this->devBounds(), deviceRgn, op);
381 } 383 }
382 384
OLDNEW
« no previous file with comments | « src/core/SkRecordDraw.cpp ('k') | src/core/SkResourceCache.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698