diff options
author | 2015-09-30 12:21:45 -0700 | |
---|---|---|
committer | 2015-09-30 12:21:45 -0700 | |
commit | 856e9d921462136da8562f8f122d42e114cd4710 (patch) | |
tree | 9ebc00a92f5aacdd54d00c528fa3ed19f48f6fd6 /src/gpu | |
parent | 8a6697af95b340aad6dee7e6228048fa305c1e59 (diff) |
Revert[4] of add ImageShader, sharing code with its Bitmap cousin
Now with GrTextureMaker subclasses to handle npot usage.
This reverts commit 476506d070dbc59b158acc1a00c34bff95ab2968.
BUG=skia:
Review URL: https://codereview.chromium.org/1370223002
Diffstat (limited to 'src/gpu')
-rw-r--r-- | src/gpu/GrTextureMaker.h | 1 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 68 | ||||
-rw-r--r-- | src/gpu/SkGrPriv.h | 10 | ||||
-rw-r--r-- | src/gpu/gl/GrGLGpu.cpp | 12 |
4 files changed, 63 insertions, 28 deletions
diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h index 669a7eeb08..1cbf63a029 100644 --- a/src/gpu/GrTextureMaker.h +++ b/src/gpu/GrTextureMaker.h @@ -24,6 +24,7 @@ public: int width() const { return fWidth; } int height() const { return fHeight; } + GrTexture* refCachedTexture(GrContext*, SkImageUsageType); GrTexture* refCachedTexture(GrContext*, const GrTextureParams*); protected: diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 7fe8fe188b..a726939788 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -37,6 +37,33 @@ # include "etc1.h" #endif +bool GrTextureUsageSupported(const GrCaps& caps, int width, int height, SkImageUsageType usage) { + if (caps.npotTextureTileSupport()) { + return true; + } + const bool is_pow2 = SkIsPow2(width) && SkIsPow2(height); + return is_pow2 || kUntiled_SkImageUsageType == usage; +} + +GrTextureParams GrImageUsageToTextureParams(SkImageUsageType usage) { + // Just need a params that will trigger the correct cache key / etc, since the usage doesn't + // tell us the specifics about filter level or specific tiling. + + const SkShader::TileMode tiles[] = { + SkShader::kClamp_TileMode, // kUntiled_SkImageUsageType + SkShader::kRepeat_TileMode, // kTiled_Unfiltered_SkImageUsageType + SkShader::kRepeat_TileMode, // kTiled_Filtered_SkImageUsageType + }; + + const GrTextureParams::FilterMode filters[] = { + GrTextureParams::kNone_FilterMode, // kUntiled_SkImageUsageType + GrTextureParams::kNone_FilterMode, // kTiled_Unfiltered_SkImageUsageType + GrTextureParams::kBilerp_FilterMode, // kTiled_Filtered_SkImageUsageType + }; + + return GrTextureParams(tiles[usage], filters[usage]); +} + /* Fill out buffer with the compressed format Ganesh expects from a colortable based bitmap. [palette (colortable) + indices]. @@ -133,8 +160,8 @@ static void get_stretch(const GrContext* ctx, int width, int height, } } -static bool make_stretched_key(const GrUniqueKey& origKey, const SkGrStretch& stretch, - GrUniqueKey* stretchedKey) { +bool GrMakeStretchedKey(const GrUniqueKey& origKey, const SkGrStretch& stretch, + GrUniqueKey* stretchedKey) { if (origKey.isValid() && SkGrStretch::kNone_Type != stretch.fType) { uint32_t width = SkToU16(stretch.fWidth); uint32_t height = SkToU16(stretch.fHeight); @@ -169,12 +196,7 @@ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& sub SkGrStretch::kBilerp_Type, // kTiled_Filtered_SkImageUsageType }; - const bool isPow2 = SkIsPow2(subset.width()) && SkIsPow2(subset.height()); - const bool needToStretch = !isPow2 && - usage != kUntiled_SkImageUsageType && - !caps.npotTextureTileSupport(); - - if (needToStretch) { + if (!GrTextureUsageSupported(caps, subset.width(), subset.height(), usage)) { GrUniqueKey tmpKey; make_unstretched_key(&tmpKey, imageID, subset); @@ -182,7 +204,7 @@ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& sub stretch.fType = stretches[usage]; stretch.fWidth = SkNextPow2(subset.width()); stretch.fHeight = SkNextPow2(subset.height()); - if (!make_stretched_key(tmpKey, stretch, key)) { + if (!GrMakeStretchedKey(tmpKey, stretch, key)) { goto UNSTRETCHED; } } else { @@ -195,7 +217,7 @@ static void make_image_keys(uint32_t imageID, const SkIRect& subset, const SkGrS GrUniqueKey* key, GrUniqueKey* stretchedKey) { make_unstretched_key(key, imageID, subset); if (SkGrStretch::kNone_Type != stretch.fType) { - make_stretched_key(*key, stretch, stretchedKey); + GrMakeStretchedKey(*key, stretch, stretchedKey); } } @@ -510,7 +532,7 @@ bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& sub return false; } GrUniqueKey stretchedKey; - make_stretched_key(key, stretch, &stretchedKey); + GrMakeStretchedKey(key, stretch, &stretchedKey); return ctx->textureProvider()->existsTextureWithUniqueKey(stretchedKey); } @@ -551,7 +573,7 @@ protected: GrUniqueKey unstretchedKey; make_unstretched_key(&unstretchedKey, fBitmap.getGenerationID(), fBitmap.getSubset()); - return make_stretched_key(unstretchedKey, stretch, stretchedKey); + return GrMakeStretchedKey(unstretchedKey, stretch, stretchedKey); } void onNotifyStretchCached(const GrUniqueKey& stretchedKey) override { @@ -579,22 +601,7 @@ GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, SkImageUsageType usage) { - // Just need a params that will trigger the correct cache key / etc, since the usage doesn't - // tell us the specifics about filter level or specific tiling. - - const SkShader::TileMode tiles[] = { - SkShader::kClamp_TileMode, // kUntiled_SkImageUsageType - SkShader::kRepeat_TileMode, // kTiled_Unfiltered_SkImageUsageType - SkShader::kRepeat_TileMode, // kTiled_Filtered_SkImageUsageType - }; - - const GrTextureParams::FilterMode filters[] = { - GrTextureParams::kNone_FilterMode, // kUntiled_SkImageUsageType - GrTextureParams::kNone_FilterMode, // kTiled_Unfiltered_SkImageUsageType - GrTextureParams::kBilerp_FilterMode, // kTiled_Filtered_SkImageUsageType - }; - - GrTextureParams params(tiles[usage], filters[usage]); + GrTextureParams params = GrImageUsageToTextureParams(usage); return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms); } @@ -908,6 +915,11 @@ GrTextureParams::FilterMode GrSkFilterQualityToGrFilterMode(SkFilterQuality pain //////////////////////////////////////////////////////////////////////////////////////////////// +GrTexture* GrTextureMaker::refCachedTexture(GrContext* ctx, SkImageUsageType usage) { + GrTextureParams params = GrImageUsageToTextureParams(usage); + return this->refCachedTexture(ctx, ¶ms); +} + GrTexture* GrTextureMaker::refCachedTexture(GrContext* ctx, const GrTextureParams* params) { SkGrStretch stretch; get_stretch(ctx, this->width(), this->height(), params, &stretch); diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h index 1564d31bc9..25fda57d9e 100644 --- a/src/gpu/SkGrPriv.h +++ b/src/gpu/SkGrPriv.h @@ -9,6 +9,7 @@ #define SkGrPriv_DEFINED #include "GrTypes.h" +#include "GrTextureAccess.h" #include "SkImageInfo.h" #include "SkXfermode.h" @@ -31,6 +32,8 @@ struct SkGrStretch { int fHeight; }; +GrTextureParams GrImageUsageToTextureParams(SkImageUsageType); + /** * Our key includes the offset, width, and height so that bitmaps created by extractSubset() * are unique. @@ -45,6 +48,11 @@ struct SkGrStretch { void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds, const GrCaps&, SkImageUsageType); +/** + * Given an "unstretched" key, and a stretch rec, produce a stretched key. + */ +bool GrMakeStretchedKey(const GrUniqueKey& origKey, const SkGrStretch&, GrUniqueKey* stretchedKey); + /** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order to convert the SkShader (if any) on the SkPaint. */ bool SkPaintToGrPaint(GrContext*, @@ -76,4 +84,6 @@ bool SkPaintToGrPaintWithXfermode(GrContext* context, bool primitiveIsSrc, GrPaint* grPaint); +bool GrTextureUsageSupported(const GrCaps&, int width, int height, SkImageUsageType); + #endif diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp index cb12fefc32..5388387c3b 100644 --- a/src/gpu/gl/GrGLGpu.cpp +++ b/src/gpu/gl/GrGLGpu.cpp @@ -2246,6 +2246,18 @@ static inline GrGLenum tile_to_gl_wrap(SkShader::TileMode tm) { void GrGLGpu::bindTexture(int unitIdx, const GrTextureParams& params, GrGLTexture* texture) { SkASSERT(texture); +#ifdef SK_DEBUG + if (!this->caps()->npotTextureTileSupport()) { + const bool tileX = SkShader::kClamp_TileMode != params.getTileModeX(); + const bool tileY = SkShader::kClamp_TileMode != params.getTileModeY(); + if (tileX || tileY) { + const int w = texture->width(); + const int h = texture->height(); + SkASSERT(SkIsPow2(w) && SkIsPow2(h)); + } + } +#endif + // If we created a rt/tex and rendered to it without using a texture and now we're texturing // from the rt it will still be the last bound texture, but it needs resolving. So keep this // out of the "last != next" check. |