void SkImageRefPool::setRAMUsed(size_t limit) { SkImageRef* ref = fTail; while (NULL != ref && fRAMUsed > limit) { // only purge it if its pixels are unlocked if (0 == ref->getLockCount() && ref->fBitmap.getPixels()) { size_t size = ref->ramUsed(); SkASSERT(size <= fRAMUsed); fRAMUsed -= size; #ifdef DUMP_IMAGEREF_LIFECYCLE SkDebugf("=== ImagePool: purge %s [%d %d %d] bytes=%d heap=%d\n", ref->getURI(), ref->fBitmap.width(), ref->fBitmap.height(), ref->fBitmap.bytesPerPixel(), (int)size, (int)fRAMUsed); #endif // remember the bitmap config (don't call reset), // just clear the pixel memory ref->fBitmap.setPixels(NULL); SkASSERT(NULL == ref->fBitmap.getPixels()); } ref = ref->fPrev; } }
SkPixelRef* BitmapFactoryGlue::installPixelRef(SkBitmap* bitmap, SkStream* stream, int sampleSize, bool ditherImage) { SkImageRef* pr = new SkImageRef_GlobalPool(stream, bitmap->config(), sampleSize); pr->setDitherImage(ditherImage); bitmap->setPixelRef(pr)->unref(); pr->isOpaque(bitmap); return pr; }
static SkPixelRef* installPixelRef(SkBitmap* bitmap, SkStream* stream, int sampleSize, bool ditherImage) { SkImageRef* pr; // only use ashmem for large images, since mmaps come at a price if (bitmap->getSize() >= 32 * 1024) { pr = new SkImageRef_ashmem(stream, bitmap->config(), sampleSize); } else { pr = new SkImageRef_GlobalPool(stream, bitmap->config(), sampleSize); } pr->setDitherImage(ditherImage); bitmap->setPixelRef(pr)->unref(); pr->isOpaque(bitmap); return pr; }
static bool SetImageRef(SkBitmap* bitmap, SkStream* stream, SkBitmap::Config pref, const char name[] = NULL) { if (SkImageDecoder::DecodeStream(stream, bitmap, pref, SkImageDecoder::kDecodeBounds_Mode, NULL)) { SkASSERT(bitmap->config() != SkBitmap::kNo_Config); SkImageRef* ref = new SkImageRef_GlobalPool(stream, bitmap->config()); ref->setURI(name); bitmap->setPixelRef(ref)->unref(); return true; } else { return false; } }
void SkImageRefPool::dump() const { #if defined(SK_DEBUG) || defined(DUMP_IMAGEREF_LIFECYCLE) SkDebugf("ImagePool dump: bugdet: %d used: %d count: %d\n", (int)fRAMBudget, (int)fRAMUsed, fCount); SkImageRef* ref = fHead; while (ref != NULL) { SkDebugf(" [%3d %3d %d] ram=%d data=%d locks=%d %s\n", ref->fBitmap.width(), ref->fBitmap.height(), ref->fBitmap.config(), ref->ramUsed(), (int)ref->fStream->getLength(), ref->getLockCount(), ref->getURI()); ref = ref->fNext; } #endif }
static bool SetImageRef(SkBitmap* bitmap, SkStream* stream, SkBitmap::Config pref, const char name[] = NULL) { #if 0 // test buffer streams SkStream* str = new SkBufferStream(stream, 717); stream->unref(); stream = str; #endif SkImageRef* ref = new SkImageRef_GlobalPool(stream, pref, 1); ref->setURI(name); if (!ref->getInfo(bitmap)) { delete ref; return false; } bitmap->setPixelRef(ref)->unref(); return true; }
static SkPixelRef* installPixelRef(SkBitmap* bitmap, SkStreamRewindable* stream, int sampleSize, bool ditherImage) { SkImageInfo bitmapInfo; if (!bitmap->asImageInfo(&bitmapInfo)) { ALOGW("bitmap has unknown configuration so no memory has been allocated"); return NULL; } SkImageRef* pr; // only use ashmem for large images, since mmaps come at a price if (bitmap->getSize() >= 32 * 1024) { pr = new SkImageRef_ashmem(bitmapInfo, stream, sampleSize); } else { pr = new SkImageRef_GlobalPool(bitmapInfo, stream, sampleSize); } pr->setDitherImage(ditherImage); bitmap->setPixelRef(pr)->unref(); pr->isOpaque(bitmap); return pr; }