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