OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SkArithmeticMode.h" | 8 #include "SkArithmeticMode.h" |
9 #include "SkColorPriv.h" | 9 #include "SkColorPriv.h" |
10 #include "SkFlattenableBuffers.h" | 10 #include "SkFlattenableBuffers.h" |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 | 243 |
244 virtual void emitCode(GrGLShaderBuilder*, | 244 virtual void emitCode(GrGLShaderBuilder*, |
245 const GrDrawEffect&, | 245 const GrDrawEffect&, |
246 EffectKey, | 246 EffectKey, |
247 const char* outputColor, | 247 const char* outputColor, |
248 const char* inputColor, | 248 const char* inputColor, |
249 const TextureSamplerArray&) SK_OVERRIDE; | 249 const TextureSamplerArray&) SK_OVERRIDE; |
250 | 250 |
251 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); | 251 static inline EffectKey GenKey(const GrDrawEffect&, const GrGLCaps&); |
252 | 252 |
253 virtual void setData(const GrGLUniformManager&, const GrDrawEffect&) SK_OVER
RIDE; | 253 virtual void setData(const GrGLContext&, const GrDrawEffect&) SK_OVERRIDE; |
254 | 254 |
255 private: | 255 private: |
256 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; | 256 static const GrEffect::CoordsType kCoordsType = GrEffect::kLocal_CoordsType; |
257 GrGLEffectMatrix fBackgroundEffectMatrix; | 257 GrGLEffectMatrix fBackgroundEffectMatrix; |
258 GrGLUniformManager::UniformHandle fKUni; | 258 GrGLUniform* fKUni; |
259 | 259 |
260 typedef GrGLEffect INHERITED; | 260 typedef GrGLEffect INHERITED; |
261 }; | 261 }; |
262 | 262 |
263 /////////////////////////////////////////////////////////////////////////////// | 263 /////////////////////////////////////////////////////////////////////////////// |
264 | 264 |
265 class GrArithmeticEffect : public GrEffect { | 265 class GrArithmeticEffect : public GrEffect { |
266 public: | 266 public: |
267 static GrEffectRef* Create(float k1, float k2, float k3, float k4, GrTexture
* background) { | 267 static GrEffectRef* Create(float k1, float k2, float k3, float k4, GrTexture
* background) { |
268 AutoEffectUnref effect(SkNEW_ARGS(GrArithmeticEffect, (k1, k2, k3, k4, b
ackground))); | 268 AutoEffectUnref effect(SkNEW_ARGS(GrArithmeticEffect, (k1, k2, k3, k4, b
ackground))); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 samplers[0], | 358 samplers[0], |
359 bgCoords, | 359 bgCoords, |
360 bgCoordsType); | 360 bgCoordsType); |
361 builder->fsCodeAppendf(";\n"); | 361 builder->fsCodeAppendf(";\n"); |
362 dstColor = "bgColor"; | 362 dstColor = "bgColor"; |
363 } else { | 363 } else { |
364 dstColor = builder->dstColor(); | 364 dstColor = builder->dstColor(); |
365 } | 365 } |
366 | 366 |
367 GrAssert(NULL != dstColor); | 367 GrAssert(NULL != dstColor); |
368 fKUni = builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, | 368 GrGLShaderBuilder::Uniform* KUni = |
369 kVec4f_GrSLType, "k"); | 369 builder->addUniform(GrGLShaderBuilder::kFragment_ShaderType, kVec4f_GrSL
Type, "k"); |
370 const char* kUni = builder->getUniformCStr(fKUni); | 370 fKUni = KUni->glUniform(); |
| 371 |
| 372 const char* kUni = KUni->c_str(); |
371 | 373 |
372 // We don't try to optimize for this case at all | 374 // We don't try to optimize for this case at all |
373 if (NULL == inputColor) { | 375 if (NULL == inputColor) { |
374 builder->fsCodeAppendf("\t\tconst vec4 src = %s;\n", GrGLSLOnesVecf(4)); | 376 builder->fsCodeAppendf("\t\tconst vec4 src = %s;\n", GrGLSLOnesVecf(4)); |
375 } else { | 377 } else { |
376 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); | 378 builder->fsCodeAppendf("\t\tvec4 src = %s;\n", inputColor); |
377 if (gUseUnpremul) { | 379 if (gUseUnpremul) { |
378 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1.
0);\n"); | 380 builder->fsCodeAppendf("\t\tsrc.rgb = clamp(src.rgb / src.a, 0.0, 1.
0);\n"); |
379 } | 381 } |
380 } | 382 } |
381 | 383 |
382 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); | 384 builder->fsCodeAppendf("\t\tvec4 dst = %s;\n", dstColor); |
383 if (gUseUnpremul) { | 385 if (gUseUnpremul) { |
384 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\
n"); | 386 builder->fsCodeAppendf("\t\tdst.rgb = clamp(dst.rgb / dst.a, 0.0, 1.0);\
n"); |
385 } | 387 } |
386 | 388 |
387 builder->fsCodeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); | 389 builder->fsCodeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); |
388 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); | 390 builder->fsCodeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); |
389 if (gUseUnpremul) { | 391 if (gUseUnpremul) { |
390 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); | 392 builder->fsCodeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); |
391 } else { | 393 } else { |
392 builder->fsCodeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); | 394 builder->fsCodeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); |
393 } | 395 } |
394 } | 396 } |
395 | 397 |
396 void GrGLArithmeticEffect::setData(const GrGLUniformManager& uman, const GrDrawE
ffect& drawEffect) { | 398 void GrGLArithmeticEffect::setData(const GrGLContext& context, const GrDrawEffec
t& drawEffect) { |
397 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); | 399 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); |
398 uman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 400 fKUni->set4f(context, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
399 GrTexture* bgTex = arith.backgroundTexture(); | 401 GrTexture* bgTex = arith.backgroundTexture(); |
400 if (bgTex) { | 402 if (bgTex) { |
401 fBackgroundEffectMatrix.setData(uman, | 403 fBackgroundEffectMatrix.setData(context, |
402 GrEffect::MakeDivByTextureWHMatrix(bgTex
), | 404 GrEffect::MakeDivByTextureWHMatrix(bgTex
), |
403 drawEffect, | 405 drawEffect, |
404 bgTex); | 406 bgTex); |
405 } | 407 } |
406 } | 408 } |
407 | 409 |
408 GrGLEffect::EffectKey GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffec
t, const GrGLCaps&) { | 410 GrGLEffect::EffectKey GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffec
t, const GrGLCaps&) { |
409 const GrArithmeticEffect& effect = drawEffect.castEffect<GrArithmeticEffect>
(); | 411 const GrArithmeticEffect& effect = drawEffect.castEffect<GrArithmeticEffect>
(); |
410 GrTexture* bgTex = effect.backgroundTexture(); | 412 GrTexture* bgTex = effect.backgroundTexture(); |
411 EffectKey bgKey = 0; | 413 EffectKey bgKey = 0; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 background); | 448 background); |
447 } | 449 } |
448 return true; | 450 return true; |
449 } | 451 } |
450 | 452 |
451 #endif | 453 #endif |
452 | 454 |
453 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) | 455 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) |
454 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) | 456 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) |
455 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 457 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |