diff options
author | bsalomon <bsalomon@google.com> | 2015-10-12 10:39:46 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-12 10:39:46 -0700 |
commit | afa95e270c64c9777647b6c58b796750ced57c39 (patch) | |
tree | 56b617f224fa34d96ed23e617ee503583e517263 /src | |
parent | 04965c6f112565c02926bc9a230e6da5f400d07a (diff) |
Remove image usage type enum. Use GrTextureParams instead.
BUG=skia:
Review URL: https://codereview.chromium.org/1404433002
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapProcShader.cpp | 2 | ||||
-rw-r--r-- | src/core/SkImageCacherator.cpp | 30 | ||||
-rw-r--r-- | src/core/SkImageCacherator.h | 5 | ||||
-rw-r--r-- | src/core/SkImageFilter.cpp | 3 | ||||
-rw-r--r-- | src/core/SkImageGenerator.cpp | 4 | ||||
-rw-r--r-- | src/core/SkLightingShader.cpp | 4 | ||||
-rw-r--r-- | src/core/SkPictureImageGenerator.cpp | 4 | ||||
-rw-r--r-- | src/effects/SkPerlinNoiseShader.cpp | 6 | ||||
-rw-r--r-- | src/effects/SkTableColorFilter.cpp | 3 | ||||
-rw-r--r-- | src/effects/gradients/SkGradientShader.cpp | 2 | ||||
-rw-r--r-- | src/gpu/GrTextureMaker.h | 3 | ||||
-rw-r--r-- | src/gpu/SkGpuDevice.cpp | 19 | ||||
-rw-r--r-- | src/gpu/SkGr.cpp | 107 | ||||
-rw-r--r-- | src/gpu/SkGrPriv.h | 14 | ||||
-rw-r--r-- | src/image/SkImageShader.cpp | 12 | ||||
-rw-r--r-- | src/image/SkImage_Base.h | 4 | ||||
-rw-r--r-- | src/image/SkImage_Generator.cpp | 6 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.cpp | 4 | ||||
-rw-r--r-- | src/image/SkImage_Gpu.h | 2 | ||||
-rw-r--r-- | src/image/SkImage_Raster.cpp | 8 | ||||
-rw-r--r-- | src/utils/SkImageGeneratorUtils.cpp | 6 |
21 files changed, 94 insertions, 154 deletions
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp index 3dd528dbda..70f692acf4 100644 --- a/src/core/SkBitmapProcShader.cpp +++ b/src/core/SkBitmapProcShader.cpp @@ -392,7 +392,7 @@ const GrFragmentProcessor* SkBitmapProcShader::asFragmentProcessor(GrContext* co GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic); GrTextureParams params(tm, textureFilterMode); - SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, ¶ms)); + SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, fRawBitmap, params)); if (!texture) { SkErrorInternals::SetError( kInternalError_SkError, diff --git a/src/core/SkImageCacherator.cpp b/src/core/SkImageCacherator.cpp index 03e358a568..5c0d05451d 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, GrTextureParams::ClampNoFilter(), &subset)); } if (!tex) { bitmap->reset(); @@ -212,12 +212,12 @@ static GrTexture* set_key_and_return(GrTexture* tex, const GrUniqueKey& key) { * 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::lockUnstretchedTexture(GrContext* ctx, SkImageUsageType usage, +GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, const GrTextureParams& params, const SkImage* client) { // textures (at least the texture-key) only support 16bit dimensions, so abort early // if we're too big. @@ -227,7 +227,7 @@ GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, SkImageUsag GrUniqueKey key; GrMakeKeyFromImageID(&key, fUniqueID, SkIRect::MakeWH(fInfo.width(), fInfo.height()), - *ctx->caps(), usage); + *ctx->caps(), params); // 1. Check the cache for a pre-existing one if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { @@ -238,7 +238,7 @@ GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, SkImageUsag { 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, params, &subset)) { return set_key_and_return(tex, key); } } @@ -267,7 +267,7 @@ GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, SkImageUsag // 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, params); } return nullptr; } @@ -278,11 +278,11 @@ GrTexture* SkImageCacherator::lockUnstretchedTexture(GrContext* ctx, SkImageUsag class Cacherator_GrTextureMaker : public GrTextureMaker { public: - Cacherator_GrTextureMaker(SkImageCacherator* cacher, SkImageUsageType usage, + Cacherator_GrTextureMaker(SkImageCacherator* cacher, const GrTextureParams& params, const SkImage* client, const GrUniqueKey& unstretchedKey) : INHERITED(cacher->info().width(), cacher->info().height()) , fCacher(cacher) - , fUsage(usage) + , fParams(params) , fClient(client) , fUnstretchedKey(unstretchedKey) {} @@ -293,7 +293,7 @@ protected: // GrTexture* onGenerateStretchedTexture(GrContext*, const SkGrStretch&) override; GrTexture* onRefUnstretchedTexture(GrContext* ctx) override { - return fCacher->lockUnstretchedTexture(ctx, fUsage, fClient); + return fCacher->lockUnstretchedTexture(ctx, fParams, fClient); } bool onMakeStretchedKey(const SkGrStretch& stretch, GrUniqueKey* stretchedKey) override { @@ -312,14 +312,14 @@ protected: private: SkImageCacherator* fCacher; - const SkImageUsageType fUsage; + const GrTextureParams& fParams; const SkImage* fClient; const GrUniqueKey fUnstretchedKey; typedef GrTextureMaker INHERITED; }; -GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usage, +GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams& params, const SkImage* client) { if (!ctx) { return nullptr; @@ -328,14 +328,14 @@ GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usa GrUniqueKey key; GrMakeKeyFromImageID(&key, this->uniqueID(), SkIRect::MakeWH(this->info().width(), this->info().height()), - *ctx->caps(), usage); + *ctx->caps(), params); - return Cacherator_GrTextureMaker(this, usage, client, key).refCachedTexture(ctx, usage); + return Cacherator_GrTextureMaker(this, params, client, key).refCachedTexture(ctx, params); } #else -GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, SkImageUsageType usage, +GrTexture* SkImageCacherator::lockAsTexture(GrContext* ctx, const GrTextureParams&, const SkImage* client) { return nullptr; } diff --git a/src/core/SkImageCacherator.h b/src/core/SkImageCacherator.h index c5c65498cc..1d00117e18 100644 --- a/src/core/SkImageCacherator.h +++ b/src/core/SkImageCacherator.h @@ -13,6 +13,7 @@ #include "SkTemplates.h" class GrContext; +class GrTextureParams; class SkBitmap; class SkImage; @@ -45,7 +46,7 @@ public: * * The caller is responsible for calling texture->unref() when they are done. */ - GrTexture* lockAsTexture(GrContext*, SkImageUsageType, const SkImage* client); + GrTexture* lockAsTexture(GrContext*, const GrTextureParams&, const SkImage* client); /** * If the underlying src naturally is represented by an encoded blob (in SkData), this returns @@ -59,7 +60,7 @@ private: bool generateBitmap(SkBitmap*); bool tryLockAsBitmap(SkBitmap*, const SkImage*); #if SK_SUPPORT_GPU - GrTexture* lockUnstretchedTexture(GrContext*, SkImageUsageType, const SkImage* client); + GrTexture* lockUnstretchedTexture(GrContext*, const GrTextureParams&, const SkImage* client); #endif class ScopedGenerator { diff --git a/src/core/SkImageFilter.cpp b/src/core/SkImageFilter.cpp index 2920714f88..4ad7f0eeba 100644 --- a/src/core/SkImageFilter.cpp +++ b/src/core/SkImageFilter.cpp @@ -464,7 +464,8 @@ bool SkImageFilter::getInputResultGPU(SkImageFilter::Proxy* proxy, if (kUnknown_SkColorType == info.colorType()) { return false; } - SkAutoTUnref<GrTexture> resultTex(GrRefCachedBitmapTexture(context, *result, nullptr)); + SkAutoTUnref<GrTexture> resultTex( + GrRefCachedBitmapTexture(context, *result,GrTextureParams::ClampNoFilter())); result->setPixelRef(new SkGrPixelRef(info, resultTex))->unref(); } return true; diff --git a/src/core/SkImageGenerator.cpp b/src/core/SkImageGenerator.cpp index 187b46047a..98a40148f2 100644 --- a/src/core/SkImageGenerator.cpp +++ b/src/core/SkImageGenerator.cpp @@ -104,12 +104,12 @@ bool SkImageGenerator::onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t return this->onGetYUV8Planes(sizes, planes, rowBytes); } -GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, SkImageUsageType usage, +GrTexture* SkImageGenerator::generateTexture(GrContext* ctx, const GrTextureParams& params, const SkIRect* subset) { if (subset && !SkIRect::MakeWH(fInfo.width(), fInfo.height()).contains(*subset)) { return nullptr; } - return this->onGenerateTexture(ctx, usage, subset); + return this->onGenerateTexture(ctx, params, subset); } ///////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/SkLightingShader.cpp b/src/core/SkLightingShader.cpp index 6121f21534..16441aa84b 100644 --- a/src/core/SkLightingShader.cpp +++ b/src/core/SkLightingShader.cpp @@ -382,7 +382,7 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( // TODO: support other tile modes GrTextureParams diffParams(kClamp_TileMode, diffFilterMode); SkAutoTUnref<GrTexture> diffuseTexture(GrRefCachedBitmapTexture(context, - fDiffuseMap, &diffParams)); + fDiffuseMap, diffParams)); if (!diffuseTexture) { SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); return nullptr; @@ -390,7 +390,7 @@ const GrFragmentProcessor* SkLightingShaderImpl::asFragmentProcessor( GrTextureParams normParams(kClamp_TileMode, normFilterMode); SkAutoTUnref<GrTexture> normalTexture(GrRefCachedBitmapTexture(context, - fNormalMap, &normParams)); + fNormalMap, normParams)); if (!normalTexture) { SkErrorInternals::SetError(kInternalError_SkError, "Couldn't convert bitmap to texture."); return nullptr; diff --git a/src/core/SkPictureImageGenerator.cpp b/src/core/SkPictureImageGenerator.cpp index 13d3cc85c5..a27291f1a8 100644 --- a/src/core/SkPictureImageGenerator.cpp +++ b/src/core/SkPictureImageGenerator.cpp @@ -22,7 +22,7 @@ protected: bool onGetPixels(const SkImageInfo& info, void* pixels, size_t rowBytes, SkPMColor ctable[], int* ctableCount) override; #if SK_SUPPORT_GPU - GrTexture* onGenerateTexture(GrContext*, SkImageUsageType, const SkIRect*) override; + GrTexture* onGenerateTexture(GrContext*, const GrTextureParams&, const SkIRect*) override; #endif private: @@ -88,7 +88,7 @@ SkImageGenerator* SkImageGenerator::NewFromPicture(const SkISize& size, const Sk #if SK_SUPPORT_GPU #include "GrTexture.h" -GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, SkImageUsageType usage, +GrTexture* SkPictureImageGenerator::onGenerateTexture(GrContext* ctx, const GrTextureParams&, const SkIRect* subset) { const SkImageInfo& info = this->getInfo(); SkImageInfo surfaceInfo = subset ? info.makeWH(subset->width(), subset->height()) : info; diff --git a/src/effects/SkPerlinNoiseShader.cpp b/src/effects/SkPerlinNoiseShader.cpp index 86463f62c3..481d1607f7 100644 --- a/src/effects/SkPerlinNoiseShader.cpp +++ b/src/effects/SkPerlinNoiseShader.cpp @@ -943,9 +943,11 @@ const GrFragmentProcessor* SkPerlinNoiseShader::asFragmentProcessor( SkPerlinNoiseShader::PaintingData* paintingData = new PaintingData(fTileSize, fSeed, fBaseFrequencyX, fBaseFrequencyY, matrix); SkAutoTUnref<GrTexture> permutationsTexture( - GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), nullptr)); + GrRefCachedBitmapTexture(context, paintingData->getPermutationsBitmap(), + GrTextureParams::ClampNoFilter())); SkAutoTUnref<GrTexture> noiseTexture( - GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), nullptr)); + GrRefCachedBitmapTexture(context, paintingData->getNoiseBitmap(), + GrTextureParams::ClampNoFilter())); SkMatrix m = viewM; m.setTranslateX(-localMatrix.getTranslateX() + SK_Scalar1); diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp index f0ed7b40c9..8f1a4d7e65 100644 --- a/src/effects/SkTableColorFilter.cpp +++ b/src/effects/SkTableColorFilter.cpp @@ -475,8 +475,7 @@ const GrFragmentProcessor* ColorTableEffect::Create(GrContext* context, SkBitmap SkAutoTUnref<GrTexture> texture; if (-1 == row) { atlas = nullptr; - // Passing params=nullptr because this effect does no tiling or filtering. - texture.reset(GrRefCachedBitmapTexture(context, bitmap, nullptr)); + texture.reset(GrRefCachedBitmapTexture(context, bitmap, GrTextureParams::ClampNoFilter())); } else { texture.reset(SkRef(atlas->getTexture())); } diff --git a/src/effects/gradients/SkGradientShader.cpp b/src/effects/gradients/SkGradientShader.cpp index 88d650c346..a96e09d9e6 100644 --- a/src/effects/gradients/SkGradientShader.cpp +++ b/src/effects/gradients/SkGradientShader.cpp @@ -1132,7 +1132,7 @@ GrGradientEffect::GrGradientEffect(GrContext* ctx, fCoordTransform.reset(kCoordSet, matrix, fAtlas->getTexture(), params.filterMode()); fTextureAccess.reset(fAtlas->getTexture(), params); } else { - SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(ctx, bitmap, ¶ms)); + SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(ctx, bitmap, params)); if (!texture) { return; } diff --git a/src/gpu/GrTextureMaker.h b/src/gpu/GrTextureMaker.h index 1cbf63a029..47141bdfb0 100644 --- a/src/gpu/GrTextureMaker.h +++ b/src/gpu/GrTextureMaker.h @@ -24,8 +24,7 @@ public: int width() const { return fWidth; } int height() const { return fHeight; } - GrTexture* refCachedTexture(GrContext*, SkImageUsageType); - GrTexture* refCachedTexture(GrContext*, const GrTextureParams*); + GrTexture* refCachedTexture(GrContext*, const GrTextureParams&); protected: /** diff --git a/src/gpu/SkGpuDevice.cpp b/src/gpu/SkGpuDevice.cpp index 9d129d579f..4d150599a1 100644 --- a/src/gpu/SkGpuDevice.cpp +++ b/src/gpu/SkGpuDevice.cpp @@ -90,7 +90,7 @@ public: AutoBitmapTexture(GrContext* context, const SkBitmap& bitmap, - const GrTextureParams* params, + const GrTextureParams& params, GrTexture** texture) { SkASSERT(texture); *texture = this->set(context, bitmap, params); @@ -98,7 +98,7 @@ public: GrTexture* set(GrContext* context, const SkBitmap& bitmap, - const GrTextureParams* params) { + const GrTextureParams& params) { // Either get the texture directly from the bitmap, or else use the cache and // remember to unref it. if (GrTexture* bmpTexture = bitmap.getTexture()) { @@ -765,7 +765,7 @@ bool SkGpuDevice::shouldTileImageID(uint32_t imageID, const SkIRect& imageRect, } // if the entire image/bitmap is already in our cache then no reason to tile it - if (GrIsImageInCache(fContext, imageID, imageRect, nullptr, ¶ms)) { + if (GrIsImageInCache(fContext, imageID, imageRect, nullptr, params)) { return false; } @@ -983,7 +983,7 @@ static void draw_aa_bitmap(GrDrawContext* drawContext, GrContext* context, // Setup texture to wrap bitmap GrTextureParams params(tm, textureFilterMode); - SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr, ¶ms)); + SkAutoTUnref<GrTexture> texture(GrRefCachedBitmapTexture(context, *bitmapPtr, params)); if (!texture) { SkErrorInternals::SetError(kInternalError_SkError, @@ -1288,7 +1288,7 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap, bitmap.height() <= fContext->caps()->maxTextureSize()); GrTexture* texture; - AutoBitmapTexture abt(fContext, bitmap, ¶ms, &texture); + AutoBitmapTexture abt(fContext, bitmap, params, &texture); if (nullptr == texture) { return; } @@ -1419,8 +1419,8 @@ void SkGpuDevice::drawSprite(const SkDraw& draw, const SkBitmap& bitmap, int h = bitmap.height(); GrTexture* texture; - // draw sprite uses the default texture params - AutoBitmapTexture abt(fContext, bitmap, nullptr, &texture); + // draw sprite neither filters nor tiles. + AutoBitmapTexture abt(fContext, bitmap, GrTextureParams::ClampNoFilter(), &texture); if (!texture) { return; } @@ -1621,7 +1621,7 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, GrTexture* texture; // We assume here that the filter will not attempt to tile the src. Otherwise, this cache lookup // must be pushed upstack. - AutoBitmapTexture abt(fContext, src, nullptr, &texture); + AutoBitmapTexture abt(fContext, src, GrTextureParams::ClampNoFilter(), &texture); if (!texture) { return false; } @@ -1631,7 +1631,8 @@ bool SkGpuDevice::filterImage(const SkImageFilter* filter, const SkBitmap& src, } static bool wrap_as_bm(GrContext* ctx, const SkImage* image, SkBitmap* bm) { - SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, kUntiled_SkImageUsageType)); + // TODO: It is wrong to assume these texture params here. + SkAutoTUnref<GrTexture> tex(as_IB(image)->asTextureRef(ctx, GrTextureParams::ClampNoFilter())); if (tex) { GrWrapTextureInBitmap(tex, image->width(), image->height(), image->isOpaque(), bm); return true; diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 8f9555ad52..ce4af0bfca 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -38,33 +38,6 @@ # 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]. @@ -124,35 +97,31 @@ static void build_index8_data(void* buffer, const SkBitmap& bitmap) { //////////////////////////////////////////////////////////////////////////////// -static void get_stretch(const GrContext* ctx, int width, int height, - const GrTextureParams* params, SkGrStretch* stretch) { +static void get_stretch(const GrCaps& caps, int width, int height, + const GrTextureParams& params, SkGrStretch* stretch) { stretch->fType = SkGrStretch::kNone_Type; bool doStretch = false; - if (params && params->isTiled() && !ctx->caps()->npotTextureTileSupport() && + if (params.isTiled() && !caps.npotTextureTileSupport() && (!SkIsPow2(width) || !SkIsPow2(height))) { doStretch = true; - stretch->fWidth = GrNextPow2(SkTMax(width, ctx->caps()->minTextureSize())); - stretch->fHeight = GrNextPow2(SkTMax(height, ctx->caps()->minTextureSize())); - } else if (width < ctx->caps()->minTextureSize() || height < ctx->caps()->minTextureSize()) { + stretch->fWidth = GrNextPow2(SkTMax(width, caps.minTextureSize())); + stretch->fHeight = GrNextPow2(SkTMax(height, caps.minTextureSize())); + } else if (width < caps.minTextureSize() || height < caps.minTextureSize()) { // The small texture issues appear to be with tiling. Hence it seems ok to scale them // up using the GPU. If issues persist we may need to CPU-stretch. doStretch = true; - stretch->fWidth = SkTMax(width, ctx->caps()->minTextureSize()); - stretch->fHeight = SkTMax(height, ctx->caps()->minTextureSize()); + stretch->fWidth = SkTMax(width, caps.minTextureSize()); + stretch->fHeight = SkTMax(height, caps.minTextureSize()); } if (doStretch) { - if (params) { - switch(params->filterMode()) { - case GrTextureParams::kNone_FilterMode: - stretch->fType = SkGrStretch::kNearest_Type; - break; - case GrTextureParams::kBilerp_FilterMode: - case GrTextureParams::kMipMap_FilterMode: - stretch->fType = SkGrStretch::kBilerp_Type; - break; - } - } else { - stretch->fType = SkGrStretch::kBilerp_Type; + switch(params.filterMode()) { + case GrTextureParams::kNone_FilterMode: + stretch->fType = SkGrStretch::kNearest_Type; + break; + case GrTextureParams::kBilerp_FilterMode: + case GrTextureParams::kMipMap_FilterMode: + stretch->fType = SkGrStretch::kBilerp_Type; + break; } } else { stretch->fWidth = -1; @@ -190,26 +159,16 @@ static void make_unstretched_key(GrUniqueKey* key, uint32_t imageID, const SkIRe } void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& subset, - const GrCaps& caps, SkImageUsageType usage) { - const SkGrStretch::Type stretches[] = { - SkGrStretch::kNone_Type, // kUntiled_SkImageUsageType - SkGrStretch::kNearest_Type, // kTiled_Unfiltered_SkImageUsageType - SkGrStretch::kBilerp_Type, // kTiled_Filtered_SkImageUsageType - }; - - if (!GrTextureUsageSupported(caps, subset.width(), subset.height(), usage)) { + const GrCaps& caps, const GrTextureParams& params) { + SkGrStretch stretch; + get_stretch(caps, subset.width(), subset.height(), params, &stretch); + if (SkGrStretch::kNone_Type != stretch.fType) { GrUniqueKey tmpKey; make_unstretched_key(&tmpKey, imageID, subset); - - SkGrStretch stretch; - stretch.fType = stretches[usage]; - stretch.fWidth = SkNextPow2(subset.width()); - stretch.fHeight = SkNextPow2(subset.height()); if (!GrMakeStretchedKey(tmpKey, stretch, key)) { - goto UNSTRETCHED; + *key = tmpKey; } } else { - UNSTRETCHED: make_unstretched_key(key, imageID, subset); } } @@ -519,9 +478,9 @@ static SkBitmap stretch_on_cpu(const SkBitmap& bmp, const SkGrStretch& stretch) } bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& subset, - GrTexture* nativeTexture, const GrTextureParams* params) { + GrTexture* nativeTexture, const GrTextureParams& params) { SkGrStretch stretch; - get_stretch(ctx, subset.width(), subset.height(), params, &stretch); + get_stretch(*ctx->caps(), subset.width(), subset.height(), params, &stretch); // Handle the case where the bitmap/image is explicitly texture backed. if (nativeTexture) { @@ -593,19 +552,10 @@ private: }; GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, const SkBitmap& bitmap, - const GrTextureParams* params) { + const GrTextureParams& params) { return Bitmap_GrTextureMaker(bitmap).refCachedTexture(ctx, params); } -// TODO: make this be the canonical signature, and turn the version that takes GrTextureParams* -// into a wrapper that contains the inverse of these tables. -GrTexture* GrRefCachedBitmapTexture(GrContext* ctx, - const SkBitmap& bitmap, - SkImageUsageType usage) { - GrTextureParams params = GrImageUsageToTextureParams(usage); - return GrRefCachedBitmapTexture(ctx, bitmap, ¶ms); -} - /////////////////////////////////////////////////////////////////////////////// // alphatype is ignore for now, but if GrPixelConfig is expanded to encompass @@ -928,14 +878,9 @@ 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) { +GrTexture* GrTextureMaker::refCachedTexture(GrContext* ctx, const GrTextureParams& params) { SkGrStretch stretch; - get_stretch(ctx, this->width(), this->height(), params, &stretch); + get_stretch(*ctx->caps(), this->width(), this->height(), params, &stretch); if (SkGrStretch::kNone_Type == stretch.fType) { return this->onRefUnstretchedTexture(ctx); diff --git a/src/gpu/SkGrPriv.h b/src/gpu/SkGrPriv.h index 88bee5cc33..6c9f731af2 100644 --- a/src/gpu/SkGrPriv.h +++ b/src/gpu/SkGrPriv.h @@ -10,8 +10,8 @@ #include "GrTypes.h" #include "GrBlend.h" -#include "GrTextureAccess.h" #include "SkImageInfo.h" +#include "SkMatrix.h" #include "SkXfermode.h" class GrCaps; @@ -19,9 +19,11 @@ class GrContext; class GrFragmentProcessor; class GrPaint; class GrTexture; +class GrTextureParams; class GrUniqueKey; +class SkData; class SkPaint; -class SkMatrix; +class SkPixelRef; struct SkIRect; struct SkGrStretch { @@ -34,8 +36,6 @@ struct SkGrStretch { int fHeight; }; -GrTextureParams GrImageUsageToTextureParams(SkImageUsageType); - /** * Our key includes the offset, width, and height so that bitmaps created by extractSubset() * are unique. @@ -48,7 +48,7 @@ GrTextureParams GrImageUsageToTextureParams(SkImageUsageType); * Note: width/height must fit in 16bits for this impl. */ void GrMakeKeyFromImageID(GrUniqueKey* key, uint32_t imageID, const SkIRect& imageBounds, - const GrCaps&, SkImageUsageType); + const GrCaps&, const GrTextureParams&); /** * Given an "unstretched" key, and a stretch rec, produce a stretched key. @@ -98,8 +98,6 @@ inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, const SkPaint ////////////////////////////////////////////////////////////////////////////// -bool GrTextureUsageSupported(const GrCaps&, int width, int height, SkImageUsageType); - GrSurfaceDesc GrImageInfoToSurfaceDesc(const SkImageInfo&); bool GrPixelConfig2ColorAndProfileType(GrPixelConfig, SkColorType*, SkColorProfileType*); @@ -117,7 +115,7 @@ GrPixelConfig GrIsCompressedTextureDataSupported(GrContext* ctx, SkData* data, const void** outStartOfDataToUpload); bool GrIsImageInCache(const GrContext* ctx, uint32_t imageID, const SkIRect& subset, - GrTexture* nativeTexture, const GrTextureParams*); + GrTexture* nativeTexture, const GrTextureParams&); GrTexture* GrCreateTextureForPixels(GrContext*, const GrUniqueKey& optionalKey, GrSurfaceDesc, SkPixelRef* pixelRefForInvalidationNotificationOrNull, diff --git a/src/image/SkImageShader.cpp b/src/image/SkImageShader.cpp index cf613e8735..56af17994c 100644 --- a/src/image/SkImageShader.cpp +++ b/src/image/SkImageShader.cpp @@ -113,17 +113,7 @@ const GrFragmentProcessor* SkImageShader::asFragmentProcessor(GrContext* context GrTextureParams::FilterMode textureFilterMode = GrSkFilterQualityToGrFilterMode(filterQuality, viewM, this->getLocalMatrix(), &doBicubic); GrTextureParams params(tm, textureFilterMode); - - SkImageUsageType usageType; - if (kClamp_TileMode == fTileModeX && kClamp_TileMode == fTileModeY) { - usageType = kUntiled_SkImageUsageType; - } else if (GrTextureParams::kNone_FilterMode == textureFilterMode) { - usageType = kTiled_Unfiltered_SkImageUsageType; - } else { - usageType = kTiled_Filtered_SkImageUsageType; - } - - SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, usageType)); + SkAutoTUnref<GrTexture> texture(as_IB(fImage)->asTextureRef(context, params)); if (!texture) { return nullptr; } diff --git a/src/image/SkImage_Base.h b/src/image/SkImage_Base.h index 20df0bca2e..7819e9c19d 100644 --- a/src/image/SkImage_Base.h +++ b/src/image/SkImage_Base.h @@ -14,6 +14,8 @@ #include <new> +class GrTextureParams; + enum { kNeedNewImageUniqueID = 0 }; @@ -36,7 +38,7 @@ public: virtual bool getROPixels(SkBitmap*) const = 0; // Caller must call unref when they are done. - virtual GrTexture* asTextureRef(GrContext*, SkImageUsageType) const = 0; + virtual GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const = 0; virtual SkImage* onNewSubset(const SkIRect&) const = 0; diff --git a/src/image/SkImage_Generator.cpp b/src/image/SkImage_Generator.cpp index 5ce552cb13..346528939a 100644 --- a/src/image/SkImage_Generator.cpp +++ b/src/image/SkImage_Generator.cpp @@ -27,7 +27,7 @@ public: bool isOpaque() const override { return fCache->info().isOpaque(); } SkImage* onNewSubset(const SkIRect&) const override; bool getROPixels(SkBitmap*) const override; - GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; + GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override; bool onIsLazyGenerated() const override { return true; } private: @@ -59,8 +59,8 @@ bool SkImage_Generator::getROPixels(SkBitmap* bitmap) const { return fCache->lockAsBitmap(bitmap, this); } -GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, SkImageUsageType usage) const { - return fCache->lockAsTexture(ctx, usage, this); +GrTexture* SkImage_Generator::asTextureRef(GrContext* ctx, const GrTextureParams& params) const { + return fCache->lockAsTexture(ctx, params, this); } SkImage* SkImage_Generator::onNewSubset(const SkIRect& subset) const { diff --git a/src/image/SkImage_Gpu.cpp b/src/image/SkImage_Gpu.cpp index 72b98cd589..ccb27eed83 100644 --- a/src/image/SkImage_Gpu.cpp +++ b/src/image/SkImage_Gpu.cpp @@ -109,8 +109,8 @@ private: typedef GrTextureMaker INHERITED; }; -GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, SkImageUsageType usage) const { - return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, usage); +GrTexture* SkImage_Gpu::asTextureRef(GrContext* ctx, const GrTextureParams& params) const { + return Texture_GrTextureMaker(this, fTexture).refCachedTexture(ctx, params); } bool SkImage_Gpu::isOpaque() const { diff --git a/src/image/SkImage_Gpu.h b/src/image/SkImage_Gpu.h index 8bfdfa7cd8..530c0445d3 100644 --- a/src/image/SkImage_Gpu.h +++ b/src/image/SkImage_Gpu.h @@ -36,7 +36,7 @@ public: } bool getROPixels(SkBitmap*) const override; - GrTexture* asTextureRef(GrContext* ctx, SkImageUsageType usage) const override; + GrTexture* asTextureRef(GrContext* ctx, const GrTextureParams& params) const override; SkImage* onNewSubset(const SkIRect&) const override; GrTexture* peekTexture() const override { return fTexture; } diff --git a/src/image/SkImage_Raster.cpp b/src/image/SkImage_Raster.cpp index b6c62e8423..b78818db6b 100644 --- a/src/image/SkImage_Raster.cpp +++ b/src/image/SkImage_Raster.cpp @@ -70,7 +70,7 @@ public: const void* onPeekPixels(SkImageInfo*, size_t* /*rowBytes*/) const override; SkData* onRefEncoded() const override; bool getROPixels(SkBitmap*) const override; - GrTexture* asTextureRef(GrContext*, SkImageUsageType) const override; + GrTexture* asTextureRef(GrContext*, const GrTextureParams&) const override; SkImage* onNewSubset(const SkIRect&) const override; // exposed for SkSurface_Raster via SkNewImageFromPixelRef @@ -167,7 +167,7 @@ bool SkImage_Raster::getROPixels(SkBitmap* dst) const { return true; } -GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, SkImageUsageType usage) const { +GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, const GrTextureParams& params) const { #if SK_SUPPORT_GPU if (!ctx) { return nullptr; @@ -182,12 +182,12 @@ GrTexture* SkImage_Raster::asTextureRef(GrContext* ctx, SkImageUsageType usage) GrUniqueKey key; GrMakeKeyFromImageID(&key, fBitmap.getGenerationID(), SkIRect::MakeWH(fBitmap.width(), fBitmap.height()), - *ctx->caps(), usage); + *ctx->caps(), params); if (GrTexture* tex = ctx->textureProvider()->findAndRefTextureByUniqueKey(key)) { return tex; } - return GrRefCachedBitmapTexture(ctx, fBitmap, usage); + return GrRefCachedBitmapTexture(ctx, fBitmap, params); #endif return nullptr; diff --git a/src/utils/SkImageGeneratorUtils.cpp b/src/utils/SkImageGeneratorUtils.cpp index 42a0fe518d..8202dbe133 100644 --- a/src/utils/SkImageGeneratorUtils.cpp +++ b/src/utils/SkImageGeneratorUtils.cpp @@ -56,7 +56,8 @@ public: {} protected: - GrTexture* onGenerateTexture(GrContext* ctx, SkImageUsageType, const SkIRect* subset) override { + GrTexture* onGenerateTexture(GrContext* ctx, const GrTextureParams&, + const SkIRect* subset) override { if (ctx) { SkASSERT(ctx == fCtx.get()); } @@ -112,7 +113,8 @@ protected: return fImage->readPixels(info, pixels, rowBytes, 0, 0); } - GrTexture* onGenerateTexture(GrContext* ctx, SkImageUsageType, const SkIRect* subset) override { + GrTexture* onGenerateTexture(GrContext* ctx, const GrTextureParams&, + const SkIRect* subset) override { // waiting on https://code.google.com/p/skia/issues/detail?id=4233 return nullptr; } |