diff options
author | Brian Salomon <bsalomon@google.com> | 2015-10-19 15:12:32 -0400 |
---|---|---|
committer | Brian Salomon <bsalomon@google.com> | 2015-10-19 15:12:32 -0400 |
commit | bc0bcc08b390e430f66710ddfbc47da39ab841d9 (patch) | |
tree | d70fcd166ca42586469882387733bb54b2d6f34a /src/core/SkImageCacherator.cpp | |
parent | 386f2d32044a4de3fc5c547da03d8f1464dd210a (diff) |
Revert recent CLs around GrTextureMaker/GrTextureParamsAdjuster
Review URL: https://codereview.chromium.org/1411353002 .
Diffstat (limited to 'src/core/SkImageCacherator.cpp')
-rw-r--r-- | src/core/SkImageCacherator.cpp | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index f59be32411..cd5ae57699 100644 --- a/src/core/SkImageCacherator.cpp +++ b/src/core/SkImageCacherator.cpp @@ -204,9 +204,7 @@ public: }; static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { - if (key.isValid()) { - tex->resourcePriv().setUniqueKey(key); - } + tex->resourcePriv().setUniqueKey(key); return tex; } @@ -219,16 +217,24 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { * 4. Ask the generator to return YUV planes, which the GPU can convert * 5. Ask the generator to return RGB(A) data, which the GPU can convert */ -GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key, - const SkImage* client) { +GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, const SkImage* client) { + // textures (at least the texture-key) only support 16bit dimensions, so abort early + // if we're too big. + if (fInfo.width() > 0xFFFF || fInfo.height() > 0xFFFF) { + return nullptr; + } + + GrUniqueKey key; + const GrTextureParams& noStretchParams = GrTextureParams::ClampNoFilter(); + GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.height()), + *ctx->caps(), noStretchParams); + // 1. Check the cache for a pre-existing one - if (key.isValid()) { - if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { - return tex; - } + if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { + return tex; } - // 2. Ask the generator to natively create one + // 2. Ask the genreator to natively create one { ScopedGenerator generator(this); SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height()); @@ -261,62 +267,54 @@ GrTexture* SkImageCacherator::lockTexture(GrContext* ctx, const GrUniqueKey& key // 5. Ask the generator to return RGB(A) data, which the GPU can convert SkBitmap bitmap; if (this->tryLockAsBitmap(&bitmap, client)) { - GrTexture* tex = GrUploadBitmapToTexture(ctx, bitmap); - if (tex) { - return set_key_and_return(tex, key); - } + return GrRefCachedBitmapTexture(ctx, bitmap, noStretchParams); } return nullptr; } /////////////////////////////////////////////////////////////////////////////////////////////////// -#include "GrTextureParamsAdjuster.h" +#include "GrTextureMaker.h" -class Cacherator_GrTextureParamsAdjuster : public GrTextureParamsAdjuster { +class Cacherator_GrTextureMaker : public GrTextureMaker { public: - Cacherator_GrTextureParamsAdjuster(SkImageCacherator* cacher, const SkImage* client) + Cacherator_GrTextureMaker(SkImageCacherator* cacher, const SkImage* client, + const GrUniqueKey& unstretchedKey) : INHERITED(cacher->info().width(), cacher->info().height()) , fCacher(cacher) , fClient(client) - { - if (client) { - GrMakeKeyFromImageID(&fOriginalKey, client->uniqueID(), - SkIRect::MakeWH(this->width(), this->height())); - } - } + , fUnstretchedKey(unstretchedKey) + {} protected: // TODO: consider overriding this, for the case where the underlying generator might be // able to efficiently produce a "stretched" texture natively (e.g. picture-backed) - // GrTexture* generateTextureForParams(GrContext*, const SkGrStretch&) override; +// GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) override; - GrTexture* refOriginalTexture(GrContext* ctx) override { - return fCacher->lockTexture(ctx, fOriginalKey, fClient); + GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { + return fCacher->lockUnstretchedTexture(ctx, fClient); } - void makeCopyKey(const CopyParams& stretch, GrUniqueKey* paramsCopyKey) override { - if (fOriginalKey.isValid()) { - MakeCopyKeyFromOrigKey(fOriginalKey, stretch, paramsCopyKey); - } + bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override { + return GrMakeStretchedKey(fUnstretchedKey, stretch, stretchedKey); } - void didCacheCopy(const GrUniqueKey& copyKey) override { + void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { if (fClient) { as_IB(fClient)->notifyAddedToCache(); } } - bool getROBitmap(SkBitmap* bitmap) override { + bool onGetROBitmap(SkBitmap* bitmap) override { return fCacher->lockAsBitmap(bitmap, fClient); } private: SkImageCacherator* fCacher; const SkImage* fClient; - GrUniqueKey fOriginalKey; + const GrUniqueKey fUnstretchedKey; - typedef GrTextureParamsAdjuster INHERITED; + typedef GrTextureMaker INHERITED; }; GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams& params, @@ -325,7 +323,12 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParam return nullptr; } - return Cacherator_GrTextureParamsAdjuster(this, client).refTextureForParams(ctx, params); + GrUniqueKey key; + GrMakeKeyFromImageID(&key, this->uniqueID(), + SkIRect::MakeWH(this->info().width(), this->info().height()), + *ctx->caps(), GrTextureParams::ClampNoFilter()); + + return Cacherator_GrTextureMaker(this, client, key).refCachedTexture(ctx, params); } #else |