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

Unified Diff: src/core/SkScaledImageCache.cpp

Issue 483493003: expose generalized imagecache key (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove more dead code 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/core/SkScaledImageCache.h ('k') | src/lazy/SkCachingPixelRef.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkScaledImageCache.cpp
diff --git a/src/core/SkScaledImageCache.cpp b/src/core/SkScaledImageCache.cpp
index 3e8929358c65bbdc2ccaee2da15fcce09fc6d238..9e672fe371da5790c7ae744da2c730c502254ece 100644
--- a/src/core/SkScaledImageCache.cpp
+++ b/src/core/SkScaledImageCache.cpp
@@ -260,32 +260,10 @@ SkScaledImageCache::~SkScaledImageCache() {
////////////////////////////////////////////////////////////////////////////////
-struct GenWHKey : public SkScaledImageCache::Key {
-public:
- GenWHKey(uint32_t genID, SkScalar scaleX, SkScalar scaleY, const SkIRect& bounds)
- : fGenID(genID)
- , fScaleX(scaleX)
- , fScaleY(scaleY)
- , fBounds(bounds) {
- this->init(7 * sizeof(uint32_t));
- }
-
- uint32_t fGenID;
- SkScalar fScaleX;
- SkScalar fScaleY;
- SkIRect fBounds;
-};
-
-SkScaledImageCache::Rec* SkScaledImageCache::findAndLock(uint32_t genID,
- SkScalar scaleX,
- SkScalar scaleY,
- const SkIRect& bounds) {
- return this->findAndLock(GenWHKey(genID, scaleX, scaleY, bounds));
-}
-
/**
This private method is the fully general record finder. All other
- record finders should call this function or the one above. */
+ record finders should call this function or the one above.
+ */
SkScaledImageCache::Rec* SkScaledImageCache::findAndLock(const SkScaledImageCache::Key& key) {
#ifdef USE_HASH
Rec* rec = fHash->find(key);
@@ -299,56 +277,18 @@ SkScaledImageCache::Rec* SkScaledImageCache::findAndLock(const SkScaledImageCach
return rec;
}
-/**
- This function finds the bounds of the bitmap *within its pixelRef*.
- If the bitmap lacks a pixelRef, it will return an empty rect, since
- that doesn't make sense. This may be a useful enough function that
- it should be somewhere else (in SkBitmap?). */
-static SkIRect get_bounds_from_bitmap(const SkBitmap& bm) {
- if (!(bm.pixelRef())) {
- return SkIRect::MakeEmpty();
- }
- SkIPoint origin = bm.pixelRefOrigin();
- return SkIRect::MakeXYWH(origin.fX, origin.fY, bm.width(), bm.height());
-}
-
-
-SkScaledImageCache::ID* SkScaledImageCache::findAndLock(uint32_t genID,
- int32_t width,
- int32_t height,
- SkBitmap* bitmap) {
- Rec* rec = this->findAndLock(genID, SK_Scalar1, SK_Scalar1,
- SkIRect::MakeWH(width, height));
+SkScaledImageCache::ID* SkScaledImageCache::findAndLock(const Key& key, SkBitmap* result) {
+ Rec* rec = this->findAndLock(key);
if (rec) {
SkASSERT(NULL == rec->fMip);
SkASSERT(rec->fBitmap.pixelRef());
- *bitmap = rec->fBitmap;
+ *result = rec->fBitmap;
}
return rec_to_id(rec);
}
-SkScaledImageCache::ID* SkScaledImageCache::findAndLock(const SkBitmap& orig,
- SkScalar scaleX,
- SkScalar scaleY,
- SkBitmap* scaled) {
- if (0 == scaleX || 0 == scaleY) {
- // degenerate, and the key we use for mipmaps
- return NULL;
- }
- Rec* rec = this->findAndLock(orig.getGenerationID(), scaleX,
- scaleY, get_bounds_from_bitmap(orig));
- if (rec) {
- SkASSERT(NULL == rec->fMip);
- SkASSERT(rec->fBitmap.pixelRef());
- *scaled = rec->fBitmap;
- }
- return rec_to_id(rec);
-}
-
-SkScaledImageCache::ID* SkScaledImageCache::findAndLockMip(const SkBitmap& orig,
- SkMipMap const ** mip) {
- Rec* rec = this->findAndLock(orig.getGenerationID(), 0, 0,
- get_bounds_from_bitmap(orig));
+SkScaledImageCache::ID* SkScaledImageCache::findAndLock(const Key& key, const SkMipMap** mip) {
+ Rec* rec = this->findAndLock(key);
if (rec) {
SkASSERT(rec->fMip);
SkASSERT(NULL == rec->fBitmap.pixelRef());
@@ -385,39 +325,12 @@ SkScaledImageCache::ID* SkScaledImageCache::addAndLock(SkScaledImageCache::Rec*
return rec_to_id(rec);
}
-SkScaledImageCache::ID* SkScaledImageCache::addAndLock(uint32_t genID,
- int32_t width,
- int32_t height,
- const SkBitmap& bitmap) {
- GenWHKey key(genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height));
- Rec* rec = SkNEW_ARGS(Rec, (key, bitmap));
- return this->addAndLock(rec);
-}
-
-SkScaledImageCache::ID* SkScaledImageCache::addAndLock(const SkBitmap& orig,
- SkScalar scaleX,
- SkScalar scaleY,
- const SkBitmap& scaled) {
- if (0 == scaleX || 0 == scaleY) {
- // degenerate, and the key we use for mipmaps
- return NULL;
- }
- SkIRect bounds = get_bounds_from_bitmap(orig);
- if (bounds.isEmpty()) {
- return NULL;
- }
- GenWHKey key(orig.getGenerationID(), scaleX, scaleY, bounds);
+SkScaledImageCache::ID* SkScaledImageCache::addAndLock(const Key& key, const SkBitmap& scaled) {
Rec* rec = SkNEW_ARGS(Rec, (key, scaled));
return this->addAndLock(rec);
}
-SkScaledImageCache::ID* SkScaledImageCache::addAndLockMip(const SkBitmap& orig,
- const SkMipMap* mip) {
- SkIRect bounds = get_bounds_from_bitmap(orig);
- if (bounds.isEmpty()) {
- return NULL;
- }
- GenWHKey key(orig.getGenerationID(), 0, 0, bounds);
+SkScaledImageCache::ID* SkScaledImageCache::addAndLock(const Key& key, const SkMipMap* mip) {
Rec* rec = SkNEW_ARGS(Rec, (key, mip));
return this->addAndLock(rec);
}
@@ -663,52 +576,24 @@ static SkScaledImageCache* get_cache() {
return gScaledImageCache;
}
-
-SkScaledImageCache::ID* SkScaledImageCache::FindAndLock(
- uint32_t pixelGenerationID,
- int32_t width,
- int32_t height,
- SkBitmap* scaled) {
- SkAutoMutexAcquire am(gMutex);
- return get_cache()->findAndLock(pixelGenerationID, width, height, scaled);
-}
-
-SkScaledImageCache::ID* SkScaledImageCache::AddAndLock(
- uint32_t pixelGenerationID,
- int32_t width,
- int32_t height,
- const SkBitmap& scaled) {
- SkAutoMutexAcquire am(gMutex);
- return get_cache()->addAndLock(pixelGenerationID, width, height, scaled);
-}
-
-
-SkScaledImageCache::ID* SkScaledImageCache::FindAndLock(const SkBitmap& orig,
- SkScalar scaleX,
- SkScalar scaleY,
- SkBitmap* scaled) {
+SkScaledImageCache::ID* SkScaledImageCache::FindAndLock(const Key& key, SkBitmap* result) {
SkAutoMutexAcquire am(gMutex);
- return get_cache()->findAndLock(orig, scaleX, scaleY, scaled);
+ return get_cache()->findAndLock(key, result);
}
-SkScaledImageCache::ID* SkScaledImageCache::FindAndLockMip(const SkBitmap& orig,
- SkMipMap const ** mip) {
+SkScaledImageCache::ID* SkScaledImageCache::FindAndLock(const Key& key, SkMipMap const ** mip) {
SkAutoMutexAcquire am(gMutex);
- return get_cache()->findAndLockMip(orig, mip);
+ return get_cache()->findAndLock(key, mip);
}
-SkScaledImageCache::ID* SkScaledImageCache::AddAndLock(const SkBitmap& orig,
- SkScalar scaleX,
- SkScalar scaleY,
- const SkBitmap& scaled) {
+SkScaledImageCache::ID* SkScaledImageCache::AddAndLock(const Key& key, const SkBitmap& scaled) {
SkAutoMutexAcquire am(gMutex);
- return get_cache()->addAndLock(orig, scaleX, scaleY, scaled);
+ return get_cache()->addAndLock(key, scaled);
}
-SkScaledImageCache::ID* SkScaledImageCache::AddAndLockMip(const SkBitmap& orig,
- const SkMipMap* mip) {
+SkScaledImageCache::ID* SkScaledImageCache::AddAndLock(const Key& key, const SkMipMap* mip) {
SkAutoMutexAcquire am(gMutex);
- return get_cache()->addAndLockMip(orig, mip);
+ return get_cache()->addAndLock(key, mip);
}
void SkScaledImageCache::Unlock(SkScaledImageCache::ID* id) {
« no previous file with comments | « src/core/SkScaledImageCache.h ('k') | src/lazy/SkCachingPixelRef.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698