diff options
author | 2014-08-29 10:25:26 -0700 | |
---|---|---|
committer | 2014-08-29 10:25:26 -0700 | |
commit | 14b6aba0997a8b463eae824d770fc5ad1ab89617 (patch) | |
tree | af4adf0e0f672cb81ef1f2b2101923f1f1af8827 | |
parent | b2f94d1f4a74f82ea4dd3feb1690ef6d05892afb (diff) |
harden requirements on SkBitmapCache
BUG=skia:
R=humper@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/521433002
-rw-r--r-- | src/core/SkBitmapCache.cpp | 6 | ||||
-rw-r--r-- | src/core/SkBitmapCache.h | 15 | ||||
-rw-r--r-- | src/core/SkBitmapProcState.cpp | 1 | ||||
-rw-r--r-- | src/lazy/SkCachingPixelRef.cpp | 1 |
4 files changed, 22 insertions, 1 deletions
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp index 99e2f5c503..8de8ab79ed 100644 --- a/src/core/SkBitmapCache.cpp +++ b/src/core/SkBitmapCache.cpp @@ -10,6 +10,10 @@ #include "SkMipMap.h" #include "SkRect.h" +SkBitmap::Allocator* SkBitmapCache::GetAllocator() { + return SkResourceCache::GetAllocator(); +} + /** This function finds the bounds of the bitmap *within its pixelRef*. If the bitmap lacks a pixelRef, it will return an empty rect, since @@ -91,6 +95,7 @@ void SkBitmapCache::Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invSca // degenerate, and the key we use for mipmaps return; } + SkASSERT(result.isImmutable()); SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (src.getGenerationID(), invScaleX, invScaleY, get_bounds_from_bitmap(src), result))); } @@ -101,6 +106,7 @@ bool SkBitmapCache::Find(uint32_t genID, int width, int height, SkBitmap* result } void SkBitmapCache::Add(uint32_t genID, int width, int height, const SkBitmap& result) { + SkASSERT(result.isImmutable()); SkResourceCache::Add(SkNEW_ARGS(BitmapRec, (genID, SK_Scalar1, SK_Scalar1, SkIRect::MakeWH(width, height), result))); } diff --git a/src/core/SkBitmapCache.h b/src/core/SkBitmapCache.h index 2b2dfbbea4..74e8546353 100644 --- a/src/core/SkBitmapCache.h +++ b/src/core/SkBitmapCache.h @@ -9,17 +9,26 @@ #define SkBitmapCache_DEFINED #include "SkScalar.h" +#include "SkBitmap.h" -class SkBitmap; class SkMipMap; class SkBitmapCache { public: /** + * Use this allocator for bitmaps, so they can use ashmem when available. + */ + static SkBitmap::Allocator* GetAllocator(); + + /** * Search based on the src bitmap and inverse scales in X and Y. If found, returns true and * result will be set to the matching bitmap with its pixels already locked. */ static bool Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, SkBitmap* result); + + /* + * result must be marked isImmutable() + */ static void Add(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY, const SkBitmap& result); @@ -28,6 +37,10 @@ public: * result will be set to the matching bitmap with its pixels already locked. */ static bool Find(uint32_t genID, int width, int height, SkBitmap* result); + + /* + * result must be marked isImmutable() + */ static void Add(uint32_t genID, int width, int height, const SkBitmap& result); }; diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index a269170422..2fa0294750 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -189,6 +189,7 @@ bool SkBitmapProcState::possiblyScaleImage() { } SkASSERT(NULL != fScaledBitmap.getPixels()); + fScaledBitmap.setImmutable(); SkBitmapCache::Add(fOrigBitmap, roundedDestWidth, roundedDestHeight, fScaledBitmap); } diff --git a/src/lazy/SkCachingPixelRef.cpp b/src/lazy/SkCachingPixelRef.cpp index 6d97aaeee9..56431880c9 100644 --- a/src/lazy/SkCachingPixelRef.cpp +++ b/src/lazy/SkCachingPixelRef.cpp @@ -54,6 +54,7 @@ bool SkCachingPixelRef::onNewLockPixels(LockRec* rec) { fErrorInDecoding = true; return false; } + fLockedBitmap.setImmutable(); SkBitmapCache::Add(this->getGenerationID(), info.fWidth, info.fHeight, fLockedBitmap); } |