GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString vCoords = fsBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
kVec2f_GrSLType, kDefault_GrSLPrecision,
void GrGLImprovedPerlinNoise::emitCode(EmitArgs& args) {
GrGLSLFragmentBuilder* fsBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- SkString vCoords = fsBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString vCoords = fsBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
kVec2f_GrSLType, kDefault_GrSLPrecision,
class DCGLFP : public GrGLSLFragmentProcessor {
void emitCode(EmitArgs& args) override {
GrGLSLFragmentBuilder* fragBuilder = args.fFragBuilder;
- fragBuilder->codeAppendf("vec2 c = %s;",
- fragBuilder->ensureFSCoords2D(args.fCoords, 0).c_str());
+ SkString coords2d = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
+ fragBuilder->codeAppendf("vec2 c = %s;", coords2d.c_str());
fragBuilder->codeAppend("vec2 r = mod(c, vec2(20.0));");
fragBuilder->codeAppend("vec4 color = vec4(0.5*sin(c.x / 15.0) + 0.5,"
"0.5*cos((c.x + c.y) / 15.0) + 0.5,"
'<(skia_src_path)/gpu/glsl/GrGLSLGeometryShaderBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLPrimitiveProcessor.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLPrimitiveProcessor.h',
- '<(skia_src_path)/gpu/glsl/GrGLSLProcessorTypes.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramBuilder.cpp',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramBuilder.h',
'<(skia_src_path)/gpu/glsl/GrGLSLProgramDataManager.cpp',
"outer_threshold");
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
- SkString maskCoords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
+ SkString maskCoords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[1]);
fragBuilder->codeAppendf("vec2 coord = %s;", coords2D.c_str());
fragBuilder->codeAppendf("vec2 mask_coord = %s;", maskCoords2D.c_str());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->codeAppendf("\t\tvec4 %s = ", dColor);
- fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str(),
- args.fCoords[0].getType());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].getType());
fragBuilder->codeAppend(";\n");
// Unpremultiply the displacement
fragBuilder->codeAppendf(
"\t\t%s.rgb = (%s.a < %s) ? vec3(0.0) : clamp(%s.rgb / %s.a, 0.0, 1.0);",
dColor, dColor, nearZero, dColor, dColor);
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 1);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[1]);
fragBuilder->codeAppendf("\t\tvec2 %s = %s + %s*(%s.",
cCoords, coords2D.c_str(), scaleUni, dColor);
GrGLSLShaderVar("scale", kFloat_GrSLType),
};
SkString sobelFuncName;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->emitFunction(kFloat_GrSLType,
"sobel",
"Bounds");
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf("\t\tvec2 coord = %s;\n", coords2D.c_str());
fragBuilder->codeAppendf("\t\tvec2 zoom_coord = %s + %s * %s;\n",
uniformHandler->getUniformCStr(fOffsetVar),
const char* range = uniformHandler->getUniformCStr(fRangeUni);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
const char* func;
switch (me.type()) {
case GrMorphologyEffect::kErode_MorphologyType:
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
GrGLSLUniformHandler* uniformHandler = args.fUniformHandler;
- SkString vCoords = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString vCoords = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fBaseFrequencyUni = uniformHandler->addUniform(kFragment_GrShaderFlag,
kVec2f_GrSLType, kDefault_GrSLPrecision,
void GrLinearGradient::GLSLLinearProcessor::emitCode(EmitArgs& args) {
const GrLinearGradient& ge = args.fFp.cast<GrLinearGradient>();
this->emitUniforms(args.fUniformHandler, ge);
- SkString t = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString t = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
t.append(".x");
this->emitColor(args.fFragBuilder,
args.fUniformHandler,
const GrRadialGradient& ge = args.fFp.cast<GrRadialGradient>();
this->emitUniforms(args.fUniformHandler, ge);
SkString t("length(");
- t.append(args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0));
+ t.append(args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]));
t.append(")");
this->emitColor(args.fFragBuilder,
args.fUniformHandler,
void GrSweepGradient::GLSLSweepProcessor::emitCode(EmitArgs& args) {
const GrSweepGradient& ge = args.fFp.cast<GrSweepGradient>();
this->emitUniforms(args.fUniformHandler, ge);
- SkString coords2D = args.fFragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = args.fFragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
SkString t;
// 0.1591549430918 is 1/(2*pi), used since atan returns values [-pi, pi]
// On Intel GPU there is an issue where it reads the second arguement to atan "- %s.x" as an int
p2.appendf("%s.z", uniformHandler->getUniformVariable(fParamUni).getName().c_str());
// We interpolate the linear component in coords[1].
- SkASSERT(args.fCoords[0].getType() == args.fCoords[1].getType());
+ SkASSERT(args.fTransformedCoords[0].getType() == args.fTransformedCoords[1].getType());
const char* coords2D;
SkString bVar;
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- if (kVec3f_GrSLType == args.fCoords[0].getType()) {
+ if (kVec3f_GrSLType == args.fTransformedCoords[0].getType()) {
fragBuilder->codeAppendf("\tvec3 interpolants = vec3(%s.xy / %s.z, %s.x / %s.z);\n",
- args.fCoords[0].c_str(), args.fCoords[0].c_str(),
- args.fCoords[1].c_str(), args.fCoords[1].c_str());
+ args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[1].c_str(),
+ args.fTransformedCoords[1].c_str());
coords2D = "interpolants.xy";
bVar = "interpolants.z";
} else {
- coords2D = args.fCoords[0].c_str();
- bVar.printf("%s.x", args.fCoords[1].c_str());
+ coords2D = args.fTransformedCoords[0].c_str();
+ bVar.printf("%s.x", args.fTransformedCoords[1].c_str());
}
// output will default to transparent black (we simply won't write anything
// if we have a vec3 from being in perspective, convert it to a vec2 first
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
const char* coords2D = coords2DString.c_str();
// t = p.x * focal.x +/- sqrt(p.x^2 + (1 - focal.x^2) * p.y^2)
// if we have a vec3 from being in perspective, convert it to a vec2 first
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
const char* coords2D = coords2DString.c_str();
// t = p.x * focalX + length(p)
// if we have a vec3 from being in perspective, convert it to a vec2 first
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
const char* coords2D = coords2DString.c_str();
// p = coords2D
// if we have a vec3 from being in perspective, convert it to a vec2 first
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2DString = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2DString = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
const char* coords2D = coords2DString.c_str();
// output will default to transparent black (we simply won't write anything
#include "gl/GrGLGpu.h"
#include "glsl/GrGLSLCaps.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProcessorTypes.h"
#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
GrGLSLShaderVar("c3", kVec4f_GrSLType),
};
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->emitFunction(kVec4f_GrSLType,
"cubicBlend",
SK_ARRAY_COUNT(gCubicBlendArgs),
fragBuilder->codeAppendf("%s;", tmpDecl.c_str());
fragBuilder->codeAppendf("%s = ", tmpVar.c_str());
- fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str(),
- args.fCoords[0].getType());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].getType());
fragBuilder->codeAppend(";");
if (GrConfigConversionEffect::kNone_PMConversion == pmConversion) {
"Kernel", arrayCount);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppendf("%s = vec4(0, 0, 0, 0);", args.fOutputColor);
const char* bias = uniformHandler->getUniformCStr(fBiasUni);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fragBuilder->codeAppend("vec4 sum = vec4(0, 0, 0, 0);");
fragBuilder->codeAppendf("vec2 coord = %s - %s * %s;", coords2D.c_str(), kernelOffset, imgInc);
fragBuilder->codeAppend("vec4 c;");
fragBuilder->codeAppendf("%s = ", args.fOutputColor);
fragBuilder->appendTextureLookupAndModulate(args.fInputColor,
args.fTexSamplers[0],
- args.fCoords[0].c_str(),
- args.fCoords[0].getType(),
+ args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].getType(),
&colorSpaceHelper);
fragBuilder->codeAppend(";");
}
const GrTextureDomain& domain = textureDomainEffect.textureDomain();
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- SkString coords2D = fragBuilder->ensureFSCoords2D(args.fCoords, 0);
+ SkString coords2D = fragBuilder->ensureCoords2D(args.fTransformedCoords[0]);
fGLDomain.sampleTexture(fragBuilder,
args.fUniformHandler,
args.fGLSLCaps,
kMat44f_GrSLType, kDefault_GrSLPrecision,
"ColorSpaceMatrix", &colorSpaceMatrix);
fragBuilder->codeAppendf("%s = vec4(", args.fOutputColor);
- fragBuilder->appendTextureLookup(args.fTexSamplers[0], args.fCoords[0].c_str(),
- args.fCoords[0].getType());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[0],
+ args.fTransformedCoords[0].c_str(),
+ args.fTransformedCoords[0].getType());
fragBuilder->codeAppend(".r,");
- fragBuilder->appendTextureLookup(args.fTexSamplers[1], args.fCoords[1].c_str(),
- args.fCoords[1].getType());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[1],
+ args.fTransformedCoords[1].c_str(),
+ args.fTransformedCoords[1].getType());
if (effect.fNV12) {
fragBuilder->codeAppendf(".rg,");
} else {
fragBuilder->codeAppend(".r,");
- fragBuilder->appendTextureLookup(args.fTexSamplers[2], args.fCoords[2].c_str(),
- args.fCoords[2].getType());
+ fragBuilder->appendTextureLookup(args.fTexSamplers[2],
+ args.fTransformedCoords[2].c_str(),
+ args.fTransformedCoords[2].getType());
fragBuilder->codeAppendf(".g,");
}
fragBuilder->codeAppendf("1.0) * %s;", colorSpaceMatrix);
firstTextureAt += args.fFp.childProcessor(i).numTextures();
firstBufferAt += args.fFp.childProcessor(i).numBuffers();
}
- GrGLSLTransformedCoordsArray childCoords;
+ SkTArray<GrShaderVar> childCoords;
const SamplerHandle* childTexSamplers = nullptr;
const SamplerHandle* childBufferSamplers = nullptr;
if (childProc.numTransforms() > 0) {
- childCoords.push_back_n(childProc.numTransforms(), &args.fCoords[firstCoordAt]);
+ childCoords.push_back_n(childProc.numTransforms(), &args.fTransformedCoords[firstCoordAt]);
}
if (childProc.numTextures() > 0) {
childTexSamplers = &args.fTexSamplers[firstTextureAt];
#define GrGLSLFragmentProcessor_DEFINED
#include "GrFragmentProcessor.h"
-#include "glsl/GrGLSLProcessorTypes.h"
+#include "GrShaderVar.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLSampler.h"
shader will be in its own block ({}) and so locally scoped names will not collide across
stages.
- @param builder Interface used to emit code in the shaders.
- @param processor The processor that generated this program stage.
- @param key The key that was computed by GenKey() from the generating GrProcessor.
- @param outputColor A predefined vec4 in the FS in which the stage should place its output
- color (or coverage).
- @param inputColor A vec4 that holds the input color to the stage in the FS. This may be
- nullptr in which case the implied input is solid white (all ones).
- TODO: Better system for communicating optimization info (e.g. input
- color is solid white, trans black, known to be opaque, etc.) that allows
- the processor to communicate back similar known info about its output.
- @param samplers Contains one entry for each GrTextureAccess of the GrProcessor. These
- can be passed to the builder to emit texture reads in the generated
- code.
+ @param fragBuilder Interface used to emit code in the shaders.
+ @param fp The processor that generated this program stage.
+ @param key The key that was computed by GenKey() from the generating
+ GrProcessor.
+ @param outputColor A predefined vec4 in the FS in which the stage should place its
+ output color (or coverage).
+ @param inputColor A vec4 that holds the input color to the stage in the FS. This may
+ be nullptr in which case the implied input is solid white (all
+ ones). TODO: Better system for communicating optimization info
+ (e.g. input color is solid white, trans black, known to be opaque,
+ etc.) that allows the processor to communicate back similar known
+ info about its output.
+ @param transformedCoords Fragment shader variables containing the coords computed using
+ each of the GrFragmentProcessor's Coord Transforms.
+ @param texSamplers Contains one entry for each GrTextureAccess of the GrProcessor.
+ These can be passed to the builder to emit texture reads in the
+ generated code.
+ @param bufferSamplers Contains one entry for each GrBufferAccess of the GrProcessor.
+ These can be passed to the builder to emit buffer reads in the
+ generated code.
*/
-
struct EmitArgs {
EmitArgs(GrGLSLFPFragmentBuilder* fragBuilder,
GrGLSLUniformHandler* uniformHandler,
const GrFragmentProcessor& fp,
const char* outputColor,
const char* inputColor,
- const GrGLSLTransformedCoordsArray& coords,
+ const SkTArray<GrShaderVar>& transformedCoords,
const SamplerHandle* texSamplers,
const SamplerHandle* bufferSamplers,
bool gpImplementsDistanceVector)
, fFp(fp)
, fOutputColor(outputColor)
, fInputColor(inputColor)
- , fCoords(coords)
+ , fTransformedCoords(transformedCoords)
, fTexSamplers(texSamplers)
, fBufferSamplers(bufferSamplers)
- , fGpImplementsDistanceVector(gpImplementsDistanceVector){}
+ , fGpImplementsDistanceVector(gpImplementsDistanceVector) {}
GrGLSLFPFragmentBuilder* fFragBuilder;
GrGLSLUniformHandler* fUniformHandler;
const GrGLSLCaps* fGLSLCaps;
const GrFragmentProcessor& fFp;
const char* fOutputColor;
const char* fInputColor;
- const GrGLSLTransformedCoordsArray& fCoords;
+ const SkTArray<GrShaderVar>& fTransformedCoords;
const SamplerHandle* fTexSamplers;
const SamplerHandle* fBufferSamplers;
bool fGpImplementsDistanceVector;
}
}
-SkString GrGLSLFragmentShaderBuilder::ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
- int index) {
- if (kVec3f_GrSLType != coords[index].getType()) {
- SkASSERT(kVec2f_GrSLType == coords[index].getType());
- return coords[index].getName();
+SkString GrGLSLFragmentShaderBuilder::ensureCoords2D(const GrShaderVar& coords) {
+ if (kVec3f_GrSLType != coords.getType()) {
+ SkASSERT(kVec2f_GrSLType == coords.getType());
+ return coords.getName();
}
- SkString coords2D("coords2D");
- if (0 != index) {
- coords2D.appendf("_%i", index);
- }
- this->codeAppendf("\tvec2 %s = %s.xy / %s.z;",
- coords2D.c_str(), coords[index].c_str(), coords[index].c_str());
+ SkString coords2D;
+ coords2D.printf("%s_ensure2D", coords.c_str());
+ this->codeAppendf("\tvec2 %s = %s.xy / %s.z;", coords2D.c_str(), coords.c_str(),
+ coords.c_str());
return coords2D;
}
#include "GrGLSLShaderBuilder.h"
#include "GrProcessor.h"
-#include "glsl/GrGLSLProcessorTypes.h"
class GrRenderTarget;
class GrGLSLVarying;
/**
* This returns a variable name to access the 2D, perspective correct version of the coords in
- * the fragment shader. If the coordinates at index are 3-dimensional, it immediately emits a
- * perspective divide into the fragment shader (xy / z) to convert them to 2D.
+ * the fragment shader. The passed in coordinates must either be of type kVec2f or kVec3f. If
+ * the coordinates are 3-dimensional, it a perspective divide into is emitted into the
+ * fragment shader (xy / z) to convert them to 2D.
*/
- virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords, int index) = 0;
+ virtual SkString ensureCoords2D(const GrShaderVar&) = 0;
/** Returns a variable name that represents the position of the fragment in the FS. The position
// Shared GrGLSLFragmentBuilder interface.
bool enableFeature(GLSLFeature) override;
- virtual SkString ensureFSCoords2D(const GrGLSLTransformedCoordsArray& coords,
- int index) override;
+ virtual SkString ensureCoords2D(const GrShaderVar&) override;
const char* fragmentPosition() override;
const char* distanceVectorName() const override;
#include "GrCoordTransform.h"
#include "glsl/GrGLSLFragmentShaderBuilder.h"
-#include "glsl/GrGLSLProcessorTypes.h"
#include "glsl/GrGLSLUniformHandler.h"
#include "glsl/GrGLSLVarying.h"
#include "glsl/GrGLSLVertexShaderBuilder.h"
#define GrGLSLPrimitiveProcessor_DEFINED
#include "GrPrimitiveProcessor.h"
-#include "glsl/GrGLSLProcessorTypes.h"
#include "glsl/GrGLSLProgramDataManager.h"
#include "glsl/GrGLSLSampler.h"
typedef SkSTArray<2, const GrCoordTransform*, true> ProcCoords;
typedef SkSTArray<8, ProcCoords> TransformsIn;
- typedef SkSTArray<8, GrGLSLTransformedCoordsArray> TransformsOut;
+ typedef SkSTArray<8, SkTArray<GrShaderVar>> TransformsOut;
struct EmitArgs {
EmitArgs(GrGLSLVertexBuilder* vertBuilder,
+++ /dev/null
-/*
- * Copyright 2015 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef GrGLSLProcessorTypes_DEFINED
-#define GrGLSLProcessorTypes_DEFINED
-
-#include "GrShaderVar.h"
-
-/**
- * These are meant to only be used by GrGLSL*Processors so they can add transformed coordinates
- * to their shader code.
- */
-typedef GrShaderVar GrGLSLTransformedCoords;
-typedef SkTArray<GrShaderVar> GrGLSLTransformedCoordsArray;
-
-#endif