OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2008 The Android Open Source Project | 3 * Copyright 2008 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (fInfo.alphaType() != newAlphaType) { | 146 if (fInfo.alphaType() != newAlphaType) { |
147 fInfo = fInfo.makeAlphaType(newAlphaType); | 147 fInfo = fInfo.makeAlphaType(newAlphaType); |
148 if (fPixelRef) { | 148 if (fPixelRef) { |
149 fPixelRef->changeAlphaType(newAlphaType); | 149 fPixelRef->changeAlphaType(newAlphaType); |
150 } | 150 } |
151 } | 151 } |
152 return true; | 152 return true; |
153 } | 153 } |
154 | 154 |
155 void SkBitmap::updatePixelsFromRef() const { | 155 void SkBitmap::updatePixelsFromRef() const { |
156 if (NULL != fPixelRef) { | 156 if (fPixelRef) { |
157 if (fPixelLockCount > 0) { | 157 if (fPixelLockCount > 0) { |
158 SkASSERT(fPixelRef->isLocked()); | 158 SkASSERT(fPixelRef->isLocked()); |
159 | 159 |
160 void* p = fPixelRef->pixels(); | 160 void* p = fPixelRef->pixels(); |
161 if (NULL != p) { | 161 if (p) { |
162 p = (char*)p | 162 p = (char*)p |
163 + fPixelRefOrigin.fY * fRowBytes | 163 + fPixelRefOrigin.fY * fRowBytes |
164 + fPixelRefOrigin.fX * fInfo.bytesPerPixel(); | 164 + fPixelRefOrigin.fX * fInfo.bytesPerPixel(); |
165 } | 165 } |
166 fPixels = p; | 166 fPixels = p; |
167 fColorTable = fPixelRef->colorTable(); | 167 fColorTable = fPixelRef->colorTable(); |
168 } else { | 168 } else { |
169 SkASSERT(0 == fPixelLockCount); | 169 SkASSERT(0 == fPixelLockCount); |
170 fPixels = NULL; | 170 fPixels = NULL; |
171 fColorTable = NULL; | 171 fColorTable = NULL; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 SkSafeRef(pr); | 214 SkSafeRef(pr); |
215 fPixelRef = pr; | 215 fPixelRef = pr; |
216 this->updatePixelsFromRef(); | 216 this->updatePixelsFromRef(); |
217 } | 217 } |
218 | 218 |
219 SkDEBUGCODE(this->validate();) | 219 SkDEBUGCODE(this->validate();) |
220 return pr; | 220 return pr; |
221 } | 221 } |
222 | 222 |
223 void SkBitmap::lockPixels() const { | 223 void SkBitmap::lockPixels() const { |
224 if (NULL != fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) { | 224 if (fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) { |
225 fPixelRef->lockPixels(); | 225 fPixelRef->lockPixels(); |
226 this->updatePixelsFromRef(); | 226 this->updatePixelsFromRef(); |
227 } | 227 } |
228 SkDEBUGCODE(this->validate();) | 228 SkDEBUGCODE(this->validate();) |
229 } | 229 } |
230 | 230 |
231 void SkBitmap::unlockPixels() const { | 231 void SkBitmap::unlockPixels() const { |
232 SkASSERT(NULL == fPixelRef || fPixelLockCount > 0); | 232 SkASSERT(NULL == fPixelRef || fPixelLockCount > 0); |
233 | 233 |
234 if (NULL != fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) { | 234 if (fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) { |
235 fPixelRef->unlockPixels(); | 235 fPixelRef->unlockPixels(); |
236 this->updatePixelsFromRef(); | 236 this->updatePixelsFromRef(); |
237 } | 237 } |
238 SkDEBUGCODE(this->validate();) | 238 SkDEBUGCODE(this->validate();) |
239 } | 239 } |
240 | 240 |
241 bool SkBitmap::lockPixelsAreWritable() const { | 241 bool SkBitmap::lockPixelsAreWritable() const { |
242 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; | 242 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; |
243 } | 243 } |
244 | 244 |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 return false; | 369 return false; |
370 } | 370 } |
371 return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), | 371 return this->installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), |
372 mask.fBounds.height()), | 372 mask.fBounds.height()), |
373 mask.fImage, mask.fRowBytes); | 373 mask.fImage, mask.fRowBytes); |
374 } | 374 } |
375 | 375 |
376 /////////////////////////////////////////////////////////////////////////////// | 376 /////////////////////////////////////////////////////////////////////////////// |
377 | 377 |
378 void SkBitmap::freePixels() { | 378 void SkBitmap::freePixels() { |
379 if (NULL != fPixelRef) { | 379 if (fPixelRef) { |
380 if (fPixelLockCount > 0) { | 380 if (fPixelLockCount > 0) { |
381 fPixelRef->unlockPixels(); | 381 fPixelRef->unlockPixels(); |
382 } | 382 } |
383 fPixelRef->unref(); | 383 fPixelRef->unref(); |
384 fPixelRef = NULL; | 384 fPixelRef = NULL; |
385 fPixelRefOrigin.setZero(); | 385 fPixelRefOrigin.setZero(); |
386 } | 386 } |
387 fPixelLockCount = 0; | 387 fPixelLockCount = 0; |
388 fPixels = NULL; | 388 fPixels = NULL; |
389 fColorTable = NULL; | 389 fColorTable = NULL; |
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 SkMatrix identity; | 1096 SkMatrix identity; |
1097 SkMask srcM, dstM; | 1097 SkMask srcM, dstM; |
1098 | 1098 |
1099 srcM.fBounds.set(0, 0, this->width(), this->height()); | 1099 srcM.fBounds.set(0, 0, this->width(), this->height()); |
1100 srcM.fRowBytes = SkAlign4(this->width()); | 1100 srcM.fRowBytes = SkAlign4(this->width()); |
1101 srcM.fFormat = SkMask::kA8_Format; | 1101 srcM.fFormat = SkMask::kA8_Format; |
1102 | 1102 |
1103 SkMaskFilter* filter = paint ? paint->getMaskFilter() : NULL; | 1103 SkMaskFilter* filter = paint ? paint->getMaskFilter() : NULL; |
1104 | 1104 |
1105 // compute our (larger?) dst bounds if we have a filter | 1105 // compute our (larger?) dst bounds if we have a filter |
1106 if (NULL != filter) { | 1106 if (filter) { |
1107 identity.reset(); | 1107 identity.reset(); |
1108 srcM.fImage = NULL; | 1108 srcM.fImage = NULL; |
1109 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { | 1109 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { |
1110 goto NO_FILTER_CASE; | 1110 goto NO_FILTER_CASE; |
1111 } | 1111 } |
1112 dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); | 1112 dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); |
1113 } else { | 1113 } else { |
1114 NO_FILTER_CASE: | 1114 NO_FILTER_CASE: |
1115 tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), sr
cM.fRowBytes); | 1115 tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), sr
cM.fRowBytes); |
1116 if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { | 1116 if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1359 str->append(", not-immutable"); | 1359 str->append(", not-immutable"); |
1360 } | 1360 } |
1361 str->append(")"); | 1361 str->append(")"); |
1362 | 1362 |
1363 SkPixelRef* pr = this->pixelRef(); | 1363 SkPixelRef* pr = this->pixelRef(); |
1364 if (NULL == pr) { | 1364 if (NULL == pr) { |
1365 // show null or the explicit pixel address (rare) | 1365 // show null or the explicit pixel address (rare) |
1366 str->appendf(" pixels:%p", this->getPixels()); | 1366 str->appendf(" pixels:%p", this->getPixels()); |
1367 } else { | 1367 } else { |
1368 const char* uri = pr->getURI(); | 1368 const char* uri = pr->getURI(); |
1369 if (NULL != uri) { | 1369 if (uri) { |
1370 str->appendf(" uri:\"%s\"", uri); | 1370 str->appendf(" uri:\"%s\"", uri); |
1371 } else { | 1371 } else { |
1372 str->appendf(" pixelref:%p", pr); | 1372 str->appendf(" pixelref:%p", pr); |
1373 } | 1373 } |
1374 } | 1374 } |
1375 | 1375 |
1376 str->append(")"); | 1376 str->append(")"); |
1377 } | 1377 } |
1378 #endif | 1378 #endif |
1379 | 1379 |
1380 /////////////////////////////////////////////////////////////////////////////// | 1380 /////////////////////////////////////////////////////////////////////////////// |
1381 | 1381 |
1382 #ifdef SK_DEBUG | 1382 #ifdef SK_DEBUG |
1383 void SkImageInfo::validate() const { | 1383 void SkImageInfo::validate() const { |
1384 SkASSERT(fWidth >= 0); | 1384 SkASSERT(fWidth >= 0); |
1385 SkASSERT(fHeight >= 0); | 1385 SkASSERT(fHeight >= 0); |
1386 SkASSERT(SkColorTypeIsValid(fColorType)); | 1386 SkASSERT(SkColorTypeIsValid(fColorType)); |
1387 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1387 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1388 } | 1388 } |
1389 #endif | 1389 #endif |
OLD | NEW |