| 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 #ifndef GrTextureDomainEffect_DEFINED | 8 #ifndef GrTextureDomainEffect_DEFINED |
| 9 #define GrTextureDomainEffect_DEFINED | 9 #define GrTextureDomainEffect_DEFINED |
| 10 | 10 |
| 11 #include "GrSingleTextureEffect.h" | 11 #include "GrSingleTextureEffect.h" |
| 12 #include "gl/GrGLFragmentProcessor.h" | 12 #include "glsl/GrGLSLFragmentProcessor.h" |
| 13 #include "glsl/GrGLSLProgramDataManager.h" | 13 #include "glsl/GrGLSLProgramDataManager.h" |
| 14 | 14 |
| 15 class GrGLProgramBuilder; | 15 class GrGLProgramBuilder; |
| 16 class GrGLSLShaderBuilder; | 16 class GrGLSLShaderBuilder; |
| 17 class GrInvariantOutput; | 17 class GrInvariantOutput; |
| 18 class GrGLSLTextureSampler; | 18 class GrGLSLTextureSampler; |
| 19 struct SkRect; | 19 struct SkRect; |
| 20 | 20 |
| 21 /** | 21 /** |
| 22 * Limits a texture's lookup coordinates to a domain. Samples outside the domain
are either clamped | 22 * Limits a texture's lookup coordinates to a domain. Samples outside the domain
are either clamped |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 (texelRect.fRight - inset) * wInv, | 82 (texelRect.fRight - inset) * wInv, |
| 83 (texelRect.fBottom - inset) * hInv | 83 (texelRect.fBottom - inset) * hInv |
| 84 ); | 84 ); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool operator== (const GrTextureDomain& that) const { | 87 bool operator== (const GrTextureDomain& that) const { |
| 88 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); | 88 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); |
| 89 } | 89 } |
| 90 | 90 |
| 91 /** | 91 /** |
| 92 * A GrGLFragmentProcessor subclass that corresponds to a GrProcessor subcla
ss that uses | 92 * A GrGLSLFragmentProcessor subclass that corresponds to a GrProcessor subc
lass that uses |
| 93 * GrTextureDomain should include this helper. It generates the texture doma
in GLSL, produces | 93 * GrTextureDomain should include this helper. It generates the texture doma
in GLSL, produces |
| 94 * the part of the effect key that reflects the texture domain code, and per
forms the uniform | 94 * the part of the effect key that reflects the texture domain code, and per
forms the uniform |
| 95 * uploads necessary for texture domains. | 95 * uploads necessary for texture domains. |
| 96 */ | 96 */ |
| 97 class GLDomain { | 97 class GLDomain { |
| 98 public: | 98 public: |
| 99 GLDomain() { | 99 GLDomain() { |
| 100 for (int i = 0; i < kPrevDomainCount; i++) { | 100 for (int i = 0; i < kPrevDomainCount; i++) { |
| 101 fPrevDomain[i] = SK_FloatNaN; | 101 fPrevDomain[i] = SK_FloatNaN; |
| 102 } | 102 } |
| 103 SkDEBUGCODE(fMode = (Mode) -1;) | 103 SkDEBUGCODE(fMode = (Mode) -1;) |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * Call this from GrGLFragmentProcessor::emitCode() to sample the textur
e W.R.T. the domain | 107 * Call this from GrGLSLFragmentProcessor::emitCode() to sample the text
ure W.R.T. the |
| 108 * and mode. | 108 * domain and mode. |
| 109 * | 109 * |
| 110 * @param outcolor name of vec4 variable to hold the sampled color. | 110 * @param outcolor name of vec4 variable to hold the sampled color. |
| 111 * @param inCoords name of vec2 variable containing the coords to be us
ed with the domain. | 111 * @param inCoords name of vec2 variable containing the coords to be us
ed with the domain. |
| 112 * It is assumed that this is a variable and not an exp
ression. | 112 * It is assumed that this is a variable and not an exp
ression. |
| 113 * @param inModulateColor if non-nullptr the sampled color will be mod
ulated with this | 113 * @param inModulateColor if non-nullptr the sampled color will be mod
ulated with this |
| 114 * expression before being written to outColor. | 114 * expression before being written to outColor. |
| 115 */ | 115 */ |
| 116 void sampleTexture(GrGLSLShaderBuilder* builder, | 116 void sampleTexture(GrGLSLShaderBuilder* builder, |
| 117 const GrTextureDomain& textureDomain, | 117 const GrTextureDomain& textureDomain, |
| 118 const char* outColor, | 118 const char* outColor, |
| 119 const SkString& inCoords, | 119 const SkString& inCoords, |
| 120 const GrGLSLTextureSampler& sampler, | 120 const GrGLSLTextureSampler& sampler, |
| 121 const char* inModulateColor = nullptr); | 121 const char* inModulateColor = nullptr); |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * Call this from GrGLFragmentProcessor::setData() to upload uniforms ne
cessary for the | 124 * Call this from GrGLSLFragmentProcessor::setData() to upload uniforms
necessary for the |
| 125 * texture domain. The rectangle is automatically adjusted to account fo
r the texture's | 125 * texture domain. The rectangle is automatically adjusted to account fo
r the texture's |
| 126 * origin. | 126 * origin. |
| 127 */ | 127 */ |
| 128 void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomai
n& textureDomain, | 128 void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomai
n& textureDomain, |
| 129 GrSurfaceOrigin textureOrigin); | 129 GrSurfaceOrigin textureOrigin); |
| 130 | 130 |
| 131 enum { | 131 enum { |
| 132 kDomainKeyBits = 2, // See DomainKey(). | 132 kDomainKeyBits = 2, // See DomainKey(). |
| 133 }; | 133 }; |
| 134 | 134 |
| 135 /** | 135 /** |
| 136 * GrGLFragmentProcessor::GenKey() must call this and include the return
ed value in it's | 136 * GrGLSLFragmentProcessor::GenKey() must call this and include the retu
rned value in it's |
| 137 * computed key. The returned will be limited to the lower kDomainKeyBit
s bits. | 137 * computed key. The returned will be limited to the lower kDomainKeyBit
s bits. |
| 138 */ | 138 */ |
| 139 static uint32_t DomainKey(const GrTextureDomain& domain) { | 139 static uint32_t DomainKey(const GrTextureDomain& domain) { |
| 140 GR_STATIC_ASSERT(kModeCount <= 4); | 140 GR_STATIC_ASSERT(kModeCount <= 4); |
| 141 return domain.mode(); | 141 return domain.mode(); |
| 142 } | 142 } |
| 143 | 143 |
| 144 private: | 144 private: |
| 145 static const int kPrevDomainCount = 4; | 145 static const int kPrevDomainCount = 4; |
| 146 SkDEBUGCODE(Mode fMode;) | 146 SkDEBUGCODE(Mode fMode;) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 GrTextureDomain fTextureDomain; | 180 GrTextureDomain fTextureDomain; |
| 181 | 181 |
| 182 private: | 182 private: |
| 183 GrTextureDomainEffect(GrTexture*, | 183 GrTextureDomainEffect(GrTexture*, |
| 184 const SkMatrix&, | 184 const SkMatrix&, |
| 185 const SkRect& domain, | 185 const SkRect& domain, |
| 186 GrTextureDomain::Mode, | 186 GrTextureDomain::Mode, |
| 187 GrTextureParams::FilterMode, | 187 GrTextureParams::FilterMode, |
| 188 GrCoordSet); | 188 GrCoordSet); |
| 189 | 189 |
| 190 GrGLFragmentProcessor* onCreateGLInstance() const override; | 190 GrGLSLFragmentProcessor* onCreateGLInstance() const override; |
| 191 | 191 |
| 192 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; | 192 void onGetGLProcessorKey(const GrGLSLCaps&, GrProcessorKeyBuilder*) const ov
erride; |
| 193 | 193 |
| 194 bool onIsEqual(const GrFragmentProcessor&) const override; | 194 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 195 | 195 |
| 196 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 196 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 197 | 197 |
| 198 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 198 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 199 | 199 |
| 200 typedef GrSingleTextureEffect INHERITED; | 200 typedef GrSingleTextureEffect INHERITED; |
| 201 }; | 201 }; |
| 202 | 202 |
| 203 #endif | 203 #endif |
| OLD | NEW |