From afa95e270c64c9777647b6c58b796750ced57c39 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Mon, 12 Oct 2015 10:39:46 -0700 Subject: Remove image usage type enum. Use GrTextureParams instead. BUG=skia: Review URL: https://codereview.chromium.org/1404433002 --- include/core/SkImageGenerator.h | 11 ++-- include/core/SkImageInfo.h | 18 +------ include/gpu/GrTextureAccess.h | 93 +-------------------------------- include/gpu/GrTextureParams.h | 110 ++++++++++++++++++++++++++++++++++++++++ include/gpu/SkGr.h | 5 +- 5 files changed, 120 insertions(+), 117 deletions(-) create mode 100644 include/gpu/GrTextureParams.h (limited to 'include') diff --git a/include/core/SkImageGenerator.h b/include/core/SkImageGenerator.h index 0e2a45e145..e04e05ea0b 100644 --- a/include/core/SkImageGenerator.h +++ b/include/core/SkImageGenerator.h @@ -13,9 +13,10 @@ #include "SkImageInfo.h" class GrContext; +class GrTexture; +class GrTextureParams; class SkBitmap; class SkData; -class GrTexture; class SkImageGenerator; class SkMatrix; class SkPaint; @@ -142,14 +143,14 @@ public: * - its internal context is the same * - it can somehow convert its texture into one that is valid for the provided context. * - * Regarding the SkImageUsageType parameter: + * Regarding the GrTextureParams parameter: * * If the context (the provided one or the generator's intrinsic one) determines that to * support the specified usage, it must return a different sized texture it may, * so the caller must inspect the texture's width/height and compare them to the generator's - * getInfo() width/height. + * getInfo() width/height. For readback usage use GrTextureParams::ClampNoFilter() */ - GrTexture* generateTexture(GrContext*, SkImageUsageType, const SkIRect* subset = nullptr); + GrTexture* generateTexture(GrContext*, const GrTextureParams&, const SkIRect* subset = nullptr); /** * If the default image decoder system can interpret the specified (encoded) data, then @@ -194,7 +195,7 @@ protected: virtual bool onGetYUV8Planes(SkISize sizes[3], void* planes[3], size_t rowBytes[3], SkYUVColorSpace* colorSpace); - virtual GrTexture* onGenerateTexture(GrContext*, SkImageUsageType, const SkIRect*) { + virtual GrTexture* onGenerateTexture(GrContext*, const GrTextureParams&, const SkIRect*) { return nullptr; } diff --git a/include/core/SkImageInfo.h b/include/core/SkImageInfo.h index 0218a74310..4b82ae6e2f 100644 --- a/include/core/SkImageInfo.h +++ b/include/core/SkImageInfo.h @@ -16,23 +16,7 @@ class SkReadBuffer; class SkWriteBuffer; /** - * This enum provides information about "how" an image will be used. For older GPUs that do not - * support non-power-of-2 tiling, some routines need to know this information before they create - * a texture. - */ -enum SkImageUsageType { - /* Image will not be tiled (regardless of filtering) */ - kUntiled_SkImageUsageType, - - /* Image will be tiled, but not filtered */ - kTiled_Unfiltered_SkImageUsageType, - - /* Image will be tiled and filtered */ - kTiled_Filtered_SkImageUsageType, -}; - -/** - * Describes how to interpret the alpha compoent of a pixel. + * Describes how to interpret the alpha component of a pixel. */ enum SkAlphaType { kUnknown_SkAlphaType, diff --git a/include/gpu/GrTextureAccess.h b/include/gpu/GrTextureAccess.h index df0bdfda0f..e3ded34ff8 100644 --- a/include/gpu/GrTextureAccess.h +++ b/include/gpu/GrTextureAccess.h @@ -10,101 +10,10 @@ #include "GrGpuResourceRef.h" #include "GrTexture.h" +#include "GrTextureParams.h" #include "SkRefCnt.h" #include "SkShader.h" -/** - * Represents the filtering and tile modes used to access a texture. It is mostly used with - * GrTextureAccess (defined below). Also, some of the texture cache methods require knowledge about - * filtering and tiling to perform a cache lookup. If it wasn't for this latter usage this would - * be folded into GrTextureAccess. The default is clamp tile modes and no filtering. - */ -class GrTextureParams { -public: - GrTextureParams() { - this->reset(); - } - - enum FilterMode { - kNone_FilterMode, - kBilerp_FilterMode, - kMipMap_FilterMode - }; - - GrTextureParams(SkShader::TileMode tileXAndY, FilterMode filterMode) { - this->reset(tileXAndY, filterMode); - } - - GrTextureParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) { - this->reset(tileModes, filterMode); - } - - GrTextureParams(const GrTextureParams& params) { - *this = params; - } - - GrTextureParams& operator= (const GrTextureParams& params) { - fTileModes[0] = params.fTileModes[0]; - fTileModes[1] = params.fTileModes[1]; - fFilterMode = params.fFilterMode; - return *this; - } - - void reset() { - this->reset(SkShader::kClamp_TileMode, kNone_FilterMode); - } - - void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) { - fTileModes[0] = fTileModes[1] = tileXAndY; - fFilterMode = filterMode; - } - - void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) { - fTileModes[0] = tileModes[0]; - fTileModes[1] = tileModes[1]; - fFilterMode = filterMode; - } - - void setClampNoFilter() { - fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; - fFilterMode = kNone_FilterMode; - } - - void setClamp() { - fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; - } - - void setFilterMode(FilterMode filterMode) { fFilterMode = filterMode; } - - void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; } - void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; } - void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; } - - SkShader::TileMode getTileModeX() const { return fTileModes[0]; } - - SkShader::TileMode getTileModeY() const { return fTileModes[1]; } - - bool isTiled() const { - return SkShader::kClamp_TileMode != fTileModes[0] || - SkShader::kClamp_TileMode != fTileModes[1]; - } - - FilterMode filterMode() const { return fFilterMode; } - - bool operator== (const GrTextureParams& other) const { - return fTileModes[0] == other.fTileModes[0] && - fTileModes[1] == other.fTileModes[1] && - fFilterMode == other.fFilterMode; - } - - bool operator!= (const GrTextureParams& other) const { return !(*this == other); } - -private: - - SkShader::TileMode fTileModes[2]; - FilterMode fFilterMode; -}; - /** A class representing the swizzle access pattern for a texture. Note that if the texture is * an alpha-only texture then the alpha channel is substituted for other components. Any mangling * to handle the r,g,b->a conversions for alpha textures is automatically included in the stage diff --git a/include/gpu/GrTextureParams.h b/include/gpu/GrTextureParams.h new file mode 100644 index 0000000000..3186b1b027 --- /dev/null +++ b/include/gpu/GrTextureParams.h @@ -0,0 +1,110 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrTextureParams_DEFINED +#define GrTextureParams_DEFINED + +#include "GrTypes.h" +#include "SkShader.h" + +/** + * Represents the filtering and tile modes used to access a texture. + */ +class GrTextureParams { +public: + static const GrTextureParams& ClampNoFilter() { + static const GrTextureParams gParams; + return gParams; + } + static const GrTextureParams& ClampBilerp() { + static const GrTextureParams gParams(SkShader::kClamp_TileMode, kBilerp_FilterMode); + return gParams; + } + + GrTextureParams() { + this->reset(); + } + + enum FilterMode { + kNone_FilterMode, + kBilerp_FilterMode, + kMipMap_FilterMode + }; + + GrTextureParams(SkShader::TileMode tileXAndY, FilterMode filterMode) { + this->reset(tileXAndY, filterMode); + } + + GrTextureParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) { + this->reset(tileModes, filterMode); + } + + GrTextureParams(const GrTextureParams& params) { + *this = params; + } + + GrTextureParams& operator= (const GrTextureParams& params) { + fTileModes[0] = params.fTileModes[0]; + fTileModes[1] = params.fTileModes[1]; + fFilterMode = params.fFilterMode; + return *this; + } + + void reset() { + this->reset(SkShader::kClamp_TileMode, kNone_FilterMode); + } + + void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) { + fTileModes[0] = fTileModes[1] = tileXAndY; + fFilterMode = filterMode; + } + + void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) { + fTileModes[0] = tileModes[0]; + fTileModes[1] = tileModes[1]; + fFilterMode = filterMode; + } + + void setClampNoFilter() { + fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; + fFilterMode = kNone_FilterMode; + } + + void setClamp() { + fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; + } + + void setFilterMode(FilterMode filterMode) { fFilterMode = filterMode; } + + void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; } + void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; } + void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; } + + SkShader::TileMode getTileModeX() const { return fTileModes[0]; } + + SkShader::TileMode getTileModeY() const { return fTileModes[1]; } + + bool isTiled() const { + return SkShader::kClamp_TileMode != fTileModes[0] || + SkShader::kClamp_TileMode != fTileModes[1]; + } + + FilterMode filterMode() const { return fFilterMode; } + + bool operator== (const GrTextureParams& other) const { + return fTileModes[0] == other.fTileModes[0] && + fTileModes[1] == other.fTileModes[1] && + fFilterMode == other.fFilterMode; + } + + bool operator!= (const GrTextureParams& other) const { return !(*this == other); } + +private: + SkShader::TileMode fTileModes[2]; + FilterMode fFilterMode; +}; +#endif diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h index 8ea3af12c7..591d3d88a4 100644 --- a/include/gpu/SkGr.h +++ b/include/gpu/SkGr.h @@ -66,9 +66,8 @@ static inline GrColor SkPMColorToGrColor(SkPMColor c) { //////////////////////////////////////////////////////////////////////////////// -GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams*); -GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, SkImageUsageType); - +GrTexture* GrRefCachedBitmapTexture(GrContext*, const SkBitmap&, const GrTextureParams&); + // TODO: Move SkImageInfo2GrPixelConfig to SkGrPriv.h (requires cleanup to SkWindow its subclasses). GrPixelConfig SkImageInfo2GrPixelConfig(SkColorType, SkAlphaType, SkColorProfileType); -- cgit v1.2.3