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

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

Issue 143073008: add installPixels (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: rebase Created 6 years, 11 months 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 | « include/core/SkPixelRef.h ('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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 this->setPixelRef(pr)->unref();
524
525 // TODO: lockPixels could/should return bool or void*/NULL
526 this->lockPixels();
527 if (NULL == this->getPixels()) {
528 return reset_return_false(this);
529 }
530 return true;
531 }
532
533 bool SkBitmap::installPixels(const SkImageInfo& info, void* pixels, size_t rb,
534 void (*releaseProc)(void* addr, void* context),
535 void* context) {
536 if (!this->setConfig(info)) {
537 this->reset();
538 return false;
539 }
540
541 SkPixelRef* pr = SkMallocPixelRef::NewWithProc(info, rb, NULL, pixels,
542 releaseProc, context);
543 if (!pr) {
544 this->reset();
545 return false;
546 }
547
548 this->setPixelRef(pr)->unref();
549 return true;
550 }
551
498 void SkBitmap::freePixels() { 552 void SkBitmap::freePixels() {
499 // if we're gonna free the pixels, we certainly need to free the mipmap 553 // if we're gonna free the pixels, we certainly need to free the mipmap
500 this->freeMipMap(); 554 this->freeMipMap();
501 555
502 if (NULL != fPixelRef) { 556 if (NULL != fPixelRef) {
503 if (fPixelLockCount > 0) { 557 if (fPixelLockCount > 0) {
504 fPixelRef->unlockPixels(); 558 fPixelRef->unlockPixels();
505 } 559 }
506 fPixelRef->unref(); 560 fPixelRef->unref();
507 fPixelRef = NULL; 561 fPixelRef = NULL;
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1649 if (NULL != uri) { 1703 if (NULL != uri) {
1650 str->appendf(" uri:\"%s\"", uri); 1704 str->appendf(" uri:\"%s\"", uri);
1651 } else { 1705 } else {
1652 str->appendf(" pixelref:%p", pr); 1706 str->appendf(" pixelref:%p", pr);
1653 } 1707 }
1654 } 1708 }
1655 1709
1656 str->append(")"); 1710 str->append(")");
1657 } 1711 }
1658 #endif 1712 #endif
OLDNEW
« no previous file with comments | « include/core/SkPixelRef.h ('k') | src/core/SkBitmapDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698