| 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 "gl/GrGLFragmentProcessor.h" |
| 13 #include "glsl/GrGLSLProgramDataManager.h" | 13 #include "glsl/GrGLSLProgramDataManager.h" |
| 14 | 14 |
| 15 class GrGLProgramBuilder; | 15 class GrGLProgramBuilder; |
| 16 class GrGLShaderBuilder; | 16 class GrGLShaderBuilder; |
| 17 class GrInvariantOutput; | 17 class GrInvariantOutput; |
| 18 class GrGLSLTextureSampler; |
| 18 struct SkRect; | 19 struct SkRect; |
| 19 | 20 |
| 20 /** | 21 /** |
| 21 * 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 |
| 22 * the edge of the domain or result in a vec4 of zeros (decal mode). The domain
is clipped to | 23 * the edge of the domain or result in a vec4 of zeros (decal mode). The domain
is clipped to |
| 23 * normalized texture coords ([0,1]x[0,1] square). Bilinear filtering can cause
texels outside the | 24 * normalized texture coords ([0,1]x[0,1] square). Bilinear filtering can cause
texels outside the |
| 24 * domain to affect the read value unless the caller considers this when calcula
ting the domain. | 25 * domain to affect the read value unless the caller considers this when calcula
ting the domain. |
| 25 */ | 26 */ |
| 26 class GrTextureDomain { | 27 class GrTextureDomain { |
| 27 public: | 28 public: |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 (texelRect.fRight - inset) * wInv, | 82 (texelRect.fRight - inset) * wInv, |
| 82 (texelRect.fBottom - inset) * hInv | 83 (texelRect.fBottom - inset) * hInv |
| 83 ); | 84 ); |
| 84 } | 85 } |
| 85 | 86 |
| 86 bool operator== (const GrTextureDomain& that) const { | 87 bool operator== (const GrTextureDomain& that) const { |
| 87 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); | 88 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); |
| 88 } | 89 } |
| 89 | 90 |
| 90 /** | 91 /** |
| 91 * A GrGLProcessor subclass that corresponds to a GrProcessor subclass that
uses GrTextureDomain | 92 * A GrGLFragmentProcessor subclass that corresponds to a GrProcessor subcla
ss that uses |
| 92 * should include this helper. It generates the texture domain GLSL, produce
s the part of the | 93 * GrTextureDomain should include this helper. It generates the texture doma
in GLSL, produces |
| 93 * effect key that reflects the texture domain code, and performs the unifor
m uploads necessary | 94 * the part of the effect key that reflects the texture domain code, and per
forms the uniform |
| 94 * for texture domains. | 95 * uploads necessary for texture domains. |
| 95 */ | 96 */ |
| 96 class GLDomain { | 97 class GLDomain { |
| 97 public: | 98 public: |
| 98 GLDomain() { | 99 GLDomain() { |
| 99 for (int i = 0; i < kPrevDomainCount; i++) { | 100 for (int i = 0; i < kPrevDomainCount; i++) { |
| 100 fPrevDomain[i] = SK_FloatNaN; | 101 fPrevDomain[i] = SK_FloatNaN; |
| 101 } | 102 } |
| 102 SkDEBUGCODE(fMode = (Mode) -1;) | 103 SkDEBUGCODE(fMode = (Mode) -1;) |
| 103 } | 104 } |
| 104 | 105 |
| 105 /** | 106 /** |
| 106 * Call this from GrGLProcessor::emitCode() to sample the texture W.R.T.
the domain and | 107 * Call this from GrGLFragmentProcessor::emitCode() to sample the textur
e W.R.T. the domain |
| 107 * mode. | 108 * and mode. |
| 108 * | 109 * |
| 109 * @param outcolor name of vec4 variable to hold the sampled color. | 110 * @param outcolor name of vec4 variable to hold the sampled color. |
| 110 * @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. |
| 111 * 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. |
| 112 * @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 |
| 113 * expression before being written to outColor. | 114 * expression before being written to outColor. |
| 114 */ | 115 */ |
| 115 void sampleTexture(GrGLShaderBuilder* builder, | 116 void sampleTexture(GrGLShaderBuilder* builder, |
| 116 const GrTextureDomain& textureDomain, | 117 const GrTextureDomain& textureDomain, |
| 117 const char* outColor, | 118 const char* outColor, |
| 118 const SkString& inCoords, | 119 const SkString& inCoords, |
| 119 const GrGLProcessor::TextureSampler sampler, | 120 const GrGLSLTextureSampler& sampler, |
| 120 const char* inModulateColor = nullptr); | 121 const char* inModulateColor = nullptr); |
| 121 | 122 |
| 122 /** | 123 /** |
| 123 * Call this from GrGLProcessor::setData() to upload uniforms necessary
for the texture | 124 * Call this from GrGLFragmentProcessor::setData() to upload uniforms ne
cessary for the |
| 124 * domain. The rectangle is automatically adjusted to account for the te
xture's origin. | 125 * texture domain. The rectangle is automatically adjusted to account fo
r the texture's |
| 126 * origin. |
| 125 */ | 127 */ |
| 126 void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomai
n& textureDomain, | 128 void setData(const GrGLSLProgramDataManager& pdman, const GrTextureDomai
n& textureDomain, |
| 127 GrSurfaceOrigin textureOrigin); | 129 GrSurfaceOrigin textureOrigin); |
| 128 | 130 |
| 129 enum { | 131 enum { |
| 130 kDomainKeyBits = 2, // See DomainKey(). | 132 kDomainKeyBits = 2, // See DomainKey(). |
| 131 }; | 133 }; |
| 132 | 134 |
| 133 /** | 135 /** |
| 134 * GrGLProcessor::GenKey() must call this and include the returned value
in it's computed | 136 * GrGLFragmentProcessor::GenKey() must call this and include the return
ed value in it's |
| 135 * key. The returned will be limited to the lower kDomainKeyBits bits. | 137 * computed key. The returned will be limited to the lower kDomainKeyBit
s bits. |
| 136 */ | 138 */ |
| 137 static uint32_t DomainKey(const GrTextureDomain& domain) { | 139 static uint32_t DomainKey(const GrTextureDomain& domain) { |
| 138 GR_STATIC_ASSERT(kModeCount <= 4); | 140 GR_STATIC_ASSERT(kModeCount <= 4); |
| 139 return domain.mode(); | 141 return domain.mode(); |
| 140 } | 142 } |
| 141 | 143 |
| 142 private: | 144 private: |
| 143 static const int kPrevDomainCount = 4; | 145 static const int kPrevDomainCount = 4; |
| 144 SkDEBUGCODE(Mode fMode;) | 146 SkDEBUGCODE(Mode fMode;) |
| 145 GrGLSLProgramDataManager::UniformHandle fDomainUni; | 147 GrGLSLProgramDataManager::UniformHandle fDomainUni; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 bool onIsEqual(const GrFragmentProcessor&) const override; | 194 bool onIsEqual(const GrFragmentProcessor&) const override; |
| 193 | 195 |
| 194 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; | 196 void onComputeInvariantOutput(GrInvariantOutput* inout) const override; |
| 195 | 197 |
| 196 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 198 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 197 | 199 |
| 198 typedef GrSingleTextureEffect INHERITED; | 200 typedef GrSingleTextureEffect INHERITED; |
| 199 }; | 201 }; |
| 200 | 202 |
| 201 #endif | 203 #endif |
| OLD | NEW |