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

Side by Side Diff: src/image/SkImage_Raster.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/image/SkImage_Gpu.cpp ('k') | src/image/SkSurface.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 Google Inc. 2 * Copyright 2012 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 "SkImage_Base.h" 8 #include "SkImage_Base.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) { 33 if ((unsigned)info.alphaType() > (unsigned)kLastEnum_SkAlphaType) {
34 return false; 34 return false;
35 } 35 }
36 36
37 if (kUnknown_SkColorType == info.colorType()) { 37 if (kUnknown_SkColorType == info.colorType()) {
38 return false; 38 return false;
39 } 39 }
40 40
41 const bool needsCT = kIndex_8_SkColorType == info.colorType(); 41 const bool needsCT = kIndex_8_SkColorType == info.colorType();
42 const bool hasCT = NULL != ctable; 42 const bool hasCT = nullptr != ctable;
43 if (needsCT != hasCT) { 43 if (needsCT != hasCT) {
44 return false; 44 return false;
45 } 45 }
46 46
47 if (rowBytes < SkImageMinRowBytes(info)) { 47 if (rowBytes < SkImageMinRowBytes(info)) {
48 return false; 48 return false;
49 } 49 }
50 50
51 size_t size = info.getSafeSize(rowBytes); 51 size_t size = info.getSafeSize(rowBytes);
52 if (0 == size) { 52 if (0 == size) {
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 fBitmap.lockPixels(); 91 fBitmap.lockPixels();
92 } 92 }
93 SkASSERT(fBitmap.isImmutable()); 93 SkASSERT(fBitmap.isImmutable());
94 } 94 }
95 95
96 bool onIsLazyGenerated() const override { 96 bool onIsLazyGenerated() const override {
97 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated(); 97 return fBitmap.pixelRef() && fBitmap.pixelRef()->isLazyGenerated();
98 } 98 }
99 99
100 private: 100 private:
101 SkImage_Raster() : INHERITED(0, 0, kNeedNewImageUniqueID, NULL) { 101 SkImage_Raster() : INHERITED(0, 0, kNeedNewImageUniqueID, nullptr) {
102 fBitmap.setImmutable(); 102 fBitmap.setImmutable();
103 } 103 }
104 104
105 SkBitmap fBitmap; 105 SkBitmap fBitmap;
106 106
107 typedef SkImage_Base INHERITED; 107 typedef SkImage_Base INHERITED;
108 }; 108 };
109 109
110 /////////////////////////////////////////////////////////////////////////////// 110 ///////////////////////////////////////////////////////////////////////////////
111 111
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 149
150 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes, 150 bool SkImage_Raster::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels, s ize_t dstRowBytes,
151 int srcX, int srcY) const { 151 int srcX, int srcY) const {
152 SkBitmap shallowCopy(fBitmap); 152 SkBitmap shallowCopy(fBitmap);
153 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY); 153 return shallowCopy.readPixels(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
154 } 154 }
155 155
156 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const { 156 const void* SkImage_Raster::onPeekPixels(SkImageInfo* infoPtr, size_t* rowBytesP tr) const {
157 const SkImageInfo info = fBitmap.info(); 157 const SkImageInfo info = fBitmap.info();
158 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) { 158 if ((kUnknown_SkColorType == info.colorType()) || !fBitmap.getPixels()) {
159 return NULL; 159 return nullptr;
160 } 160 }
161 *infoPtr = info; 161 *infoPtr = info;
162 *rowBytesPtr = fBitmap.rowBytes(); 162 *rowBytesPtr = fBitmap.rowBytes();
163 return fBitmap.getPixels(); 163 return fBitmap.getPixels();
164 } 164 }
165 165
166 SkData* SkImage_Raster::onRefEncoded() const { 166 SkData* SkImage_Raster::onRefEncoded() const {
167 SkPixelRef* pr = fBitmap.pixelRef(); 167 SkPixelRef* pr = fBitmap.pixelRef();
168 const SkImageInfo prInfo = pr->info(); 168 const SkImageInfo prInfo = pr->info();
169 const SkImageInfo bmInfo = fBitmap.info(); 169 const SkImageInfo bmInfo = fBitmap.info();
170 170
171 // we only try if we (the image) cover the entire area of the pixelRef 171 // we only try if we (the image) cover the entire area of the pixelRef
172 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) { 172 if (prInfo.width() == bmInfo.width() && prInfo.height() == bmInfo.height()) {
173 return pr->refEncodedData(); 173 return pr->refEncodedData();
174 } 174 }
175 return NULL; 175 return nullptr;
176 } 176 }
177 177
178 bool SkImage_Raster::getROPixels(SkBitmap* dst) const { 178 bool SkImage_Raster::getROPixels(SkBitmap* dst) const {
179 *dst = fBitmap; 179 *dst = fBitmap;
180 return true; 180 return true;
181 } 181 }
182 182
183 /////////////////////////////////////////////////////////////////////////////// 183 ///////////////////////////////////////////////////////////////////////////////
184 184
185 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes, 185 SkImage* SkImage::NewRasterCopy(const SkImageInfo& info, const void* pixels, siz e_t rowBytes,
186 SkColorTable* ctable) { 186 SkColorTable* ctable) {
187 size_t size; 187 size_t size;
188 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable, &size) || !pixels) { 188 if (!SkImage_Raster::ValidArgs(info, rowBytes, ctable, &size) || !pixels) {
189 return NULL; 189 return nullptr;
190 } 190 }
191 191
192 // Here we actually make a copy of the caller's pixel data 192 // Here we actually make a copy of the caller's pixel data
193 SkAutoDataUnref data(SkData::NewWithCopy(pixels, size)); 193 SkAutoDataUnref data(SkData::NewWithCopy(pixels, size));
194 return new SkImage_Raster(info, data, rowBytes, ctable, NULL); 194 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr);
195 } 195 }
196 196
197 197
198 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) { 198 SkImage* SkImage::NewRasterData(const SkImageInfo& info, SkData* data, size_t ro wBytes) {
199 size_t size; 199 size_t size;
200 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, &size) || !data) { 200 if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, &size) || !data) {
201 return NULL; 201 return nullptr;
202 } 202 }
203 203
204 // did they give us enough data? 204 // did they give us enough data?
205 if (data->size() < size) { 205 if (data->size() < size) {
206 return NULL; 206 return nullptr;
207 } 207 }
208 208
209 SkColorTable* ctable = NULL; 209 SkColorTable* ctable = nullptr;
210 return new SkImage_Raster(info, data, rowBytes, ctable, NULL); 210 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr);
211 } 211 }
212 212
213 SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz e_t rowBytes, 213 SkImage* SkImage::NewFromRaster(const SkImageInfo& info, const void* pixels, siz e_t rowBytes,
214 RasterReleaseProc proc, ReleaseContext ctx) { 214 RasterReleaseProc proc, ReleaseContext ctx) {
215 size_t size; 215 size_t size;
216 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, &size) || !pixels) { 216 if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, &size) || !pixels) {
217 return NULL; 217 return nullptr;
218 } 218 }
219 219
220 SkColorTable* ctable = NULL; 220 SkColorTable* ctable = nullptr;
221 SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx)); 221 SkAutoDataUnref data(SkData::NewWithProc(pixels, size, proc, ctx));
222 return new SkImage_Raster(info, data, rowBytes, ctable, NULL); 222 return new SkImage_Raster(info, data, rowBytes, ctable, nullptr);
223 } 223 }
224 224
225 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s ubset) { 225 SkImage* SkImage::NewFromGenerator(SkImageGenerator* generator, const SkIRect* s ubset) {
226 SkBitmap bitmap; 226 SkBitmap bitmap;
227 if (!SkInstallDiscardablePixelRef(generator, subset, &bitmap, NULL)) { 227 if (!SkInstallDiscardablePixelRef(generator, subset, &bitmap, nullptr)) {
228 return NULL; 228 return nullptr;
229 } 229 }
230 if (0 == bitmap.width() || 0 == bitmap.height()) { 230 if (0 == bitmap.width() || 0 == bitmap.height()) {
231 return NULL; 231 return nullptr;
232 } 232 }
233 233
234 return new SkImage_Raster(bitmap, NULL); 234 return new SkImage_Raster(bitmap, nullptr);
235 } 235 }
236 236
237 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr, 237 SkImage* SkNewImageFromPixelRef(const SkImageInfo& info, SkPixelRef* pr,
238 const SkIPoint& pixelRefOrigin, size_t rowBytes, 238 const SkIPoint& pixelRefOrigin, size_t rowBytes,
239 const SkSurfaceProps* props) { 239 const SkSurfaceProps* props) {
240 if (!SkImage_Raster::ValidArgs(info, rowBytes, NULL, NULL)) { 240 if (!SkImage_Raster::ValidArgs(info, rowBytes, nullptr, nullptr)) {
241 return NULL; 241 return nullptr;
242 } 242 }
243 return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes, props); 243 return new SkImage_Raster(info, pr, pixelRefOrigin, rowBytes, props);
244 } 244 }
245 245
246 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr ops, 246 SkImage* SkNewImageFromRasterBitmap(const SkBitmap& bm, const SkSurfaceProps* pr ops,
247 ForceCopyMode forceCopy) { 247 ForceCopyMode forceCopy) {
248 SkASSERT(NULL == bm.getTexture()); 248 SkASSERT(nullptr == bm.getTexture());
249 249
250 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), NULL, NULL)) { 250 if (!SkImage_Raster::ValidArgs(bm.info(), bm.rowBytes(), nullptr, nullptr)) {
251 return NULL; 251 return nullptr;
252 } 252 }
253 253
254 SkImage* image = NULL; 254 SkImage* image = nullptr;
255 if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) { 255 if (kYes_ForceCopyMode == forceCopy || !bm.isImmutable()) {
256 SkBitmap tmp(bm); 256 SkBitmap tmp(bm);
257 tmp.lockPixels(); 257 tmp.lockPixels();
258 if (tmp.getPixels()) { 258 if (tmp.getPixels()) {
259 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(), 259 image = SkImage::NewRasterCopy(tmp.info(), tmp.getPixels(), tmp.rowB ytes(),
260 tmp.getColorTable()); 260 tmp.getColorTable());
261 } 261 }
262 262
263 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here 263 // we don't expose props to NewRasterCopy (need a private vers) so post- init it here
264 if (image && props) { 264 if (image && props) {
(...skipping 20 matching lines...) Expand all
285 // pixelref since the caller might call setImmutable() themselves 285 // pixelref since the caller might call setImmutable() themselves
286 // (thus changing our state). 286 // (thus changing our state).
287 if (fBitmap.isImmutable()) { 287 if (fBitmap.isImmutable()) {
288 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes()); 288 bitmap->setInfo(fBitmap.info(), fBitmap.rowBytes());
289 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin()); 289 bitmap->setPixelRef(fBitmap.pixelRef(), fBitmap.pixelRefOrigin());
290 return true; 290 return true;
291 } 291 }
292 } 292 }
293 return this->INHERITED::onAsLegacyBitmap(bitmap, mode); 293 return this->INHERITED::onAsLegacyBitmap(bitmap, mode);
294 } 294 }
OLDNEW
« no previous file with comments | « src/image/SkImage_Gpu.cpp ('k') | src/image/SkSurface.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698