tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 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 | #include "GrTextureDomainEffect.h" |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 9 | #include "GrSimpleTextureEffect.h" |
bsalomon@google.com | 2eaaefd | 2012-10-29 19:51:22 +0000 | [diff] [blame] | 10 | #include "GrTBackendEffectFactory.h" |
bsalomon@google.com | d698f77 | 2012-10-25 13:22:00 +0000 | [diff] [blame] | 11 | #include "gl/GrGLEffect.h" |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 12 | #include "gl/GrGLEffectMatrix.h" |
| 13 | #include "SkFloatingPoint.h" |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 14 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 15 | class GrGLTextureDomainEffect : public GrGLEffect { |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 16 | public: |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 17 | GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&); |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 18 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 19 | virtual void emitCode(GrGLShaderBuilder*, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 20 | const GrDrawEffect&, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 21 | EffectKey, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 22 | const char* outputColor, |
| 23 | const char* inputColor, |
| 24 | const TextureSamplerArray&) SK_OVERRIDE; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 25 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 26 | virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVERRIDE; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 27 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 28 | static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 29 | |
| 30 | private: |
bsalomon@google.com | dbbc4e2 | 2012-07-25 17:48:39 +0000 | [diff] [blame] | 31 | GrGLUniformManager::UniformHandle fNameUni; |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 32 | GrGLEffectMatrix fEffectMatrix; |
| 33 | GrGLfloat fPrevDomain[4]; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 34 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 35 | typedef GrGLEffect INHERITED; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 36 | }; |
| 37 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 38 | GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& factory, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 39 | const GrDrawEffect& drawEffect) |
bsalomon@google.com | 374e759 | 2012-10-23 17:30:45 +0000 | [diff] [blame] | 40 | : INHERITED(factory) |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 41 | , fEffectMatrix(drawEffect.castEffect<GrTextureDomainEffect>().coordsType()) { |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 42 | fPrevDomain[0] = SK_FloatNaN; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 43 | } |
| 44 | |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 45 | void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 46 | const GrDrawEffect& drawEffect, |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 47 | EffectKey key, |
bsalomon@google.com | 22a800a | 2012-10-26 19:16:46 +0000 | [diff] [blame] | 48 | const char* outputColor, |
| 49 | const char* inputColor, |
| 50 | const TextureSamplerArray& samplers) { |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 51 | const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 52 | |
commit-bot@chromium.org | 7ab7ca4 | 2013-08-28 15:59:13 +0000 | [diff] [blame] | 53 | SkString coords; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 54 | fEffectMatrix.emitCodeMakeFSCoords2D(builder, key, &coords); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 55 | const char* domain; |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 56 | fNameUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility, |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 57 | kVec4f_GrSLType, "TexDom", &domain); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 58 | if (GrTextureDomainEffect::kClamp_WrapMode == texDom.wrapMode()) { |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 59 | |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 60 | builder->fsCodeAppendf("\tvec2 clampCoord = clamp(%s, %s.xy, %s.zw);\n", |
commit-bot@chromium.org | 7ab7ca4 | 2013-08-28 15:59:13 +0000 | [diff] [blame] | 61 | coords.c_str(), domain, domain); |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 62 | |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 63 | builder->fsCodeAppendf("\t%s = ", outputColor); |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 64 | builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], "clampCoord"); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 65 | builder->fsCodeAppend(";\n"); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 66 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 67 | SkASSERT(GrTextureDomainEffect::kDecal_WrapMode == texDom.wrapMode()); |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 68 | |
| 69 | if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) { |
skia.committer@gmail.com | 0c23faf | 2013-03-03 07:16:29 +0000 | [diff] [blame] | 70 | // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| 71 | // call) causes the compilation error "Calls to any function that |
| 72 | // may require a gradient calculation inside a conditional block |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 73 | // may return undefined results". This appears to be an issue with |
| 74 | // the 'any' call since even the simple "result=black; if (any()) |
| 75 | // result=white;" code fails to compile. |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 76 | builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); |
| 77 | builder->fsCodeAppend("\tvec4 inside = "); |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 78 | builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str()); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 79 | builder->fsCodeAppend(";\n"); |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 80 | |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 81 | builder->fsCodeAppendf("\tfloat x = abs(2.0*(%s.x - %s.x)/(%s.z - %s.x) - 1.0);\n", |
commit-bot@chromium.org | 7ab7ca4 | 2013-08-28 15:59:13 +0000 | [diff] [blame] | 82 | coords.c_str(), domain, domain, domain); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 83 | builder->fsCodeAppendf("\tfloat y = abs(2.0*(%s.y - %s.y)/(%s.w - %s.y) - 1.0);\n", |
commit-bot@chromium.org | 7ab7ca4 | 2013-08-28 15:59:13 +0000 | [diff] [blame] | 84 | coords.c_str(), domain, domain, domain); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 85 | builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
| 86 | builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outputColor); |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 87 | } else { |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 88 | builder->fsCodeAppend("\tbvec4 outside;\n"); |
commit-bot@chromium.org | 7ab7ca4 | 2013-08-28 15:59:13 +0000 | [diff] [blame] | 89 | builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", coords.c_str(), domain); |
| 90 | builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", coords.c_str(), domain); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 91 | builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", outputColor); |
commit-bot@chromium.org | 74a3a21 | 2013-08-30 19:43:59 +0000 | [diff] [blame] | 92 | builder->fsAppendTextureLookupAndModulate(inputColor, samplers[0], coords.c_str()); |
bsalomon@google.com | f910d3b | 2013-03-07 17:06:57 +0000 | [diff] [blame] | 93 | builder->fsCodeAppend(";\n"); |
robertphillips@google.com | 13f181f | 2013-03-02 12:02:08 +0000 | [diff] [blame] | 94 | } |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 95 | } |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 96 | } |
| 97 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 98 | void GrGLTextureDomainEffect::setData(const GrGLUniformManager& uman, |
| 99 | const GrDrawEffect& drawEffect) { |
| 100 | const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 101 | const SkRect& domain = texDom.domain(); |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 102 | |
| 103 | float values[4] = { |
bsalomon@google.com | 8171288 | 2012-11-01 17:12:34 +0000 | [diff] [blame] | 104 | SkScalarToFloat(domain.left()), |
| 105 | SkScalarToFloat(domain.top()), |
| 106 | SkScalarToFloat(domain.right()), |
| 107 | SkScalarToFloat(domain.bottom()) |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 108 | }; |
| 109 | // vertical flip if necessary |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 110 | if (kBottomLeft_GrSurfaceOrigin == texDom.texture(0)->origin()) { |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 111 | values[1] = 1.0f - values[1]; |
| 112 | values[3] = 1.0f - values[3]; |
| 113 | // The top and bottom were just flipped, so correct the ordering |
| 114 | // of elements so that values = (l, t, r, b). |
| 115 | SkTSwap(values[1], values[3]); |
| 116 | } |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 117 | if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { |
| 118 | uman.set4fv(fNameUni, 0, 1, values); |
robertphillips@google.com | 6b96d36 | 2013-04-15 21:51:52 +0000 | [diff] [blame] | 119 | memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 120 | } |
| 121 | fEffectMatrix.setData(uman, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 122 | texDom.getMatrix(), |
| 123 | drawEffect, |
| 124 | texDom.texture(0)); |
skia.committer@gmail.com | 1aa90cf | 2012-11-06 13:18:25 +0000 | [diff] [blame] | 125 | } |
bsalomon@google.com | 92b6a94 | 2012-11-02 19:50:26 +0000 | [diff] [blame] | 126 | |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 127 | GrGLEffect::EffectKey GrGLTextureDomainEffect::GenKey(const GrDrawEffect& drawEffect, |
| 128 | const GrGLCaps&) { |
| 129 | const GrTextureDomainEffect& texDom = drawEffect.castEffect<GrTextureDomainEffect>(); |
| 130 | EffectKey key = texDom.wrapMode(); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 131 | key <<= GrGLEffectMatrix::kKeyBits; |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 132 | EffectKey matrixKey = GrGLEffectMatrix::GenKey(texDom.getMatrix(), |
| 133 | drawEffect, |
| 134 | texDom.coordsType(), |
| 135 | texDom.texture(0)); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 136 | return key | matrixKey; |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | |
| 140 | /////////////////////////////////////////////////////////////////////////////// |
| 141 | |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 142 | GrEffectRef* GrTextureDomainEffect::Create(GrTexture* texture, |
| 143 | const SkMatrix& matrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 144 | const SkRect& domain, |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 145 | WrapMode wrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 146 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 147 | CoordsType coordsType) { |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 148 | static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| 149 | if (kClamp_WrapMode == wrapMode && domain.contains(kFullRect)) { |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 150 | return GrSimpleTextureEffect::Create(texture, matrix, filterMode); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 151 | } else { |
| 152 | SkRect clippedDomain; |
| 153 | // We don't currently handle domains that are empty or don't intersect the texture. |
bsalomon@google.com | fe4e491 | 2012-11-08 20:32:13 +0000 | [diff] [blame] | 154 | // It is OK if the domain rect is a line or point, but it should not be inverted. We do not |
| 155 | // handle rects that do not intersect the [0..1]x[0..1] rect. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 156 | SkASSERT(domain.fLeft <= domain.fRight); |
| 157 | SkASSERT(domain.fTop <= domain.fBottom); |
bsalomon@google.com | fe4e491 | 2012-11-08 20:32:13 +0000 | [diff] [blame] | 158 | clippedDomain.fLeft = SkMaxScalar(domain.fLeft, kFullRect.fLeft); |
| 159 | clippedDomain.fRight = SkMinScalar(domain.fRight, kFullRect.fRight); |
| 160 | clippedDomain.fTop = SkMaxScalar(domain.fTop, kFullRect.fTop); |
| 161 | clippedDomain.fBottom = SkMinScalar(domain.fBottom, kFullRect.fBottom); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 162 | SkASSERT(clippedDomain.fLeft <= clippedDomain.fRight); |
| 163 | SkASSERT(clippedDomain.fTop <= clippedDomain.fBottom); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 164 | |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 165 | AutoEffectUnref effect(SkNEW_ARGS(GrTextureDomainEffect, (texture, |
| 166 | matrix, |
| 167 | clippedDomain, |
| 168 | wrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 169 | filterMode, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 170 | coordsType))); |
bsalomon@google.com | a1ebbe4 | 2013-01-16 15:51:47 +0000 | [diff] [blame] | 171 | return CreateEffectRef(effect); |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 172 | |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 173 | } |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 174 | } |
| 175 | |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 176 | GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 177 | const SkMatrix& matrix, |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 178 | const SkRect& domain, |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 179 | WrapMode wrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 180 | GrTextureParams::FilterMode filterMode, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 181 | CoordsType coordsType) |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 182 | : GrSingleTextureEffect(texture, matrix, filterMode, coordsType) |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 183 | , fWrapMode(wrapMode) |
bsalomon@google.com | 1ce49fc | 2012-09-18 14:14:49 +0000 | [diff] [blame] | 184 | , fTextureDomain(domain) { |
| 185 | } |
| 186 | |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 187 | GrTextureDomainEffect::~GrTextureDomainEffect() { |
| 188 | |
| 189 | } |
| 190 | |
bsalomon@google.com | 396e61f | 2012-10-25 19:00:29 +0000 | [diff] [blame] | 191 | const GrBackendEffectFactory& GrTextureDomainEffect::getFactory() const { |
| 192 | return GrTBackendEffectFactory<GrTextureDomainEffect>::getInstance(); |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 193 | } |
| 194 | |
bsalomon@google.com | 8a252f7 | 2013-01-22 20:35:13 +0000 | [diff] [blame] | 195 | bool GrTextureDomainEffect::onIsEqual(const GrEffect& sBase) const { |
bsalomon@google.com | 6340a41 | 2013-01-22 19:55:59 +0000 | [diff] [blame] | 196 | const GrTextureDomainEffect& s = CastEffect<GrTextureDomainEffect>(sBase); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 197 | return this->hasSameTextureParamsMatrixAndCoordsType(s) && |
| 198 | this->fTextureDomain == s.fTextureDomain; |
bsalomon@google.com | 68b58c9 | 2013-01-17 16:50:08 +0000 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | void GrTextureDomainEffect::getConstantColorComponents(GrColor* color, uint32_t* validFlags) const { |
| 202 | if (kDecal_WrapMode == fWrapMode) { |
| 203 | *validFlags = 0; |
| 204 | } else { |
| 205 | this->updateConstantColorComponentsForModulation(color, validFlags); |
| 206 | } |
tomhudson@google.com | 2f68e76 | 2012-07-17 18:43:21 +0000 | [diff] [blame] | 207 | } |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 208 | |
| 209 | /////////////////////////////////////////////////////////////////////////////// |
| 210 | |
bsalomon@google.com | f271cc7 | 2012-10-24 19:35:13 +0000 | [diff] [blame] | 211 | GR_DEFINE_EFFECT_TEST(GrTextureDomainEffect); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 212 | |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 213 | GrEffectRef* GrTextureDomainEffect::TestCreate(SkRandom* random, |
sugoi@google.com | e0e385c | 2013-03-11 18:50:03 +0000 | [diff] [blame] | 214 | GrContext*, |
bsalomon@google.com | c26d94f | 2013-03-25 18:19:00 +0000 | [diff] [blame] | 215 | const GrDrawTargetCaps&, |
bsalomon@google.com | 0ac6af4 | 2013-01-16 15:16:18 +0000 | [diff] [blame] | 216 | GrTexture* textures[]) { |
bsalomon@google.com | 6f261be | 2012-10-24 19:07:10 +0000 | [diff] [blame] | 217 | int texIdx = random->nextBool() ? GrEffectUnitTest::kSkiaPMTextureIdx : |
| 218 | GrEffectUnitTest::kAlphaTextureIdx; |
commit-bot@chromium.org | fd03d4a | 2013-07-17 21:39:42 +0000 | [diff] [blame] | 219 | SkRect domain; |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 220 | domain.fLeft = random->nextUScalar1(); |
| 221 | domain.fRight = random->nextRangeScalar(domain.fLeft, SK_Scalar1); |
| 222 | domain.fTop = random->nextUScalar1(); |
| 223 | domain.fBottom = random->nextRangeScalar(domain.fTop, SK_Scalar1); |
bsalomon@google.com | 7b7cdd1 | 2012-11-07 16:17:24 +0000 | [diff] [blame] | 224 | WrapMode wrapMode = random->nextBool() ? kClamp_WrapMode : kDecal_WrapMode; |
| 225 | const SkMatrix& matrix = GrEffectUnitTest::TestMatrix(random); |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 226 | bool bilerp = random->nextBool(); |
| 227 | CoordsType coords = random->nextBool() ? kLocal_CoordsType : kPosition_CoordsType; |
| 228 | return GrTextureDomainEffect::Create(textures[texIdx], |
| 229 | matrix, |
| 230 | domain, |
| 231 | wrapMode, |
humper@google.com | b86add1 | 2013-07-25 18:49:07 +0000 | [diff] [blame] | 232 | bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_FilterMode, |
bsalomon@google.com | c781888 | 2013-03-20 19:19:53 +0000 | [diff] [blame] | 233 | coords); |
bsalomon@google.com | 0a7672f | 2012-08-03 18:12:20 +0000 | [diff] [blame] | 234 | } |