| 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/GrGLEffect.h" | 12 #include "gl/GrGLProcessor.h" |
| 13 | 13 |
| 14 class GrGLProgramBuilder; | 14 class GrGLProgramBuilder; |
| 15 class GrGLShaderBuilder; | 15 class GrGLShaderBuilder; |
| 16 struct SkRect; | 16 struct SkRect; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * Limits a texture's lookup coordinates to a domain. Samples outside the domain
are either clamped | 19 * Limits a texture's lookup coordinates to a domain. Samples outside the domain
are either clamped |
| 20 * the edge of the domain or result in a vec4 of zeros (decal mode). The domain
is clipped to | 20 * the edge of the domain or result in a vec4 of zeros (decal mode). The domain
is clipped to |
| 21 * normalized texture coords ([0,1]x[0,1] square). Bilinear filtering can cause
texels outside the | 21 * normalized texture coords ([0,1]x[0,1] square). Bilinear filtering can cause
texels outside the |
| 22 * domain to affect the read value unless the caller considers this when calcula
ting the domain. | 22 * domain to affect the read value unless the caller considers this when calcula
ting the domain. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 texelRect.fBottom * hInv | 66 texelRect.fBottom * hInv |
| 67 }; | 67 }; |
| 68 return result; | 68 return result; |
| 69 } | 69 } |
| 70 | 70 |
| 71 bool operator== (const GrTextureDomain& that) const { | 71 bool operator== (const GrTextureDomain& that) const { |
| 72 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); | 72 return fMode == that.fMode && (kIgnore_Mode == fMode || fDomain == that.
fDomain); |
| 73 } | 73 } |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * A GrGLEffect subclass that corresponds to a GrEffect subclass that uses G
rTextureDomain | 76 * A GrGLProcessor subclass that corresponds to a GrProcessor subclass that
uses GrTextureDomain |
| 77 * should include this helper. It generates the texture domain GLSL, produce
s the part of the | 77 * should include this helper. It generates the texture domain GLSL, produce
s the part of the |
| 78 * effect key that reflects the texture domain code, and performs the unifor
m uploads necessary | 78 * effect key that reflects the texture domain code, and performs the unifor
m uploads necessary |
| 79 * for texture domains. | 79 * for texture domains. |
| 80 */ | 80 */ |
| 81 class GLDomain { | 81 class GLDomain { |
| 82 public: | 82 public: |
| 83 GLDomain() { | 83 GLDomain() { |
| 84 fPrevDomain[0] = SK_FloatNaN; | 84 fPrevDomain[0] = SK_FloatNaN; |
| 85 SkDEBUGCODE(fMode = (Mode) -1;) | 85 SkDEBUGCODE(fMode = (Mode) -1;) |
| 86 } | 86 } |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * Call this from GrGLEffect::emitCode() to sample the texture W.R.T. th
e domain and mode. | 89 * Call this from GrGLProcessor::emitCode() to sample the texture W.R.T.
the domain and |
| 90 * mode. |
| 90 * | 91 * |
| 91 * @param outcolor name of vec4 variable to hold the sampled color. | 92 * @param outcolor name of vec4 variable to hold the sampled color. |
| 92 * @param inCoords name of vec2 variable containing the coords to be us
ed with the domain. | 93 * @param inCoords name of vec2 variable containing the coords to be us
ed with the domain. |
| 93 * It is assumed that this is a variable and not an exp
ression. | 94 * It is assumed that this is a variable and not an exp
ression. |
| 94 * @param inModulateColor if non-NULL the sampled color will be modula
ted with this | 95 * @param inModulateColor if non-NULL the sampled color will be modula
ted with this |
| 95 * expression before being written to outColor. | 96 * expression before being written to outColor. |
| 96 */ | 97 */ |
| 97 void sampleTexture(GrGLShaderBuilder* builder, | 98 void sampleTexture(GrGLShaderBuilder* builder, |
| 98 const GrTextureDomain& textureDomain, | 99 const GrTextureDomain& textureDomain, |
| 99 const char* outColor, | 100 const char* outColor, |
| 100 const SkString& inCoords, | 101 const SkString& inCoords, |
| 101 const GrGLEffect::TextureSampler sampler, | 102 const GrGLProcessor::TextureSampler sampler, |
| 102 const char* inModulateColor = NULL); | 103 const char* inModulateColor = NULL); |
| 103 | 104 |
| 104 /** | 105 /** |
| 105 * Call this from GrGLEffect::setData() to upload uniforms necessary for
the texture domain. | 106 * Call this from GrGLProcessor::setData() to upload uniforms necessary
for the texture |
| 106 * The rectangle is automatically adjusted to account for the texture's
origin. | 107 * domain. The rectangle is automatically adjusted to account for the te
xture's origin. |
| 107 */ | 108 */ |
| 108 void setData(const GrGLProgramDataManager& pdman, const GrTextureDomain&
textureDomain, | 109 void setData(const GrGLProgramDataManager& pdman, const GrTextureDomain&
textureDomain, |
| 109 GrSurfaceOrigin textureOrigin); | 110 GrSurfaceOrigin textureOrigin); |
| 110 | 111 |
| 111 enum { | 112 enum { |
| 112 kDomainKeyBits = 2, // See DomainKey(). | 113 kDomainKeyBits = 2, // See DomainKey(). |
| 113 }; | 114 }; |
| 114 | 115 |
| 115 /** | 116 /** |
| 116 * GrGLEffect::GenKey() must call this and include the returned value in
it's computed key. | 117 * GrGLProcessor::GenKey() must call this and include the returned value
in it's computed |
| 117 * The returned will be limited to the lower kDomainKeyBits bits. | 118 * key. The returned will be limited to the lower kDomainKeyBits bits. |
| 118 */ | 119 */ |
| 119 static uint32_t DomainKey(const GrTextureDomain& domain) { | 120 static uint32_t DomainKey(const GrTextureDomain& domain) { |
| 120 GR_STATIC_ASSERT(kModeCount <= 4); | 121 GR_STATIC_ASSERT(kModeCount <= 4); |
| 121 return domain.mode(); | 122 return domain.mode(); |
| 122 } | 123 } |
| 123 | 124 |
| 124 private: | 125 private: |
| 125 SkDEBUGCODE(Mode fMode;) | 126 SkDEBUGCODE(Mode fMode;) |
| 126 GrGLProgramDataManager::UniformHandle fDomainUni; | 127 GrGLProgramDataManager::UniformHandle fDomainUni; |
| 127 SkString fDomainName; | 128 SkString fDomainName; |
| 128 GrGLfloat fPrevDomain[4]; | 129 GrGLfloat fPrevDomain[4]; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 protected: | 132 protected: |
| 132 Mode fMode; | 133 Mode fMode; |
| 133 SkRect fDomain; | 134 SkRect fDomain; |
| 134 int fIndex; | 135 int fIndex; |
| 135 | 136 |
| 136 typedef GrSingleTextureEffect INHERITED; | 137 typedef GrSingleTextureEffect INHERITED; |
| 137 }; | 138 }; |
| 138 | 139 |
| 139 class GrGLTextureDomainEffect; | 140 class GrGLTextureDomainEffect; |
| 140 | 141 |
| 141 /** | 142 /** |
| 142 * A basic texture effect that uses GrTextureDomain. | 143 * A basic texture effect that uses GrTextureDomain. |
| 143 */ | 144 */ |
| 144 class GrTextureDomainEffect : public GrSingleTextureEffect { | 145 class GrTextureDomainEffect : public GrSingleTextureEffect { |
| 145 | 146 |
| 146 public: | 147 public: |
| 147 static GrEffect* Create(GrTexture*, | 148 static GrFragmentProcessor* Create(GrTexture*, |
| 148 const SkMatrix&, | 149 const SkMatrix&, |
| 149 const SkRect& domain, | 150 const SkRect& domain, |
| 150 GrTextureDomain::Mode, | 151 GrTextureDomain::Mode, |
| 151 GrTextureParams::FilterMode filterMode, | 152 GrTextureParams::FilterMode filterMode, |
| 152 GrCoordSet = kLocal_GrCoordSet); | 153 GrCoordSet = kLocal_GrCoordSet); |
| 153 | 154 |
| 154 virtual ~GrTextureDomainEffect(); | 155 virtual ~GrTextureDomainEffect(); |
| 155 | 156 |
| 156 static const char* Name() { return "TextureDomain"; } | 157 static const char* Name() { return "TextureDomain"; } |
| 157 | 158 |
| 158 typedef GrGLTextureDomainEffect GLEffect; | 159 typedef GrGLTextureDomainEffect GLProcessor; |
| 159 | 160 |
| 160 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; | 161 virtual const GrBackendFragmentProcessorFactory& getFactory() const SK_OVERR
IDE; |
| 161 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; | 162 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags
) const SK_OVERRIDE; |
| 162 | 163 |
| 163 const GrTextureDomain& textureDomain() const { return fTextureDomain; } | 164 const GrTextureDomain& textureDomain() const { return fTextureDomain; } |
| 164 | 165 |
| 165 protected: | 166 protected: |
| 166 GrTextureDomain fTextureDomain; | 167 GrTextureDomain fTextureDomain; |
| 167 | 168 |
| 168 private: | 169 private: |
| 169 GrTextureDomainEffect(GrTexture*, | 170 GrTextureDomainEffect(GrTexture*, |
| 170 const SkMatrix&, | 171 const SkMatrix&, |
| 171 const SkRect& domain, | 172 const SkRect& domain, |
| 172 GrTextureDomain::Mode, | 173 GrTextureDomain::Mode, |
| 173 GrTextureParams::FilterMode, | 174 GrTextureParams::FilterMode, |
| 174 GrCoordSet); | 175 GrCoordSet); |
| 175 | 176 |
| 176 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 177 virtual bool onIsEqual(const GrProcessor&) const SK_OVERRIDE; |
| 177 | 178 |
| 178 GR_DECLARE_EFFECT_TEST; | 179 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 179 | 180 |
| 180 typedef GrSingleTextureEffect INHERITED; | 181 typedef GrSingleTextureEffect INHERITED; |
| 181 }; | 182 }; |
| 182 | 183 |
| 183 #endif | 184 #endif |
| OLD | NEW |