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

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

Issue 817853002: Remove localcoordchange functions off paint (Closed) Base URL: https://skia.googlesource.com/skia.git@local-matrix-on-gp
Patch Set: changing ignores Created 6 years 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
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 // leave room for 32-bit float GPU rounding e rrors. 557 // leave room for 32-bit float GPU rounding e rrors.
558 558
559 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder(); 559 GrGLFPFragmentBuilder* fsBuilder = builder->getFragmentShaderBuilder();
560 fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor); 560 fsBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
561 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].get Type()); 561 fsBuilder->appendTextureLookup(samplers[0], coords[0].c_str(), coords[0].get Type());
562 fsBuilder->codeAppend(";\n"); 562 fsBuilder->codeAppend(";\n");
563 563
564 // Unpremultiply the displacement 564 // Unpremultiply the displacement
565 fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);", 565 fsBuilder->codeAppendf("\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
566 dColor, dColor, nearZero, dColor, dColor); 566 dColor, dColor, nearZero, dColor, dColor);
567 567 SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 1);
568 fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.", 568 fsBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
569 cCoords, coords[1].c_str(), scaleUni, dColor); 569 cCoords, coords2D.c_str(), scaleUni, dColor);
570 570
571 switch (fXChannelSelector) { 571 switch (fXChannelSelector) {
572 case SkDisplacementMapEffect::kR_ChannelSelectorType: 572 case SkDisplacementMapEffect::kR_ChannelSelectorType:
573 fsBuilder->codeAppend("r"); 573 fsBuilder->codeAppend("r");
574 break; 574 break;
575 case SkDisplacementMapEffect::kG_ChannelSelectorType: 575 case SkDisplacementMapEffect::kG_ChannelSelectorType:
576 fsBuilder->codeAppend("g"); 576 fsBuilder->codeAppend("g");
577 break; 577 break;
578 case SkDisplacementMapEffect::kB_ChannelSelectorType: 578 case SkDisplacementMapEffect::kB_ChannelSelectorType:
579 fsBuilder->codeAppend("b"); 579 fsBuilder->codeAppend("b");
(...skipping 24 matching lines...) Expand all
604 SkDEBUGFAIL("Unknown Y channel selector"); 604 SkDEBUGFAIL("Unknown Y channel selector");
605 } 605 }
606 fsBuilder->codeAppend("-vec2(0.5));\t\t"); 606 fsBuilder->codeAppend("-vec2(0.5));\t\t");
607 607
608 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and 608 // FIXME : This can be achieved with a "clamp to border" texture repeat mode and
609 // a 0 border color instead of computing if cCoords is out of bounds here. 609 // a 0 border color instead of computing if cCoords is out of bounds here.
610 fsBuilder->codeAppendf( 610 fsBuilder->codeAppendf(
611 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0); \t\t", 611 "bool %s = (%s.x < 0.0) || (%s.y < 0.0) || (%s.x > 1.0) || (%s.y > 1.0); \t\t",
612 outOfBounds, cCoords, cCoords, cCoords, cCoords); 612 outOfBounds, cCoords, cCoords, cCoords, cCoords);
613 fsBuilder->codeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds); 613 fsBuilder->codeAppendf("%s = %s ? vec4(0.0) : ", outputColor, outOfBounds);
614 fsBuilder->appendTextureLookup(samplers[1], cCoords, coords[1].getType()); 614
615 // cCoords is always a vec2f
616 fsBuilder->appendTextureLookup(samplers[1], cCoords, kVec2f_GrSLType);
615 fsBuilder->codeAppend(";\n"); 617 fsBuilder->codeAppend(";\n");
616 } 618 }
617 619
618 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman, 620 void GrGLDisplacementMapEffect::setData(const GrGLProgramDataManager& pdman,
619 const GrProcessor& proc) { 621 const GrProcessor& proc) {
620 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 622 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
621 GrTexture* colorTex = displacementMap.texture(1); 623 GrTexture* colorTex = displacementMap.texture(1);
622 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo rTex->width())); 624 SkScalar scaleX = SkScalarDiv(displacementMap.scale().fX, SkIntToScalar(colo rTex->width()));
623 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo rTex->height())); 625 SkScalar scaleY = SkScalarDiv(displacementMap.scale().fY, SkIntToScalar(colo rTex->height()));
624 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX), 626 pdman.set2f(fScaleUni, SkScalarToFloat(scaleX),
625 colorTex->origin() == kTopLeft_GrSurfaceOrigin ? 627 colorTex->origin() == kTopLeft_GrSurfaceOrigin ?
626 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY)); 628 SkScalarToFloat(scaleY) : SkScalarToFloat(-scaleY));
627 } 629 }
628 630
629 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc, 631 void GrGLDisplacementMapEffect::GenKey(const GrProcessor& proc,
630 const GrGLCaps&, GrProcessorKeyBuilder* b ) { 632 const GrGLCaps&, GrProcessorKeyBuilder* b ) {
631 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 633 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
632 634
633 uint32_t xKey = displacementMap.xChannelSelector(); 635 uint32_t xKey = displacementMap.xChannelSelector();
634 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 636 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
635 637
636 b->add32(xKey | yKey); 638 b->add32(xKey | yKey);
637 } 639 }
638 #endif 640 #endif
639 641
OLDNEW
« no previous file with comments | « include/gpu/GrPaint.h ('k') | src/gpu/GrAAConvexPathRenderer.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698