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

Unified Diff: src/image/SkImage_Generator.cpp

Issue 2453473004: Avoid separate allocation of SkImageCacherator (Closed)
Patch Set: pass validator to ctor Created 4 years, 2 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/SkImageCacherator.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/image/SkImage_Generator.cpp
diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp
index 412f573ba6dbe38d3a9da521fdc48889715db07d..8fa022de7bdc1a6f11fb21c73cf0504ec0963e0b 100644
--- a/src/image/SkImage_Generator.cpp
+++ b/src/image/SkImage_Generator.cpp
@@ -16,20 +16,20 @@
class SkImage_Generator : public SkImage_Base {
public:
- SkImage_Generator(SkImageCacherator* cache)
- : INHERITED(cache->info().width(), cache->info().height(), cache->uniqueID())
- , fCache(cache) // take ownership
+ SkImage_Generator(SkImageCacherator::Validator* validator)
+ : INHERITED(validator->fInfo.width(), validator->fInfo.height(), validator->fUniqueID)
+ , fCache(validator)
{}
virtual SkImageInfo onImageInfo() const override {
- return fCache->info();
+ return fCache.info();
}
SkAlphaType onAlphaType() const override {
- return fCache->info().alphaType();
+ return fCache.info().alphaType();
}
bool onReadPixels(const SkImageInfo&, void*, size_t, int srcX, int srcY, CachingHint) const override;
- SkImageCacherator* peekCacherator() const override { return fCache; }
+ SkImageCacherator* peekCacherator() const override { return &fCache; }
SkData* onRefEncoded(GrContext*) const override;
sk_sp<SkImage> onMakeSubset(const SkIRect&) const override;
bool getROPixels(SkBitmap*, CachingHint) const override;
@@ -38,7 +38,7 @@ public:
bool onIsLazyGenerated() const override { return true; }
private:
- SkAutoTDelete<SkImageCacherator> fCache;
+ mutable SkImageCacherator fCache;
typedef SkImage_Base INHERITED;
};
@@ -49,13 +49,13 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
int srcX, int srcY, CachingHint chint) const {
SkBitmap bm;
if (kDisallow_CachingHint == chint) {
- if (fCache->lockAsBitmapOnlyIfAlreadyCached(&bm)) {
+ if (fCache.lockAsBitmapOnlyIfAlreadyCached(&bm)) {
return bm.readPixels(dstInfo, dstPixels, dstRB, srcX, srcY);
} else {
// Try passing the caller's buffer directly down to the generator. If this fails we
// may still succeed in the general case, as the generator may prefer some other
// config, which we could then convert via SkBitmap::readPixels.
- if (fCache->directGeneratePixels(dstInfo, dstPixels, dstRB, srcX, srcY)) {
+ if (fCache.directGeneratePixels(dstInfo, dstPixels, dstRB, srcX, srcY)) {
return true;
}
// else fall through
@@ -69,16 +69,16 @@ bool SkImage_Generator::onReadPixels(const SkImageInfo& dstInfo, void* dstPixels
}
SkData* SkImage_Generator::onRefEncoded(GrContext* ctx) const {
- return fCache->refEncoded(ctx);
+ return fCache.refEncoded(ctx);
}
bool SkImage_Generator::getROPixels(SkBitmap* bitmap, CachingHint chint) const {
- return fCache->lockAsBitmap(bitmap, this, chint);
+ return fCache.lockAsBitmap(bitmap, this, chint);
}
GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams& params,
SkSourceGammaTreatment gammaTreatment) const {
- return fCache->lockAsTexture(ctx, params, gammaTreatment, this);
+ return fCache.lockAsTexture(ctx, params, gammaTreatment, this);
}
sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
@@ -98,12 +98,7 @@ sk_sp<SkImage> SkImage_Generator::onMakeSubset(const SkIRect& subset) const {
}
sk_sp<SkImage> SkImage::MakeFromGenerator(SkImageGenerator* generator, const SkIRect* subset) {
- if (!generator) {
- return nullptr;
- }
- SkImageCacherator* cache = SkImageCacherator::NewFromGenerator(generator, subset);
- if (!cache) {
- return nullptr;
- }
- return sk_make_sp<SkImage_Generator>(cache);
+ SkImageCacherator::Validator validator(generator, subset);
+
+ return validator ? sk_make_sp<SkImage_Generator>(&validator) : nullptr;
reed1 2016/10/27 13:45:19 Can we force somebody to assert (Validator?) if we
f(malita) 2016/10/27 14:17:07 The SkImageCacherator ctor (the only "user" of val
}
« no previous file with comments | « src/core/SkImageCacherator.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698