| Index: src/core/SkImageCacherator.cpp
|
| diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp
|
| index b35e053b0df0098f048ee1ac7c02246affb57ab5..cc1067ff67d9cc6260b9d196a113e87c1269ae9d 100644
|
| --- a/src/core/SkImageCacherator.cpp
|
| +++ b/src/core/SkImageCacherator.cpp
|
| @@ -18,7 +18,7 @@
|
| #include "GrContext.h"
|
| #include "GrGpuResourcePriv.h"
|
| #include "GrResourceKey.h"
|
| -#include "GrTextureAccess.h"
|
| +#include "GrTextureParams.h"
|
| #include "GrYUVProvider.h"
|
| #include "SkGr.h"
|
| #include "SkGrPriv.h"
|
| @@ -140,7 +140,7 @@ bool SkImageCacherator::lockAsBitmap(SkBitmap* bitmap, const SkImage* client) {
|
| {
|
| ScopedGenerator generator(this);
|
| SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
|
| - tex.reset(generator->generateTexture(nullptr, kUntiled_SkImageUsageType, &subset));
|
| + tex.reset(generator->generateTexture(nullptr, &subset));
|
| }
|
| if (!tex) {
|
| bitmap->reset();
|
| @@ -207,24 +207,17 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) {
|
| tex->resourcePriv().setUniqueKey(key);
|
| return tex;
|
| }
|
| -#endif
|
|
|
| /*
|
| * We have a 5 ways to try to return a texture (in sorted order)
|
| *
|
| * 1. Check the cache for a pre-existing one
|
| - * 2. Ask the genreator to natively create one
|
| + * 2. Ask the generator to natively create one
|
| * 3. Ask the generator to return a compressed form that the GPU might support
|
| * 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::lockAsTexture(GrContext* ctx, SkImageUsageType usage,
|
| - const SkImage* client) {
|
| -#if SK_SUPPORT_GPU
|
| - if (!ctx) {
|
| - return nullptr;
|
| - }
|
| -
|
| +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) {
|
| @@ -232,8 +225,9 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
|
| }
|
|
|
| GrUniqueKey key;
|
| + const GrTextureParams& noStretchParams = GrTextureParams::ClampNoFilter();
|
| GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.height()),
|
| - *ctx->caps(), usage);
|
| + *ctx->caps(), noStretchParams);
|
|
|
| // 1. Check the cache for a pre-existing one
|
| if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) {
|
| @@ -244,7 +238,7 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
|
| {
|
| ScopedGenerator generator(this);
|
| SkIRect subset = SkIRect::MakeXYWH(fOrigin.x(), fOrigin.y(), fInfo.width(), fInfo.height());
|
| - if (GrTexture* tex = generator->generateTexture(ctx, usage, &subset)) {
|
| + if (GrTexture* tex = generator->generateTexture(ctx, &subset)) {
|
| return set_key_and_return(tex, key);
|
| }
|
| }
|
| @@ -273,10 +267,77 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa
|
| // 5. Ask the generator to return RGB(A) data, which the GPU can convert
|
| SkBitmap bitmap;
|
| if (this->tryLockAsBitmap(&bitmap, client)) {
|
| - return GrRefCachedBitmapTexture(ctx, bitmap, usage);
|
| + return GrRefCachedBitmapTexture(ctx, bitmap, noStretchParams);
|
| }
|
| -#endif
|
| + return nullptr;
|
| +}
|
| +
|
| +///////////////////////////////////////////////////////////////////////////////////////////////////
|
| +
|
| +#include "GrTextureMaker.h"
|
| +
|
| +class Cacherator_GrTextureMaker : public GrTextureMaker {
|
| +public:
|
| + Cacherator_GrTextureMaker(SkImageCacherator* cacher, const GrTextureParams& params,
|
| + const SkImage* client, const GrUniqueKey& unstretchedKey)
|
| + : INHERITED(cacher->info().width(), cacher->info().height())
|
| + , fCacher(cacher)
|
| + , fParams(params)
|
| + , fClient(client)
|
| + , 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* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) override;
|
| +
|
| + GrTexture* onRefUnstretchedTexture(GrContext* ctx, const GrTextureParams*) override {
|
| + return fCacher->lockUnstretchedTexture(ctx, fClient);
|
| + }
|
| +
|
| + bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override {
|
| + return GrMakeStretchedKey(fUnstretchedKey, stretch, stretchedKey);
|
| + }
|
| +
|
| + void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override {
|
| + if (fClient) {
|
| + as_IB(fClient)->notifyAddedToCache();
|
| + }
|
| + }
|
| +
|
| + bool onGetROBitmap(SkBitmap* bitmap) override {
|
| + return fCacher->lockAsBitmap(bitmap, fClient);
|
| + }
|
| +
|
| +private:
|
| + SkImageCacherator* fCacher;
|
| + const GrTextureParams& fParams;
|
| + const SkImage* fClient;
|
| + const GrUniqueKey fUnstretchedKey;
|
| +
|
| + typedef GrTextureMaker INHERITED;
|
| +};
|
|
|
| +GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams& params,
|
| + const SkImage* client) {
|
| + if (!ctx) {
|
| + return nullptr;
|
| + }
|
| +
|
| + GrUniqueKey key;
|
| + GrMakeKeyFromImageID(&key, this->uniqueID(),
|
| + SkIRect::MakeWH(this->info().width(), this->info().height()),
|
| + *ctx->caps(), GrTextureParams::ClampNoFilter());
|
| +
|
| + return Cacherator_GrTextureMaker(this, params, client, key).refCachedTexture(ctx, params);
|
| +}
|
| +
|
| +#else
|
| +
|
| +GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams&,
|
| + const SkImage* client) {
|
| return nullptr;
|
| }
|
|
|
| +#endif
|
|
|