Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/effects/SkDisplacementMapEffect.cpp

Issue 551253004: Changes to remove program effects builder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 const char* scaleUni = builder->getUniformCStr(fScaleUni); 555 const char* scaleUni = builder->getUniformCStr(fScaleUni);
556 const char* dColor = "dColor"; 556 const char* dColor = "dColor";
557 const char* cCoords = "cCoords"; 557 const char* cCoords = "cCoords";
558 const char* outOfBounds = "outOfBounds"; 558 const char* outOfBounds = "outOfBounds";
559 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use 559 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use
560 // a number smaller than that to approximate 0, but 560 // a number smaller than that to approximate 0, but
561 // leave room for 32-bit float GPU rounding e rrors. 561 // leave room for 32-bit float GPU rounding e rrors.
562 562
563 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 563 GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
564 fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor); 564 fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
565 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].typ e()); 565 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].get Type());
566 fsBuilder->codeAppend(";\n"); 566 fsBuilder->codeAppend(";\n");
567 567
568 // Unpremultiply the displacement 568 // Unpremultiply the displacement
569 fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);", 569 fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
570 dColor, dColor, nearZero, dColor, dColor); 570 dColor, dColor, nearZero, dColor, dColor);
571 571
572 fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", 572 fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
573 cCoords, coords[1].c_str(), scaleUni, dColor); 573 cCoords, coords[1].c_str(), scaleUni, dColor);
574 574
575 switch (fXChannelSelector) { 575 switch (fXChannelSelector) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 SkDEBUGFAIL("Unknown Y channel selector"); 608 SkDEBUGFAIL("Unknown Y channel selector");
609 } 609 }
610 fsBuilder->codeAppend("-vec2(0.5));\t\t"); 610 fsBuilder->codeAppend("-vec2(0.5));\t\t");
611 611
612 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and 612 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and
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].getType());
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 GrEffect& effect) { 623 const GrEffect& effect) {
624 const GrDisplacementMapEffect& displacementMap = effect.cast<GrDisplacementM apEffect>(); 624 const GrDisplacementMapEffect& displacementMap = effect.cast<GrDisplacementM apEffect>();
625 GrTexture* colorTex = displacementMap.texture(1); 625 GrTexture* colorTex = displacementMap.texture(1);
626 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo rTex->width())); 626 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo rTex->width()));
627 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo rTex->height())); 627 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo rTex->height()));
628 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), 628 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
629 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? 629 colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
630 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); 630 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
631 } 631 }
632 632
633 void GrGLDisplacementMapEffect::GenKey(const GrEffect& effect, 633 void GrGLDisplacementMapEffect::GenKey(const GrEffect& effect,
634 const GrGLCaps&, GrEffectKeyBuilder* b) { 634 const GrGLCaps&, GrEffectKeyBuilder* b) {
635 const GrDisplacementMapEffect& displacementMap = effect.cast<GrDisplacementM apEffect>(); 635 const GrDisplacementMapEffect& displacementMap = effect.cast<GrDisplacementM apEffect>();
636 636
637 uint32_t xKey = displacementMap.xChannelSelector(); 637 uint32_t xKey = displacementMap.xChannelSelector();
638 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 638 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
639 639
640 b->add32(xKey | yKey); 640 b->add32(xKey | yKey);
641 } 641 }
642 #endif 642 #endif
OLDNEW
« no previous file with comments | « src/effects/SkArithmeticMode.cpp ('k') | src/effects/gradients/SkTwoPointConicalGradient_gpu.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698