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

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

Issue 1490283004: Create GLSLUniformHandler class for gpu backend (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: clean up public api of uniformhandler Created 5 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 | « src/effects/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.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 "SkDevice.h" 9 #include "SkDevice.h"
10 #include "SkReadBuffer.h" 10 #include "SkReadBuffer.h"
11 #include "SkWriteBuffer.h" 11 #include "SkWriteBuffer.h"
12 #include "SkUnPreMultiply.h" 12 #include "SkUnPreMultiply.h"
13 #include "SkColorPriv.h" 13 #include "SkColorPriv.h"
14 #if SK_SUPPORT_GPU 14 #if SK_SUPPORT_GPU
15 #include "GrContext.h" 15 #include "GrContext.h"
16 #include "GrDrawContext.h" 16 #include "GrDrawContext.h"
17 #include "GrCoordTransform.h" 17 #include "GrCoordTransform.h"
18 #include "GrInvariantOutput.h" 18 #include "GrInvariantOutput.h"
19 #include "effects/GrTextureDomain.h" 19 #include "effects/GrTextureDomain.h"
20 #include "glsl/GrGLSLFragmentProcessor.h" 20 #include "glsl/GrGLSLFragmentProcessor.h"
21 #include "glsl/GrGLSLFragmentShaderBuilder.h" 21 #include "glsl/GrGLSLFragmentShaderBuilder.h"
22 #include "glsl/GrGLSLProgramBuilder.h"
23 #include "glsl/GrGLSLProgramDataManager.h" 22 #include "glsl/GrGLSLProgramDataManager.h"
23 #include "glsl/GrGLSLUniformHandler.h"
24 #endif 24 #endif
25 25
26 namespace { 26 namespace {
27 27
28 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most 28 #define kChannelSelectorKeyBits 3; // Max value is 4, so 3 bits are required at most
29 29
30 template<SkDisplacementMapEffect::ChannelSelectorType type> 30 template<SkDisplacementMapEffect::ChannelSelectorType type>
31 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) { 31 uint32_t getValue(SkColor, const SkUnPreMultiply::Scale*) {
32 SkDEBUGFAIL("Unknown channel selector"); 32 SkDEBUGFAIL("Unknown channel selector");
33 return 0; 33 return 0;
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector()) 542 : fXChannelSelector(proc.cast<GrDisplacementMapEffect>().xChannelSelector())
543 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) { 543 , fYChannelSelector(proc.cast<GrDisplacementMapEffect>().yChannelSelector()) {
544 } 544 }
545 545
546 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() { 546 GrGLDisplacementMapEffect::~GrGLDisplacementMapEffect() {
547 } 547 }
548 548
549 void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) { 549 void GrGLDisplacementMapEffect::emitCode(EmitArgs& args) {
550 const GrTextureDomain& domain = args.fFp.cast<GrDisplacementMapEffect>().dom ain(); 550 const GrTextureDomain& domain = args.fFp.cast<GrDisplacementMapEffect>().dom ain();
551 551
552 fScaleUni = args.fBuilder->addUniform(GrGLSLProgramBuilder::kFragment_Visibi lity, 552 fScaleUni = args.fUniformHandler->addUniform(GrGLSLUniformHandler::kFragment _Visibility,
553 kVec2f_GrSLType, kDefault_GrSLPrecisio n, "Scale"); 553 kVec2f_GrSLType, kDefault_GrSLP recision, "Scale");
554 const char* scaleUni = args.fBuilder->getUniformCStr(fScaleUni); 554 const char* scaleUni = args.fUniformHandler->getUniformCStr(fScaleUni);
555 const char* dColor = "dColor"; 555 const char* dColor = "dColor";
556 const char* cCoords = "cCoords"; 556 const char* cCoords = "cCoords";
557 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use 557 const char* nearZero = "1e-6"; // Since 6.10352e−5 is the smallest half floa t, use
558 // a number smaller than that to approximate 0, but 558 // a number smaller than that to approximate 0, but
559 // leave room for 32-bit float GPU rounding e rrors. 559 // leave room for 32-bit float GPU rounding e rrors.
560 560
561 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder; 561 GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
562 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor); 562 fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
563 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(), 563 fragBuilder->appendTextureLookup(args.fSamplers[0], args.fCoords[0].c_str(),
564 args.fCoords[0].getType()); 564 args.fCoords[0].getType());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
603 case SkDisplacementMapEffect::kA_ChannelSelectorType: 603 case SkDisplacementMapEffect::kA_ChannelSelectorType:
604 fragBuilder->codeAppend("a"); 604 fragBuilder->codeAppend("a");
605 break; 605 break;
606 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType: 606 case SkDisplacementMapEffect::kUnknown_ChannelSelectorType:
607 default: 607 default:
608 SkDEBUGFAIL("Unknown Y channel selector"); 608 SkDEBUGFAIL("Unknown Y channel selector");
609 } 609 }
610 fragBuilder->codeAppend("-vec2(0.5));\t\t"); 610 fragBuilder->codeAppend("-vec2(0.5));\t\t");
611 611
612 fGLDomain.sampleTexture(fragBuilder, 612 fGLDomain.sampleTexture(fragBuilder,
613 args.fUniformHandler,
613 args.fGLSLCaps, 614 args.fGLSLCaps,
614 domain, 615 domain,
615 args.fOutputColor, 616 args.fOutputColor,
616 SkString(cCoords), 617 SkString(cCoords),
617 args.fSamplers[1]); 618 args.fSamplers[1]);
618 fragBuilder->codeAppend(";\n"); 619 fragBuilder->codeAppend(";\n");
619 } 620 }
620 621
621 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman, 622 void GrGLDisplacementMapEffect::onSetData(const GrGLSLProgramDataManager& pdman,
622 const GrProcessor& proc) { 623 const GrProcessor& proc) {
(...skipping 11 matching lines...) Expand all
634 const GrGLSLCaps&, GrProcessorKeyBuilder* b) { 635 const GrGLSLCaps&, GrProcessorKeyBuilder* b) {
635 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>(); 636 const GrDisplacementMapEffect& displacementMap = proc.cast<GrDisplacementMap Effect>();
636 637
637 uint32_t xKey = displacementMap.xChannelSelector(); 638 uint32_t xKey = displacementMap.xChannelSelector();
638 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s; 639 uint32_t yKey = displacementMap.yChannelSelector() << kChannelSelectorKeyBit s;
639 640
640 b->add32(xKey | yKey); 641 b->add32(xKey | yKey);
641 } 642 }
642 #endif 643 #endif
643 644
OLDNEW
« no previous file with comments | « src/effects/SkColorMatrixFilter.cpp ('k') | src/effects/SkLightingImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698