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>
This commit is contained in:
parent
42102420c0
commit
d4b6787511
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user