Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: src/core/SkBitmap.cpp

Issue 111323005: Remvoe duplicate impl for SkImageInfo flattening (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « samplecode/SamplePicture.cpp ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 Sk64 size = this->getSize64(); 456 SkImageInfo info;
457 SkASSERT(!size.isNeg() && size.is32()); 457 if (!this->asImageInfo(&info)) {
458 this->setPixelRef(NULL, 0);
459 return;
460 }
458 461
459 this->setPixelRef(new SkMallocPixelRef(p, size.get32(), ctable, false))->unr ef(); 462 SkPixelRef* pr = SkMallocPixelRef::NewDirect(info, p, fRowBytes, ctable);
463 if (NULL == pr) {
464 this->setPixelRef(NULL, 0);
465 return;
466 }
467
468 this->setPixelRef(pr)->unref();
469
460 // since we're already allocated, we lockPixels right away 470 // since we're already allocated, we lockPixels right away
461 this->lockPixels(); 471 this->lockPixels();
462 SkDEBUGCODE(this->validate();) 472 SkDEBUGCODE(this->validate();)
463 } 473 }
464 474
465 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) { 475 bool SkBitmap::allocPixels(Allocator* allocator, SkColorTable* ctable) {
466 HeapAllocator stdalloc; 476 HeapAllocator stdalloc;
467 477
468 if (NULL == allocator) { 478 if (NULL == allocator) {
469 allocator = &stdalloc; 479 allocator = &stdalloc;
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 return fPixelRef ? fPixelRef->getTexture() : NULL; 524 return fPixelRef ? fPixelRef->getTexture() : NULL;
515 } 525 }
516 526
517 /////////////////////////////////////////////////////////////////////////////// 527 ///////////////////////////////////////////////////////////////////////////////
518 528
519 /** We explicitly use the same allocator for our pixels that SkMask does, 529 /** We explicitly use the same allocator for our pixels that SkMask does,
520 so that we can freely assign memory allocated by one class to the other. 530 so that we can freely assign memory allocated by one class to the other.
521 */ 531 */
522 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst, 532 bool SkBitmap::HeapAllocator::allocPixelRef(SkBitmap* dst,
523 SkColorTable* ctable) { 533 SkColorTable* ctable) {
524 Sk64 size = dst->getSize64(); 534 SkImageInfo info;
525 if (size.isNeg() || !size.is32()) { 535 if (!dst->asImageInfo(&info)) {
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) {
526 return false; 543 return false;
527 } 544 }
528 545
529 void* addr = sk_malloc_flags(size.get32(), 0); // returns NULL on failure 546 dst->setPixelRef(pr, 0)->unref();
530 if (NULL == addr) {
531 return false;
532 }
533
534 dst->setPixelRef(new SkMallocPixelRef(addr, size.get32(), ctable))->unref();
535 // since we're already allocated, we lockPixels right away 547 // since we're already allocated, we lockPixels right away
536 dst->lockPixels(); 548 dst->lockPixels();
537 return true; 549 return true;
538 } 550 }
539 551
540 /////////////////////////////////////////////////////////////////////////////// 552 ///////////////////////////////////////////////////////////////////////////////
541 553
542 size_t SkBitmap::getSafeSize() const { 554 size_t SkBitmap::getSafeSize() const {
543 // This is intended to be a size_t version of ComputeSafeSize64(), just 555 // This is intended to be a size_t version of ComputeSafeSize64(), just
544 // faster. The computation is meant to be identical. 556 // faster. The computation is meant to be identical.
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1699 if (NULL != uri) { 1711 if (NULL != uri) {
1700 str->appendf(" uri:\"%s\"", uri); 1712 str->appendf(" uri:\"%s\"", uri);
1701 } else { 1713 } else {
1702 str->appendf(" pixelref:%p", pr); 1714 str->appendf(" pixelref:%p", pr);
1703 } 1715 }
1704 } 1716 }
1705 1717
1706 str->append(")"); 1718 str->append(")");
1707 } 1719 }
1708 #endif 1720 #endif
OLDNEW
« no previous file with comments | « samplecode/SamplePicture.cpp ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698