commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +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 "GrTextureDomain.h" |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 9 | #include "GrInvariantOutput.h" |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 10 | #include "GrSimpleTextureEffect.h" |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 11 | #include "SkFloatingPoint.h" |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 12 | #include "gl/GrGLProcessor.h" |
| 13 | #include "gl/builders/GrGLProgramBuilder.h" |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 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}; |
commit-bot@chromium.org | 2663263 | 2014-03-25 15:13:18 +0000 | [diff] [blame] | 19 | if (domain.contains(kFullRect) && kClamp_Mode == mode) { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 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 the 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); |
senorblanco | d0d37ca | 2015-04-02 04:54:56 -0700 | [diff] [blame] | 31 | fDomain.fLeft = SkScalarPin(domain.fLeft, kFullRect.fLeft, kFullRect.fRight); |
| 32 | fDomain.fRight = SkScalarPin(domain.fRight, kFullRect.fLeft, kFullRect.fRight); |
| 33 | fDomain.fTop = SkScalarPin(domain.fTop, kFullRect.fTop, kFullRect.fBottom); |
| 34 | fDomain.fBottom = SkScalarPin(domain.fBottom, kFullRect.fTop, kFullRect.fBottom); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 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& textureDomain, |
| 44 | const char* outColor, |
| 45 | const SkString& inCoords, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 46 | const GrGLProcessor::TextureSampler sampler, |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 47 | const char* inModulateColor) { |
reed@google.com | d7b1af6 | 2013-12-09 20:31:50 +0000 | [diff] [blame] | 48 | SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 49 | SkDEBUGCODE(fMode = textureDomain.mode();) |
| 50 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 51 | GrGLProgramBuilder* program = builder->getProgramBuilder(); |
| 52 | |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 53 | if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 54 | const char* name; |
| 55 | SkString uniName("TexDom"); |
| 56 | if (textureDomain.fIndex >= 0) { |
| 57 | uniName.appendS32(textureDomain.fIndex); |
| 58 | } |
bsalomon | 422f56f | 2014-12-09 10:18:12 -0800 | [diff] [blame] | 59 | fDomainUni = program->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
| 60 | kVec4f_GrSLType, kDefault_GrSLPrecision, |
| 61 | uniName.c_str(), &name); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 62 | fDomainName = name; |
| 63 | } |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 64 | |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 65 | switch (textureDomain.mode()) { |
| 66 | case kIgnore_Mode: { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 67 | builder->codeAppendf("\t%s = ", outColor); |
| 68 | builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 69 | inCoords.c_str()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 70 | builder->codeAppend(";\n"); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 71 | break; |
| 72 | } |
| 73 | case kClamp_Mode: { |
| 74 | SkString clampedCoords; |
| 75 | clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)", |
| 76 | inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str()); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 77 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 78 | builder->codeAppendf("\t%s = ", outColor); |
| 79 | builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 80 | clampedCoords.c_str()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 81 | builder->codeAppend(";\n"); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 82 | break; |
| 83 | } |
| 84 | case kDecal_Mode: { |
| 85 | // Add a block since we're going to declare variables. |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 86 | GrGLShaderBuilder::ShaderBlock block(builder); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 87 | |
| 88 | const char* domain = fDomainName.c_str(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 89 | if (kImagination_GrGLVendor == program->ctxInfo().vendor()) { |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 90 | // On the NexusS and GalaxyNexus, the other path (with the 'any' |
| 91 | // call) causes the compilation error "Calls to any function that |
| 92 | // may require a gradient calculation inside a conditional block |
| 93 | // may return undefined results". This appears to be an issue with |
| 94 | // the 'any' call since even the simple "result=black; if (any()) |
| 95 | // result=white;" code fails to compile. |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 96 | builder->codeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n"); |
| 97 | builder->codeAppend("\tvec4 inside = "); |
| 98 | builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 99 | inCoords.c_str()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 100 | builder->codeAppend(";\n"); |
| 101 | builder->codeAppendf("\tfloat x = (%s).x;\n", inCoords.c_str()); |
| 102 | builder->codeAppendf("\tfloat y = (%s).y;\n", inCoords.c_str()); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 103 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 104 | builder->codeAppendf("\tx = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0);\n", |
joshualitt | d9e183f | 2014-07-31 07:26:36 -0700 | [diff] [blame] | 105 | domain, domain, domain); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 106 | builder->codeAppendf("\ty = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0);\n", |
joshualitt | d9e183f | 2014-07-31 07:26:36 -0700 | [diff] [blame] | 107 | domain, domain, domain); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 108 | builder->codeAppend("\tfloat blend = step(1.0, max(x, y));\n"); |
| 109 | builder->codeAppendf("\t%s = mix(inside, outside, blend);\n", outColor); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 110 | } else { |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 111 | builder->codeAppend("\tbvec4 outside;\n"); |
| 112 | builder->codeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(), |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 113 | domain); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 114 | builder->codeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(), |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 115 | domain); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 116 | builder->codeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ", |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 117 | outColor); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 118 | builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 119 | inCoords.c_str()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 120 | builder->codeAppend(";\n"); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 121 | } |
| 122 | break; |
| 123 | } |
| 124 | case kRepeat_Mode: { |
| 125 | SkString clampedCoords; |
| 126 | clampedCoords.printf("\tmod(%s - %s.xy, %s.zw - %s.xy) + %s.xy", |
| 127 | inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str(), |
| 128 | fDomainName.c_str(), fDomainName.c_str()); |
| 129 | |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 130 | builder->codeAppendf("\t%s = ", outColor); |
| 131 | builder->appendTextureLookupAndModulate(inModulateColor, sampler, |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 132 | clampedCoords.c_str()); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 133 | builder->codeAppend(";\n"); |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 134 | break; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | } |
| 138 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 139 | void GrTextureDomain::GLDomain::setData(const GrGLProgramDataManager& pdman, |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 140 | const GrTextureDomain& textureDomain, |
| 141 | GrSurfaceOrigin textureOrigin) { |
| 142 | SkASSERT(textureDomain.mode() == fMode); |
| 143 | if (kIgnore_Mode != textureDomain.mode()) { |
| 144 | GrGLfloat values[4] = { |
| 145 | SkScalarToFloat(textureDomain.domain().left()), |
| 146 | SkScalarToFloat(textureDomain.domain().top()), |
| 147 | SkScalarToFloat(textureDomain.domain().right()), |
| 148 | SkScalarToFloat(textureDomain.domain().bottom()) |
| 149 | }; |
| 150 | // vertical flip if necessary |
| 151 | if (kBottomLeft_GrSurfaceOrigin == textureOrigin) { |
| 152 | values[1] = 1.0f - values[1]; |
| 153 | values[3] = 1.0f - values[3]; |
| 154 | // The top and bottom were just flipped, so correct the ordering |
| 155 | // of elements so that values = (l, t, r, b). |
| 156 | SkTSwap(values[1], values[3]); |
| 157 | } |
| 158 | if (0 != memcmp(values, fPrevDomain, 4 * sizeof(GrGLfloat))) { |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 159 | pdman.set4fv(fDomainUni, 1, values); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 160 | memcpy(fPrevDomain, values, 4 * sizeof(GrGLfloat)); |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
| 166 | ////////////////////////////////////////////////////////////////////////////// |
| 167 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 168 | class GrGLTextureDomainEffect : public GrGLFragmentProcessor { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 169 | public: |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 170 | GrGLTextureDomainEffect(const GrProcessor&); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 171 | |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 172 | virtual void emitCode(GrGLFPBuilder*, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 173 | const GrFragmentProcessor&, |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 174 | const char* outputColor, |
| 175 | const char* inputColor, |
| 176 | const TransformedCoordsArray&, |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 177 | const TextureSamplerArray&) override; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 178 | |
mtklein | 36352bf | 2015-03-25 18:17:31 -0700 | [diff] [blame] | 179 | void setData(const GrGLProgramDataManager&, const GrProcessor&) override; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 180 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 181 | static inline void GenKey(const GrProcessor&, const GrGLSLCaps&, GrProcessorKeyBuilder*); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | GrTextureDomain::GLDomain fGLDomain; |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 185 | typedef GrGLFragmentProcessor INHERITED; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 186 | }; |
| 187 | |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 188 | GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrProcessor&) { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 189 | } |
| 190 | |
joshualitt | 1598899 | 2014-10-09 15:04:05 -0700 | [diff] [blame] | 191 | void GrGLTextureDomainEffect::emitCode(GrGLFPBuilder* builder, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 192 | const GrFragmentProcessor& fp, |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 193 | const char* outputColor, |
| 194 | const char* inputColor, |
| 195 | const TransformedCoordsArray& coords, |
| 196 | const TextureSamplerArray& samplers) { |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 197 | const GrTextureDomainEffect& textureDomainEffect = fp.cast<GrTextureDomainEffect>(); |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 198 | const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 199 | |
egdaniel | 29bee0f | 2015-04-29 11:54:42 -0700 | [diff] [blame] | 200 | GrGLFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
joshualitt | 30ba436 | 2014-08-21 20:18:45 -0700 | [diff] [blame] | 201 | SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0); |
| 202 | fGLDomain.sampleTexture(fsBuilder, domain, outputColor, coords2D, samplers[0], inputColor); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 203 | } |
| 204 | |
kkinnunen | 7510b22 | 2014-07-30 00:04:16 -0700 | [diff] [blame] | 205 | void GrGLTextureDomainEffect::setData(const GrGLProgramDataManager& pdman, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 206 | const GrProcessor& processor) { |
| 207 | const GrTextureDomainEffect& textureDomainEffect = processor.cast<GrTextureDomainEffect>(); |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 208 | const GrTextureDomain& domain = textureDomainEffect.textureDomain(); |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 209 | fGLDomain.setData(pdman, domain, processor.texture(0)->origin()); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 210 | } |
| 211 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 212 | void GrGLTextureDomainEffect::GenKey(const GrProcessor& processor, const GrGLSLCaps&, |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 213 | GrProcessorKeyBuilder* b) { |
| 214 | const GrTextureDomain& domain = processor.cast<GrTextureDomainEffect>().textureDomain(); |
bsalomon | 63e99f7 | 2014-07-21 08:03:14 -0700 | [diff] [blame] | 215 | b->add32(GrTextureDomain::GLDomain::DomainKey(domain)); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | |
| 219 | /////////////////////////////////////////////////////////////////////////////// |
| 220 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 221 | GrFragmentProcessor* GrTextureDomainEffect::Create(GrTexture* texture, |
| 222 | const SkMatrix& matrix, |
| 223 | const SkRect& domain, |
| 224 | GrTextureDomain::Mode mode, |
| 225 | GrTextureParams::FilterMode filterMode, |
| 226 | GrCoordSet coordSet) { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 227 | static const SkRect kFullRect = {0, 0, SK_Scalar1, SK_Scalar1}; |
| 228 | if (GrTextureDomain::kIgnore_Mode == mode || |
| 229 | (GrTextureDomain::kClamp_Mode == mode && domain.contains(kFullRect))) { |
| 230 | return GrSimpleTextureEffect::Create(texture, matrix, filterMode); |
| 231 | } else { |
| 232 | |
bsalomon | 55fad7a | 2014-07-08 07:34:20 -0700 | [diff] [blame] | 233 | return SkNEW_ARGS(GrTextureDomainEffect, (texture, |
| 234 | matrix, |
| 235 | domain, |
| 236 | mode, |
| 237 | filterMode, |
| 238 | coordSet)); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | GrTextureDomainEffect::GrTextureDomainEffect(GrTexture* texture, |
| 243 | const SkMatrix& matrix, |
| 244 | const SkRect& domain, |
| 245 | GrTextureDomain::Mode mode, |
| 246 | GrTextureParams::FilterMode filterMode, |
| 247 | GrCoordSet coordSet) |
| 248 | : GrSingleTextureEffect(texture, matrix, filterMode, coordSet) |
| 249 | , fTextureDomain(domain, mode) { |
joshualitt | 5ae5fc5 | 2014-07-29 12:59:27 -0700 | [diff] [blame] | 250 | SkASSERT(mode != GrTextureDomain::kRepeat_Mode || |
| 251 | filterMode == GrTextureParams::kNone_FilterMode); |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 252 | this->initClassID<GrTextureDomainEffect>(); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 253 | } |
| 254 | |
| 255 | GrTextureDomainEffect::~GrTextureDomainEffect() { |
| 256 | |
| 257 | } |
| 258 | |
jvanverth | cfc1886 | 2015-04-28 08:48:20 -0700 | [diff] [blame] | 259 | void GrTextureDomainEffect::getGLProcessorKey(const GrGLSLCaps& caps, |
joshualitt | eb2a676 | 2014-12-04 11:35:33 -0800 | [diff] [blame] | 260 | GrProcessorKeyBuilder* b) const { |
| 261 | GrGLTextureDomainEffect::GenKey(*this, caps, b); |
| 262 | } |
| 263 | |
| 264 | GrGLFragmentProcessor* GrTextureDomainEffect::createGLInstance() const { |
| 265 | return SkNEW_ARGS(GrGLTextureDomainEffect, (*this)); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 266 | } |
| 267 | |
bsalomon | 0e08fc1 | 2014-10-15 08:19:04 -0700 | [diff] [blame] | 268 | bool GrTextureDomainEffect::onIsEqual(const GrFragmentProcessor& sBase) const { |
joshualitt | 49586be | 2014-09-16 08:21:41 -0700 | [diff] [blame] | 269 | const GrTextureDomainEffect& s = sBase.cast<GrTextureDomainEffect>(); |
bsalomon | 420d7e9 | 2014-10-16 09:18:09 -0700 | [diff] [blame] | 270 | return this->fTextureDomain == s.fTextureDomain; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 271 | } |
| 272 | |
egdaniel | 605dd0f | 2014-11-12 08:35:25 -0800 | [diff] [blame] | 273 | void GrTextureDomainEffect::onComputeInvariantOutput(GrInvariantOutput* inout) const { |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 274 | if (GrTextureDomain::kDecal_Mode == fTextureDomain.mode()) { // TODO: helper |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 275 | if (GrPixelConfigIsAlphaOnly(this->texture(0)->config())) { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 276 | inout->mulByUnknownSingleComponent(); |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 277 | } else { |
joshualitt | 56995b5 | 2014-12-11 15:44:02 -0800 | [diff] [blame] | 278 | inout->mulByUnknownFourComponents(); |
egdaniel | f8449ba | 2014-11-25 10:24:56 -0800 | [diff] [blame] | 279 | } |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 280 | } else { |
egdaniel | 1a8ecdf | 2014-10-03 06:24:12 -0700 | [diff] [blame] | 281 | this->updateInvariantOutputForModulation(inout); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 282 | } |
| 283 | } |
| 284 | |
| 285 | /////////////////////////////////////////////////////////////////////////////// |
| 286 | |
joshualitt | b0a8a37 | 2014-09-23 09:50:21 -0700 | [diff] [blame] | 287 | GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrTextureDomainEffect); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 288 | |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame^] | 289 | GrFragmentProcessor* GrTextureDomainEffect::TestCreate(GrProcessorTestData* d) { |
| 290 | int texIdx = d->fRandom->nextBool() ? GrProcessorUnitTest::kSkiaPMTextureIdx : |
| 291 | GrProcessorUnitTest::kAlphaTextureIdx; |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 292 | SkRect domain; |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame^] | 293 | domain.fLeft = d->fRandom->nextUScalar1(); |
| 294 | domain.fRight = d->fRandom->nextRangeScalar(domain.fLeft, SK_Scalar1); |
| 295 | domain.fTop = d->fRandom->nextUScalar1(); |
| 296 | domain.fBottom = d->fRandom->nextRangeScalar(domain.fTop, SK_Scalar1); |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 297 | GrTextureDomain::Mode mode = |
joshualitt | 0067ff5 | 2015-07-08 14:26:19 -0700 | [diff] [blame^] | 298 | (GrTextureDomain::Mode) d->fRandom->nextULessThan(GrTextureDomain::kModeCount); |
| 299 | const SkMatrix& matrix = GrTest::TestMatrix(d->fRandom); |
| 300 | bool bilerp = mode != GrTextureDomain::kRepeat_Mode ? d->fRandom->nextBool() : false; |
| 301 | GrCoordSet coords = d->fRandom->nextBool() ? kLocal_GrCoordSet : kDevice_GrCoordSet; |
| 302 | return GrTextureDomainEffect::Create(d->fTextures[texIdx], |
commit-bot@chromium.org | 907fbd5 | 2013-12-09 17:03:02 +0000 | [diff] [blame] | 303 | matrix, |
| 304 | domain, |
| 305 | mode, |
| 306 | bilerp ? GrTextureParams::kBilerp_FilterMode : GrTextureParams::kNone_FilterMode, |
| 307 | coords); |
| 308 | } |