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 "SkReadBuffer.h" | 10 #include "SkReadBuffer.h" |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 return SkArithmeticMode_scalar::Create(k1, k2, k3, k4, enforcePMColor); | 242 return SkArithmeticMode_scalar::Create(k1, k2, k3, k4, enforcePMColor); |
243 } | 243 } |
244 | 244 |
245 | 245 |
246 ////////////////////////////////////////////////////////////////////////////// | 246 ////////////////////////////////////////////////////////////////////////////// |
247 | 247 |
248 #if SK_SUPPORT_GPU | 248 #if SK_SUPPORT_GPU |
249 | 249 |
250 class GrGLArithmeticEffect : public GrGLEffect { | 250 class GrGLArithmeticEffect : public GrGLEffect { |
251 public: | 251 public: |
252 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrDrawEffect&); | 252 GrGLArithmeticEffect(const GrBackendEffectFactory&, const GrEffect&); |
253 virtual ~GrGLArithmeticEffect(); | 253 virtual ~GrGLArithmeticEffect(); |
254 | 254 |
255 virtual void emitCode(GrGLProgramBuilder*, | 255 virtual void emitCode(GrGLProgramBuilder*, |
256 const GrDrawEffect&, | 256 const GrEffect&, |
257 const GrEffectKey&, | 257 const GrEffectKey&, |
258 const char* outputColor, | 258 const char* outputColor, |
259 const char* inputColor, | 259 const char* inputColor, |
260 const TransformedCoordsArray&, | 260 const TransformedCoordsArray&, |
261 const TextureSamplerArray&) SK_OVERRIDE; | 261 const TextureSamplerArray&) SK_OVERRIDE; |
262 | 262 |
263 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 263 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
264 | 264 |
265 static void GenKey(const GrDrawEffect&, const GrGLCaps& caps, GrEffectKeyBui
lder* b); | 265 static void GenKey(const GrEffect&, const GrGLCaps& caps, GrEffectKeyBuilder
* b); |
266 | 266 |
267 private: | 267 private: |
268 GrGLProgramDataManager::UniformHandle fKUni; | 268 GrGLProgramDataManager::UniformHandle fKUni; |
269 bool fEnforcePMColor; | 269 bool fEnforcePMColor; |
270 | 270 |
271 typedef GrGLEffect INHERITED; | 271 typedef GrGLEffect INHERITED; |
272 }; | 272 }; |
273 | 273 |
274 /////////////////////////////////////////////////////////////////////////////// | 274 /////////////////////////////////////////////////////////////////////////////// |
275 | 275 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 this->addTextureAccess(&fBackgroundAccess); | 323 this->addTextureAccess(&fBackgroundAccess); |
324 } else { | 324 } else { |
325 this->setWillReadDstColor(); | 325 this->setWillReadDstColor(); |
326 } | 326 } |
327 } | 327 } |
328 | 328 |
329 GrArithmeticEffect::~GrArithmeticEffect() { | 329 GrArithmeticEffect::~GrArithmeticEffect() { |
330 } | 330 } |
331 | 331 |
332 bool GrArithmeticEffect::onIsEqual(const GrEffect& sBase) const { | 332 bool GrArithmeticEffect::onIsEqual(const GrEffect& sBase) const { |
333 const GrArithmeticEffect& s = CastEffect<GrArithmeticEffect>(sBase); | 333 const GrArithmeticEffect& s = GrEffect::CastEffect<GrArithmeticEffect>(sBase
); |
334 return fK1 == s.fK1 && | 334 return fK1 == s.fK1 && |
335 fK2 == s.fK2 && | 335 fK2 == s.fK2 && |
336 fK3 == s.fK3 && | 336 fK3 == s.fK3 && |
337 fK4 == s.fK4 && | 337 fK4 == s.fK4 && |
338 fEnforcePMColor == s.fEnforcePMColor && | 338 fEnforcePMColor == s.fEnforcePMColor && |
339 backgroundTexture() == s.backgroundTexture(); | 339 backgroundTexture() == s.backgroundTexture(); |
340 } | 340 } |
341 | 341 |
342 const GrBackendEffectFactory& GrArithmeticEffect::getFactory() const { | 342 const GrBackendEffectFactory& GrArithmeticEffect::getFactory() const { |
343 return GrTBackendEffectFactory<GrArithmeticEffect>::getInstance(); | 343 return GrTBackendEffectFactory<GrArithmeticEffect>::getInstance(); |
344 } | 344 } |
345 | 345 |
346 void GrArithmeticEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { | 346 void GrArithmeticEffect::getConstantColorComponents(GrColor* color, uint32_t* va
lidFlags) const { |
347 // TODO: optimize this | 347 // TODO: optimize this |
348 *validFlags = 0; | 348 *validFlags = 0; |
349 } | 349 } |
350 | 350 |
351 /////////////////////////////////////////////////////////////////////////////// | 351 /////////////////////////////////////////////////////////////////////////////// |
352 | 352 |
353 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendEffectFactory& factory
, | 353 GrGLArithmeticEffect::GrGLArithmeticEffect(const GrBackendEffectFactory& factory
, |
354 const GrDrawEffect& drawEffect) | 354 const GrEffect& effect) |
355 : INHERITED(factory), | 355 : INHERITED(factory), |
356 fEnforcePMColor(true) { | 356 fEnforcePMColor(true) { |
357 } | 357 } |
358 | 358 |
359 GrGLArithmeticEffect::~GrGLArithmeticEffect() { | 359 GrGLArithmeticEffect::~GrGLArithmeticEffect() { |
360 } | 360 } |
361 | 361 |
362 void GrGLArithmeticEffect::emitCode(GrGLProgramBuilder* builder, | 362 void GrGLArithmeticEffect::emitCode(GrGLProgramBuilder* builder, |
363 const GrDrawEffect& drawEffect, | 363 const GrEffect& effect, |
364 const GrEffectKey& key, | 364 const GrEffectKey& key, |
365 const char* outputColor, | 365 const char* outputColor, |
366 const char* inputColor, | 366 const char* inputColor, |
367 const TransformedCoordsArray& coords, | 367 const TransformedCoordsArray& coords, |
368 const TextureSamplerArray& samplers) { | 368 const TextureSamplerArray& samplers) { |
369 | 369 |
370 GrTexture* backgroundTex = drawEffect.castEffect<GrArithmeticEffect>().backg
roundTexture(); | 370 GrTexture* backgroundTex = GrEffect::CastEffect<GrArithmeticEffect>(effect).
backgroundTexture(); |
371 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); | 371 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); |
372 const char* dstColor; | 372 const char* dstColor; |
373 if (backgroundTex) { | 373 if (backgroundTex) { |
374 fsBuilder->codeAppend("\t\tvec4 bgColor = "); | 374 fsBuilder->codeAppend("\t\tvec4 bgColor = "); |
375 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); | 375 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0]
.type()); |
376 fsBuilder->codeAppendf(";\n"); | 376 fsBuilder->codeAppendf(";\n"); |
377 dstColor = "bgColor"; | 377 dstColor = "bgColor"; |
378 } else { | 378 } else { |
379 dstColor = fsBuilder->dstColor(); | 379 dstColor = fsBuilder->dstColor(); |
380 } | 380 } |
(...skipping 20 matching lines...) Expand all Loading... |
401 | 401 |
402 fsBuilder->codeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); | 402 fsBuilder->codeAppendf("\t\t%s = %s.x * src * dst + %s.y * src + %s.z * dst
+ %s.w;\n", outputColor, kUni, kUni, kUni, kUni); |
403 fsBuilder->codeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); | 403 fsBuilder->codeAppendf("\t\t%s = clamp(%s, 0.0, 1.0);\n", outputColor, outpu
tColor); |
404 if (gUseUnpremul) { | 404 if (gUseUnpremul) { |
405 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); | 405 fsBuilder->codeAppendf("\t\t%s.rgb *= %s.a;\n", outputColor, outputColor
); |
406 } else if (fEnforcePMColor) { | 406 } else if (fEnforcePMColor) { |
407 fsBuilder->codeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); | 407 fsBuilder->codeAppendf("\t\t%s.rgb = min(%s.rgb, %s.a);\n", outputColor,
outputColor, outputColor); |
408 } | 408 } |
409 } | 409 } |
410 | 410 |
411 void GrGLArithmeticEffect::setData(const GrGLProgramDataManager& pdman, const Gr
DrawEffect& drawEffect) { | 411 void GrGLArithmeticEffect::setData(const GrGLProgramDataManager& pdman, const Gr
Effect& effect) { |
412 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); | 412 const GrArithmeticEffect& arith = GrEffect::CastEffect<GrArithmeticEffect>(e
ffect); |
413 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); | 413 pdman.set4f(fKUni, arith.k1(), arith.k2(), arith.k3(), arith.k4()); |
414 fEnforcePMColor = arith.enforcePMColor(); | 414 fEnforcePMColor = arith.enforcePMColor(); |
415 } | 415 } |
416 | 416 |
417 void GrGLArithmeticEffect::GenKey(const GrDrawEffect& drawEffect, | 417 void GrGLArithmeticEffect::GenKey(const GrEffect& effect, |
418 const GrGLCaps&, GrEffectKeyBuilder* b) { | 418 const GrGLCaps&, GrEffectKeyBuilder* b) { |
419 const GrArithmeticEffect& arith = drawEffect.castEffect<GrArithmeticEffect>(
); | 419 const GrArithmeticEffect& arith = GrEffect::CastEffect<GrArithmeticEffect>(e
ffect); |
420 uint32_t key = arith.enforcePMColor() ? 1 : 0; | 420 uint32_t key = arith.enforcePMColor() ? 1 : 0; |
421 if (arith.backgroundTexture()) { | 421 if (arith.backgroundTexture()) { |
422 key |= 2; | 422 key |= 2; |
423 } | 423 } |
424 b->add32(key); | 424 b->add32(key); |
425 } | 425 } |
426 | 426 |
427 GrEffect* GrArithmeticEffect::TestCreate(SkRandom* rand, | 427 GrEffect* GrArithmeticEffect::TestCreate(SkRandom* rand, |
428 GrContext*, | 428 GrContext*, |
429 const GrDrawTargetCaps&, | 429 const GrDrawTargetCaps&, |
(...skipping 19 matching lines...) Expand all Loading... |
449 background); | 449 background); |
450 } | 450 } |
451 return true; | 451 return true; |
452 } | 452 } |
453 | 453 |
454 #endif | 454 #endif |
455 | 455 |
456 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) | 456 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkArithmeticMode) |
457 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) | 457 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkArithmeticMode_scalar) |
458 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END | 458 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END |
OLD | NEW |