diff options
author | Christopher Cameron <ccameron@chromium.org> | 2017-07-13 15:18:08 -0700 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-07-17 12:14:37 +0000 |
commit | d4b678751117983dc92a85a3879445bd8aa33ffb (patch) | |
tree | 9407bd9c60164a9a1ab535666a89675b35896cba /src/image | |
parent | 42102420c02a525f57264c124ef941882d22c5a1 (diff) |
Make SkImage_Lazy cache its result from onMakeColorSpace
May sites will all onMakeColorSpace every frame, resulting repeatedly
re-created new SkImage_Lazy class instances, new cache keys, and
repeated cache misses.
Save the most recent result from onMakeColorSpace, to avoid this thrash.
Bug:741607
Change-Id: I34091327a17275722f82ed372eb0b341806a9ddc
Reviewed-on: https://skia-review.googlesource.com/23287
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Mike Reed <reed@google.com>
Diffstat (limited to 'src/image')
-rw-r--r-- | src/image/SkImage_Lazy.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/image/SkImage_Lazy.cpp b/src/image/SkImage_Lazy.cpp index 809ada01f6..e760d036a2 100644 --- a/src/image/SkImage_Lazy.cpp +++ b/src/image/SkImage_Lazy.cpp @@ -159,6 +159,12 @@ private: uint32_t getUniqueID(CachedFormat) const; + // Repeated calls to onMakeColorSpace will result in a proliferation of unique IDs and + // SkImage_Lazy instances. Cache the result of the last successful onMakeColorSpace call. + mutable SkMutex fOnMakeColorSpaceMutex; + mutable sk_sp<SkColorSpace> fOnMakeColorSpaceTarget; + mutable sk_sp<SkImage> fOnMakeColorSpaceResult; + typedef SkImage_Base INHERITED; }; @@ -649,10 +655,20 @@ sk_sp<SkImage> SkImage_Lazy::onMakeSubset(const SkIRect& subset) const { sk_sp<SkImage> SkImage_Lazy::onMakeColorSpace(sk_sp<SkColorSpace> target, SkColorType targetColorType, SkTransferFunctionBehavior premulBehavior) const { + SkAutoExclusive autoAquire(fOnMakeColorSpaceMutex); + if (target && fOnMakeColorSpaceTarget && + SkColorSpace::Equals(target.get(), fOnMakeColorSpaceTarget.get())) { + return fOnMakeColorSpaceResult; + } const SkIRect generatorSubset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height()); Validator validator(fSharedGenerator, &generatorSubset, target); - return validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr; + sk_sp<SkImage> result = validator ? sk_sp<SkImage>(new SkImage_Lazy(&validator)) : nullptr; + if (result) { + fOnMakeColorSpaceTarget = target; + fOnMakeColorSpaceResult = result; + } + return result; } sk_sp<SkImage> SkImage::MakeFromGenerator(std::unique_ptr<SkImageGenerator> generator, |