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

Side by Side Diff: src/image/SkImage.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/gpu/glsl/GrGLSLCaps.cpp ('k') | src/image/SkImagePriv.h » ('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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkCanvas.h" 9 #include "SkCanvas.h"
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 17 matching lines...) Expand all
28 , fHeight(height) 28 , fHeight(height)
29 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : unique ID) 29 , fUniqueID(kNeedNewImageUniqueID == uniqueID ? SkNextID::ImageID() : unique ID)
30 { 30 {
31 SkASSERT(width > 0); 31 SkASSERT(width > 0);
32 SkASSERT(height > 0); 32 SkASSERT(height > 0);
33 } 33 }
34 34
35 const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const { 35 const void* SkImage::peekPixels(SkImageInfo* info, size_t* rowBytes) const {
36 SkImageInfo infoStorage; 36 SkImageInfo infoStorage;
37 size_t rowBytesStorage; 37 size_t rowBytesStorage;
38 if (NULL == info) { 38 if (nullptr == info) {
39 info = &infoStorage; 39 info = &infoStorage;
40 } 40 }
41 if (NULL == rowBytes) { 41 if (nullptr == rowBytes) {
42 rowBytes = &rowBytesStorage; 42 rowBytes = &rowBytesStorage;
43 } 43 }
44 return as_IB(this)->onPeekPixels(info, rowBytes); 44 return as_IB(this)->onPeekPixels(info, rowBytes);
45 } 45 }
46 46
47 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes, 47 bool SkImage::readPixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst RowBytes,
48 int srcX, int srcY) const { 48 int srcX, int srcY) const {
49 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY); 49 SkReadPixelsRec rec(dstInfo, dstPixels, dstRowBytes, srcX, srcY);
50 if (!rec.trim(this->width(), this->height())) { 50 if (!rec.trim(this->width(), this->height())) {
51 return false; 51 return false;
52 } 52 }
53 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec. fX, rec.fY); 53 return as_IB(this)->onReadPixels(rec.fInfo, rec.fPixels, rec.fRowBytes, rec. fX, rec.fY);
54 } 54 }
55 55
56 SkShader* SkImage::newShader(SkShader::TileMode tileX, 56 SkShader* SkImage::newShader(SkShader::TileMode tileX,
57 SkShader::TileMode tileY, 57 SkShader::TileMode tileY,
58 const SkMatrix* localMatrix) const { 58 const SkMatrix* localMatrix) const {
59 return as_IB(this)->onNewShader(tileX, tileY, localMatrix); 59 return as_IB(this)->onNewShader(tileX, tileY, localMatrix);
60 } 60 }
61 61
62 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const { 62 SkData* SkImage::encode(SkImageEncoder::Type type, int quality) const {
63 SkBitmap bm; 63 SkBitmap bm;
64 if (as_IB(this)->getROPixels(&bm)) { 64 if (as_IB(this)->getROPixels(&bm)) {
65 return SkImageEncoder::EncodeData(bm, type, quality); 65 return SkImageEncoder::EncodeData(bm, type, quality);
66 } 66 }
67 return NULL; 67 return nullptr;
68 } 68 }
69 69
70 SkData* SkImage::refEncoded() const { 70 SkData* SkImage::refEncoded() const {
71 return as_IB(this)->onRefEncoded(); 71 return as_IB(this)->onRefEncoded();
72 } 72 }
73 73
74 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) { 74 SkImage* SkImage::NewFromEncoded(SkData* encoded, const SkIRect* subset) {
75 if (NULL == encoded || 0 == encoded->size()) { 75 if (nullptr == encoded || 0 == encoded->size()) {
76 return NULL; 76 return nullptr;
77 } 77 }
78 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded); 78 SkImageGenerator* generator = SkImageGenerator::NewFromEncoded(encoded);
79 return generator ? SkImage::NewFromGenerator(generator, subset) : NULL; 79 return generator ? SkImage::NewFromGenerator(generator, subset) : nullptr;
80 } 80 }
81 81
82 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const { 82 SkSurface* SkImage::newSurface(const SkImageInfo& info, const SkSurfaceProps* pr ops) const {
83 if (NULL == props) { 83 if (nullptr == props) {
84 props = &as_IB(this)->props(); 84 props = &as_IB(this)->props();
85 } 85 }
86 return as_IB(this)->onNewSurface(info, *props); 86 return as_IB(this)->onNewSurface(info, *props);
87 } 87 }
88 88
89 const char* SkImage::toString(SkString* str) const { 89 const char* SkImage::toString(SkString* str) const {
90 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(), 90 str->appendf("image: (id:%d (%d, %d) %s)", this->uniqueID(), this->width(), this->height(),
91 this->isOpaque() ? "opaque" : ""); 91 this->isOpaque() ? "opaque" : "");
92 return str->c_str(); 92 return str->c_str();
93 } 93 }
94 94
95 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset, 95 SkImage* SkImage::newImage(int newWidth, int newHeight, const SkIRect* subset,
96 SkFilterQuality quality) const { 96 SkFilterQuality quality) const {
97 if (newWidth <= 0 || newHeight <= 0) { 97 if (newWidth <= 0 || newHeight <= 0) {
98 return NULL; 98 return nullptr;
99 } 99 }
100 100
101 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height()); 101 const SkIRect bounds = SkIRect::MakeWH(this->width(), this->height());
102 102
103 if (subset) { 103 if (subset) {
104 if (!bounds.contains(*subset)) { 104 if (!bounds.contains(*subset)) {
105 return NULL; 105 return nullptr;
106 } 106 }
107 if (bounds == *subset) { 107 if (bounds == *subset) {
108 subset = NULL; // and fall through to check below 108 subset = nullptr; // and fall through to check below
109 } 109 }
110 } 110 }
111 111
112 if (NULL == subset && this->width() == newWidth && this->height() == newHeig ht) { 112 if (nullptr == subset && this->width() == newWidth && this->height() == newH eight) {
113 return SkRef(const_cast<SkImage*>(this)); 113 return SkRef(const_cast<SkImage*>(this));
114 } 114 }
115 115
116 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality); 116 return as_IB(this)->onNewImage(newWidth, newHeight, subset, quality);
117 } 117 }
118 118
119 #if SK_SUPPORT_GPU 119 #if SK_SUPPORT_GPU
120 120
121 GrTexture* SkImage::getTexture() const { 121 GrTexture* SkImage::getTexture() const {
122 return as_IB(this)->getTexture(); 122 return as_IB(this)->getTexture();
(...skipping 10 matching lines...) Expand all
133 context->prepareSurfaceForExternalIO(texture); 133 context->prepareSurfaceForExternalIO(texture);
134 } 134 }
135 } 135 }
136 return texture->getTextureHandle(); 136 return texture->getTextureHandle();
137 } 137 }
138 return 0; 138 return 0;
139 } 139 }
140 140
141 #else 141 #else
142 142
143 GrTexture* SkImage::getTexture() const { return NULL; } 143 GrTexture* SkImage::getTexture() const { return nullptr; }
144 144
145 bool SkImage::isTextureBacked() const { return false; } 145 bool SkImage::isTextureBacked() const { return false; }
146 146
147 GrBackendObject SkImage::getTextureHandle(bool) const { return 0; } 147 GrBackendObject SkImage::getTextureHandle(bool) const { return 0; }
148 148
149 #endif 149 #endif
150 150
151 /////////////////////////////////////////////////////////////////////////////// 151 ///////////////////////////////////////////////////////////////////////////////
152 152
153 static bool raster_canvas_supports(const SkImageInfo& info) { 153 static bool raster_canvas_supports(const SkImageInfo& info) {
(...skipping 25 matching lines...) Expand all
179 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint); 179 canvas.drawImage(this, -SkIntToScalar(srcX), -SkIntToScalar(srcY), &paint);
180 180
181 return true; 181 return true;
182 } 182 }
183 183
184 SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* su bset, 184 SkImage* SkImage_Base::onNewImage(int newWidth, int newHeight, const SkIRect* su bset,
185 SkFilterQuality quality) const { 185 SkFilterQuality quality) const {
186 const bool opaque = this->isOpaque(); 186 const bool opaque = this->isOpaque();
187 const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColor Type, 187 const SkImageInfo info = SkImageInfo::Make(newWidth, newHeight, kN32_SkColor Type,
188 opaque ? kOpaque_SkAlphaType : kP remul_SkAlphaType); 188 opaque ? kOpaque_SkAlphaType : kP remul_SkAlphaType);
189 SkAutoTUnref<SkSurface> surface(this->newSurface(info, NULL)); 189 SkAutoTUnref<SkSurface> surface(this->newSurface(info, nullptr));
190 if (!surface.get()) { 190 if (!surface.get()) {
191 return NULL; 191 return nullptr;
192 } 192 }
193 193
194 SkRect src; 194 SkRect src;
195 if (subset) { 195 if (subset) {
196 src.set(*subset); 196 src.set(*subset);
197 } else { 197 } else {
198 src = SkRect::MakeIWH(this->width(), this->height()); 198 src = SkRect::MakeIWH(this->width(), this->height());
199 } 199 }
200 200
201 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height() ); 201 surface->getCanvas()->scale(newWidth / src.width(), newHeight / src.height() );
(...skipping 22 matching lines...) Expand all
224 } 224 }
225 225
226 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const { 226 bool SkImage::readPixels(const SkPixmap& pmap, int srcX, int srcY) const {
227 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY); 227 return this->readPixels(pmap.info(), pmap.writable_addr(), pmap.rowBytes(), srcX, srcY);
228 } 228 }
229 229
230 //////////////////////////////////////////////////////////////////////////////// /////////////////// 230 //////////////////////////////////////////////////////////////////////////////// ///////////////////
231 231
232 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) { 232 SkImage* SkImage::NewFromBitmap(const SkBitmap& bm) {
233 SkPixelRef* pr = bm.pixelRef(); 233 SkPixelRef* pr = bm.pixelRef();
234 if (NULL == pr) { 234 if (nullptr == pr) {
235 return NULL; 235 return nullptr;
236 } 236 }
237 237
238 #if SK_SUPPORT_GPU 238 #if SK_SUPPORT_GPU
239 if (GrTexture* tex = pr->getTexture()) { 239 if (GrTexture* tex = pr->getTexture()) {
240 SkAutoTUnref<GrTexture> unrefCopy; 240 SkAutoTUnref<GrTexture> unrefCopy;
241 if (!bm.isImmutable()) { 241 if (!bm.isImmutable()) {
242 const bool notBudgeted = false; 242 const bool notBudgeted = false;
243 tex = GrDeepCopyTexture(tex, notBudgeted); 243 tex = GrDeepCopyTexture(tex, notBudgeted);
244 if (NULL == tex) { 244 if (nullptr == tex) {
245 return NULL; 245 return nullptr;
246 } 246 }
247 unrefCopy.reset(tex); 247 unrefCopy.reset(tex);
248 } 248 }
249 const SkImageInfo info = bm.info(); 249 const SkImageInfo info = bm.info();
250 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(), 250 return new SkImage_Gpu(info.width(), info.height(), bm.getGenerationID() , info.alphaType(),
251 tex, 0, SkSurface::kNo_Budgeted); 251 tex, 0, SkSurface::kNo_Budgeted);
252 } 252 }
253 #endif 253 #endif
254 254
255 // This will check for immutable (share or copy) 255 // This will check for immutable (share or copy)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 bool SkImage::isLazyGenerated() const { 290 bool SkImage::isLazyGenerated() const {
291 return as_IB(this)->onIsLazyGenerated(); 291 return as_IB(this)->onIsLazyGenerated();
292 } 292 }
293 293
294 //////////////////////////////////////////////////////////////////////////////// ////// 294 //////////////////////////////////////////////////////////////////////////////// //////
295 295
296 #if !SK_SUPPORT_GPU 296 #if !SK_SUPPORT_GPU
297 297
298 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph aType, 298 SkImage* SkImage::NewFromTexture(GrContext*, const GrBackendTextureDesc&, SkAlph aType,
299 TextureReleaseProc, ReleaseContext) { 299 TextureReleaseProc, ReleaseContext) {
300 return NULL; 300 return nullptr;
301 } 301 }
302 302
303 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) { 303 SkImage* SkImage::NewFromAdoptedTexture(GrContext*, const GrBackendTextureDesc&, SkAlphaType) {
304 return NULL; 304 return nullptr;
305 } 305 }
306 306
307 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) { 307 SkImage* SkImage::NewFromTextureCopy(GrContext*, const GrBackendTextureDesc&, Sk AlphaType) {
308 return NULL; 308 return nullptr;
309 } 309 }
310 310
311 #endif 311 #endif
OLDNEW
« no previous file with comments | « src/gpu/glsl/GrGLSLCaps.cpp ('k') | src/image/SkImagePriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698