Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 The Android Open Source Project | 2 * Copyright 2012 The Android Open Source Project |
| 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 #include "SkBlendImageFilter.h" | 8 #include "SkBlendImageFilter.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkColorPriv.h" | 10 #include "SkColorPriv.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 paint.setXfermodeMode(modeToXfermode(fMode)); | 87 paint.setXfermodeMode(modeToXfermode(fMode)); |
| 88 canvas.drawBitmap(foreground, 0, 0, &paint); | 88 canvas.drawBitmap(foreground, 0, 0, &paint); |
| 89 return true; | 89 return true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 /////////////////////////////////////////////////////////////////////////////// | 92 /////////////////////////////////////////////////////////////////////////////// |
| 93 | 93 |
| 94 #if SK_SUPPORT_GPU | 94 #if SK_SUPPORT_GPU |
| 95 class GrGLBlendEffect : public GrGLEffect { | 95 class GrGLBlendEffect : public GrGLEffect { |
| 96 public: | 96 public: |
| 97 GrGLBlendEffect(const GrBackendEffectFactory& factory, | 97 GrGLBlendEffect(const GrBackendEffectFactory& factory, |
|
robertphillips
2013/03/19 15:09:38
mv up a line?
bsalomon
2013/03/19 19:34:43
Done.
| |
| 98 const GrEffectRef& effect); | 98 const GrDrawEffect&); |
| 99 virtual ~GrGLBlendEffect(); | 99 virtual ~GrGLBlendEffect(); |
| 100 | 100 |
| 101 virtual void emitCode(GrGLShaderBuilder*, | 101 virtual void emitCode(GrGLShaderBuilder*, |
| 102 const GrEffectStage&, | 102 const GrDrawEffect&, |
| 103 EffectKey, | 103 EffectKey, |
| 104 const char* vertexCoords, | |
| 105 const char* outputColor, | 104 const char* outputColor, |
| 106 const char* inputColor, | 105 const char* inputColor, |
| 107 const TextureSamplerArray&) SK_OVERRIDE; | 106 const TextureSamplerArray&) SK_OVERRIDE; |
| 108 | 107 |
| 109 static inline EffectKey GenKey(const GrEffectStage&, const GrGLCaps&); | 108 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
| 110 | 109 |
| 111 virtual void setData(const GrGLUniformManager&, const GrEffectStage&); | 110 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER RIDE; |
| 112 | 111 |
| 113 private: | 112 private: |
| 113 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; | |
| 114 | |
| 114 SkBlendImageFilter::Mode fMode; | 115 SkBlendImageFilter::Mode fMode; |
| 115 GrGLEffectMatrix fForegroundEffectMatrix; | 116 GrGLEffectMatrix fForegroundEffectMatrix; |
| 116 GrGLEffectMatrix fBackgroundEffectMatrix; | 117 GrGLEffectMatrix fBackgroundEffectMatrix; |
| 117 | 118 |
| 118 typedef GrGLEffect INHERITED; | 119 typedef GrGLEffect INHERITED; |
| 119 }; | 120 }; |
| 120 | 121 |
| 121 /////////////////////////////////////////////////////////////////////////////// | 122 /////////////////////////////////////////////////////////////////////////////// |
| 122 | 123 |
| 123 class GrBlendEffect : public GrEffect { | 124 class GrBlendEffect : public GrEffect { |
| 124 public: | 125 public: |
| 125 static GrEffectRef* Create(SkBlendImageFilter::Mode mode, | 126 static GrEffectRef* Create(SkBlendImageFilter::Mode mode, |
| 126 GrTexture* foreground, | 127 GrTexture* foreground, |
| 127 GrTexture* background) { | 128 GrTexture* background) { |
| 128 AutoEffectUnref effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, back ground))); | 129 AutoEffectUnref effect(SkNEW_ARGS(GrBlendEffect, (mode, foreground, back ground))); |
| 129 return CreateEffectRef(effect); | 130 return CreateEffectRef(effect); |
| 130 } | 131 } |
| 131 | 132 |
| 132 virtual ~GrBlendEffect(); | 133 virtual ~GrBlendEffect(); |
| 133 | 134 |
| 134 const GrBackendEffectFactory& getFactory() const; | 135 virtual const GrBackendEffectFactory& getFactory() const SK_OVERRIDE; |
| 135 SkBlendImageFilter::Mode mode() const { return fMode; } | 136 SkBlendImageFilter::Mode mode() const { return fMode; } |
| 136 | 137 |
| 137 typedef GrGLBlendEffect GLEffect; | 138 typedef GrGLBlendEffect GLEffect; |
| 138 static const char* Name() { return "Blend"; } | 139 static const char* Name() { return "Blend"; } |
| 139 | 140 |
| 140 void getConstantColorComponents(GrColor* color, uint32_t* validFlags) const SK_OVERRIDE; | 141 virtual void getConstantColorComponents(GrColor* color, uint32_t* validFlags ) const SK_OVERRIDE; |
| 141 | 142 |
| 142 private: | 143 private: |
| 143 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; | 144 virtual bool onIsEqual(const GrEffect&) const SK_OVERRIDE; |
| 144 | 145 |
| 145 GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTextur e* background); | 146 GrBlendEffect(SkBlendImageFilter::Mode mode, GrTexture* foreground, GrTextur e* background); |
| 146 GrTextureAccess fForegroundAccess; | 147 GrTextureAccess fForegroundAccess; |
| 147 GrTextureAccess fBackgroundAccess; | 148 GrTextureAccess fBackgroundAccess; |
| 148 SkBlendImageFilter::Mode fMode; | 149 SkBlendImageFilter::Mode fMode; |
| 149 | 150 |
| 150 typedef GrEffect INHERITED; | 151 typedef GrEffect INHERITED; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) { | 218 GrPixelConfigIsOpaque(fBackgroundAccess.getTexture()->config())) { |
| 218 *validFlags = kA_ValidComponentFlag; | 219 *validFlags = kA_ValidComponentFlag; |
| 219 *color = GrColorPackRGBA(0, 0, 0, 0xff); | 220 *color = GrColorPackRGBA(0, 0, 0, 0xff); |
| 220 } else { | 221 } else { |
| 221 *validFlags = 0; | 222 *validFlags = 0; |
| 222 } | 223 } |
| 223 } | 224 } |
| 224 | 225 |
| 225 /////////////////////////////////////////////////////////////////////////////// | 226 /////////////////////////////////////////////////////////////////////////////// |
| 226 | 227 |
| 227 GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, const Gr EffectRef& effect) | 228 GrGLBlendEffect::GrGLBlendEffect(const GrBackendEffectFactory& factory, |
| 228 : INHERITED(factory), | 229 const GrDrawEffect& drawEffect) |
| 229 fMode(CastEffect<GrBlendEffect>(effect).mode()) { | 230 : INHERITED(factory) |
| 231 , fMode(drawEffect.castEffect<GrBlendEffect>().mode()) | |
| 232 , fForegroundEffectMatrix(kCoordsType) | |
| 233 , fBackgroundEffectMatrix(kCoordsType) { | |
| 230 } | 234 } |
| 231 | 235 |
| 232 GrGLBlendEffect::~GrGLBlendEffect() { | 236 GrGLBlendEffect::~GrGLBlendEffect() { |
| 233 } | 237 } |
| 234 | 238 |
| 235 void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder, | 239 void GrGLBlendEffect::emitCode(GrGLShaderBuilder* builder, |
| 236 const GrEffectStage&, | 240 const GrDrawEffect&, |
| 237 EffectKey key, | 241 EffectKey key, |
| 238 const char* vertexCoords, | |
| 239 const char* outputColor, | 242 const char* outputColor, |
| 240 const char* inputColor, | 243 const char* inputColor, |
| 241 const TextureSamplerArray& samplers) { | 244 const TextureSamplerArray& samplers) { |
| 245 const GrGLShaderVar& localCoords = builder->localCoordsAttribute(); | |
| 242 const char* fgCoords; | 246 const char* fgCoords; |
| 243 const char* bgCoords; | 247 const char* bgCoords; |
| 244 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode( | 248 GrSLType fgCoordsType = fForegroundEffectMatrix.emitCode(builder, key, &fgCo ords, NULL, "FG"); |
| 245 builder, key, vertexCoords, &fgCoords, NULL, "FG"); | 249 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode(builder, key, &bgCo ords, NULL, "BG"); |
| 246 GrSLType bgCoordsType = fBackgroundEffectMatrix.emitCode( | |
| 247 builder, key, vertexCoords, &bgCoords, NULL, "BG"); | |
| 248 | 250 |
| 249 const char* bgColor = "bgColor"; | 251 const char* bgColor = "bgColor"; |
| 250 const char* fgColor = "fgColor"; | 252 const char* fgColor = "fgColor"; |
| 251 | 253 |
| 252 builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor); | 254 builder->fsCodeAppendf("\t\tvec4 %s = ", fgColor); |
| 253 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, | 255 builder->appendTextureLookup(GrGLShaderBuilder::kFragment_ShaderType, |
| 254 samplers[0], | 256 samplers[0], |
| 255 fgCoords, | 257 fgCoords, |
| 256 fgCoordsType); | 258 fgCoordsType); |
| 257 builder->fsCodeAppend(";\n"); | 259 builder->fsCodeAppend(";\n"); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 276 break; | 278 break; |
| 277 case SkBlendImageFilter::kDarken_Mode: | 279 case SkBlendImageFilter::kDarken_Mode: |
| 278 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); | 280 builder->fsCodeAppendf("\t\t%s.rgb = min((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); |
| 279 break; | 281 break; |
| 280 case SkBlendImageFilter::kLighten_Mode: | 282 case SkBlendImageFilter::kLighten_Mode: |
| 281 builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); | 283 builder->fsCodeAppendf("\t\t%s.rgb = max((1.0 - %s.a) * %s.rgb + %s.rgb, (1.0 - %s.a) * %s.rgb + %s.rgb);\n", outputColor, fgColor, bgColor, fgColor, bg Color, fgColor, bgColor); |
| 282 break; | 284 break; |
| 283 } | 285 } |
| 284 } | 286 } |
| 285 | 287 |
| 286 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrEffectStag e& stage) { | 288 void GrGLBlendEffect::setData(const GrGLUniformManager& uman, const GrDrawEffect & drawEffect) { |
| 287 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage); | 289 const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>(); |
| 288 GrTexture* fgTex = blend.texture(0); | 290 GrTexture* fgTex = blend.texture(0); |
| 289 GrTexture* bgTex = blend.texture(1); | 291 GrTexture* bgTex = blend.texture(1); |
| 290 fForegroundEffectMatrix.setData(uman, | 292 fForegroundEffectMatrix.setData(uman, |
| 291 GrEffect::MakeDivByTextureWHMatrix(fgTex), | 293 GrEffect::MakeDivByTextureWHMatrix(fgTex), |
| 292 stage.getCoordChangeMatrix(), | 294 drawEffect, |
| 293 fgTex); | 295 fgTex); |
| 294 fBackgroundEffectMatrix.setData(uman, | 296 fBackgroundEffectMatrix.setData(uman, |
| 295 GrEffect::MakeDivByTextureWHMatrix(bgTex), | 297 GrEffect::MakeDivByTextureWHMatrix(bgTex), |
| 296 stage.getCoordChangeMatrix(), | 298 drawEffect, |
| 297 bgTex); | 299 bgTex); |
| 298 | 300 |
| 299 } | 301 } |
| 300 | 302 |
| 301 GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrEffectStage& stage, const GrGLCaps&) { | 303 GrGLEffect::EffectKey GrGLBlendEffect::GenKey(const GrDrawEffect& drawEffect, co nst GrGLCaps&) { |
| 302 const GrBlendEffect& blend = GetEffectFromStage<GrBlendEffect>(stage); | 304 const GrBlendEffect& blend = drawEffect.castEffect<GrBlendEffect>(); |
| 303 | 305 |
| 304 GrTexture* fgTex = blend.texture(0); | 306 GrTexture* fgTex = blend.texture(0); |
| 305 GrTexture* bgTex = blend.texture(1); | 307 GrTexture* bgTex = blend.texture(1); |
| 306 | 308 |
| 307 EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(fgTex), | 309 EffectKey fgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(fgTex), |
| 308 stage.getCoordChangeMatrix(), | 310 drawEffect, |
| 311 kCoordsType, | |
| 309 fgTex); | 312 fgTex); |
| 310 | 313 |
| 311 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex), | 314 EffectKey bgKey = GrGLEffectMatrix::GenKey(GrEffect::MakeDivByTextureWHMatri x(bgTex), |
| 312 stage.getCoordChangeMatrix(), | 315 drawEffect, |
| 316 kCoordsType, | |
| 313 bgTex); | 317 bgTex); |
| 314 bgKey <<= GrGLEffectMatrix::kKeyBits; | 318 bgKey <<= GrGLEffectMatrix::kKeyBits; |
| 315 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits); | 319 EffectKey modeKey = blend.mode() << (2 * GrGLEffectMatrix::kKeyBits); |
| 316 | 320 |
| 317 return modeKey | bgKey | fgKey; | 321 return modeKey | bgKey | fgKey; |
| 318 } | 322 } |
| 319 #endif | 323 #endif |
| OLD | NEW |