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

Side by Side Diff: src/core/SkPixmap.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/core/SkPixelRef.cpp ('k') | src/core/SkPtrRecorder.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 2015 Google Inc. 2 * Copyright 2015 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 "SkColorPriv.h" 8 #include "SkColorPriv.h"
9 #include "SkConfig8888.h" 9 #include "SkConfig8888.h"
10 #include "SkMask.h" 10 #include "SkMask.h"
11 #include "SkPixmap.h" 11 #include "SkPixmap.h"
12 #include "SkUtils.h" 12 #include "SkUtils.h"
13 13
14 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) { 14 void SkAutoPixmapUnlock::reset(const SkPixmap& pm, void (*unlock)(void*), void* ctx) {
15 SkASSERT(pm.addr() != NULL); 15 SkASSERT(pm.addr() != nullptr);
16 16
17 this->unlock(); 17 this->unlock();
18 fPixmap = pm; 18 fPixmap = pm;
19 fUnlockProc = unlock; 19 fUnlockProc = unlock;
20 fUnlockContext = ctx; 20 fUnlockContext = ctx;
21 fIsLocked = true; 21 fIsLocked = true;
22 } 22 }
23 23
24 //////////////////////////////////////////////////////////////////////////////// ///////////////// 24 //////////////////////////////////////////////////////////////////////////////// /////////////////
25 25
26 void SkPixmap::reset() { 26 void SkPixmap::reset() {
27 fPixels = NULL; 27 fPixels = nullptr;
28 fCTable = NULL; 28 fCTable = nullptr;
29 fRowBytes = 0; 29 fRowBytes = 0;
30 fInfo = SkImageInfo::MakeUnknown(); 30 fInfo = SkImageInfo::MakeUnknown();
31 } 31 }
32 32
33 void SkPixmap::reset(const SkImageInfo& info, const void* addr, size_t rowBytes, SkColorTable* ct) { 33 void SkPixmap::reset(const SkImageInfo& info, const void* addr, size_t rowBytes, SkColorTable* ct) {
34 if (addr) { 34 if (addr) {
35 SkASSERT(info.validRowBytes(rowBytes)); 35 SkASSERT(info.validRowBytes(rowBytes));
36 } 36 }
37 fPixels = addr; 37 fPixels = addr;
38 fCTable = ct; 38 fCTable = ct;
39 fRowBytes = rowBytes; 39 fRowBytes = rowBytes;
40 fInfo = info; 40 fInfo = info;
41 } 41 }
42 42
43 bool SkPixmap::reset(const SkMask& src) { 43 bool SkPixmap::reset(const SkMask& src) {
44 if (SkMask::kA8_Format == src.fFormat) { 44 if (SkMask::kA8_Format == src.fFormat) {
45 this->reset(SkImageInfo::MakeA8(src.fBounds.width(), src.fBounds.height( )), 45 this->reset(SkImageInfo::MakeA8(src.fBounds.width(), src.fBounds.height( )),
46 src.fImage, src.fRowBytes, NULL); 46 src.fImage, src.fRowBytes, nullptr);
47 return true; 47 return true;
48 } 48 }
49 this->reset(); 49 this->reset();
50 return false; 50 return false;
51 } 51 }
52 52
53 bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const { 53 bool SkPixmap::extractSubset(SkPixmap* result, const SkIRect& subset) const {
54 SkIRect srcRect, r; 54 SkIRect srcRect, r;
55 srcRect.set(0, 0, this->width(), this->height()); 55 srcRect.set(0, 0, this->width(), this->height());
56 if (!r.intersect(srcRect, subset)) { 56 if (!r.intersect(srcRect, subset)) {
57 return false; // r is empty (i.e. no intersection) 57 return false; // r is empty (i.e. no intersection)
58 } 58 }
59 59
60 // If the upper left of the rectangle was outside the bounds of this SkBitma p, we should have 60 // If the upper left of the rectangle was outside the bounds of this SkBitma p, we should have
61 // exited above. 61 // exited above.
62 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width( ))); 62 SkASSERT(static_cast<unsigned>(r.fLeft) < static_cast<unsigned>(this->width( )));
63 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height( ))); 63 SkASSERT(static_cast<unsigned>(r.fTop) < static_cast<unsigned>(this->height( )));
64 64
65 const void* pixels = NULL; 65 const void* pixels = nullptr;
66 if (fPixels) { 66 if (fPixels) {
67 const size_t bpp = fInfo.bytesPerPixel(); 67 const size_t bpp = fInfo.bytesPerPixel();
68 pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp; 68 pixels = (const uint8_t*)fPixels + r.fTop * fRowBytes + r.fLeft * bpp;
69 } 69 }
70 result->reset(fInfo.makeWH(r.width(), r.height()), pixels, fRowBytes, fCTabl e); 70 result->reset(fInfo.makeWH(r.width(), r.height()), pixels, fRowBytes, fCTabl e);
71 return true; 71 return true;
72 } 72 }
73 73
74 bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB, 74 bool SkPixmap::readPixels(const SkImageInfo& requestedDstInfo, void* dstPixels, size_t dstRB,
75 int x, int y) const { 75 int x, int y) const {
76 if (kUnknown_SkColorType == requestedDstInfo.colorType()) { 76 if (kUnknown_SkColorType == requestedDstInfo.colorType()) {
77 return false; 77 return false;
78 } 78 }
79 if (NULL == dstPixels || dstRB < requestedDstInfo.minRowBytes()) { 79 if (nullptr == dstPixels || dstRB < requestedDstInfo.minRowBytes()) {
80 return false; 80 return false;
81 } 81 }
82 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) { 82 if (0 == requestedDstInfo.width() || 0 == requestedDstInfo.height()) {
83 return false; 83 return false;
84 } 84 }
85 85
86 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs tInfo.height()); 86 SkIRect srcR = SkIRect::MakeXYWH(x, y, requestedDstInfo.width(), requestedDs tInfo.height());
87 if (!srcR.intersect(0, 0, this->width(), this->height())) { 87 if (!srcR.intersect(0, 0, this->width(), this->height())) {
88 return false; 88 return false;
89 } 89 }
(...skipping 19 matching lines...) Expand all
109 109
110 static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b ) { 110 static uint16_t pack_8888_to_4444(unsigned a, unsigned r, unsigned g, unsigned b ) {
111 unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) | 111 unsigned pixel = (SkA32To4444(a) << SK_A4444_SHIFT) |
112 (SkR32To4444(r) << SK_R4444_SHIFT) | 112 (SkR32To4444(r) << SK_R4444_SHIFT) |
113 (SkG32To4444(g) << SK_G4444_SHIFT) | 113 (SkG32To4444(g) << SK_G4444_SHIFT) |
114 (SkB32To4444(b) << SK_B4444_SHIFT); 114 (SkB32To4444(b) << SK_B4444_SHIFT);
115 return SkToU16(pixel); 115 return SkToU16(pixel);
116 } 116 }
117 117
118 bool SkPixmap::erase(SkColor color, const SkIRect& inArea) const { 118 bool SkPixmap::erase(SkColor color, const SkIRect& inArea) const {
119 if (NULL == fPixels) { 119 if (nullptr == fPixels) {
120 return false; 120 return false;
121 } 121 }
122 SkIRect area; 122 SkIRect area;
123 if (!area.intersect(this->bounds(), inArea)) { 123 if (!area.intersect(this->bounds(), inArea)) {
124 return false; 124 return false;
125 } 125 }
126 126
127 U8CPU a = SkColorGetA(color); 127 U8CPU a = SkColorGetA(color);
128 U8CPU r = SkColorGetR(color); 128 U8CPU r = SkColorGetR(color);
129 U8CPU g = SkColorGetG(color); 129 U8CPU g = SkColorGetG(color);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 break; 200 break;
201 } 201 }
202 default: 202 default:
203 return false; // no change, so don't call notifyPixelsChanged() 203 return false; // no change, so don't call notifyPixelsChanged()
204 } 204 }
205 return true; 205 return true;
206 } 206 }
207 207
208 //////////////////////////////////////////////////////////////////////////////// ////////////////// 208 //////////////////////////////////////////////////////////////////////////////// //////////////////
209 209
210 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(NULL) {} 210 SkAutoPixmapStorage::SkAutoPixmapStorage() : fStorage(nullptr) {}
211 211
212 SkAutoPixmapStorage::~SkAutoPixmapStorage() { 212 SkAutoPixmapStorage::~SkAutoPixmapStorage() {
213 this->freeStorage(); 213 this->freeStorage();
214 } 214 }
215 215
216 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) { 216 bool SkAutoPixmapStorage::tryAlloc(const SkImageInfo& info) {
217 this->freeStorage(); 217 this->freeStorage();
218 218
219 size_t rb = info.minRowBytes(); 219 size_t rb = info.minRowBytes();
220 size_t size = info.getSafeSize(rb); 220 size_t size = info.getSafeSize(rb);
221 if (0 == size) { 221 if (0 == size) {
222 return false; 222 return false;
223 } 223 }
224 void* pixels = sk_malloc_flags(size, 0); 224 void* pixels = sk_malloc_flags(size, 0);
225 if (NULL == pixels) { 225 if (nullptr == pixels) {
226 return false; 226 return false;
227 } 227 }
228 this->reset(info, pixels, rb); 228 this->reset(info, pixels, rb);
229 fStorage = pixels; 229 fStorage = pixels;
230 return true; 230 return true;
231 } 231 }
232 232
233 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) { 233 void SkAutoPixmapStorage::alloc(const SkImageInfo& info) {
234 if (!this->tryAlloc(info)) { 234 if (!this->tryAlloc(info)) {
235 sk_throw(); 235 sk_throw();
236 } 236 }
237 } 237 }
OLDNEW
« no previous file with comments | « src/core/SkPixelRef.cpp ('k') | src/core/SkPtrRecorder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698