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

Unified Diff: src/core/SkBitmapCache.cpp

Issue 471473002: Optimize CSS box-shadow performance (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: backed blur mask with a bitmap Created 6 years, 3 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/SkBitmapCache.h ('k') | src/core/SkMaskCache.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkBitmapCache.cpp
diff --git a/src/core/SkBitmapCache.cpp b/src/core/SkBitmapCache.cpp
index c954a3099e67d44232c1969a7e9814325b287e9b..6013fd2ed916bd67b6a8ec42b3dda464ad6ea4c8 100644
--- a/src/core/SkBitmapCache.cpp
+++ b/src/core/SkBitmapCache.cpp
@@ -61,6 +61,59 @@ struct BitmapRec : public SkResourceCache::Rec {
virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + fBitmap.getSize(); }
};
+struct RRectBlurKey : public SkResourceCache::Key {
+public:
+ RRectBlurKey(SkScalar sigma, const SkRRect& rrect)
+ : fSigma(sigma)
+ , fRRect(rrect) {
+ this->init(sizeof(fSigma) + sizeof(fRRect));
+ }
+
+ SkScalar fSigma;
+ SkRRect fRRect;
+};
+
+struct RRectBlurRec : public SkResourceCache::Rec {
+ RRectBlurRec(SkScalar sigma, const SkRRect& rrect, const SkBitmap& result)
+ : fKey(sigma, rrect)
+ , fBitmap(result)
+ {}
+
+ RRectBlurKey fKey;
+ SkBitmap fBitmap;
+
+ virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
+ virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fBitmap); }
reed1 2014/09/04 14:15:39 sizeof(fBitmap) does not account for the ram of th
qiankun 2014/09/09 03:03:03 Done.
+};
+
+struct RectsBlurKey : public SkResourceCache::Key {
+public:
+ RectsBlurKey(SkScalar sigma, int32_t count, const SkRect rects[])
+ : fSigma(sigma)
+ , fRecCount(count) {
+ for (int i = 0; i < count; i++) {
+ fRects[i] = rects[i];
+ }
+ this->init(sizeof(fSigma) + sizeof(fRecCount) + sizeof(SkRect) * fRecCount);
+ }
+
+ SkScalar fSigma;
+ int32_t fRecCount;
+ SkRect fRects[2];
+};
+
+struct RectsBlurRec : public SkResourceCache::Rec {
+ RectsBlurRec(SkScalar sigma, unsigned count, const SkRect rects[], const SkBitmap& result)
+ : fKey(sigma, count, rects)
+ , fBitmap(result)
+ {}
+
+ RectsBlurKey fKey;
+ SkBitmap fBitmap;
+
+ virtual const Key& getKey() const SK_OVERRIDE { return fKey; }
+ virtual size_t bytesUsed() const SK_OVERRIDE { return sizeof(fKey) + sizeof(fBitmap); }
+};
static bool find_and_return(const BitmapKey& key, SkBitmap* result) {
const BitmapRec* rec = (BitmapRec*)SkResourceCache::FindAndLock(key);
if (rec) {
@@ -79,6 +132,42 @@ static bool find_and_return(const BitmapKey& key, SkBitmap* result) {
return false;
}
+static bool find_and_return(const RRectBlurKey& key, SkBitmap* result) {
+ const RRectBlurRec* rec = (RRectBlurRec*)SkResourceCache::FindAndLock(key);
+ if (rec) {
+ *result = rec->fBitmap;
+ SkResourceCache::Unlock(rec);
+
+ result->lockPixels();
+ if (result->getPixels()) {
+ return true;
+ }
+ // todo: we should explicitly purge rec from the cache at this point, since
+ // it is effectively purged already (has no memory behind it)
+ result->reset();
+ // fall-through to false
+ }
+ return false;
+}
+
+static bool find_and_return(const RectsBlurKey& key, SkBitmap* result) {
+ const RectsBlurRec* rec = (RectsBlurRec*)SkResourceCache::FindAndLock(key);
+ if (rec) {
+ *result = rec->fBitmap;
+ SkResourceCache::Unlock(rec);
+
+ result->lockPixels();
+ if (result->getPixels()) {
+ return true;
+ }
+ // todo: we should explicitly purge rec from the cache at this point, since
+ // it is effectively purged already (has no memory behind it)
+ result->reset();
+ // fall-through to false
+ }
+ return false;
+}
+
bool SkBitmapCache::Find(const SkBitmap& src, SkScalar invScaleX, SkScalar invScaleY,
SkBitmap* result) {
if (0 == invScaleX || 0 == invScaleY) {
@@ -121,6 +210,25 @@ bool SkBitmapCache::Add(uint32_t genID, const SkIRect& subset, const SkBitmap& r
return true;
}
}
+
+bool SkBitmapCache::Find(SkScalar sigma, const SkRRect& rrect, SkBitmap* result) {
+ RRectBlurKey key(sigma, rrect);
+ return find_and_return(key, result);
+}
+
+void SkBitmapCache::Add(SkScalar sigma, const SkRRect& rrect, const SkBitmap& result) {
+ SkResourceCache::Add(SkNEW_ARGS(RRectBlurRec, (sigma, rrect, result)));
+}
+
+bool SkBitmapCache::Find(SkScalar sigma, int32_t count, const SkRect rects[], SkBitmap* result) {
+ RectsBlurKey key(sigma, count, rects);
+ return find_and_return(key, result);
+}
+
+void SkBitmapCache::Add(SkScalar sigma, int32_t count, const SkRect rects[], const SkBitmap& result) {
+ SkResourceCache::Add(SkNEW_ARGS(RectsBlurRec, (sigma, count, rects, result)));
+}
+
//////////////////////////////////////////////////////////////////////////////////////////
struct MipMapRec : public SkResourceCache::Rec {
« no previous file with comments | « src/core/SkBitmapCache.h ('k') | src/core/SkMaskCache.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698