| 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 "GrTextureDomain.h" |
| 9 #include "GrSimpleTextureEffect.h" | 9 #include "GrSimpleTextureEffect.h" |
| 10 #include "GrTBackendEffectFactory.h" | 10 #include "GrTBackendEffectFactory.h" |
| 11 #include "gl/GrGLEffect.h" | 11 #include "gl/GrGLEffect.h" |
| 12 #include "SkFloatingPoint.h" | 12 #include "SkFloatingPoint.h" |
| 13 | 13 |
| 14 |
| 15 GrTextureDomain::GrTextureDomain(const SkRect& domain, Mode mode, int index) |
| 16 : fIndex(index) { |
| 17 |
| 18 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| 19 if (domain.contains(kFullRect)) { |
| 20 fMode = kIgnore_Mode; |
| 21 } else { |
| 22 fMode = mode; |
| 23 } |
| 24 |
| 25 if (fMode != kIgnore_Mode) { |
| 26 // We don't currently handle domains that are empty or don't intersect t
he texture. |
| 27 // It is OK if the domain rect is a line or point, but it should not be
inverted. We do not |
| 28 // handle rects that do not intersect the [0..1]x[0..1] rect. |
| 29 SkASSERT(domain.fLeft <= domain.fRight); |
| 30 SkASSERT(domain.fTop <= domain.fBottom); |
| 31 fDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); |
| 32 fDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); |
| 33 fDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); |
| 34 fDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); |
| 35 SkASSERT(fDomain.fLeft <= fDomain.fRight); |
| 36 SkASSERT(fDomain.fTop <= fDomain.fBottom); |
| 37 } |
| 38 } |
| 39 |
| 40 ////////////////////////////////////////////////////////////////////////////// |
| 41 |
| 42 void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder, |
| 43 const GrTextureDomain& textureDoma
in, |
| 44 const char* outColor, |
| 45 const SkString& inCoords, |
| 46 const GrGLEffect::TextureSampler s
ampler, |
| 47 const char* inModulateColor) { |
| 48 SkASSERT(-1 == fMode || textureDomain.mode() == fMode); |
| 49 SkDEBUGCODE(fMode = textureDomain.mode();) |
| 50 |
| 51 if (kIgnore_Mode == textureDomain.mode()) { |
| 52 builder->fsCodeAppendf("\t%s = ", outColor); |
| 53 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, |
| 54 inCoords.c_str()); |
| 55 builder->fsCodeAppend(";\n"); |
| 56 return; |
| 57 } |
| 58 |
| 59 if (!fDomainUni.isValid()) { |
| 60 const char* name; |
| 61 SkString uniName("TexDom"); |
| 62 if (textureDomain.fIndex >= 0) { |
| 63 uniName.appendS32(textureDomain.fIndex); |
| 64 } |
| 65 fDomainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility
, |
| 66 kVec4f_GrSLType, uniName.c_str(), &n
ame); |
| 67 fDomainName = name; |
| 68 } |
| 69 if (kClamp_Mode == textureDomain.mode()) { |
| 70 SkString clampedCoords; |
| 71 clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", |
| 72 inCoords.c_str(), fDomainName.c_str(), fDomainNa
me.c_str()); |
| 73 |
| 74 builder->fsCodeAppendf("\t%s = ", outColor); |
| 75 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler, clam
pedCoords.c_str()); |
| 76 builder->fsCodeAppend(";\n"); |
| 77 } else { |
| 78 SkASSERT(GrTextureDomain::kDecal_Mode == textureDomain.mode()); |
| 79 // Add a block since we're going to declare variables. |
| 80 GrGLShaderBuilder::FSBlock block(builder); |
| 81 |
| 82 const char* domain = fDomainName.c_str(); |
| 83 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
| 84 // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| 85 // call) causes the compilation error "Calls to any function that |
| 86 // may require a gradient calculation inside a conditional block |
| 87 // may return undefined results". This appears to be an issue with |
| 88 // the 'any' call since even the simple "result=black; if (any()) |
| 89 // result=white;" code fails to compile. |
| 90 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"
); |
| 91 builder->fsCodeAppend("\tvec4 inside = "); |
| 92 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
inCoords.c_str()); |
| 93 builder->fsCodeAppend(";\n"); |
| 94 |
| 95 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s
.x) - 1.0);\n", |
| 96 inCoords.c_str(), domain, domain, domain); |
| 97 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s
.y) - 1.0);\n", |
| 98 inCoords.c_str(), domain, domain, domain); |
| 99 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
| 100 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outC
olor); |
| 101 } else { |
| 102 builder->fsCodeAppend("\tbvec4 outside;\n"); |
| 103 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCo
ords.c_str(), |
| 104 domain); |
| 105 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", i
nCoords.c_str(), |
| 106 domain); |
| 107 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.
0) : ", outColor); |
| 108 builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
inCoords.c_str()); |
| 109 builder->fsCodeAppend(";\n"); |
| 110 } |
| 111 } |
| 112 } |
| 113 |
| 114 void GrTextureDomain::GLDomain::setData(const GrGLUniformManager& uman, |
| 115 const GrTextureDomain& textureDomain, |
| 116 GrSurfaceOrigin textureOrigin) { |
| 117 SkASSERT(textureDomain.mode() == fMode); |
| 118 if (kIgnore_Mode != textureDomain.mode()) { |
| 119 GrGLfloat values[4] = { |
| 120 SkScalarToFloat(textureDomain.domain().left()), |
| 121 SkScalarToFloat(textureDomain.domain().top()), |
| 122 SkScalarToFloat(textureDomain.domain().right()), |
| 123 SkScalarToFloat(textureDomain.domain().bottom()) |
| 124 }; |
| 125 // vertical flip if necessary |
| 126 if (kBottomLeft_GrSurfaceOrigin == textureOrigin) { |
| 127 values[1] = 1.0f - values[1]; |
| 128 values[3] = 1.0f - values[3]; |
| 129 // The top and bottom were just flipped, so correct the ordering |
| 130 // of elements so that values = (l, t, r, b). |
| 131 SkTSwap(values[1], values[3]); |
| 132 } |
| 133 if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { |
| 134 uman.set4fv(fDomainUni, 1, values); |
| 135 memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); |
| 136 } |
| 137 } |
| 138 } |
| 139 |
| 140 |
| 141 ////////////////////////////////////////////////////////////////////////////// |
| 142 |
| 14 class GrGLTextureDomainEffect : public GrGLEffect { | 143 class GrGLTextureDomainEffect : public GrGLEffect { |
| 15 public: | 144 public: |
| 16 GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 145 GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
| 17 | 146 |
| 18 virtual void emitCode(GrGLShaderBuilder*, | 147 virtual void emitCode(GrGLShaderBuilder*, |
| 19 const GrDrawEffect&, | 148 const GrDrawEffect&, |
| 20 EffectKey, | 149 EffectKey, |
| 21 const char* outputColor, | 150 const char* outputColor, |
| 22 const char* inputColor, | 151 const char* inputColor, |
| 23 const TransformedCoordsArray&, | 152 const TransformedCoordsArray&, |
| 24 const TextureSamplerArray&) SK_OVERRIDE; | 153 const TextureSamplerArray&) SK_OVERRIDE; |
| 25 | 154 |
| 26 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 155 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; |
| 27 | 156 |
| 28 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 157 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
| 29 | 158 |
| 30 private: | 159 private: |
| 31 GrGLUniformManager::UniformHandle fNameUni; | 160 GrTextureDomain::GLDomain fGLDomain; |
| 32 GrGLfloat fPrevDomain[4]; | |
| 33 | |
| 34 typedef GrGLEffect INHERITED; | 161 typedef GrGLEffect INHERITED; |
| 35 }; | 162 }; |
| 36 | 163 |
| 37 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& f
actory, | 164 GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& f
actory, |
| 38 const GrDrawEffect&) | 165 const GrDrawEffect&) |
| 39 : INHERITED(factory) { | 166 : INHERITED(factory) { |
| 40 fPrevDomain[0] = SK_FloatNaN; | |
| 41 } | 167 } |
| 42 | 168 |
| 43 void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, | 169 void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, |
| 44 const GrDrawEffect& drawEffect, | 170 const GrDrawEffect& drawEffect, |
| 45 EffectKey key, | 171 EffectKey key, |
| 46 const char* outputColor, | 172 const char* outputColor, |
| 47 const char* inputColor, | 173 const char* inputColor, |
| 48 const TransformedCoordsArray& coords, | 174 const TransformedCoordsArray& coords, |
| 49 const TextureSamplerArray& samplers) { | 175 const TextureSamplerArray& samplers) { |
| 50 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); | 176 const GrTextureDomainEffect& effect = drawEffect.castEffect<GrTextureDomainE
ffect>(); |
| 177 const GrTextureDomain& domain = effect.textureDomain(); |
| 51 | 178 |
| 52 SkString coords2D = builder->ensureFSCoords2D(coords, 0); | 179 SkString coords2D = builder->ensureFSCoords2D(coords, 0); |
| 53 const char* domain; | 180 fGLDomain.sampleTexture(builder, domain, outputColor, coords2D, samplers[0],
inputColor); |
| 54 fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, | |
| 55 kVec4f_GrSLType, "TexDom", &domain); | |
| 56 if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) { | |
| 57 | |
| 58 builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n", | |
| 59 coords2D.c_str(), domain, domain); | |
| 60 | |
| 61 builder->fsCodeAppendf("\t%s = ", outputColor); | |
| 62 builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "clam
pCoord"); | |
| 63 builder->fsCodeAppend(";\n"); | |
| 64 } else { | |
| 65 SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode()); | |
| 66 | |
| 67 if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { | |
| 68 // On the NexusS and GalaxyNexus, the other path (with the 'any' | |
| 69 // call) causes the compilation error "Calls to any function that | |
| 70 // may require a gradient calculation inside a conditional block | |
| 71 // may return undefined results". This appears to be an issue with | |
| 72 // the 'any' call since even the simple "result=black; if (any()) | |
| 73 // result=white;" code fails to compile. | |
| 74 builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"
); | |
| 75 builder->fsCodeAppend("\tvec4 inside = "); | |
| 76 builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], c
oords2D.c_str()); | |
| 77 builder->fsCodeAppend(";\n"); | |
| 78 | |
| 79 builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s
.x) - 1.0);\n", | |
| 80 coords2D.c_str(), domain, domain, domain); | |
| 81 builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s
.y) - 1.0);\n", | |
| 82 coords2D.c_str(), domain, domain, domain); | |
| 83 builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); | |
| 84 builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outp
utColor); | |
| 85 } else { | |
| 86 builder->fsCodeAppend("\tbvec4 outside;\n"); | |
| 87 builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coor
ds2D.c_str(), domain); | |
| 88 builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", c
oords2D.c_str(), domain); | |
| 89 builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.
0) : ", outputColor); | |
| 90 builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], c
oords2D.c_str()); | |
| 91 builder->fsCodeAppend(";\n"); | |
| 92 } | |
| 93 } | |
| 94 } | 181 } |
| 95 | 182 |
| 96 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, | 183 void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, |
| 97 const GrDrawEffect& drawEffect) { | 184 const GrDrawEffect& drawEffect) { |
| 98 const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainE
ffect>(); | 185 const GrTextureDomainEffect& effect = drawEffect.castEffect<GrTextureDomainE
ffect>(); |
| 99 const SkRect& domain = texDom.domain(); | 186 const GrTextureDomain& domain = effect.textureDomain(); |
| 100 | 187 fGLDomain.setData(uman, domain, effect.texture(0)->origin()); |
| 101 float values[4] = { | |
| 102 SkScalarToFloat(domain.left()), | |
| 103 SkScalarToFloat(domain.top()), | |
| 104 SkScalarToFloat(domain.right()), | |
| 105 SkScalarToFloat(domain.bottom()) | |
| 106 }; | |
| 107 // vertical flip if necessary | |
| 108 if (kBottomLeft_GrSurfaceOrigin == texDom.texture(0)->origin()) { | |
| 109 values[1] = 1.0f - values[1]; | |
| 110 values[3] = 1.0f - values[3]; | |
| 111 // The top and bottom were just flipped, so correct the ordering | |
| 112 // of elements so that values = (l, t, r, b). | |
| 113 SkTSwap(values[1], values[3]); | |
| 114 } | |
| 115 if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { | |
| 116 uman.set4fv(fNameUni, 1, values); | |
| 117 memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); | |
| 118 } | |
| 119 } | 188 } |
| 120 | 189 |
| 121 GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEf
fect, | 190 GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEf
fect, |
| 122 const GrGLCaps&) { | 191 const GrGLCaps&) { |
| 123 return drawEffect.castEffect<GrTextureDomainEffect>().wrapMode(); | 192 const GrTextureDomain& domain = drawEffect.castEffect<GrTextureDomainEffect>
().textureDomain(); |
| 193 return GrTextureDomain::GLDomain::DomainKey(domain); |
| 124 } | 194 } |
| 125 | 195 |
| 126 | 196 |
| 127 /////////////////////////////////////////////////////////////////////////////// | 197 /////////////////////////////////////////////////////////////////////////////// |
| 128 | 198 |
| 129 GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, | 199 GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, |
| 130 const SkMatrix& matrix, | 200 const SkMatrix& matrix, |
| 131 const SkRect& domain, | 201 const SkRect& domain, |
| 132 WrapMode wrapMode, | 202 GrTextureDomain::Mode mode, |
| 133 GrTextureParams::FilterMode filterMod
e, | 203 GrTextureParams::FilterMode filterMod
e, |
| 134 GrCoordSet coordSet) { | 204 GrCoordSet coordSet) { |
| 135 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; | 205 static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| 136 if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { | 206 if (GrTextureDomain::kIgnore_Mode == mode || |
| 207 (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { |
| 137 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); | 208 return GrSimpleTextureEffect::Create(texture, matrix, filterMode); |
| 138 } else { | 209 } else { |
| 139 SkRect clippedDomain; | |
| 140 // We don't currently handle domains that are empty or don't intersect t
he texture. | |
| 141 // It is OK if the domain rect is a line or point, but it should not be
inverted. We do not | |
| 142 // handle rects that do not intersect the [0..1]x[0..1] rect. | |
| 143 SkASSERT(domain.fLeft <= domain.fRight); | |
| 144 SkASSERT(domain.fTop <= domain.fBottom); | |
| 145 clippedDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); | |
| 146 clippedDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); | |
| 147 clippedDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); | |
| 148 clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); | |
| 149 SkASSERT(clippedDomain.fLeft <= clippedDomain.fRight); | |
| 150 SkASSERT(clippedDomain.fTop <= clippedDomain.fBottom); | |
| 151 | 210 |
| 152 AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, | 211 AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, |
| 153 matrix, | 212 matrix, |
| 154 clippedDomain, | 213 domain, |
| 155 wrapMode, | 214 mode, |
| 156 filterMode, | 215 filterMode, |
| 157 coordSet))); | 216 coordSet))); |
| 158 return CreateEffectRef(effect); | 217 return CreateEffectRef(effect); |
| 159 | 218 |
| 160 } | 219 } |
| 161 } | 220 } |
| 162 | 221 |
| 163 GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, | 222 GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, |
| 164 const SkMatrix& matrix, | 223 const SkMatrix& matrix, |
| 165 const SkRect& domain, | 224 const SkRect& domain, |
| 166 WrapMode wrapMode, | 225 GrTextureDomain::Mode mode, |
| 167 GrTextureParams::FilterMode filterM
ode, | 226 GrTextureParams::FilterMode filterM
ode, |
| 168 GrCoordSet coordSet) | 227 GrCoordSet coordSet) |
| 169 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) | 228 : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) |
| 170 , fWrapMode(wrapMode) | 229 , fTextureDomain(domain, mode) { |
| 171 , fTextureDomain(domain) { | |
| 172 } | 230 } |
| 173 | 231 |
| 174 GrTextureDomainEffect::~GrTextureDomainEffect() { | 232 GrTextureDomainEffect::~GrTextureDomainEffect() { |
| 175 | 233 |
| 176 } | 234 } |
| 177 | 235 |
| 178 const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { | 236 const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { |
| 179 return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); | 237 return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); |
| 180 } | 238 } |
| 181 | 239 |
| 182 bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { | 240 bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { |
| 183 const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase); | 241 const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase); |
| 184 return this->hasSameTextureParamsMatrixAndSourceCoords(s) && | 242 return this->hasSameTextureParamsMatrixAndSourceCoords(s) && |
| 185 this->fTextureDomain == s.fTextureDomain; | 243 this->fTextureDomain == s.fTextureDomain; |
| 186 } | 244 } |
| 187 | 245 |
| 188 void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { | 246 void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t*
validFlags) const { |
| 189 if (kDecal_WrapMode == fWrapMode) { | 247 if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper |
| 190 *validFlags = 0; | 248 *validFlags = 0; |
| 191 } else { | 249 } else { |
| 192 this->updateConstantColorComponentsForModulation(color, validFlags); | 250 this->updateConstantColorComponentsForModulation(color, validFlags); |
| 193 } | 251 } |
| 194 } | 252 } |
| 195 | 253 |
| 196 /////////////////////////////////////////////////////////////////////////////// | 254 /////////////////////////////////////////////////////////////////////////////// |
| 197 | 255 |
| 198 GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); | 256 GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); |
| 199 | 257 |
| 200 GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random, | 258 GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random, |
| 201 GrContext*, | 259 GrContext*, |
| 202 const GrDrawTargetCaps&, | 260 const GrDrawTargetCaps&, |
| 203 GrTexture* textures[]) { | 261 GrTexture* textures[]) { |
| 204 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : | 262 int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 205 GrEffectUnitTest::kAlphaTextureIdx; | 263 GrEffectUnitTest::kAlphaTextureIdx; |
| 206 SkRect domain; | 264 SkRect domain; |
| 207 domain.fLeft = random->nextUScalar1(); | 265 domain.fLeft = random->nextUScalar1(); |
| 208 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); | 266 domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); |
| 209 domain.fTop = random->nextUScalar1(); | 267 domain.fTop = random->nextUScalar1(); |
| 210 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); | 268 domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); |
| 211 WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; | 269 GrTextureDomain::Mode mode = |
| 270 (GrTextureDomain::Mode) random->nextULessThan(GrTextureDomain::kModeCoun
t); |
| 212 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); | 271 const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
| 213 bool bilerp = random->nextBool(); | 272 bool bilerp = random->nextBool(); |
| 214 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo
rdSet; | 273 GrCoordSet coords = random->nextBool() ? kLocal_GrCoordSet : kPosition_GrCoo
rdSet; |
| 215 return GrTextureDomainEffect::Create(textures[texIdx], | 274 return GrTextureDomainEffect::Create(textures[texIdx], |
| 216 matrix, | 275 matrix, |
| 217 domain, | 276 domain, |
| 218 wrapMode, | 277 mode, |
| 219 bilerp ? GrTextureParams::kBilerp_Filte
rMode : GrTextureParams::kNone_FilterMode, | 278 bilerp ? GrTextureParams::kBilerp_Filte
rMode : GrTextureParams::kNone_FilterMode, |
| 220 coords); | 279 coords); |
| 221 } | 280 } |
| OLD | NEW |