| 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 | 9 |
| 10 #include "SkBitmap.h" | 10 #include "SkBitmap.h" |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 544 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); | 544 kVec2f_GrSLType, kDefault_GrSLP
recision, "Scale"); |
| 545 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); | 545 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni); |
| 546 const char* dColor = "dColor"; | 546 const char* dColor = "dColor"; |
| 547 const char* cCoords = "cCoords"; | 547 const char* cCoords = "cCoords"; |
| 548 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use | 548 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa
t, use |
| 549 // a number smaller than that to approximate
0, but | 549 // a number smaller than that to approximate
0, but |
| 550 // leave room for 32-bit float GPU rounding e
rrors. | 550 // leave room for 32-bit float GPU rounding e
rrors. |
| 551 | 551 |
| 552 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; | 552 GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder; |
| 553 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); | 553 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); |
| 554 fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str
(), | 554 |
| 555 args.fCoords[0].getType()); | 555 fragBuilder->appendTextureLookup(args.fUniformHandler->getSampler(args.fTexS
amplers[0]), |
| 556 args.fCoords[0].c_str(), |
| 557 args.fCoords[0].getType()); |
| 556 fragBuilder->codeAppend(";\n"); | 558 fragBuilder->codeAppend(";\n"); |
| 557 | 559 |
| 558 // Unpremultiply the displacement | 560 // Unpremultiply the displacement |
| 559 fragBuilder->codeAppendf( | 561 fragBuilder->codeAppendf( |
| 560 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, | 562 "\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);"
, |
| 561 dColor, dColor, nearZero, dColor, dColor); | 563 dColor, dColor, nearZero, dColor, dColor); |
| 562 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); | 564 SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1); |
| 563 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", | 565 fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", |
| 564 cCoords, coords2D.c_str(), scaleUni, dColor); | 566 cCoords, coords2D.c_str(), scaleUni, dColor); |
| 565 | 567 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 SkDEBUGFAIL("Unknown Y channel selector"); | 601 SkDEBUGFAIL("Unknown Y channel selector"); |
| 600 } | 602 } |
| 601 fragBuilder->codeAppend("-vec2(0.5));\t\t"); | 603 fragBuilder->codeAppend("-vec2(0.5));\t\t"); |
| 602 | 604 |
| 603 fGLDomain.sampleTexture(fragBuilder, | 605 fGLDomain.sampleTexture(fragBuilder, |
| 604 args.fUniformHandler, | 606 args.fUniformHandler, |
| 605 args.fGLSLCaps, | 607 args.fGLSLCaps, |
| 606 domain, | 608 domain, |
| 607 args.fOutputColor, | 609 args.fOutputColor, |
| 608 SkString(cCoords), | 610 SkString(cCoords), |
| 609 args.fTexSamplers[1]); | 611 args.fUniformHandler->getSampler(args.fTexSamplers[1
])); |
| 610 fragBuilder->codeAppend(";\n"); | 612 fragBuilder->codeAppend(";\n"); |
| 611 } | 613 } |
| 612 | 614 |
| 613 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, | 615 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, |
| 614 const GrProcessor& proc) { | 616 const GrProcessor& proc) { |
| 615 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 617 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 616 GrTexture* colorTex = displacementMap.texture(1); | 618 GrTexture* colorTex = displacementMap.texture(1); |
| 617 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); | 619 SkScalar scaleX = displacementMap.scale().fX / colorTex->width(); |
| 618 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); | 620 SkScalar scaleY = displacementMap.scale().fY / colorTex->height(); |
| 619 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), | 621 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), |
| 620 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? | 622 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? |
| 621 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); | 623 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); |
| 622 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); | 624 fGLDomain.setData(pdman, displacementMap.domain(), colorTex->origin()); |
| 623 } | 625 } |
| 624 | 626 |
| 625 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, | 627 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, |
| 626 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { | 628 const GrGLSLCaps&, GrProcessorKeyBuilder*
b) { |
| 627 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); | 629 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap
Effect>(); |
| 628 | 630 |
| 629 uint32_t xKey = displacementMap.xChannelSelector(); | 631 uint32_t xKey = displacementMap.xChannelSelector(); |
| 630 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; | 632 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit
s; |
| 631 | 633 |
| 632 b->add32(xKey | yKey); | 634 b->add32(xKey | yKey); |
| 633 } | 635 } |
| 634 #endif | 636 #endif |
| OLD | NEW |