OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2008 The Android Open Source Project | 2 * Copyright 2008 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 "SkAtomics.h" | 8 #include "SkAtomics.h" |
9 #include "SkBitmap.h" | 9 #include "SkBitmap.h" |
10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 memcpy(this, &src, sizeof(src)); | 49 memcpy(this, &src, sizeof(src)); |
50 | 50 |
51 // inc src reference counts | 51 // inc src reference counts |
52 SkSafeRef(src.fPixelRef); | 52 SkSafeRef(src.fPixelRef); |
53 | 53 |
54 // we reset our locks if we get blown away | 54 // we reset our locks if we get blown away |
55 fPixelLockCount = 0; | 55 fPixelLockCount = 0; |
56 | 56 |
57 if (fPixelRef) { | 57 if (fPixelRef) { |
58 // ignore the values from the memcpy | 58 // ignore the values from the memcpy |
59 fPixels = NULL; | 59 fPixels = nullptr; |
60 fColorTable = NULL; | 60 fColorTable = nullptr; |
61 // Note that what to for genID is somewhat arbitrary. We have no | 61 // Note that what to for genID is somewhat arbitrary. We have no |
62 // way to track changes to raw pixels across multiple SkBitmaps. | 62 // way to track changes to raw pixels across multiple SkBitmaps. |
63 // Would benefit from an SkRawPixelRef type created by | 63 // Would benefit from an SkRawPixelRef type created by |
64 // setPixels. | 64 // setPixels. |
65 // Just leave the memcpy'ed one but they'll get out of sync | 65 // Just leave the memcpy'ed one but they'll get out of sync |
66 // as soon either is modified. | 66 // as soon either is modified. |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 SkDEBUGCODE(this->validate();) | 70 SkDEBUGCODE(this->validate();) |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 void* p = fPixelRef->pixels(); | 158 void* p = fPixelRef->pixels(); |
159 if (p) { | 159 if (p) { |
160 p = (char*)p | 160 p = (char*)p |
161 + fPixelRefOrigin.fY * fRowBytes | 161 + fPixelRefOrigin.fY * fRowBytes |
162 + fPixelRefOrigin.fX * fInfo.bytesPerPixel(); | 162 + fPixelRefOrigin.fX * fInfo.bytesPerPixel(); |
163 } | 163 } |
164 fPixels = p; | 164 fPixels = p; |
165 fColorTable = fPixelRef->colorTable(); | 165 fColorTable = fPixelRef->colorTable(); |
166 } else { | 166 } else { |
167 SkASSERT(0 == fPixelLockCount); | 167 SkASSERT(0 == fPixelLockCount); |
168 fPixels = NULL; | 168 fPixels = nullptr; |
169 fColorTable = NULL; | 169 fColorTable = nullptr; |
170 } | 170 } |
171 } | 171 } |
172 } | 172 } |
173 | 173 |
174 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { | 174 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, int dx, int dy) { |
175 #ifdef SK_DEBUG | 175 #ifdef SK_DEBUG |
176 if (pr) { | 176 if (pr) { |
177 if (kUnknown_SkColorType != fInfo.colorType()) { | 177 if (kUnknown_SkColorType != fInfo.colorType()) { |
178 const SkImageInfo& prInfo = pr->info(); | 178 const SkImageInfo& prInfo = pr->info(); |
179 SkASSERT(fInfo.width() <= prInfo.width()); | 179 SkASSERT(fInfo.width() <= prInfo.width()); |
(...skipping 20 matching lines...) Expand all Loading... |
200 if (pr) { | 200 if (pr) { |
201 const SkImageInfo& info = pr->info(); | 201 const SkImageInfo& info = pr->info(); |
202 fPixelRefOrigin.set(SkPin32(dx, 0, info.width()), SkPin32(dy, 0, info.he
ight())); | 202 fPixelRefOrigin.set(SkPin32(dx, 0, info.width()), SkPin32(dy, 0, info.he
ight())); |
203 } else { | 203 } else { |
204 // ignore dx,dy if there is no pixelref | 204 // ignore dx,dy if there is no pixelref |
205 fPixelRefOrigin.setZero(); | 205 fPixelRefOrigin.setZero(); |
206 } | 206 } |
207 | 207 |
208 if (fPixelRef != pr) { | 208 if (fPixelRef != pr) { |
209 this->freePixels(); | 209 this->freePixels(); |
210 SkASSERT(NULL == fPixelRef); | 210 SkASSERT(nullptr == fPixelRef); |
211 | 211 |
212 SkSafeRef(pr); | 212 SkSafeRef(pr); |
213 fPixelRef = pr; | 213 fPixelRef = pr; |
214 this->updatePixelsFromRef(); | 214 this->updatePixelsFromRef(); |
215 } | 215 } |
216 | 216 |
217 SkDEBUGCODE(this->validate();) | 217 SkDEBUGCODE(this->validate();) |
218 return pr; | 218 return pr; |
219 } | 219 } |
220 | 220 |
221 void SkBitmap::lockPixels() const { | 221 void SkBitmap::lockPixels() const { |
222 if (fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) { | 222 if (fPixelRef && 0 == sk_atomic_inc(&fPixelLockCount)) { |
223 fPixelRef->lockPixels(); | 223 fPixelRef->lockPixels(); |
224 this->updatePixelsFromRef(); | 224 this->updatePixelsFromRef(); |
225 } | 225 } |
226 SkDEBUGCODE(this->validate();) | 226 SkDEBUGCODE(this->validate();) |
227 } | 227 } |
228 | 228 |
229 void SkBitmap::unlockPixels() const { | 229 void SkBitmap::unlockPixels() const { |
230 SkASSERT(NULL == fPixelRef || fPixelLockCount > 0); | 230 SkASSERT(nullptr == fPixelRef || fPixelLockCount > 0); |
231 | 231 |
232 if (fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) { | 232 if (fPixelRef && 1 == sk_atomic_dec(&fPixelLockCount)) { |
233 fPixelRef->unlockPixels(); | 233 fPixelRef->unlockPixels(); |
234 this->updatePixelsFromRef(); | 234 this->updatePixelsFromRef(); |
235 } | 235 } |
236 SkDEBUGCODE(this->validate();) | 236 SkDEBUGCODE(this->validate();) |
237 } | 237 } |
238 | 238 |
239 bool SkBitmap::lockPixelsAreWritable() const { | 239 bool SkBitmap::lockPixelsAreWritable() const { |
240 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; | 240 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; |
241 } | 241 } |
242 | 242 |
243 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { | 243 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
244 if (NULL == p) { | 244 if (nullptr == p) { |
245 this->setPixelRef(NULL); | 245 this->setPixelRef(nullptr); |
246 return; | 246 return; |
247 } | 247 } |
248 | 248 |
249 if (kUnknown_SkColorType == fInfo.colorType()) { | 249 if (kUnknown_SkColorType == fInfo.colorType()) { |
250 this->setPixelRef(NULL); | 250 this->setPixelRef(nullptr); |
251 return; | 251 return; |
252 } | 252 } |
253 | 253 |
254 SkPixelRef* pr = SkMallocPixelRef::NewDirect(fInfo, p, fRowBytes, ctable); | 254 SkPixelRef* pr = SkMallocPixelRef::NewDirect(fInfo, p, fRowBytes, ctable); |
255 if (NULL == pr) { | 255 if (nullptr == pr) { |
256 this->setPixelRef(NULL); | 256 this->setPixelRef(nullptr); |
257 return; | 257 return; |
258 } | 258 } |
259 | 259 |
260 this->setPixelRef(pr)->unref(); | 260 this->setPixelRef(pr)->unref(); |
261 | 261 |
262 // since we're already allocated, we lockPixels right away | 262 // since we're already allocated, we lockPixels right away |
263 this->lockPixels(); | 263 this->lockPixels(); |
264 SkDEBUGCODE(this->validate();) | 264 SkDEBUGCODE(this->validate();) |
265 } | 265 } |
266 | 266 |
267 bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) { | 267 bool SkBitmap::tryAllocPixels(Allocator* allocator, SkColorTable* ctable) { |
268 HeapAllocator stdalloc; | 268 HeapAllocator stdalloc; |
269 | 269 |
270 if (NULL == allocator) { | 270 if (nullptr == allocator) { |
271 allocator = &stdalloc; | 271 allocator = &stdalloc; |
272 } | 272 } |
273 return allocator->allocPixelRef(this, ctable); | 273 return allocator->allocPixelRef(this, ctable); |
274 } | 274 } |
275 | 275 |
276 /////////////////////////////////////////////////////////////////////////////// | 276 /////////////////////////////////////////////////////////////////////////////// |
277 | 277 |
278 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
{ | 278 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, size_t rowBytes)
{ |
279 if (kIndex_8_SkColorType == requestedInfo.colorType()) { | 279 if (kIndex_8_SkColorType == requestedInfo.colorType()) { |
280 return reset_return_false(this); | 280 return reset_return_false(this); |
281 } | 281 } |
282 if (!this->setInfo(requestedInfo, rowBytes)) { | 282 if (!this->setInfo(requestedInfo, rowBytes)) { |
283 return reset_return_false(this); | 283 return reset_return_false(this); |
284 } | 284 } |
285 | 285 |
286 // setInfo may have corrected info (e.g. 565 is always opaque). | 286 // setInfo may have corrected info (e.g. 565 is always opaque). |
287 const SkImageInfo& correctedInfo = this->info(); | 287 const SkImageInfo& correctedInfo = this->info(); |
288 // setInfo may have computed a valid rowbytes if 0 were passed in | 288 // setInfo may have computed a valid rowbytes if 0 were passed in |
289 rowBytes = this->rowBytes(); | 289 rowBytes = this->rowBytes(); |
290 | 290 |
291 SkMallocPixelRef::PRFactory defaultFactory; | 291 SkMallocPixelRef::PRFactory defaultFactory; |
292 | 292 |
293 SkPixelRef* pr = defaultFactory.create(correctedInfo, rowBytes, NULL); | 293 SkPixelRef* pr = defaultFactory.create(correctedInfo, rowBytes, nullptr); |
294 if (NULL == pr) { | 294 if (nullptr == pr) { |
295 return reset_return_false(this); | 295 return reset_return_false(this); |
296 } | 296 } |
297 this->setPixelRef(pr)->unref(); | 297 this->setPixelRef(pr)->unref(); |
298 | 298 |
299 // TODO: lockPixels could/should return bool or void*/NULL | 299 // TODO: lockPixels could/should return bool or void*/nullptr |
300 this->lockPixels(); | 300 this->lockPixels(); |
301 if (NULL == this->getPixels()) { | 301 if (nullptr == this->getPixels()) { |
302 return reset_return_false(this); | 302 return reset_return_false(this); |
303 } | 303 } |
304 return true; | 304 return true; |
305 } | 305 } |
306 | 306 |
307 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactor
y* factory, | 307 bool SkBitmap::tryAllocPixels(const SkImageInfo& requestedInfo, SkPixelRefFactor
y* factory, |
308 SkColorTable* ctable) { | 308 SkColorTable* ctable) { |
309 if (kIndex_8_SkColorType == requestedInfo.colorType() && NULL == ctable) { | 309 if (kIndex_8_SkColorType == requestedInfo.colorType() && nullptr == ctable)
{ |
310 return reset_return_false(this); | 310 return reset_return_false(this); |
311 } | 311 } |
312 if (!this->setInfo(requestedInfo)) { | 312 if (!this->setInfo(requestedInfo)) { |
313 return reset_return_false(this); | 313 return reset_return_false(this); |
314 } | 314 } |
315 | 315 |
316 // setInfo may have corrected info (e.g. 565 is always opaque). | 316 // setInfo may have corrected info (e.g. 565 is always opaque). |
317 const SkImageInfo& correctedInfo = this->info(); | 317 const SkImageInfo& correctedInfo = this->info(); |
318 | 318 |
319 SkMallocPixelRef::PRFactory defaultFactory; | 319 SkMallocPixelRef::PRFactory defaultFactory; |
320 if (NULL == factory) { | 320 if (nullptr == factory) { |
321 factory = &defaultFactory; | 321 factory = &defaultFactory; |
322 } | 322 } |
323 | 323 |
324 SkPixelRef* pr = factory->create(correctedInfo, correctedInfo.minRowBytes(),
ctable); | 324 SkPixelRef* pr = factory->create(correctedInfo, correctedInfo.minRowBytes(),
ctable); |
325 if (NULL == pr) { | 325 if (nullptr == pr) { |
326 return reset_return_false(this); | 326 return reset_return_false(this); |
327 } | 327 } |
328 this->setPixelRef(pr)->unref(); | 328 this->setPixelRef(pr)->unref(); |
329 | 329 |
330 // TODO: lockPixels could/should return bool or void*/NULL | 330 // TODO: lockPixels could/should return bool or void*/nullptr |
331 this->lockPixels(); | 331 this->lockPixels(); |
332 if (NULL == this->getPixels()) { | 332 if (nullptr == this->getPixels()) { |
333 return reset_return_false(this); | 333 return reset_return_false(this); |
334 } | 334 } |
335 return true; | 335 return true; |
336 } | 336 } |
337 | 337 |
338 static void invoke_release_proc(void (*proc)(void* pixels, void* ctx), void* pix
els, void* ctx) { | 338 static void invoke_release_proc(void (*proc)(void* pixels, void* ctx), void* pix
els, void* ctx) { |
339 if (proc) { | 339 if (proc) { |
340 proc(pixels, ctx); | 340 proc(pixels, ctx); |
341 } | 341 } |
342 } | 342 } |
343 | 343 |
344 bool SkBitmap::installPixels(const SkImageInfo& requestedInfo, void* pixels, siz
e_t rb, | 344 bool SkBitmap::installPixels(const SkImageInfo& requestedInfo, void* pixels, siz
e_t rb, |
345 SkColorTable* ct, void (*releaseProc)(void* addr, v
oid* context), | 345 SkColorTable* ct, void (*releaseProc)(void* addr, v
oid* context), |
346 void* context) { | 346 void* context) { |
347 if (!this->setInfo(requestedInfo, rb)) { | 347 if (!this->setInfo(requestedInfo, rb)) { |
348 invoke_release_proc(releaseProc, pixels, context); | 348 invoke_release_proc(releaseProc, pixels, context); |
349 this->reset(); | 349 this->reset(); |
350 return false; | 350 return false; |
351 } | 351 } |
352 if (NULL == pixels) { | 352 if (nullptr == pixels) { |
353 invoke_release_proc(releaseProc, pixels, context); | 353 invoke_release_proc(releaseProc, pixels, context); |
354 return true; // we behaved as if they called setInfo() | 354 return true; // we behaved as if they called setInfo() |
355 } | 355 } |
356 | 356 |
357 // setInfo may have corrected info (e.g. 565 is always opaque). | 357 // setInfo may have corrected info (e.g. 565 is always opaque). |
358 const SkImageInfo& correctedInfo = this->info(); | 358 const SkImageInfo& correctedInfo = this->info(); |
359 | 359 |
360 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(correctedInfo, rb, ct, pixels
, releaseProc, | 360 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(correctedInfo, rb, ct, pixels
, releaseProc, |
361 context); | 361 context); |
362 if (!pr) { | 362 if (!pr) { |
(...skipping 20 matching lines...) Expand all Loading... |
383 } | 383 } |
384 | 384 |
385 /////////////////////////////////////////////////////////////////////////////// | 385 /////////////////////////////////////////////////////////////////////////////// |
386 | 386 |
387 void SkBitmap::freePixels() { | 387 void SkBitmap::freePixels() { |
388 if (fPixelRef) { | 388 if (fPixelRef) { |
389 if (fPixelLockCount > 0) { | 389 if (fPixelLockCount > 0) { |
390 fPixelRef->unlockPixels(); | 390 fPixelRef->unlockPixels(); |
391 } | 391 } |
392 fPixelRef->unref(); | 392 fPixelRef->unref(); |
393 fPixelRef = NULL; | 393 fPixelRef = nullptr; |
394 fPixelRefOrigin.setZero(); | 394 fPixelRefOrigin.setZero(); |
395 } | 395 } |
396 fPixelLockCount = 0; | 396 fPixelLockCount = 0; |
397 fPixels = NULL; | 397 fPixels = nullptr; |
398 fColorTable = NULL; | 398 fColorTable = nullptr; |
399 } | 399 } |
400 | 400 |
401 uint32_t SkBitmap::getGenerationID() const { | 401 uint32_t SkBitmap::getGenerationID() const { |
402 return (fPixelRef) ? fPixelRef->getGenerationID() : 0; | 402 return (fPixelRef) ? fPixelRef->getGenerationID() : 0; |
403 } | 403 } |
404 | 404 |
405 void SkBitmap::notifyPixelsChanged() const { | 405 void SkBitmap::notifyPixelsChanged() const { |
406 SkASSERT(!this->isImmutable()); | 406 SkASSERT(!this->isImmutable()); |
407 if (fPixelRef) { | 407 if (fPixelRef) { |
408 fPixelRef->notifyPixelsChanged(); | 408 fPixelRef->notifyPixelsChanged(); |
409 } | 409 } |
410 } | 410 } |
411 | 411 |
412 GrTexture* SkBitmap::getTexture() const { | 412 GrTexture* SkBitmap::getTexture() const { |
413 return fPixelRef ? fPixelRef->getTexture() : NULL; | 413 return fPixelRef ? fPixelRef->getTexture() : nullptr; |
414 } | 414 } |
415 | 415 |
416 /////////////////////////////////////////////////////////////////////////////// | 416 /////////////////////////////////////////////////////////////////////////////// |
417 | 417 |
418 /** We explicitly use the same allocator for our pixels that SkMask does, | 418 /** We explicitly use the same allocator for our pixels that SkMask does, |
419 so that we can freely assign memory allocated by one class to the other. | 419 so that we can freely assign memory allocated by one class to the other. |
420 */ | 420 */ |
421 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, | 421 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, |
422 SkColorTable* ctable) { | 422 SkColorTable* ctable) { |
423 const SkImageInfo info = dst->info(); | 423 const SkImageInfo info = dst->info(); |
424 if (kUnknown_SkColorType == info.colorType()) { | 424 if (kUnknown_SkColorType == info.colorType()) { |
425 // SkDebugf("unsupported config for info %d\n", dst->config()); | 425 // SkDebugf("unsupported config for info %d\n", dst->config()); |
426 return false; | 426 return false; |
427 } | 427 } |
428 | 428 |
429 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), ctable
); | 429 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), ctable
); |
430 if (NULL == pr) { | 430 if (nullptr == pr) { |
431 return false; | 431 return false; |
432 } | 432 } |
433 | 433 |
434 dst->setPixelRef(pr)->unref(); | 434 dst->setPixelRef(pr)->unref(); |
435 // since we're already allocated, we lockPixels right away | 435 // since we're already allocated, we lockPixels right away |
436 dst->lockPixels(); | 436 dst->lockPixels(); |
437 return true; | 437 return true; |
438 } | 438 } |
439 | 439 |
440 /////////////////////////////////////////////////////////////////////////////// | 440 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 srcP += src.rowBytes(); | 475 srcP += src.rowBytes(); |
476 dstP += dstRowBytes; | 476 dstP += dstRowBytes; |
477 } | 477 } |
478 | 478 |
479 return true; | 479 return true; |
480 } | 480 } |
481 } | 481 } |
482 } | 482 } |
483 | 483 |
484 bool SkBitmap::copyPixelsTo(void* dst, size_t dstSize, size_t dstRB, bool preser
veDstPad) const { | 484 bool SkBitmap::copyPixelsTo(void* dst, size_t dstSize, size_t dstRB, bool preser
veDstPad) const { |
485 if (NULL == dst) { | 485 if (nullptr == dst) { |
486 return false; | 486 return false; |
487 } | 487 } |
488 SkAutoPixmapUnlock result; | 488 SkAutoPixmapUnlock result; |
489 if (!this->requestLock(&result)) { | 489 if (!this->requestLock(&result)) { |
490 return false; | 490 return false; |
491 } | 491 } |
492 return copy_pixels_to(result.pixmap(), dst, dstSize, dstRB, preserveDstPad); | 492 return copy_pixels_to(result.pixmap(), dst, dstSize, dstRB, preserveDstPad); |
493 } | 493 } |
494 | 494 |
495 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
532 case kRGB_565_SkColorType: | 532 case kRGB_565_SkColorType: |
533 base += x << 1; | 533 base += x << 1; |
534 break; | 534 break; |
535 case kAlpha_8_SkColorType: | 535 case kAlpha_8_SkColorType: |
536 case kIndex_8_SkColorType: | 536 case kIndex_8_SkColorType: |
537 case kGray_8_SkColorType: | 537 case kGray_8_SkColorType: |
538 base += x; | 538 base += x; |
539 break; | 539 break; |
540 default: | 540 default: |
541 SkDEBUGFAIL("Can't return addr for config"); | 541 SkDEBUGFAIL("Can't return addr for config"); |
542 base = NULL; | 542 base = nullptr; |
543 break; | 543 break; |
544 } | 544 } |
545 } | 545 } |
546 return base; | 546 return base; |
547 } | 547 } |
548 | 548 |
549 SkColor SkBitmap::getColor(int x, int y) const { | 549 SkColor SkBitmap::getColor(int x, int y) const { |
550 SkASSERT((unsigned)x < (unsigned)this->width()); | 550 SkASSERT((unsigned)x < (unsigned)this->width()); |
551 SkASSERT((unsigned)y < (unsigned)this->height()); | 551 SkASSERT((unsigned)y < (unsigned)this->height()); |
552 | 552 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 a &= row[x]; | 598 a &= row[x]; |
599 } | 599 } |
600 if (0xFF != a) { | 600 if (0xFF != a) { |
601 return false; | 601 return false; |
602 } | 602 } |
603 } | 603 } |
604 return true; | 604 return true; |
605 } break; | 605 } break; |
606 case kIndex_8_SkColorType: { | 606 case kIndex_8_SkColorType: { |
607 const SkColorTable* ctable = pmap.ctable(); | 607 const SkColorTable* ctable = pmap.ctable(); |
608 if (NULL == ctable) { | 608 if (nullptr == ctable) { |
609 return false; | 609 return false; |
610 } | 610 } |
611 const SkPMColor* table = ctable->readColors(); | 611 const SkPMColor* table = ctable->readColors(); |
612 SkPMColor c = (SkPMColor)~0; | 612 SkPMColor c = (SkPMColor)~0; |
613 for (int i = ctable->count() - 1; i >= 0; --i) { | 613 for (int i = ctable->count() - 1; i >= 0; --i) { |
614 c &= table[i]; | 614 c &= table[i]; |
615 } | 615 } |
616 return 0xFF == SkGetPackedA32(c); | 616 return 0xFF == SkGetPackedA32(c); |
617 } break; | 617 } break; |
618 case kRGB_565_SkColorType: | 618 case kRGB_565_SkColorType: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 void SkBitmap::eraseColor(SkColor c) const { | 689 void SkBitmap::eraseColor(SkColor c) const { |
690 this->erase(c, SkIRect::MakeWH(this->width(), this->height())); | 690 this->erase(c, SkIRect::MakeWH(this->width(), this->height())); |
691 } | 691 } |
692 | 692 |
693 ////////////////////////////////////////////////////////////////////////////////
////// | 693 ////////////////////////////////////////////////////////////////////////////////
////// |
694 ////////////////////////////////////////////////////////////////////////////////
////// | 694 ////////////////////////////////////////////////////////////////////////////////
////// |
695 | 695 |
696 bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { | 696 bool SkBitmap::extractSubset(SkBitmap* result, const SkIRect& subset) const { |
697 SkDEBUGCODE(this->validate();) | 697 SkDEBUGCODE(this->validate();) |
698 | 698 |
699 if (NULL == result || NULL == fPixelRef) { | 699 if (nullptr == result || nullptr == fPixelRef) { |
700 return false; // no src pixels | 700 return false; // no src pixels |
701 } | 701 } |
702 | 702 |
703 SkIRect srcRect, r; | 703 SkIRect srcRect, r; |
704 srcRect.set(0, 0, this->width(), this->height()); | 704 srcRect.set(0, 0, this->width(), this->height()); |
705 if (!r.intersect(srcRect, subset)) { | 705 if (!r.intersect(srcRect, subset)) { |
706 return false; // r is empty (i.e. no intersection) | 706 return false; // r is empty (i.e. no intersection) |
707 } | 707 } |
708 | 708 |
709 if (fPixelRef->getTexture() != NULL) { | 709 if (fPixelRef->getTexture() != nullptr) { |
710 // Do a deep copy | 710 // Do a deep copy |
711 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->prof
ileType(), &subset); | 711 SkPixelRef* pixelRef = fPixelRef->deepCopy(this->colorType(), this->prof
ileType(), &subset); |
712 if (pixelRef != NULL) { | 712 if (pixelRef != nullptr) { |
713 SkBitmap dst; | 713 SkBitmap dst; |
714 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), | 714 dst.setInfo(SkImageInfo::Make(subset.width(), subset.height(), |
715 this->colorType(), this->alphaType()))
; | 715 this->colorType(), this->alphaType()))
; |
716 dst.setIsVolatile(this->isVolatile()); | 716 dst.setIsVolatile(this->isVolatile()); |
717 dst.setPixelRef(pixelRef)->unref(); | 717 dst.setPixelRef(pixelRef)->unref(); |
718 SkDEBUGCODE(dst.validate()); | 718 SkDEBUGCODE(dst.validate()); |
719 result->swap(dst); | 719 result->swap(dst); |
720 return true; | 720 return true; |
721 } | 721 } |
722 } | 722 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 if (fPixelRef->readPixels(&tmpSrc, &subset)) { | 809 if (fPixelRef->readPixels(&tmpSrc, &subset)) { |
810 if (fPixelRef->info().alphaType() == kUnpremul_SkAlphaType) { | 810 if (fPixelRef->info().alphaType() == kUnpremul_SkAlphaType) { |
811 // FIXME: The only meaningful implementation of readPixels | 811 // FIXME: The only meaningful implementation of readPixels |
812 // (GrPixelRef) assumes premultiplied pixels. | 812 // (GrPixelRef) assumes premultiplied pixels. |
813 return false; | 813 return false; |
814 } | 814 } |
815 SkASSERT(tmpSrc.width() == this->width()); | 815 SkASSERT(tmpSrc.width() == this->width()); |
816 SkASSERT(tmpSrc.height() == this->height()); | 816 SkASSERT(tmpSrc.height() == this->height()); |
817 | 817 |
818 // did we get lucky and we can just return tmpSrc? | 818 // did we get lucky and we can just return tmpSrc? |
819 if (tmpSrc.colorType() == dstColorType && NULL == alloc) { | 819 if (tmpSrc.colorType() == dstColorType && nullptr == alloc) { |
820 dst->swap(tmpSrc); | 820 dst->swap(tmpSrc); |
821 // If the result is an exact copy, clone the gen ID. | 821 // If the result is an exact copy, clone the gen ID. |
822 if (dst->pixelRef() && dst->pixelRef()->info() == fPixelRef->inf
o()) { | 822 if (dst->pixelRef() && dst->pixelRef()->info() == fPixelRef->inf
o()) { |
823 dst->pixelRef()->cloneGenID(*fPixelRef); | 823 dst->pixelRef()->cloneGenID(*fPixelRef); |
824 } | 824 } |
825 return true; | 825 return true; |
826 } | 826 } |
827 | 827 |
828 // fall through to the raster case | 828 // fall through to the raster case |
829 src = &tmpSrc; | 829 src = &tmpSrc; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
881 const SkColorType dstCT = this->colorType(); | 881 const SkColorType dstCT = this->colorType(); |
882 const SkColorProfileType dstPT = this->profileType(); | 882 const SkColorProfileType dstPT = this->profileType(); |
883 | 883 |
884 if (!this->canCopyTo(dstCT)) { | 884 if (!this->canCopyTo(dstCT)) { |
885 return false; | 885 return false; |
886 } | 886 } |
887 | 887 |
888 // If we have a PixelRef, and it supports deep copy, use it. | 888 // If we have a PixelRef, and it supports deep copy, use it. |
889 // Currently supported only by texture-backed bitmaps. | 889 // Currently supported only by texture-backed bitmaps. |
890 if (fPixelRef) { | 890 if (fPixelRef) { |
891 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstPT, NULL); | 891 SkPixelRef* pixelRef = fPixelRef->deepCopy(dstCT, dstPT, nullptr); |
892 if (pixelRef) { | 892 if (pixelRef) { |
893 uint32_t rowBytes; | 893 uint32_t rowBytes; |
894 if (this->colorType() == dstCT && this->profileType() == dstPT) { | 894 if (this->colorType() == dstCT && this->profileType() == dstPT) { |
895 // Since there is no subset to pass to deepCopy, and deepCopy | 895 // Since there is no subset to pass to deepCopy, and deepCopy |
896 // succeeded, the new pixel ref must be identical. | 896 // succeeded, the new pixel ref must be identical. |
897 SkASSERT(fPixelRef->info() == pixelRef->info()); | 897 SkASSERT(fPixelRef->info() == pixelRef->info()); |
898 pixelRef->cloneGenID(*fPixelRef); | 898 pixelRef->cloneGenID(*fPixelRef); |
899 // Use the same rowBytes as the original. | 899 // Use the same rowBytes as the original. |
900 rowBytes = fRowBytes; | 900 rowBytes = fRowBytes; |
901 } else { | 901 } else { |
902 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. | 902 // With the new config, an appropriate fRowBytes will be compute
d by setInfo. |
903 rowBytes = 0; | 903 rowBytes = 0; |
904 } | 904 } |
905 | 905 |
906 const SkImageInfo info = fInfo.makeColorType(dstCT); | 906 const SkImageInfo info = fInfo.makeColorType(dstCT); |
907 if (!dst->setInfo(info, rowBytes)) { | 907 if (!dst->setInfo(info, rowBytes)) { |
908 return false; | 908 return false; |
909 } | 909 } |
910 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); | 910 dst->setPixelRef(pixelRef, fPixelRefOrigin)->unref(); |
911 return true; | 911 return true; |
912 } | 912 } |
913 } | 913 } |
914 | 914 |
915 if (this->getTexture()) { | 915 if (this->getTexture()) { |
916 return false; | 916 return false; |
917 } else { | 917 } else { |
918 return this->copyTo(dst, dstCT, NULL); | 918 return this->copyTo(dst, dstCT, nullptr); |
919 } | 919 } |
920 } | 920 } |
921 | 921 |
922 /////////////////////////////////////////////////////////////////////////////// | 922 /////////////////////////////////////////////////////////////////////////////// |
923 | 923 |
924 static void rect_memset(uint8_t* array, U8CPU value, SkISize size, size_t rowByt
es) { | 924 static void rect_memset(uint8_t* array, U8CPU value, SkISize size, size_t rowByt
es) { |
925 for (int y = 0; y < size.height(); ++y) { | 925 for (int y = 0; y < size.height(); ++y) { |
926 memset(array, value, size.width()); | 926 memset(array, value, size.width()); |
927 array += rowBytes; | 927 array += rowBytes; |
928 } | 928 } |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
971 s += rb; | 971 s += rb; |
972 alpha += alphaRowBytes; | 972 alpha += alphaRowBytes; |
973 } | 973 } |
974 } | 974 } |
975 } else { // src is opaque, so just fill alpha[] with 0xFF | 975 } else { // src is opaque, so just fill alpha[] with 0xFF |
976 rect_memset(alpha, 0xFF, pmap.info().dimensions(), alphaRowBytes); | 976 rect_memset(alpha, 0xFF, pmap.info().dimensions(), alphaRowBytes); |
977 } | 977 } |
978 } | 978 } |
979 | 979 |
980 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int
alphaRowBytes) { | 980 static bool GetBitmapAlpha(const SkBitmap& src, uint8_t* SK_RESTRICT alpha, int
alphaRowBytes) { |
981 SkASSERT(alpha != NULL); | 981 SkASSERT(alpha != nullptr); |
982 SkASSERT(alphaRowBytes >= src.width()); | 982 SkASSERT(alphaRowBytes >= src.width()); |
983 | 983 |
984 SkAutoPixmapUnlock apl; | 984 SkAutoPixmapUnlock apl; |
985 if (!src.requestLock(&apl)) { | 985 if (!src.requestLock(&apl)) { |
986 rect_memset(alpha, 0, src.info().dimensions(), alphaRowBytes); | 986 rect_memset(alpha, 0, src.info().dimensions(), alphaRowBytes); |
987 return false; | 987 return false; |
988 } | 988 } |
989 get_bitmap_alpha(apl.pixmap(), alpha, alphaRowBytes); | 989 get_bitmap_alpha(apl.pixmap(), alpha, alphaRowBytes); |
990 return true; | 990 return true; |
991 } | 991 } |
992 | 992 |
993 #include "SkPaint.h" | 993 #include "SkPaint.h" |
994 #include "SkMaskFilter.h" | 994 #include "SkMaskFilter.h" |
995 #include "SkMatrix.h" | 995 #include "SkMatrix.h" |
996 | 996 |
997 bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, | 997 bool SkBitmap::extractAlpha(SkBitmap* dst, const SkPaint* paint, |
998 Allocator *allocator, SkIPoint* offset) const { | 998 Allocator *allocator, SkIPoint* offset) const { |
999 SkDEBUGCODE(this->validate();) | 999 SkDEBUGCODE(this->validate();) |
1000 | 1000 |
1001 SkBitmap tmpBitmap; | 1001 SkBitmap tmpBitmap; |
1002 SkMatrix identity; | 1002 SkMatrix identity; |
1003 SkMask srcM, dstM; | 1003 SkMask srcM, dstM; |
1004 | 1004 |
1005 srcM.fBounds.set(0, 0, this->width(), this->height()); | 1005 srcM.fBounds.set(0, 0, this->width(), this->height()); |
1006 srcM.fRowBytes = SkAlign4(this->width()); | 1006 srcM.fRowBytes = SkAlign4(this->width()); |
1007 srcM.fFormat = SkMask::kA8_Format; | 1007 srcM.fFormat = SkMask::kA8_Format; |
1008 | 1008 |
1009 SkMaskFilter* filter = paint ? paint->getMaskFilter() : NULL; | 1009 SkMaskFilter* filter = paint ? paint->getMaskFilter() : nullptr; |
1010 | 1010 |
1011 // compute our (larger?) dst bounds if we have a filter | 1011 // compute our (larger?) dst bounds if we have a filter |
1012 if (filter) { | 1012 if (filter) { |
1013 identity.reset(); | 1013 identity.reset(); |
1014 srcM.fImage = NULL; | 1014 srcM.fImage = nullptr; |
1015 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { | 1015 if (!filter->filterMask(&dstM, srcM, identity, nullptr)) { |
1016 goto NO_FILTER_CASE; | 1016 goto NO_FILTER_CASE; |
1017 } | 1017 } |
1018 dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); | 1018 dstM.fRowBytes = SkAlign4(dstM.fBounds.width()); |
1019 } else { | 1019 } else { |
1020 NO_FILTER_CASE: | 1020 NO_FILTER_CASE: |
1021 tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), sr
cM.fRowBytes); | 1021 tmpBitmap.setInfo(SkImageInfo::MakeA8(this->width(), this->height()), sr
cM.fRowBytes); |
1022 if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { | 1022 if (!tmpBitmap.tryAllocPixels(allocator, nullptr)) { |
1023 // Allocation of pixels for alpha bitmap failed. | 1023 // Allocation of pixels for alpha bitmap failed. |
1024 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", | 1024 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", |
1025 tmpBitmap.width(), tmpBitmap.height()); | 1025 tmpBitmap.width(), tmpBitmap.height()); |
1026 return false; | 1026 return false; |
1027 } | 1027 } |
1028 GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes); | 1028 GetBitmapAlpha(*this, tmpBitmap.getAddr8(0, 0), srcM.fRowBytes); |
1029 if (offset) { | 1029 if (offset) { |
1030 offset->set(0, 0); | 1030 offset->set(0, 0); |
1031 } | 1031 } |
1032 tmpBitmap.swap(*dst); | 1032 tmpBitmap.swap(*dst); |
1033 return true; | 1033 return true; |
1034 } | 1034 } |
1035 srcM.fImage = SkMask::AllocImage(srcM.computeImageSize()); | 1035 srcM.fImage = SkMask::AllocImage(srcM.computeImageSize()); |
1036 SkAutoMaskFreeImage srcCleanup(srcM.fImage); | 1036 SkAutoMaskFreeImage srcCleanup(srcM.fImage); |
1037 | 1037 |
1038 GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes); | 1038 GetBitmapAlpha(*this, srcM.fImage, srcM.fRowBytes); |
1039 if (!filter->filterMask(&dstM, srcM, identity, NULL)) { | 1039 if (!filter->filterMask(&dstM, srcM, identity, nullptr)) { |
1040 goto NO_FILTER_CASE; | 1040 goto NO_FILTER_CASE; |
1041 } | 1041 } |
1042 SkAutoMaskFreeImage dstCleanup(dstM.fImage); | 1042 SkAutoMaskFreeImage dstCleanup(dstM.fImage); |
1043 | 1043 |
1044 tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.hei
ght()), | 1044 tmpBitmap.setInfo(SkImageInfo::MakeA8(dstM.fBounds.width(), dstM.fBounds.hei
ght()), |
1045 dstM.fRowBytes); | 1045 dstM.fRowBytes); |
1046 if (!tmpBitmap.tryAllocPixels(allocator, NULL)) { | 1046 if (!tmpBitmap.tryAllocPixels(allocator, nullptr)) { |
1047 // Allocation of pixels for alpha bitmap failed. | 1047 // Allocation of pixels for alpha bitmap failed. |
1048 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", | 1048 SkDebugf("extractAlpha failed to allocate (%d,%d) alpha bitmap\n", |
1049 tmpBitmap.width(), tmpBitmap.height()); | 1049 tmpBitmap.width(), tmpBitmap.height()); |
1050 return false; | 1050 return false; |
1051 } | 1051 } |
1052 memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize()); | 1052 memcpy(tmpBitmap.getPixels(), dstM.fImage, dstM.computeImageSize()); |
1053 if (offset) { | 1053 if (offset) { |
1054 offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop); | 1054 offset->set(dstM.fBounds.fLeft, dstM.fBounds.fTop); |
1055 } | 1055 } |
1056 SkDEBUGCODE(tmpBitmap.validate();) | 1056 SkDEBUGCODE(tmpBitmap.validate();) |
(...skipping 27 matching lines...) Expand all Loading... |
1084 if (kIndex_8_SkColorType == info.colorType() && ct) { | 1084 if (kIndex_8_SkColorType == info.colorType() && ct) { |
1085 buffer->writeBool(true); | 1085 buffer->writeBool(true); |
1086 ct->writeToBuffer(*buffer); | 1086 ct->writeToBuffer(*buffer); |
1087 } else { | 1087 } else { |
1088 buffer->writeBool(false); | 1088 buffer->writeBool(false); |
1089 } | 1089 } |
1090 } | 1090 } |
1091 | 1091 |
1092 void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { | 1092 void SkBitmap::WriteRawPixels(SkWriteBuffer* buffer, const SkBitmap& bitmap) { |
1093 const SkImageInfo info = bitmap.info(); | 1093 const SkImageInfo info = bitmap.info(); |
1094 if (0 == info.width() || 0 == info.height() || NULL == bitmap.pixelRef()) { | 1094 if (0 == info.width() || 0 == info.height() || nullptr == bitmap.pixelRef())
{ |
1095 buffer->writeUInt(0); // instead of snugRB, signaling no pixels | 1095 buffer->writeUInt(0); // instead of snugRB, signaling no pixels |
1096 return; | 1096 return; |
1097 } | 1097 } |
1098 | 1098 |
1099 SkAutoPixmapUnlock result; | 1099 SkAutoPixmapUnlock result; |
1100 if (!bitmap.requestLock(&result)) { | 1100 if (!bitmap.requestLock(&result)) { |
1101 buffer->writeUInt(0); // instead of snugRB, signaling no pixels | 1101 buffer->writeUInt(0); // instead of snugRB, signaling no pixels |
1102 return; | 1102 return; |
1103 } | 1103 } |
1104 | 1104 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1203 SkASSERT(fPixelRef); | 1203 SkASSERT(fPixelRef); |
1204 SkASSERT(fPixelLockCount > 0); | 1204 SkASSERT(fPixelLockCount > 0); |
1205 SkASSERT(fPixelRef->isLocked()); | 1205 SkASSERT(fPixelRef->isLocked()); |
1206 SkASSERT(fPixelRef->rowBytes() == fRowBytes); | 1206 SkASSERT(fPixelRef->rowBytes() == fRowBytes); |
1207 SkASSERT(fPixelRefOrigin.fX >= 0); | 1207 SkASSERT(fPixelRefOrigin.fX >= 0); |
1208 SkASSERT(fPixelRefOrigin.fY >= 0); | 1208 SkASSERT(fPixelRefOrigin.fY >= 0); |
1209 SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrig
in.fX); | 1209 SkASSERT(fPixelRef->info().width() >= (int)this->width() + fPixelRefOrig
in.fX); |
1210 SkASSERT(fPixelRef->info().height() >= (int)this->height() + fPixelRefOr
igin.fY); | 1210 SkASSERT(fPixelRef->info().height() >= (int)this->height() + fPixelRefOr
igin.fY); |
1211 SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes()); | 1211 SkASSERT(fPixelRef->rowBytes() >= fInfo.minRowBytes()); |
1212 } else { | 1212 } else { |
1213 SkASSERT(NULL == fColorTable); | 1213 SkASSERT(nullptr == fColorTable); |
1214 } | 1214 } |
1215 } | 1215 } |
1216 #endif | 1216 #endif |
1217 | 1217 |
1218 #ifndef SK_IGNORE_TO_STRING | 1218 #ifndef SK_IGNORE_TO_STRING |
1219 #include "SkString.h" | 1219 #include "SkString.h" |
1220 void SkBitmap::toString(SkString* str) const { | 1220 void SkBitmap::toString(SkString* str) const { |
1221 | 1221 |
1222 static const char* gColorTypeNames[kLastEnum_SkColorType + 1] = { | 1222 static const char* gColorTypeNames[kLastEnum_SkColorType + 1] = { |
1223 "UNKNOWN", "A8", "565", "4444", "RGBA", "BGRA", "INDEX8", | 1223 "UNKNOWN", "A8", "565", "4444", "RGBA", "BGRA", "INDEX8", |
1224 }; | 1224 }; |
1225 | 1225 |
1226 str->appendf("bitmap: ((%d, %d) %s", this->width(), this->height(), | 1226 str->appendf("bitmap: ((%d, %d) %s", this->width(), this->height(), |
1227 gColorTypeNames[this->colorType()]); | 1227 gColorTypeNames[this->colorType()]); |
1228 | 1228 |
1229 str->append(" ("); | 1229 str->append(" ("); |
1230 if (this->isOpaque()) { | 1230 if (this->isOpaque()) { |
1231 str->append("opaque"); | 1231 str->append("opaque"); |
1232 } else { | 1232 } else { |
1233 str->append("transparent"); | 1233 str->append("transparent"); |
1234 } | 1234 } |
1235 if (this->isImmutable()) { | 1235 if (this->isImmutable()) { |
1236 str->append(", immutable"); | 1236 str->append(", immutable"); |
1237 } else { | 1237 } else { |
1238 str->append(", not-immutable"); | 1238 str->append(", not-immutable"); |
1239 } | 1239 } |
1240 str->append(")"); | 1240 str->append(")"); |
1241 | 1241 |
1242 SkPixelRef* pr = this->pixelRef(); | 1242 SkPixelRef* pr = this->pixelRef(); |
1243 if (NULL == pr) { | 1243 if (nullptr == pr) { |
1244 // show null or the explicit pixel address (rare) | 1244 // show null or the explicit pixel address (rare) |
1245 str->appendf(" pixels:%p", this->getPixels()); | 1245 str->appendf(" pixels:%p", this->getPixels()); |
1246 } else { | 1246 } else { |
1247 const char* uri = pr->getURI(); | 1247 const char* uri = pr->getURI(); |
1248 if (uri) { | 1248 if (uri) { |
1249 str->appendf(" uri:\"%s\"", uri); | 1249 str->appendf(" uri:\"%s\"", uri); |
1250 } else { | 1250 } else { |
1251 str->appendf(" pixelref:%p", pr); | 1251 str->appendf(" pixelref:%p", pr); |
1252 } | 1252 } |
1253 } | 1253 } |
1254 | 1254 |
1255 str->append(")"); | 1255 str->append(")"); |
1256 } | 1256 } |
1257 #endif | 1257 #endif |
1258 | 1258 |
1259 /////////////////////////////////////////////////////////////////////////////// | 1259 /////////////////////////////////////////////////////////////////////////////// |
1260 | 1260 |
1261 bool SkBitmap::requestLock(SkAutoPixmapUnlock* result) const { | 1261 bool SkBitmap::requestLock(SkAutoPixmapUnlock* result) const { |
1262 SkASSERT(result); | 1262 SkASSERT(result); |
1263 | 1263 |
1264 SkPixelRef* pr = fPixelRef; | 1264 SkPixelRef* pr = fPixelRef; |
1265 if (NULL == pr) { | 1265 if (nullptr == pr) { |
1266 return false; | 1266 return false; |
1267 } | 1267 } |
1268 | 1268 |
1269 // We have to lock the whole thing (using the pixelref's dimensions) until t
he api supports | 1269 // We have to lock the whole thing (using the pixelref's dimensions) until t
he api supports |
1270 // a partial lock (with offset/origin). Hence we can't use our fInfo. | 1270 // a partial lock (with offset/origin). Hence we can't use our fInfo. |
1271 SkPixelRef::LockRequest req = { pr->info().dimensions(), kNone_SkFilterQuali
ty }; | 1271 SkPixelRef::LockRequest req = { pr->info().dimensions(), kNone_SkFilterQuali
ty }; |
1272 SkPixelRef::LockResult res; | 1272 SkPixelRef::LockResult res; |
1273 if (pr->requestLock(req, &res)) { | 1273 if (pr->requestLock(req, &res)) { |
1274 SkASSERT(res.fPixels); | 1274 SkASSERT(res.fPixels); |
1275 // The bitmap may be a subset of the pixelref's dimensions | 1275 // The bitmap may be a subset of the pixelref's dimensions |
(...skipping 24 matching lines...) Expand all Loading... |
1300 /////////////////////////////////////////////////////////////////////////////// | 1300 /////////////////////////////////////////////////////////////////////////////// |
1301 | 1301 |
1302 #ifdef SK_DEBUG | 1302 #ifdef SK_DEBUG |
1303 void SkImageInfo::validate() const { | 1303 void SkImageInfo::validate() const { |
1304 SkASSERT(fWidth >= 0); | 1304 SkASSERT(fWidth >= 0); |
1305 SkASSERT(fHeight >= 0); | 1305 SkASSERT(fHeight >= 0); |
1306 SkASSERT(SkColorTypeIsValid(fColorType)); | 1306 SkASSERT(SkColorTypeIsValid(fColorType)); |
1307 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); | 1307 SkASSERT(SkAlphaTypeIsValid(fAlphaType)); |
1308 } | 1308 } |
1309 #endif | 1309 #endif |
OLD | NEW |