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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 SkASSERT(0 == fPixelLockCount); | 361 SkASSERT(0 == fPixelLockCount); |
362 fPixels = NULL; | 362 fPixels = NULL; |
363 if (fColorTable) { | 363 if (fColorTable) { |
364 fColorTable->unref(); | 364 fColorTable->unref(); |
365 fColorTable = NULL; | 365 fColorTable = NULL; |
366 } | 366 } |
367 } | 367 } |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 bool SkBitmap::asImageInfo(SkImageInfo* info) const { | |
372 SkColorType ct; | |
373 switch (this->config()) { | |
374 case kNo_Config: | |
375 case kA1_Config: | |
376 return false; | |
377 case kA8_Config: | |
378 ct = kAlpha_8_SkColorType; | |
379 break; | |
380 case kIndex8_Config: | |
381 ct = kIndex8_SkColorType; | |
382 break; | |
383 case kRGB_565_Config: | |
384 ct = kRGB_565_SkColorType; | |
385 break; | |
386 case kARGB_4444_Config: | |
387 ct = kARGB_4444_SkColorType; | |
388 break; | |
389 case kARGB_8888_Config: | |
390 ct = kPMColor_SkColorType; | |
391 break; | |
392 } | |
393 if (info) { | |
394 info->fWidth = fWidth; | |
395 info->fHeight = fHeight; | |
396 info->fAlphaType = this->alphaType(); | |
397 info->fColorType = ct; | |
398 } | |
399 return true; | |
400 } | |
401 | |
371 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, size_t offset) { | 402 SkPixelRef* SkBitmap::setPixelRef(SkPixelRef* pr, size_t offset) { |
372 // do this first, we that we never have a non-zero offset with a null ref | 403 // do this first, we that we never have a non-zero offset with a null ref |
373 if (NULL == pr) { | 404 if (NULL == pr) { |
374 offset = 0; | 405 offset = 0; |
375 } | 406 } |
376 | 407 |
377 if (fPixelRef != pr || fPixelRefOffset != offset) { | 408 if (fPixelRef != pr || fPixelRefOffset != offset) { |
378 if (fPixelRef != pr) { | 409 if (fPixelRef != pr) { |
379 this->freePixels(); | 410 this->freePixels(); |
380 SkASSERT(NULL == fPixelRef); | 411 SkASSERT(NULL == fPixelRef); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 | 445 |
415 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { | 446 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
416 if (NULL == p) { | 447 if (NULL == p) { |
417 this->setPixelRef(NULL, 0); | 448 this->setPixelRef(NULL, 0); |
418 return; | 449 return; |
419 } | 450 } |
420 | 451 |
421 Sk64 size = this->getSize64(); | 452 Sk64 size = this->getSize64(); |
422 SkASSERT(!size.isNeg() && size.is32()); | 453 SkASSERT(!size.isNeg() && size.is32()); |
423 | 454 |
424 this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unr ef(); | 455 SkImageInfo info; |
456 if (!this->asImageInfo(&info)) { | |
457 this->setPixelRef(NULL, 0); | |
458 return; | |
459 } | |
460 this->setPixelRef(new SkMallocPixelRef(info, p, fRowBytes, ctable, false))-> unref(); | |
scroggo
2013/11/19 18:17:09
SkNEW_ARGS
reed1
2013/11/20 20:56:56
Done.
| |
425 // since we're already allocated, we lockPixels right away | 461 // since we're already allocated, we lockPixels right away |
426 this->lockPixels(); | 462 this->lockPixels(); |
427 SkDEBUGCODE(this->validate();) | 463 SkDEBUGCODE(this->validate();) |
428 } | 464 } |
429 | 465 |
430 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { | 466 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { |
431 HeapAllocator stdalloc; | 467 HeapAllocator stdalloc; |
432 | 468 |
433 if (NULL == allocator) { | 469 if (NULL == allocator) { |
434 allocator = &stdalloc; | 470 allocator = &stdalloc; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
484 /** We explicitly use the same allocator for our pixels that SkMask does, | 520 /** We explicitly use the same allocator for our pixels that SkMask does, |
485 so that we can freely assign memory allocated by one class to the other. | 521 so that we can freely assign memory allocated by one class to the other. |
486 */ | 522 */ |
487 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, | 523 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, |
488 SkColorTable* ctable) { | 524 SkColorTable* ctable) { |
489 Sk64 size = dst->getSize64(); | 525 Sk64 size = dst->getSize64(); |
490 if (size.isNeg() || !size.is32()) { | 526 if (size.isNeg() || !size.is32()) { |
491 return false; | 527 return false; |
492 } | 528 } |
493 | 529 |
530 SkImageInfo info; | |
531 if (!dst->asImageInfo(&info)) { | |
532 SkDebugf("unsupported config for info %d\n", dst->config()); | |
533 return false; | |
534 } | |
535 | |
494 void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure | 536 void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure |
495 if (NULL == addr) { | 537 if (NULL == addr) { |
496 return false; | 538 return false; |
497 } | 539 } |
498 | 540 |
499 dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref(); | 541 SkPixelRef* pr = SkNEW_ARGS(SkMallocPixelRef, |
542 (info, addr, dst->rowBytes(), ctable, true)); | |
543 dst->setPixelRef(pr, 0)->unref(); | |
500 // since we're already allocated, we lockPixels right away | 544 // since we're already allocated, we lockPixels right away |
501 dst->lockPixels(); | 545 dst->lockPixels(); |
502 return true; | 546 return true; |
503 } | 547 } |
504 | 548 |
505 /////////////////////////////////////////////////////////////////////////////// | 549 /////////////////////////////////////////////////////////////////////////////// |
506 | 550 |
507 size_t SkBitmap::getSafeSize() const { | 551 size_t SkBitmap::getSafeSize() const { |
508 // This is intended to be a size_t version of ComputeSafeSize64(), just | 552 // This is intended to be a size_t version of ComputeSafeSize64(), just |
509 // faster. The computation is meant to be identical. | 553 // faster. The computation is meant to be identical. |
(...skipping 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1709 if (NULL != uri) { | 1753 if (NULL != uri) { |
1710 str->appendf(" uri:\"%s\"", uri); | 1754 str->appendf(" uri:\"%s\"", uri); |
1711 } else { | 1755 } else { |
1712 str->appendf(" pixelref:%p", pr); | 1756 str->appendf(" pixelref:%p", pr); |
1713 } | 1757 } |
1714 } | 1758 } |
1715 | 1759 |
1716 str->append(")"); | 1760 str->append(")"); |
1717 } | 1761 } |
1718 #endif | 1762 #endif |
OLD | NEW |