| 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 "SkDisplacementMapEffect.h" | 8 #include "SkDisplacementMapEffect.h" |
| 9 #include "SkReadBuffer.h" | 9 #include "SkReadBuffer.h" |
| 10 #include "SkWriteBuffer.h" | 10 #include "SkWriteBuffer.h" |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 466 , fDisplacementAccess(displacement) | 466 , fDisplacementAccess(displacement) |
| 467 , fColorTransform(kLocal_GrCoordSet, color) | 467 , fColorTransform(kLocal_GrCoordSet, color) |
| 468 , fColorAccess(color) | 468 , fColorAccess(color) |
| 469 , fXChannelSelector(xChannelSelector) | 469 , fXChannelSelector(xChannelSelector) |
| 470 , fYChannelSelector(yChannelSelector) | 470 , fYChannelSelector(yChannelSelector) |
| 471 , fScale(scale) { | 471 , fScale(scale) { |
| 472 this->addCoordTransform(&fDisplacementTransform); | 472 this->addCoordTransform(&fDisplacementTransform); |
| 473 this->addTextureAccess(&fDisplacementAccess); | 473 this->addTextureAccess(&fDisplacementAccess); |
| 474 this->addCoordTransform(&fColorTransform); | 474 this->addCoordTransform(&fColorTransform); |
| 475 this->addTextureAccess(&fColorAccess); | 475 this->addTextureAccess(&fColorAccess); |
| 476 this->setWillNotUseInputColor(); | |
| 477 } | 476 } |
| 478 | 477 |
| 479 GrDisplacementMapEffect::~GrDisplacementMapEffect() { | 478 GrDisplacementMapEffect::~GrDisplacementMapEffect() { |
| 480 } | 479 } |
| 481 | 480 |
| 482 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ | 481 bool GrDisplacementMapEffect::onIsEqual(const GrFragmentProcessor& sBase) const
{ |
| 483 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); | 482 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); |
| 484 return fDisplacementAccess.getTexture() == s.fDisplacementAccess.getTexture(
) && | 483 return fDisplacementAccess.getTexture() == s.fDisplacementAccess.getTexture(
) && |
| 485 fColorAccess.getTexture() == s.fColorAccess.getTexture() && | 484 fColorAccess.getTexture() == s.fColorAccess.getTexture() && |
| 486 fXChannelSelector == s.fXChannelSelector && | 485 fXChannelSelector == s.fXChannelSelector && |
| 487 fYChannelSelector == s.fYChannelSelector && | 486 fYChannelSelector == s.fYChannelSelector && |
| 488 fScale == s.fScale; | 487 fScale == s.fScale; |
| 489 } | 488 } |
| 490 | 489 |
| 491 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c
onst { | 490 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c
onst { |
| 492 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta
nce(); | 491 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta
nce(); |
| 493 } | 492 } |
| 494 | 493 |
| 495 void GrDisplacementMapEffect::onComputeInvariantOutput(InvariantOutput* inout) c
onst { | 494 void GrDisplacementMapEffect::onComputeInvariantOutput(InvariantOutput* inout) c
onst { |
| 496 // Any displacement offset bringing a pixel out of bounds will output a colo
r of (0,0,0,0), | 495 // Any displacement offset bringing a pixel out of bounds will output a colo
r of (0,0,0,0), |
| 497 // so the only way we'd get a constant alpha is if the input color image has
a constant alpha | 496 // so the only way we'd get a constant alpha is if the input color image has
a constant alpha |
| 498 // and no displacement offset push any texture coordinates out of bounds OR
if the constant | 497 // and no displacement offset push any texture coordinates out of bounds OR
if the constant |
| 499 // alpha is 0. Since this isn't trivial to compute at this point, let's assu
me the output is | 498 // alpha is 0. Since this isn't trivial to compute at this point, let's assu
me the output is |
| 500 // not of constant color when a displacement effect is applied. | 499 // not of constant color when a displacement effect is applied. |
| 501 inout->setToUnknown(); | 500 inout->setToUnknown(InvariantOutput::kWillNot_ReadInput); |
| 502 } | 501 } |
| 503 | 502 |
| 504 /////////////////////////////////////////////////////////////////////////////// | 503 /////////////////////////////////////////////////////////////////////////////// |
| 505 | 504 |
| 506 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); | 505 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); |
| 507 | 506 |
| 508 GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(SkRandom* random, | 507 GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(SkRandom* random, |
| 509 GrContext*, | 508 GrContext*, |
| 510 const GrDrawTargetCaps&, | 509 const GrDrawTargetCaps&, |
| 511 GrTexture* textures[]) { | 510 GrTexture* textures[]) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 632 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 631 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 633 const GrGLCaps&, GrProcessorKeyBuilder* b
) { | 632 const GrGLCaps&, GrProcessorKeyBuilder* b
) { |
| 634 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 633 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 635 | 634 |
| 636 uint32_t xKey = displacementMap.xChannelSelector(); | 635 uint32_t xKey = displacementMap.xChannelSelector(); |
| 637 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 636 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 638 | 637 |
| 639 b->add32(xKey | yKey); | 638 b->add32(xKey | yKey); |
| 640 } | 639 } |
| 641 #endif | 640 #endif |
| OLD | NEW |