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

Side by Side Diff: src/effects/SkMergeImageFilter.cpp

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 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/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.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 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
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 "SkMergeImageFilter.h" 8 #include "SkMergeImageFilter.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkDevice.h" 10 #include "SkDevice.h"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkValidationUtils.h" 13 #include "SkValidationUtils.h"
14 14
15 /////////////////////////////////////////////////////////////////////////////// 15 ///////////////////////////////////////////////////////////////////////////////
16 16
17 void SkMergeImageFilter::initAllocModes() { 17 void SkMergeImageFilter::initAllocModes() {
18 int inputCount = countInputs(); 18 int inputCount = countInputs();
19 if (inputCount) { 19 if (inputCount) {
20 size_t size = sizeof(uint8_t) * inputCount; 20 size_t size = sizeof(uint8_t) * inputCount;
21 if (size <= sizeof(fStorage)) { 21 if (size <= sizeof(fStorage)) {
22 fModes = SkTCast<uint8_t*>(fStorage); 22 fModes = SkTCast<uint8_t*>(fStorage);
23 } else { 23 } else {
24 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size)); 24 fModes = SkTCast<uint8_t*>(sk_malloc_throw(size));
25 } 25 }
26 } else { 26 } else {
27 fModes = NULL; 27 fModes = nullptr;
28 } 28 }
29 } 29 }
30 30
31 void SkMergeImageFilter::initModes(const SkXfermode::Mode modes[]) { 31 void SkMergeImageFilter::initModes(const SkXfermode::Mode modes[]) {
32 if (modes) { 32 if (modes) {
33 this->initAllocModes(); 33 this->initAllocModes();
34 int inputCount = countInputs(); 34 int inputCount = countInputs();
35 for (int i = 0; i < inputCount; ++i) { 35 for (int i = 0; i < inputCount; ++i) {
36 fModes[i] = SkToU8(modes[i]); 36 fModes[i] = SkToU8(modes[i]);
37 } 37 }
38 } else { 38 } else {
39 fModes = NULL; 39 fModes = nullptr;
40 } 40 }
41 } 41 }
42 42
43 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count, 43 SkMergeImageFilter::SkMergeImageFilter(SkImageFilter* filters[], int count,
44 const SkXfermode::Mode modes[], 44 const SkXfermode::Mode modes[],
45 const CropRect* cropRect) 45 const CropRect* cropRect)
46 : INHERITED(count, filters, cropRect) { 46 : INHERITED(count, filters, cropRect) {
47 SkASSERT(count >= 0); 47 SkASSERT(count >= 0);
48 this->initModes(modes); 48 this->initModes(modes);
49 } 49 }
(...skipping 14 matching lines...) Expand all
64 64
65 SkIRect bounds; 65 SkIRect bounds;
66 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) { 66 if (!this->applyCropRect(ctx, src, SkIPoint::Make(0, 0), &bounds)) {
67 return false; 67 return false;
68 } 68 }
69 69
70 const int x0 = bounds.left(); 70 const int x0 = bounds.left();
71 const int y0 = bounds.top(); 71 const int y0 = bounds.top();
72 72
73 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight())); 73 SkAutoTUnref<SkBaseDevice> dst(proxy->createDevice(bounds.width(), bounds.he ight()));
74 if (NULL == dst) { 74 if (nullptr == dst) {
75 return false; 75 return false;
76 } 76 }
77 SkCanvas canvas(dst); 77 SkCanvas canvas(dst);
78 SkPaint paint; 78 SkPaint paint;
79 79
80 bool didProduceResult = false; 80 bool didProduceResult = false;
81 int inputCount = countInputs(); 81 int inputCount = countInputs();
82 for (int i = 0; i < inputCount; ++i) { 82 for (int i = 0; i < inputCount; ++i) {
83 SkBitmap tmp; 83 SkBitmap tmp;
84 const SkBitmap* srcPtr; 84 const SkBitmap* srcPtr;
85 SkIPoint pos = SkIPoint::Make(0, 0); 85 SkIPoint pos = SkIPoint::Make(0, 0);
86 SkImageFilter* filter = getInput(i); 86 SkImageFilter* filter = getInput(i);
87 if (filter) { 87 if (filter) {
88 if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) { 88 if (!filter->filterImage(proxy, src, ctx, &tmp, &pos)) {
89 continue; 89 continue;
90 } 90 }
91 srcPtr = &tmp; 91 srcPtr = &tmp;
92 } else { 92 } else {
93 srcPtr = &src; 93 srcPtr = &src;
94 } 94 }
95 95
96 if (fModes) { 96 if (fModes) {
97 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]); 97 paint.setXfermodeMode((SkXfermode::Mode)fModes[i]);
98 } else { 98 } else {
99 paint.setXfermode(NULL); 99 paint.setXfermode(nullptr);
100 } 100 }
101 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint); 101 canvas.drawSprite(*srcPtr, pos.x() - x0, pos.y() - y0, &paint);
102 didProduceResult = true; 102 didProduceResult = true;
103 } 103 }
104 104
105 if (!didProduceResult) 105 if (!didProduceResult)
106 return false; 106 return false;
107 107
108 offset->fX = bounds.left(); 108 offset->fX = bounds.left();
109 offset->fY = bounds.top(); 109 offset->fY = bounds.top();
110 *result = dst->accessBitmap(false); 110 *result = dst->accessBitmap(false);
111 return true; 111 return true;
112 } 112 }
113 113
114 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) { 114 SkFlattenable* SkMergeImageFilter::CreateProc(SkReadBuffer& buffer) {
115 Common common; 115 Common common;
116 if (!common.unflatten(buffer, -1)) { 116 if (!common.unflatten(buffer, -1)) {
117 return NULL; 117 return nullptr;
118 } 118 }
119 119
120 const int count = common.inputCount(); 120 const int count = common.inputCount();
121 bool hasModes = buffer.readBool(); 121 bool hasModes = buffer.readBool();
122 if (hasModes) { 122 if (hasModes) {
123 SkAutoSTArray<4, SkXfermode::Mode> modes(count); 123 SkAutoSTArray<4, SkXfermode::Mode> modes(count);
124 SkAutoSTArray<4, uint8_t> modes8(count); 124 SkAutoSTArray<4, uint8_t> modes8(count);
125 if (!buffer.readByteArray(modes8.get(), count)) { 125 if (!buffer.readByteArray(modes8.get(), count)) {
126 return NULL; 126 return nullptr;
127 } 127 }
128 for (int i = 0; i < count; ++i) { 128 for (int i = 0; i < count; ++i) {
129 modes[i] = (SkXfermode::Mode)modes8[i]; 129 modes[i] = (SkXfermode::Mode)modes8[i];
130 buffer.validate(SkIsValidMode(modes[i])); 130 buffer.validate(SkIsValidMode(modes[i]));
131 } 131 }
132 if (!buffer.isValid()) { 132 if (!buffer.isValid()) {
133 return NULL; 133 return nullptr;
134 } 134 }
135 return Create(common.inputs(), count, modes.get(), &common.cropRect()); 135 return Create(common.inputs(), count, modes.get(), &common.cropRect());
136 } 136 }
137 return Create(common.inputs(), count, NULL, &common.cropRect()); 137 return Create(common.inputs(), count, nullptr, &common.cropRect());
138 } 138 }
139 139
140 void SkMergeImageFilter::flatten(SkWriteBuffer& buffer) const { 140 void SkMergeImageFilter::flatten(SkWriteBuffer& buffer) const {
141 this->INHERITED::flatten(buffer); 141 this->INHERITED::flatten(buffer);
142 buffer.writeBool(fModes != NULL); 142 buffer.writeBool(fModes != nullptr);
143 if (fModes) { 143 if (fModes) {
144 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0])); 144 buffer.writeByteArray(fModes, countInputs() * sizeof(fModes[0]));
145 } 145 }
146 } 146 }
147 147
148 #ifndef SK_IGNORE_TO_STRING 148 #ifndef SK_IGNORE_TO_STRING
149 void SkMergeImageFilter::toString(SkString* str) const { 149 void SkMergeImageFilter::toString(SkString* str) const {
150 str->appendf("SkMergeImageFilter: ("); 150 str->appendf("SkMergeImageFilter: (");
151 151
152 for (int i = 0; i < this->countInputs(); ++i) { 152 for (int i = 0; i < this->countInputs(); ++i) {
153 SkImageFilter* filter = this->getInput(i); 153 SkImageFilter* filter = this->getInput(i);
154 str->appendf("%d: (", i); 154 str->appendf("%d: (", i);
155 filter->toString(str); 155 filter->toString(str);
156 str->appendf(")"); 156 str->appendf(")");
157 } 157 }
158 158
159 str->append(")"); 159 str->append(")");
160 } 160 }
161 #endif 161 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMatrixConvolutionImageFilter.cpp ('k') | src/effects/SkMorphologyImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698