| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "GrTextureDomainEffect.h" | 8 #include "GrTextureDomainEffect.h" |
| 9 #include "GrSimpleTextureEffect.h" | 9 #include "GrSimpleTextureEffect.h" |
| 10 #include "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 return key | matrixKey; | 146 return key | matrixKey; |
| 147 } | 147 } |
| 148 | 148 |
| 149 | 149 |
| 150 /////////////////////////////////////////////////////////////////////////////// | 150 /////////////////////////////////////////////////////////////////////////////// |
| 151 | 151 |
| 152 GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, | 152 GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, |
| 153 const SkMatrix& matrix, | 153 const SkMatrix& matrix, |
| 154 const SkRect& domain, | 154 const SkRect& domain, |
| 155 WrapMode wrapMode, | 155 WrapMode wrapMode, |
| 156 bool bilerp, | 156 GrTextureParams::FilterMode filterMod
e, |
| 157 CoordsType coordsType) { | 157 CoordsType coordsType) { |
| 158 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; | 158 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| 159 if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { | 159 if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { |
| 160 return GrSimpleTextureEffect::Create(texture, matrix, bilerp); | 160 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); |
| 161 } else { | 161 } else { |
| 162 SkRect clippedDomain; | 162 SkRect clippedDomain; |
| 163 // We don't currently handle domains that are empty or don't intersect t
he texture. | 163 // We don't currently handle domains that are empty or don't intersect t
he texture. |
| 164 // It is OK if the domain rect is a line or point, but it should not be
inverted. We do not | 164 // It is OK if the domain rect is a line or point, but it should not be
inverted. We do not |
| 165 // handle rects that do not intersect the [0..1]x[0..1] rect. | 165 // handle rects that do not intersect the [0..1]x[0..1] rect. |
| 166 GrAssert(domain.fLeft <= domain.fRight); | 166 GrAssert(domain.fLeft <= domain.fRight); |
| 167 GrAssert(domain.fTop <= domain.fBottom); | 167 GrAssert(domain.fTop <= domain.fBottom); |
| 168 clippedDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); | 168 clippedDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); |
| 169 clippedDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); | 169 clippedDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); |
| 170 clippedDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); | 170 clippedDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); |
| 171 clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); | 171 clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); |
| 172 GrAssert(clippedDomain.fLeft <= clippedDomain.fRight); | 172 GrAssert(clippedDomain.fLeft <= clippedDomain.fRight); |
| 173 GrAssert(clippedDomain.fTop <= clippedDomain.fBottom); | 173 GrAssert(clippedDomain.fTop <= clippedDomain.fBottom); |
| 174 | 174 |
| 175 AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, | 175 AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, |
| 176 matrix, | 176 matrix, |
| 177 clippedDomain, | 177 clippedDomain, |
| 178 wrapMode, | 178 wrapMode, |
| 179 bilerp, | 179 filterMode, |
| 180 coordsType))); | 180 coordsType))); |
| 181 return CreateEffectRef(effect); | 181 return CreateEffectRef(effect); |
| 182 | 182 |
| 183 } | 183 } |
| 184 } | 184 } |
| 185 | 185 |
| 186 GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, | 186 GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, |
| 187 const SkMatrix& matrix, | 187 const SkMatrix& matrix, |
| 188 const SkRect& domain, | 188 const SkRect& domain, |
| 189 WrapMode wrapMode, | 189 WrapMode wrapMode, |
| 190 bool bilerp, | 190 GrTextureParams::FilterMode filterM
ode, |
| 191 CoordsType coordsType) | 191 CoordsType coordsType) |
| 192 : GrSingleTextureEffect(texture, matrix, bilerp, coordsType) | 192 : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) |
| 193 , fWrapMode(wrapMode) | 193 , fWrapMode(wrapMode) |
| 194 , fTextureDomain(domain) { | 194 , fTextureDomain(domain) { |
| 195 } | 195 } |
| 196 | 196 |
| 197 GrTextureDomainEffect::~GrTextureDomainEffect() { | 197 GrTextureDomainEffect::~GrTextureDomainEffect() { |
| 198 | 198 |
| 199 } | 199 } |
| 200 | 200 |
| 201 const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { | 201 const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { |
| 202 return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); | 202 return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 232 domain.fTop = random->nextUScalar1(); | 232 domain.fTop = random->nextUScalar1(); |
| 233 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); | 233 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); |
| 234 WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; | 234 WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; |
| 235 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); | 235 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
| 236 bool bilerp = random->nextBool(); | 236 bool bilerp = random->nextBool(); |
| 237 CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_Coord
sType; | 237 CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_Coord
sType; |
| 238 return GrTextureDomainEffect::Create(textures[texIdx], | 238 return GrTextureDomainEffect::Create(textures[texIdx], |
| 239 matrix, | 239 matrix, |
| 240 domain, | 240 domain, |
| 241 wrapMode, | 241 wrapMode, |
| 242 bilerp, | 242 bilerp ? GrTextureParams::kBilerp_Filte
rMode : GrTextureParams::kNone_FilterMode, |
| 243 coords); | 243 coords); |
| 244 } | 244 } |
| OLD | NEW |