| 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 435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 bool SkBitmap::lockPixelsAreWritable() const { | 446 bool SkBitmap::lockPixelsAreWritable() const { |
| 447 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; | 447 return (fPixelRef) ? fPixelRef->lockPixelsAreWritable() : false; |
| 448 } | 448 } |
| 449 | 449 |
| 450 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { | 450 void SkBitmap::setPixels(void* p, SkColorTable* ctable) { |
| 451 if (NULL == p) { | 451 if (NULL == p) { |
| 452 this->setPixelRef(NULL, 0); | 452 this->setPixelRef(NULL, 0); |
| 453 return; | 453 return; |
| 454 } | 454 } |
| 455 | 455 |
| 456 SkImageInfo info; | 456 Sk64 size = this->getSize64(); |
| 457 if (!this->asImageInfo(&info)) { | 457 SkASSERT(!size.isNeg() && size.is32()); |
| 458 this->setPixelRef(NULL, 0); | |
| 459 return; | |
| 460 } | |
| 461 | 458 |
| 462 SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable); | 459 this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unr
ef(); |
| 463 if (NULL == pr) { | |
| 464 this->setPixelRef(NULL, 0); | |
| 465 return; | |
| 466 } | |
| 467 | |
| 468 this->setPixelRef(pr)->unref(); | |
| 469 | |
| 470 // since we're already allocated, we lockPixels right away | 460 // since we're already allocated, we lockPixels right away |
| 471 this->lockPixels(); | 461 this->lockPixels(); |
| 472 SkDEBUGCODE(this->validate();) | 462 SkDEBUGCODE(this->validate();) |
| 473 } | 463 } |
| 474 | 464 |
| 475 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { | 465 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { |
| 476 HeapAllocator stdalloc; | 466 HeapAllocator stdalloc; |
| 477 | 467 |
| 478 if (NULL == allocator) { | 468 if (NULL == allocator) { |
| 479 allocator = &stdalloc; | 469 allocator = &stdalloc; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 return fPixelRef ? fPixelRef->getTexture() : NULL; | 514 return fPixelRef ? fPixelRef->getTexture() : NULL; |
| 525 } | 515 } |
| 526 | 516 |
| 527 /////////////////////////////////////////////////////////////////////////////// | 517 /////////////////////////////////////////////////////////////////////////////// |
| 528 | 518 |
| 529 /** We explicitly use the same allocator for our pixels that SkMask does, | 519 /** We explicitly use the same allocator for our pixels that SkMask does, |
| 530 so that we can freely assign memory allocated by one class to the other. | 520 so that we can freely assign memory allocated by one class to the other. |
| 531 */ | 521 */ |
| 532 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, | 522 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, |
| 533 SkColorTable* ctable) { | 523 SkColorTable* ctable) { |
| 534 SkImageInfo info; | 524 Sk64 size = dst->getSize64(); |
| 535 if (!dst->asImageInfo(&info)) { | 525 if (size.isNeg() || !size.is32()) { |
| 536 // SkDebugf("unsupported config for info %d\n", dst->config()); | |
| 537 return false; | |
| 538 } | |
| 539 | |
| 540 SkPixelRef* pr = SkMallocPixelRef::NewAllocate(info, dst->rowBytes(), | |
| 541 ctable); | |
| 542 if (NULL == pr) { | |
| 543 return false; | 526 return false; |
| 544 } | 527 } |
| 545 | 528 |
| 546 dst->setPixelRef(pr, 0)->unref(); | 529 void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure |
| 530 if (NULL == addr) { |
| 531 return false; |
| 532 } |
| 533 |
| 534 dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref(); |
| 547 // since we're already allocated, we lockPixels right away | 535 // since we're already allocated, we lockPixels right away |
| 548 dst->lockPixels(); | 536 dst->lockPixels(); |
| 549 return true; | 537 return true; |
| 550 } | 538 } |
| 551 | 539 |
| 552 /////////////////////////////////////////////////////////////////////////////// | 540 /////////////////////////////////////////////////////////////////////////////// |
| 553 | 541 |
| 554 size_t SkBitmap::getSafeSize() const { | 542 size_t SkBitmap::getSafeSize() const { |
| 555 // This is intended to be a size_t version of ComputeSafeSize64(), just | 543 // This is intended to be a size_t version of ComputeSafeSize64(), just |
| 556 // faster. The computation is meant to be identical. | 544 // faster. The computation is meant to be identical. |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1711 if (NULL != uri) { | 1699 if (NULL != uri) { |
| 1712 str->appendf(" uri:\"%s\"", uri); | 1700 str->appendf(" uri:\"%s\"", uri); |
| 1713 } else { | 1701 } else { |
| 1714 str->appendf(" pixelref:%p", pr); | 1702 str->appendf(" pixelref:%p", pr); |
| 1715 } | 1703 } |
| 1716 } | 1704 } |
| 1717 | 1705 |
| 1718 str->append(")"); | 1706 str->append(")"); |
| 1719 } | 1707 } |
| 1720 #endif | 1708 #endif |
| OLD | NEW |