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

Unified Diff: src/gpu/effects/GrTextureDomain.cpp

Issue 491673002: Initial refactor of shaderbuilder (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/effects/GrTextureDomain.cpp
diff --git a/src/gpu/effects/GrTextureDomain.cpp b/src/gpu/effects/GrTextureDomain.cpp
index 2bad5e8fc52e4c8b95c0529fb3175027eea06ccd..40006a3f4998d63fd0f685d741eb01651e64659a 100644
--- a/src/gpu/effects/GrTextureDomain.cpp
+++ b/src/gpu/effects/GrTextureDomain.cpp
@@ -5,11 +5,11 @@
* found in the LICENSE file.
*/
+#include "gl/builders/GrGLProgramBuilder.h"
#include "GrTextureDomain.h"
#include "GrSimpleTextureEffect.h"
#include "GrTBackendEffectFactory.h"
#include "gl/GrGLEffect.h"
-#include "gl/GrGLShaderBuilder.h"
#include "SkFloatingPoint.h"
@@ -49,23 +49,25 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder,
SkASSERT((Mode)-1 == fMode || textureDomain.mode() == fMode);
SkDEBUGCODE(fMode = textureDomain.mode();)
+ GrGLProgramBuilder* program = builder->getProgramBuilder();
+
if (textureDomain.mode() != kIgnore_Mode && !fDomainUni.isValid()) {
const char* name;
SkString uniName("TexDom");
if (textureDomain.fIndex >= 0) {
uniName.appendS32(textureDomain.fIndex);
}
- fDomainUni = builder->addUniform(GrGLShaderBuilder::kFragment_Visibility,
- kVec4f_GrSLType, uniName.c_str(), &name);
+ fDomainUni = program->addUniform(GrGLProgramBuilder::kFragment_Visibility, kVec4f_GrSLType,
+ uniName.c_str(), &name);
fDomainName = name;
}
switch (textureDomain.mode()) {
case kIgnore_Mode: {
- builder->fsCodeAppendf("\t%s = ", outColor);
- builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
+ builder->codeAppendf("\t%s = ", outColor);
+ builder->appendTextureLookupAndModulate(inModulateColor, sampler,
inCoords.c_str());
- builder->fsCodeAppend(";\n");
+ builder->codeAppend(";\n");
break;
}
case kClamp_Mode: {
@@ -73,49 +75,49 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder,
clampedCoords.appendf("\tclamp(%s, %s.xy, %s.zw)",
inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str());
- builder->fsCodeAppendf("\t%s = ", outColor);
- builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
+ builder->codeAppendf("\t%s = ", outColor);
+ builder->appendTextureLookupAndModulate(inModulateColor, sampler,
clampedCoords.c_str());
- builder->fsCodeAppend(";\n");
+ builder->codeAppend(";\n");
break;
}
case kDecal_Mode: {
// Add a block since we're going to declare variables.
- GrGLShaderBuilder::FSBlock block(builder);
+ GrGLShaderBuilder::ShaderBlock block(builder);
const char* domain = fDomainName.c_str();
- if (kImagination_GrGLVendor == builder->ctxInfo().vendor()) {
+ if (kImagination_GrGLVendor == program->ctxInfo().vendor()) {
// On the NexusS and GalaxyNexus, the other path (with the 'any'
// call) causes the compilation error "Calls to any function that
// may require a gradient calculation inside a conditional block
// may return undefined results". This appears to be an issue with
// the 'any' call since even the simple "result=black; if (any())
// result=white;" code fails to compile.
- builder->fsCodeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n");
- builder->fsCodeAppend("\tvec4 inside = ");
- builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
+ builder->codeAppend("\tvec4 outside = vec4(0.0, 0.0, 0.0, 0.0);\n");
+ builder->codeAppend("\tvec4 inside = ");
+ builder->appendTextureLookupAndModulate(inModulateColor, sampler,
inCoords.c_str());
- builder->fsCodeAppend(";\n");
- builder->fsCodeAppendf("\tfloat x = (%s).x;\n", inCoords.c_str());
- builder->fsCodeAppendf("\tfloat y = (%s).y;\n", inCoords.c_str());
+ builder->codeAppend(";\n");
+ builder->codeAppendf("\tfloat x = (%s).x;\n", inCoords.c_str());
+ builder->codeAppendf("\tfloat y = (%s).y;\n", inCoords.c_str());
- builder->fsCodeAppendf("\tx = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0);\n",
+ builder->codeAppendf("\tx = abs(2.0*(x - %s.x)/(%s.z - %s.x) - 1.0);\n",
domain, domain, domain);
- builder->fsCodeAppendf("\ty = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0);\n",
+ builder->codeAppendf("\ty = abs(2.0*(y - %s.y)/(%s.w - %s.y) - 1.0);\n",
domain, domain, domain);
- builder->fsCodeAppend("\tfloat blend = step(1.0, max(x, y));\n");
- builder->fsCodeAppendf("\t%s = mix(inside, outside, blend);\n", outColor);
+ builder->codeAppend("\tfloat blend = step(1.0, max(x, y));\n");
+ builder->codeAppendf("\t%s = mix(inside, outside, blend);\n", outColor);
} else {
- builder->fsCodeAppend("\tbvec4 outside;\n");
- builder->fsCodeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(),
+ builder->codeAppend("\tbvec4 outside;\n");
+ builder->codeAppendf("\toutside.xy = lessThan(%s, %s.xy);\n", inCoords.c_str(),
domain);
- builder->fsCodeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(),
+ builder->codeAppendf("\toutside.zw = greaterThan(%s, %s.zw);\n", inCoords.c_str(),
domain);
- builder->fsCodeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ",
+ builder->codeAppendf("\t%s = any(outside) ? vec4(0.0, 0.0, 0.0, 0.0) : ",
outColor);
- builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
+ builder->appendTextureLookupAndModulate(inModulateColor, sampler,
inCoords.c_str());
- builder->fsCodeAppend(";\n");
+ builder->codeAppend(";\n");
}
break;
}
@@ -125,10 +127,10 @@ void GrTextureDomain::GLDomain::sampleTexture(GrGLShaderBuilder* builder,
inCoords.c_str(), fDomainName.c_str(), fDomainName.c_str(),
fDomainName.c_str(), fDomainName.c_str());
- builder->fsCodeAppendf("\t%s = ", outColor);
- builder->fsAppendTextureLookupAndModulate(inModulateColor, sampler,
+ builder->codeAppendf("\t%s = ", outColor);
+ builder->appendTextureLookupAndModulate(inModulateColor, sampler,
clampedCoords.c_str());
- builder->fsCodeAppend(";\n");
+ builder->codeAppend(";\n");
break;
}
}
@@ -167,7 +169,7 @@ class GrGLTextureDomainEffect : public GrGLEffect {
public:
GrGLTextureDomainEffect(const GrBackendEffectFactory&, const GrDrawEffect&);
- virtual void emitCode(GrGLShaderBuilder*,
+ virtual void emitCode(GrGLProgramBuilder*,
const GrDrawEffect&,
const GrEffectKey&,
const char* outputColor,
@@ -189,7 +191,7 @@ GrGLTextureDomainEffect::GrGLTextureDomainEffect(const GrBackendEffectFactory& f
: INHERITED(factory) {
}
-void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
+void GrGLTextureDomainEffect::emitCode(GrGLProgramBuilder* builder,
const GrDrawEffect& drawEffect,
const GrEffectKey& key,
const char* outputColor,
@@ -199,8 +201,9 @@ void GrGLTextureDomainEffect::emitCode(GrGLShaderBuilder* builder,
const GrTextureDomainEffect& effect = drawEffect.castEffect<GrTextureDomainEffect>();
const GrTextureDomain& domain = effect.textureDomain();
- SkString coords2D = builder->ensureFSCoords2D(coords, 0);
- fGLDomain.sampleTexture(builder, domain, outputColor, coords2D, samplers[0], inputColor);
+ GrGLFragmentShaderBuilder* fsBuilder = builder->getFragmentShaderBuilder();
+ SkString coords2D = fsBuilder->ensureFSCoords2D(coords, 0);
+ fGLDomain.sampleTexture(fsBuilder, domain, outputColor, coords2D, samplers[0], inputColor);
}
void GrGLTextureDomainEffect::setData(const GrGLProgramDataManager& pdman,
« no previous file with comments | « src/gpu/effects/GrTextureDomain.h ('k') | src/gpu/effects/GrYUVtoRGBEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698