bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #ifndef GrTextureParams_DEFINED |
| 9 | #define GrTextureParams_DEFINED |
| 10 | |
| 11 | #include "GrTypes.h" |
| 12 | #include "SkShader.h" |
| 13 | |
| 14 | /** |
| 15 | * Represents the filtering and tile modes used to access a texture. |
| 16 | */ |
| 17 | class GrTextureParams { |
| 18 | public: |
| 19 | static const GrTextureParams& ClampNoFilter() { |
| 20 | static const GrTextureParams gParams; |
| 21 | return gParams; |
| 22 | } |
| 23 | static const GrTextureParams& ClampBilerp() { |
| 24 | static const GrTextureParams gParams(SkShader::kClamp_TileMode, kBilerp_FilterMode); |
| 25 | return gParams; |
| 26 | } |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 27 | static const GrTextureParams& ClampNoFilterForceAllowSRGB() { |
| 28 | static const GrTextureParams gParams(SkShader::kClamp_TileMode, kNone_FilterMode, |
| 29 | kForceAllowSRGB_SRGBMode); |
| 30 | return gParams; |
| 31 | } |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 32 | |
| 33 | GrTextureParams() { |
| 34 | this->reset(); |
| 35 | } |
| 36 | |
| 37 | enum FilterMode { |
| 38 | kNone_FilterMode, |
| 39 | kBilerp_FilterMode, |
| 40 | kMipMap_FilterMode |
| 41 | }; |
| 42 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 43 | enum SRGBMode { |
| 44 | kRespectDestination_SRGBMode, |
| 45 | kForceAllowSRGB_SRGBMode, |
| 46 | }; |
| 47 | |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 48 | GrTextureParams(SkShader::TileMode tileXAndY, FilterMode filterMode) { |
| 49 | this->reset(tileXAndY, filterMode); |
| 50 | } |
| 51 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 52 | GrTextureParams(SkShader::TileMode tileXandY, FilterMode filterMode, SRGBMode srgbMode) { |
| 53 | this->reset(tileXandY, filterMode, srgbMode); |
| 54 | } |
| 55 | |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 56 | GrTextureParams(const SkShader::TileMode tileModes[2], FilterMode filterMode) { |
| 57 | this->reset(tileModes, filterMode); |
| 58 | } |
| 59 | |
| 60 | GrTextureParams(const GrTextureParams& params) { |
| 61 | *this = params; |
| 62 | } |
| 63 | |
| 64 | GrTextureParams& operator= (const GrTextureParams& params) { |
| 65 | fTileModes[0] = params.fTileModes[0]; |
| 66 | fTileModes[1] = params.fTileModes[1]; |
| 67 | fFilterMode = params.fFilterMode; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 68 | fSRGBMode = params.fSRGBMode; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 69 | return *this; |
| 70 | } |
| 71 | |
| 72 | void reset() { |
| 73 | this->reset(SkShader::kClamp_TileMode, kNone_FilterMode); |
| 74 | } |
| 75 | |
| 76 | void reset(SkShader::TileMode tileXAndY, FilterMode filterMode) { |
| 77 | fTileModes[0] = fTileModes[1] = tileXAndY; |
| 78 | fFilterMode = filterMode; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 79 | fSRGBMode = kRespectDestination_SRGBMode; |
| 80 | } |
| 81 | |
| 82 | void reset(SkShader::TileMode tileXandY, FilterMode filterMode, SRGBMode srgbMode) { |
| 83 | fTileModes[0] = fTileModes[1] = tileXandY; |
| 84 | fFilterMode = filterMode; |
| 85 | fSRGBMode = srgbMode; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void reset(const SkShader::TileMode tileModes[2], FilterMode filterMode) { |
| 89 | fTileModes[0] = tileModes[0]; |
| 90 | fTileModes[1] = tileModes[1]; |
| 91 | fFilterMode = filterMode; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 92 | fSRGBMode = kRespectDestination_SRGBMode; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | void setClampNoFilter() { |
| 96 | fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; |
| 97 | fFilterMode = kNone_FilterMode; |
| 98 | } |
| 99 | |
| 100 | void setClamp() { |
| 101 | fTileModes[0] = fTileModes[1] = SkShader::kClamp_TileMode; |
| 102 | } |
| 103 | |
| 104 | void setFilterMode(FilterMode filterMode) { fFilterMode = filterMode; } |
| 105 | |
| 106 | void setTileModeX(const SkShader::TileMode tm) { fTileModes[0] = tm; } |
| 107 | void setTileModeY(const SkShader::TileMode tm) { fTileModes[1] = tm; } |
| 108 | void setTileModeXAndY(const SkShader::TileMode tm) { fTileModes[0] = fTileModes[1] = tm; } |
| 109 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 110 | void setSRGBMode(SRGBMode srgbMode) { fSRGBMode = srgbMode; } |
| 111 | |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 112 | SkShader::TileMode getTileModeX() const { return fTileModes[0]; } |
| 113 | |
| 114 | SkShader::TileMode getTileModeY() const { return fTileModes[1]; } |
| 115 | |
| 116 | bool isTiled() const { |
| 117 | return SkShader::kClamp_TileMode != fTileModes[0] || |
| 118 | SkShader::kClamp_TileMode != fTileModes[1]; |
| 119 | } |
| 120 | |
| 121 | FilterMode filterMode() const { return fFilterMode; } |
| 122 | |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 123 | SRGBMode srgbMode() const { return fSRGBMode; } |
| 124 | |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 125 | bool operator== (const GrTextureParams& other) const { |
| 126 | return fTileModes[0] == other.fTileModes[0] && |
| 127 | fTileModes[1] == other.fTileModes[1] && |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 128 | fFilterMode == other.fFilterMode && |
| 129 | fSRGBMode == other.fSRGBMode; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | bool operator!= (const GrTextureParams& other) const { return !(*this == other); } |
| 133 | |
| 134 | private: |
| 135 | SkShader::TileMode fTileModes[2]; |
| 136 | FilterMode fFilterMode; |
brianosman | a635936 | 2016-03-21 06:55:37 -0700 | [diff] [blame] | 137 | SRGBMode fSRGBMode; |
bsalomon | afa95e2 | 2015-10-12 10:39:46 -0700 | [diff] [blame] | 138 | }; |
| 139 | #endif |