| 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" |
| 11 #include "SkUnPreMultiply.h" | 11 #include "SkUnPreMultiply.h" |
| 12 #include "SkColorPriv.h" | 12 #include "SkColorPriv.h" |
| 13 #if SK_SUPPORT_GPU | 13 #if SK_SUPPORT_GPU |
| 14 #include "GrContext.h" | 14 #include "GrContext.h" |
| 15 #include "GrCoordTransform.h" | 15 #include "GrCoordTransform.h" |
| 16 #include "GrInvariantOutput.h" |
| 16 #include "gl/GrGLProcessor.h" | 17 #include "gl/GrGLProcessor.h" |
| 17 #include "gl/builders/GrGLProgramBuilder.h" | 18 #include "gl/builders/GrGLProgramBuilder.h" |
| 18 #include "GrTBackendProcessorFactory.h" | 19 #include "GrTBackendProcessorFactory.h" |
| 19 #endif | 20 #endif |
| 20 | 21 |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most | 24 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at
most |
| 24 | 25 |
| 25 template<SkDisplacementMapEffect::ChannelSelectorType type> | 26 template<SkDisplacementMapEffect::ChannelSelectorType type> |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 347 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const | 348 SkDisplacementMapEffect::ChannelSelectorType yChannelSelector() const |
| 348 { return fYChannelSelector; } | 349 { return fYChannelSelector; } |
| 349 const SkVector& scale() const { return fScale; } | 350 const SkVector& scale() const { return fScale; } |
| 350 | 351 |
| 351 typedef GrGLDisplacementMapEffect GLProcessor; | 352 typedef GrGLDisplacementMapEffect GLProcessor; |
| 352 static const char* Name() { return "DisplacementMap"; } | 353 static const char* Name() { return "DisplacementMap"; } |
| 353 | 354 |
| 354 private: | 355 private: |
| 355 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; | 356 virtual bool onIsEqual(const GrFragmentProcessor&) const SK_OVERRIDE; |
| 356 | 357 |
| 357 virtual void onComputeInvariantOutput(InvariantOutput* inout) const SK_OVERR
IDE; | 358 virtual void onComputeInvariantOutput(GrInvariantOutput* inout) const SK_OVE
RRIDE; |
| 358 | 359 |
| 359 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, | 360 GrDisplacementMapEffect(SkDisplacementMapEffect::ChannelSelectorType xChanne
lSelector, |
| 360 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, | 361 SkDisplacementMapEffect::ChannelSelectorType yChanne
lSelector, |
| 361 const SkVector& scale, | 362 const SkVector& scale, |
| 362 GrTexture* displacement, const SkMatrix& offsetMatri
x, | 363 GrTexture* displacement, const SkMatrix& offsetMatri
x, |
| 363 GrTexture* color); | 364 GrTexture* color); |
| 364 | 365 |
| 365 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; | 366 GR_DECLARE_FRAGMENT_PROCESSOR_TEST; |
| 366 | 367 |
| 367 GrCoordTransform fDisplacementTransform; | 368 GrCoordTransform fDisplacementTransform; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 482 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); | 483 const GrDisplacementMapEffect& s = sBase.cast<GrDisplacementMapEffect>(); |
| 483 return fXChannelSelector == s.fXChannelSelector && | 484 return fXChannelSelector == s.fXChannelSelector && |
| 484 fYChannelSelector == s.fYChannelSelector && | 485 fYChannelSelector == s.fYChannelSelector && |
| 485 fScale == s.fScale; | 486 fScale == s.fScale; |
| 486 } | 487 } |
| 487 | 488 |
| 488 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c
onst { | 489 const GrBackendFragmentProcessorFactory& GrDisplacementMapEffect::getFactory() c
onst { |
| 489 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta
nce(); | 490 return GrTBackendFragmentProcessorFactory<GrDisplacementMapEffect>::getInsta
nce(); |
| 490 } | 491 } |
| 491 | 492 |
| 492 void GrDisplacementMapEffect::onComputeInvariantOutput(InvariantOutput* inout) c
onst { | 493 void GrDisplacementMapEffect::onComputeInvariantOutput(GrInvariantOutput* inout)
const { |
| 493 // Any displacement offset bringing a pixel out of bounds will output a colo
r of (0,0,0,0), | 494 // Any displacement offset bringing a pixel out of bounds will output a colo
r of (0,0,0,0), |
| 494 // so the only way we'd get a constant alpha is if the input color image has
a constant alpha | 495 // so the only way we'd get a constant alpha is if the input color image has
a constant alpha |
| 495 // and no displacement offset push any texture coordinates out of bounds OR
if the constant | 496 // and no displacement offset push any texture coordinates out of bounds OR
if the constant |
| 496 // alpha is 0. Since this isn't trivial to compute at this point, let's assu
me the output is | 497 // alpha is 0. Since this isn't trivial to compute at this point, let's assu
me the output is |
| 497 // not of constant color when a displacement effect is applied. | 498 // not of constant color when a displacement effect is applied. |
| 498 inout->setToUnknown(InvariantOutput::kWillNot_ReadInput); | 499 inout->setToUnknown(GrInvariantOutput::kWillNot_ReadInput); |
| 499 } | 500 } |
| 500 | 501 |
| 501 /////////////////////////////////////////////////////////////////////////////// | 502 /////////////////////////////////////////////////////////////////////////////// |
| 502 | 503 |
| 503 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); | 504 GR_DEFINE_FRAGMENT_PROCESSOR_TEST(GrDisplacementMapEffect); |
| 504 | 505 |
| 505 GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(SkRandom* random, | 506 GrFragmentProcessor* GrDisplacementMapEffect::TestCreate(SkRandom* random, |
| 506 GrContext*, | 507 GrContext*, |
| 507 const GrDrawTargetCaps&, | 508 const GrDrawTargetCaps&, |
| 508 GrTexture* textures[]) { | 509 GrTexture* textures[]) { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 629 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 630 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 630 const GrGLCaps&, GrProcessorKeyBuilder* b
) { | 631 const GrGLCaps&, GrProcessorKeyBuilder* b
) { |
| 631 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 632 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 632 | 633 |
| 633 uint32_t xKey = displacementMap.xChannelSelector(); | 634 uint32_t xKey = displacementMap.xChannelSelector(); |
| 634 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 635 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 635 | 636 |
| 636 b->add32(xKey | yKey); | 637 b->add32(xKey | yKey); |
| 637 } | 638 } |
| 638 #endif | 639 #endif |
| OLD | NEW |