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

Unified Diff: src/lazy/SkCachingPixelRef.cpp

Issue 507483002: retool image cache to be generic cache (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase + add comment in unlock Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/lazy/SkCachingPixelRef.h ('k') | tests/ImageCacheTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/lazy/SkCachingPixelRef.cpp
diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp
index c59682854bc04e56e47ae9e504606387c95da69e..6d97aaeee97e6ca1d2984ab5de0bcef04b7f7e5c 100644
--- a/src/lazy/SkCachingPixelRef.cpp
+++ b/src/lazy/SkCachingPixelRef.cpp
@@ -30,13 +30,11 @@ SkCachingPixelRef::SkCachingPixelRef(const SkImageInfo& info,
: INHERITED(info)
, fImageGenerator(generator)
, fErrorInDecoding(false)
- , fScaledCacheId(NULL)
, fRowBytes(rowBytes) {
SkASSERT(fImageGenerator != NULL);
}
SkCachingPixelRef::~SkCachingPixelRef() {
SkDELETE(fImageGenerator);
- SkASSERT(NULL == fScaledCacheId);
// Assert always unlock before unref.
}
@@ -46,48 +44,28 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) {
}
const SkImageInfo& info = this->info();
- SkBitmap bitmap;
- SkASSERT(NULL == fScaledCacheId);
- fScaledCacheId = SkBitmapCache::FindAndLock(this->getGenerationID(), info.fWidth, info.fHeight,
- &bitmap);
- if (NULL == fScaledCacheId) {
+ if (!SkBitmapCache::Find(this->getGenerationID(), info.fWidth, info.fHeight, &fLockedBitmap)) {
// Cache has been purged, must re-decode.
- if (!bitmap.allocPixels(info, fRowBytes)) {
+ if (!fLockedBitmap.allocPixels(info, fRowBytes)) {
fErrorInDecoding = true;
return false;
}
- SkAutoLockPixels autoLockPixels(bitmap);
- if (!fImageGenerator->getPixels(info, bitmap.getPixels(), fRowBytes)) {
+ if (!fImageGenerator->getPixels(info, fLockedBitmap.getPixels(), fRowBytes)) {
fErrorInDecoding = true;
return false;
}
- fScaledCacheId = SkBitmapCache::AddAndLock(this->getGenerationID(),
- info.fWidth, info.fHeight, bitmap);
- SkASSERT(fScaledCacheId != NULL);
+ SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, fLockedBitmap);
}
- // Now bitmap should contain a concrete PixelRef of the decoded
- // image.
- SkAutoLockPixels autoLockPixels(bitmap);
- void* pixels = bitmap.getPixels();
+ // Now bitmap should contain a concrete PixelRef of the decoded image.
+ void* pixels = fLockedBitmap.getPixels();
SkASSERT(pixels != NULL);
-
- // At this point, the autoLockPixels will unlockPixels()
- // to remove bitmap's lock on the pixels. We will then
- // destroy bitmap. The *only* guarantee that this pointer
- // remains valid is the guarantee made by
- // SkScaledImageCache that it will not destroy the *other*
- // bitmap (SkScaledImageCache::Rec.fBitmap) that holds a
- // reference to the concrete PixelRef while this record is
- // locked.
rec->fPixels = pixels;
rec->fColorTable = NULL;
- rec->fRowBytes = bitmap.rowBytes();
+ rec->fRowBytes = fLockedBitmap.rowBytes();
return true;
}
void SkCachingPixelRef::onUnlockPixels() {
- SkASSERT(fScaledCacheId != NULL);
- SkScaledImageCache::Unlock( static_cast<SkScaledImageCache::ID*>(fScaledCacheId));
- fScaledCacheId = NULL;
+ fLockedBitmap.reset();
}
« no previous file with comments | « src/lazy/SkCachingPixelRef.h ('k') | tests/ImageCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698