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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
481 | 481 |
482 this->setPixelRef(pr)->unref(); | 482 this->setPixelRef(pr)->unref(); |
483 | 483 |
484 // since we're already allocated, we lockPixels right away | 484 // since we're already allocated, we lockPixels right away |
485 this->lockPixels(); | 485 this->lockPixels(); |
486 SkDEBUGCODE(this->validate();) | 486 SkDEBUGCODE(this->validate();) |
487 } | 487 } |
488 | 488 |
489 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { | 489 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { |
490 HeapAllocator stdalloc; | 490 HeapAllocator stdalloc; |
491 | 491 |
492 if (NULL == allocator) { | 492 if (NULL == allocator) { |
493 allocator = &stdalloc; | 493 allocator = &stdalloc; |
494 } | 494 } |
495 return allocator->allocPixelRef(this, ctable); | 495 return allocator->allocPixelRef(this, ctable); |
496 } | 496 } |
497 | 497 |
498 /////////////////////////////////////////////////////////////////////////////// | |
499 | |
500 static bool reset_return_false(SkBitmap* bm) { | |
501 bm->reset(); | |
502 return false; | |
503 } | |
504 | |
505 bool SkBitmap::allocPixels(const SkImageInfo& info, SkPixelRefFactory* factory, | |
506 SkColorTable* ctable) { | |
507 if (kIndex_8_SkColorType == info.fColorType && NULL == ctable) { | |
508 return reset_return_false(this); | |
509 } | |
510 if (!this->setConfig(info)) { | |
511 return reset_return_false(this); | |
512 } | |
513 | |
514 SkMallocPixelRef::PRFactory defaultFactory; | |
515 if (NULL == factory) { | |
516 factory = &defaultFactory; | |
517 } | |
518 | |
519 SkPixelRef* pr = factory->create(info, ctable); | |
520 if (NULL == pr) { | |
521 return reset_return_false(this); | |
522 } | |
523 return this->setPixelRef(pr); | |
scroggo
2014/01/24 16:18:59
pr needs to be unref'ed.
hal.canary
2014/01/24 16:46:50
Use a SkAutoTUnref<SkPixelRef>!
| |
524 } | |
525 | |
526 bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb, | |
527 void (*releaseProc)(void* addr, void* context), | |
528 void* context) { | |
529 if (!this->setConfig(info)) { | |
530 this->reset(); | |
531 return false; | |
532 } | |
533 | |
534 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, NULL, pixels, | |
535 releaseProc, context); | |
536 if (!pr) { | |
537 this->reset(); | |
538 return false; | |
539 } | |
540 | |
541 this->setPixelRef(pr)->unref(); | |
542 return true; | |
543 } | |
544 | |
498 void SkBitmap::freePixels() { | 545 void SkBitmap::freePixels() { |
499 // if we're gonna free the pixels, we certainly need to free the mipmap | 546 // if we're gonna free the pixels, we certainly need to free the mipmap |
500 this->freeMipMap(); | 547 this->freeMipMap(); |
501 | 548 |
502 if (NULL != fPixelRef) { | 549 if (NULL != fPixelRef) { |
503 if (fPixelLockCount > 0) { | 550 if (fPixelLockCount > 0) { |
504 fPixelRef->unlockPixels(); | 551 fPixelRef->unlockPixels(); |
505 } | 552 } |
506 fPixelRef->unref(); | 553 fPixelRef->unref(); |
507 fPixelRef = NULL; | 554 fPixelRef = NULL; |
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1649 if (NULL != uri) { | 1696 if (NULL != uri) { |
1650 str->appendf(" uri:\"%s\"", uri); | 1697 str->appendf(" uri:\"%s\"", uri); |
1651 } else { | 1698 } else { |
1652 str->appendf(" pixelref:%p", pr); | 1699 str->appendf(" pixelref:%p", pr); |
1653 } | 1700 } |
1654 } | 1701 } |
1655 | 1702 |
1656 str->append(")"); | 1703 str->append(")"); |
1657 } | 1704 } |
1658 #endif | 1705 #endif |
OLD | NEW |