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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 *dst = bounds; | 293 *dst = bounds; |
294 return true; | 294 return true; |
295 } | 295 } |
296 | 296 |
297 /////////////////////////////////////////////////////////////////////////////// | 297 /////////////////////////////////////////////////////////////////////////////// |
298 | 298 |
299 #if SK_SUPPORT_GPU | 299 #if SK_SUPPORT_GPU |
300 class GrGLDisplacementMapEffect : public GrGLEffect { | 300 class GrGLDisplacementMapEffect : public GrGLEffect { |
301 public: | 301 public: |
302 GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory, | 302 GrGLDisplacementMapEffect(const GrBackendEffectFactory& factory, |
303 const GrDrawEffect& drawEffect); | 303 const GrEffect& effect); |
304 virtual ~GrGLDisplacementMapEffect(); | 304 virtual ~GrGLDisplacementMapEffect(); |
305 | 305 |
306 virtual void emitCode(GrGLProgramBuilder*, | 306 virtual void emitCode(GrGLProgramBuilder*, |
307 const GrDrawEffect&, | 307 const GrEffect&, |
308 const GrEffectKey&, | 308 const GrEffectKey&, |
309 const char* outputColor, | 309 const char* outputColor, |
310 const char* inputColor, | 310 const char* inputColor, |
311 const TransformedCoordsArray&, | 311 const TransformedCoordsArray&, |
312 const TextureSamplerArray&) SK_OVERRIDE; | 312 const TextureSamplerArray&) SK_OVERRIDE; |
313 | 313 |
314 static inline void GenKey(const GrDrawEffect&, const GrGLCaps&, GrEffectKeyB
uilder*); | 314 static inline void GenKey(const GrEffect&, const GrGLCaps&, GrEffectKeyBuild
er*); |
315 | 315 |
316 virtual void setData(const GrGLProgramDataManager&, const GrDrawEffect&) SK_
OVERRIDE; | 316 virtual void setData(const GrGLProgramDataManager&, const GrEffect&) SK_OVER
RIDE; |
317 | 317 |
318 private: | 318 private: |
319 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; | 319 SkDisplacementMapEffect::ChannelSelectorType fXChannelSelector; |
320 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; | 320 SkDisplacementMapEffect::ChannelSelectorType fYChannelSelector; |
321 GrGLProgramDataManager::UniformHandle fScaleUni; | 321 GrGLProgramDataManager::UniformHandle fScaleUni; |
322 | 322 |
323 typedef GrGLEffect INHERITED; | 323 typedef GrGLEffect INHERITED; |
324 }; | 324 }; |
325 | 325 |
326 /////////////////////////////////////////////////////////////////////////////// | 326 /////////////////////////////////////////////////////////////////////////////// |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 476 this->setWillNotUseInputColor(); |
477 } | 477 } |
478 | 478 |
479 GrDisplacementMapEffect::~GrDisplacementMapEffect() { | 479 GrDisplacementMapEffect::~GrDisplacementMapEffect() { |
480 } | 480 } |
481 | 481 |
482 bool GrDisplacementMapEffect::onIsEqual(const GrEffect& sBase) const { | 482 bool GrDisplacementMapEffect::onIsEqual(const GrEffect& sBase) const { |
483 const GrDisplacementMapEffect& s = CastEffect<GrDisplacementMapEffect>(sBase
); | 483 const GrDisplacementMapEffect& s = GrEffect::CastEffect<GrDisplacementMapEff
ect>(sBase); |
484 return fDisplacementAccess.getTexture() == s.fDisplacementAccess.getTexture(
) && | 484 return fDisplacementAccess.getTexture() == s.fDisplacementAccess.getTexture(
) && |
485 fColorAccess.getTexture() == s.fColorAccess.getTexture() && | 485 fColorAccess.getTexture() == s.fColorAccess.getTexture() && |
486 fXChannelSelector == s.fXChannelSelector && | 486 fXChannelSelector == s.fXChannelSelector && |
487 fYChannelSelector == s.fYChannelSelector && | 487 fYChannelSelector == s.fYChannelSelector && |
488 fScale == s.fScale; | 488 fScale == s.fScale; |
489 } | 489 } |
490 | 490 |
491 const GrBackendEffectFactory& GrDisplacementMapEffect::getFactory() const { | 491 const GrBackendEffectFactory& GrDisplacementMapEffect::getFactory() const { |
492 return GrTBackendEffectFactory<GrDisplacementMapEffect>::getInstance(); | 492 return GrTBackendEffectFactory<GrDisplacementMapEffect>::getInstance(); |
493 } | 493 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 random->nextRangeScalar(0, 100.0f)); | 525 random->nextRangeScalar(0, 100.0f)); |
526 | 526 |
527 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, | 527 return GrDisplacementMapEffect::Create(xChannelSelector, yChannelSelector, s
cale, |
528 textures[texIdxDispl], SkMatrix::I(), | 528 textures[texIdxDispl], SkMatrix::I(), |
529 textures[texIdxColor]); | 529 textures[texIdxColor]); |
530 } | 530 } |
531 | 531 |
532 /////////////////////////////////////////////////////////////////////////////// | 532 /////////////////////////////////////////////////////////////////////////////// |
533 | 533 |
534 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactor
y& factory, | 534 GrGLDisplacementMapEffect::GrGLDisplacementMapEffect(const GrBackendEffectFactor
y& factory, |
535 const GrDrawEffect& drawEff
ect) | 535 const GrEffect& effect) |
536 : INHERITED(factory) | 536 : INHERITED(factory) |
537 , fXChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().xChanne
lSelector()) | 537 , fXChannelSelector(GrEffect::CastEffect<GrDisplacementMapEffect>(effect).xC
hannelSelector()) |
538 , fYChannelSelector(drawEffect.castEffect<GrDisplacementMapEffect>().yChanne
lSelector()) { | 538 , fYChannelSelector(GrEffect::CastEffect<GrDisplacementMapEffect>(effect).yC
hannelSelector()) { |
539 } | 539 } |
540 | 540 |
541 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { | 541 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { |
542 } | 542 } |
543 | 543 |
544 void GrGLDisplacementMapEffect::emitCode(GrGLProgramBuilder* builder, | 544 void GrGLDisplacementMapEffect::emitCode(GrGLProgramBuilder* builder, |
545 const GrDrawEffect&, | 545 const GrEffect&, |
546 const GrEffectKey& key, | 546 const GrEffectKey& key, |
547 const char* outputColor, | 547 const char* outputColor, |
548 const char* inputColor, | 548 const char* inputColor, |
549 const TransformedCoordsArray& coords, | 549 const TransformedCoordsArray& coords, |
550 const TextureSamplerArray& samplers) { | 550 const TextureSamplerArray& samplers) { |
551 sk_ignore_unused_variable(inputColor); | 551 sk_ignore_unused_variable(inputColor); |
552 | 552 |
553 fScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, | 553 fScaleUni = builder->addUniform(GrGLProgramBuilder::kFragment_Visibility, |
554 kVec2f_GrSLType, "Scale"); | 554 kVec2f_GrSLType, "Scale"); |
555 const char* scaleUni = builder->getUniformCStr(fScaleUni); | 555 const char* scaleUni = builder->getUniformCStr(fScaleUni); |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 // a 0 border color instead of computing if cCoords is out of bounds
here. | 613 // a 0 border color instead of computing if cCoords is out of bounds
here. |
614 fsBuilder->codeAppendf( | 614 fsBuilder->codeAppendf( |
615 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);
\t\t", | 615 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0);
\t\t", |
616 outOfBounds, cCoords, cCoords, cCoords, cCoords); | 616 outOfBounds, cCoords, cCoords, cCoords, cCoords); |
617 fsBuilder->codeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); | 617 fsBuilder->codeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); |
618 fsBuilder->appendTextureLookup(samplers[1], cCoords, coords[1].type()); | 618 fsBuilder->appendTextureLookup(samplers[1], cCoords, coords[1].type()); |
619 fsBuilder->codeAppend(";\n"); | 619 fsBuilder->codeAppend(";\n"); |
620 } | 620 } |
621 | 621 |
622 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, | 622 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, |
623 const GrDrawEffect& drawEffect) { | 623 const GrEffect& effect) { |
624 const GrDisplacementMapEffect& displacementMap = | 624 const GrDisplacementMapEffect& displacementMap = |
625 drawEffect.castEffect<GrDisplacementMapEffect>(); | 625 GrEffect::CastEffect<GrDisplacementMapEffect>(effect); |
626 GrTexture* colorTex = displacementMap.texture(1); | 626 GrTexture* colorTex = displacementMap.texture(1); |
627 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo
rTex->width())); | 627 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo
rTex->width())); |
628 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo
rTex->height())); | 628 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo
rTex->height())); |
629 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 629 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
630 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 630 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
631 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 631 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
632 } | 632 } |
633 | 633 |
634 void GrGLDisplacementMapEffect::GenKey(const GrDrawEffect& drawEffect, | 634 void GrGLDisplacementMapEffect::GenKey(const GrEffect& effect, |
635 const GrGLCaps&, GrEffectKeyBuilder* b) { | 635 const GrGLCaps&, GrEffectKeyBuilder* b) { |
636 const GrDisplacementMapEffect& displacementMap = | 636 const GrDisplacementMapEffect& displacementMap = |
637 drawEffect.castEffect<GrDisplacementMapEffect>(); | 637 GrEffect::CastEffect<GrDisplacementMapEffect>(effect); |
638 | 638 |
639 uint32_t xKey = displacementMap.xChannelSelector(); | 639 uint32_t xKey = displacementMap.xChannelSelector(); |
640 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 640 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
641 | 641 |
642 b->add32(xKey | yKey); | 642 b->add32(xKey | yKey); |
643 } | 643 } |
644 #endif | 644 #endif |
OLD | NEW |