Flip the switch to turn on GrCustomStage implementation of gradients;
remove old implementation, including enums & state on various structs. http://codereview.appspot.com/6245078/ git-svn-id: http://skia.googlecode.com/svn/trunk@4129 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
0bdbed3802
commit
898e7b568f
@ -38,37 +38,6 @@ public:
|
||||
kDefault_Filter = kNearest_Filter
|
||||
};
|
||||
|
||||
/**
|
||||
* The intepretation of the texture matrix depends on the sample mode. The
|
||||
* texture matrix is applied both when the texture coordinates are explicit
|
||||
* and when vertex positions are used as texture coordinates. In the latter
|
||||
* case the texture matrix is applied to the pre-view-matrix position
|
||||
* values.
|
||||
*
|
||||
* kNormal_SampleMode
|
||||
* The post-matrix texture coordinates are in normalize space with (0,0) at
|
||||
* the top-left and (1,1) at the bottom right.
|
||||
* kRadial_SampleMode
|
||||
* The matrix specifies the radial gradient parameters.
|
||||
* (0,0) in the post-matrix space is center of the radial gradient.
|
||||
* kRadial2_SampleMode
|
||||
* Matrix transforms to space where first circle is centered at the
|
||||
* origin. The second circle will be centered (x, 0) where x may be
|
||||
* 0 and is provided by setRadial2Params. The post-matrix space is
|
||||
* normalized such that 1 is the second radius - first radius.
|
||||
* kSweepSampleMode
|
||||
* The angle from the origin of texture coordinates in post-matrix space
|
||||
* determines the gradient value.
|
||||
*/
|
||||
enum SampleMode {
|
||||
kNormal_SampleMode, //!< sample color directly
|
||||
kRadial_SampleMode, //!< treat as radial gradient
|
||||
kRadial2_SampleMode, //!< treat as 2-point radial gradient
|
||||
kSweep_SampleMode, //!< treat as sweep gradient
|
||||
|
||||
kDefault_SampleMode = kNormal_SampleMode
|
||||
};
|
||||
|
||||
/**
|
||||
* Describes how a texture is sampled when coordinates are outside the
|
||||
* texture border
|
||||
@ -86,10 +55,7 @@ public:
|
||||
* unfiltered, and use identity matrix.
|
||||
*/
|
||||
GrSamplerState()
|
||||
: fRadial2CenterX1()
|
||||
, fRadial2Radius0()
|
||||
, fRadial2PosRoot()
|
||||
, fCustomStage (NULL) {
|
||||
: fCustomStage (NULL) {
|
||||
memset(this, 0, sizeof(GrSamplerState));
|
||||
this->reset();
|
||||
}
|
||||
@ -119,16 +85,11 @@ public:
|
||||
// memcpy() breaks refcounting
|
||||
fWrapX = s.fWrapX;
|
||||
fWrapY = s.fWrapY;
|
||||
fSampleMode = s.fSampleMode;
|
||||
fFilter = s.fFilter;
|
||||
fMatrix = s.fMatrix;
|
||||
fSwapRAndB = s.fSwapRAndB;
|
||||
fTextureDomain = s.fTextureDomain;
|
||||
|
||||
fRadial2CenterX1 = s.fRadial2CenterX1;
|
||||
fRadial2Radius0 = s.fRadial2Radius0;
|
||||
fRadial2PosRoot = s.fRadial2PosRoot;
|
||||
|
||||
fCustomStage = s.fCustomStage;
|
||||
SkSafeRef(fCustomStage);
|
||||
|
||||
@ -137,21 +98,14 @@ public:
|
||||
|
||||
WrapMode getWrapX() const { return fWrapX; }
|
||||
WrapMode getWrapY() const { return fWrapY; }
|
||||
SampleMode getSampleMode() const { return fSampleMode; }
|
||||
const GrMatrix& getMatrix() const { return fMatrix; }
|
||||
const GrRect& getTextureDomain() const { return fTextureDomain; }
|
||||
bool hasTextureDomain() const {return SkIntToScalar(0) != fTextureDomain.right();}
|
||||
Filter getFilter() const { return fFilter; }
|
||||
bool swapsRAndB() const { return fSwapRAndB; }
|
||||
bool isGradient() const {
|
||||
return kRadial_SampleMode == fSampleMode ||
|
||||
kRadial2_SampleMode == fSampleMode ||
|
||||
kSweep_SampleMode == fSampleMode;
|
||||
}
|
||||
|
||||
void setWrapX(WrapMode mode) { fWrapX = mode; }
|
||||
void setWrapY(WrapMode mode) { fWrapY = mode; }
|
||||
void setSampleMode(SampleMode mode) { fSampleMode = mode; }
|
||||
|
||||
/**
|
||||
* Access the sampler's matrix. See SampleMode for explanation of
|
||||
@ -195,7 +149,6 @@ public:
|
||||
const GrMatrix& matrix) {
|
||||
fWrapX = wrapXAndY;
|
||||
fWrapY = wrapXAndY;
|
||||
fSampleMode = kDefault_SampleMode;
|
||||
fFilter = filter;
|
||||
fMatrix = matrix;
|
||||
fTextureDomain.setEmpty();
|
||||
@ -212,26 +165,6 @@ public:
|
||||
this->reset(kDefault_WrapMode, kDefault_Filter, GrMatrix::I());
|
||||
}
|
||||
|
||||
GrScalar getRadial2CenterX1() const { return fRadial2CenterX1; }
|
||||
GrScalar getRadial2Radius0() const { return fRadial2Radius0; }
|
||||
bool isRadial2PosRoot() const { return SkToBool(fRadial2PosRoot); }
|
||||
// do the radial gradient params lead to a linear (rather than quadratic)
|
||||
// equation.
|
||||
bool radial2IsDegenerate() const { return GR_Scalar1 == fRadial2CenterX1; }
|
||||
|
||||
/**
|
||||
* Sets the parameters for kRadial2_SampleMode. The texture
|
||||
* matrix must be set so that the first point is at (0,0) and the second
|
||||
* point lies on the x-axis. The second radius minus the first is 1 unit.
|
||||
* The additional parameters to define the gradient are specified by this
|
||||
* function.
|
||||
*/
|
||||
void setRadial2Params(GrScalar centerX1, GrScalar radius0, bool posRoot) {
|
||||
fRadial2CenterX1 = centerX1;
|
||||
fRadial2Radius0 = radius0;
|
||||
fRadial2PosRoot = posRoot;
|
||||
}
|
||||
|
||||
void setCustomStage(GrCustomStage* stage) {
|
||||
GrSafeAssign(fCustomStage, stage);
|
||||
}
|
||||
@ -240,17 +173,11 @@ public:
|
||||
private:
|
||||
WrapMode fWrapX : 8;
|
||||
WrapMode fWrapY : 8;
|
||||
SampleMode fSampleMode : 8;
|
||||
Filter fFilter : 8;
|
||||
GrMatrix fMatrix;
|
||||
bool fSwapRAndB;
|
||||
GrMatrix fMatrix;
|
||||
GrRect fTextureDomain;
|
||||
|
||||
// these are undefined unless fSampleMode == kRadial2_SampleMode
|
||||
GrScalar fRadial2CenterX1;
|
||||
GrScalar fRadial2Radius0;
|
||||
SkBool8 fRadial2PosRoot;
|
||||
|
||||
GrCustomStage* fCustomStage;
|
||||
};
|
||||
|
||||
|
@ -6,13 +6,14 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkGpuDevice.h"
|
||||
|
||||
#include "effects/GrGradientEffects.h"
|
||||
|
||||
#include "GrContext.h"
|
||||
#include "GrDefaultTextContext.h"
|
||||
#include "GrTextContext.h"
|
||||
|
||||
#include "SkGpuDevice.h"
|
||||
#include "SkGrTexturePixelRef.h"
|
||||
|
||||
#include "SkColorFilter.h"
|
||||
@ -421,14 +422,6 @@ SK_COMPILE_ASSERT(SkShader::kTwoPointRadial_BitmapType == 4,
|
||||
shader_type_mismatch);
|
||||
SK_COMPILE_ASSERT(SkShader::kLast_BitmapType == 4, shader_type_mismatch);
|
||||
|
||||
static const GrSamplerState::SampleMode sk_bmp_type_to_sample_mode[] = {
|
||||
(GrSamplerState::SampleMode) -1, // kNone_BitmapType
|
||||
GrSamplerState::kNormal_SampleMode, // kDefault_BitmapType
|
||||
GrSamplerState::kRadial_SampleMode, // kRadial_BitmapType
|
||||
GrSamplerState::kSweep_SampleMode, // kSweep_BitmapType
|
||||
GrSamplerState::kRadial2_SampleMode, // kTwoPointRadial_BitmapType
|
||||
};
|
||||
|
||||
namespace {
|
||||
|
||||
// converts a SkPaint to a GrPaint, ignoring the skPaint's shader
|
||||
@ -524,8 +517,7 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
||||
SkShader::BitmapType bmptype = shader->asABitmap(&bitmap, matrix,
|
||||
tileModes, twoPointParams);
|
||||
|
||||
GrSamplerState::SampleMode sampleMode = sk_bmp_type_to_sample_mode[bmptype];
|
||||
if (-1 == sampleMode) {
|
||||
if (SkShader::kNone_BitmapType == bmptype) {
|
||||
SkShader::GradientInfo info;
|
||||
SkColor color;
|
||||
|
||||
@ -546,7 +538,21 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
||||
return false;
|
||||
}
|
||||
GrSamplerState* sampler = grPaint->textureSampler(kShaderTextureIdx);
|
||||
sampler->setSampleMode(sampleMode);
|
||||
switch (bmptype) {
|
||||
case SkShader::kRadial_BitmapType: {
|
||||
sampler->setCustomStage(new GrRadialGradient());
|
||||
} break;
|
||||
case SkShader::kSweep_BitmapType: {
|
||||
sampler->setCustomStage(new GrSweepGradient());
|
||||
} break;
|
||||
case SkShader::kTwoPointRadial_BitmapType: {
|
||||
sampler->setCustomStage(new GrRadial2Gradient(twoPointParams[0],
|
||||
twoPointParams[1],
|
||||
twoPointParams[2] < 0));
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (skPaint.isFilterBitmap()) {
|
||||
sampler->setFilter(GrSamplerState::kBilinear_Filter);
|
||||
} else {
|
||||
@ -554,11 +560,6 @@ inline bool skPaint2GrPaintShader(SkGpuDevice* dev,
|
||||
}
|
||||
sampler->setWrapX(sk_tile_mode_to_grwrap(tileModes[0]));
|
||||
sampler->setWrapY(sk_tile_mode_to_grwrap(tileModes[1]));
|
||||
if (GrSamplerState::kRadial2_SampleMode == sampleMode) {
|
||||
sampler->setRadial2Params(twoPointParams[0],
|
||||
twoPointParams[1],
|
||||
twoPointParams[2] < 0);
|
||||
}
|
||||
|
||||
GrTexture* texture = act->set(dev, bitmap, sampler);
|
||||
if (NULL == texture) {
|
||||
@ -1354,7 +1355,6 @@ void SkGpuDevice::internalDrawBitmap(const SkDraw& draw,
|
||||
|
||||
sampler->setWrapX(GrSamplerState::kClamp_WrapMode);
|
||||
sampler->setWrapY(GrSamplerState::kClamp_WrapMode);
|
||||
sampler->setSampleMode(GrSamplerState::kNormal_SampleMode);
|
||||
sampler->matrix()->reset();
|
||||
|
||||
GrTexture* texture;
|
||||
|
@ -212,7 +212,7 @@ void GrGLRadial2Gradient::emitFS(GrGLShaderBuilder* state,
|
||||
|
||||
// If we aren't degenerate, emit some extra code, and accept a slightly
|
||||
// more complex coord.
|
||||
if (fIsDegenerate) {
|
||||
if (!fIsDegenerate) {
|
||||
|
||||
// ac4 = 4.0 * params[0] * c
|
||||
code->appendf("\tfloat %s = %s * 4.0 * %s;\n",
|
||||
|
@ -12,6 +12,29 @@
|
||||
#include "GrTypes.h"
|
||||
#include "GrScalar.h"
|
||||
|
||||
/*
|
||||
* The intepretation of the texture matrix depends on the sample mode. The
|
||||
* texture matrix is applied both when the texture coordinates are explicit
|
||||
* and when vertex positions are used as texture coordinates. In the latter
|
||||
* case the texture matrix is applied to the pre-view-matrix position
|
||||
* values.
|
||||
*
|
||||
* Normal SampleMode
|
||||
* The post-matrix texture coordinates are in normalize space with (0,0) at
|
||||
* the top-left and (1,1) at the bottom right.
|
||||
* RadialGradient
|
||||
* The matrix specifies the radial gradient parameters.
|
||||
* (0,0) in the post-matrix space is center of the radial gradient.
|
||||
* Radial2Gradient
|
||||
* Matrix transforms to space where first circle is centered at the
|
||||
* origin. The second circle will be centered (x, 0) where x may be
|
||||
* 0 and is provided by setRadial2Params. The post-matrix space is
|
||||
* normalized such that 1 is the second radius - first radius.
|
||||
* SweepGradient
|
||||
* The angle from the origin of texture coordinates in post-matrix space
|
||||
* determines the gradient value.
|
||||
*/
|
||||
|
||||
class GrGLRadialGradient;
|
||||
|
||||
class GrRadialGradient : public GrCustomStage {
|
||||
|
@ -1158,14 +1158,6 @@ void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
|
||||
GrAssert(kUnusedUniform != locations.fNormalizedTexelSizeUni);
|
||||
}
|
||||
|
||||
if (kUseUniform == locations.fRadial2Uni) {
|
||||
GrStringBuilder radial2ParamName;
|
||||
radial2_param_name(s, &radial2ParamName);
|
||||
GL_CALL_RET(locations.fRadial2Uni,
|
||||
GetUniformLocation(progID, radial2ParamName.c_str()));
|
||||
GrAssert(kUnusedUniform != locations.fRadial2Uni);
|
||||
}
|
||||
|
||||
if (kUseUniform == locations.fTexDomUni) {
|
||||
GrStringBuilder texDomName;
|
||||
tex_domain_name(s, &texDomName);
|
||||
@ -1188,8 +1180,6 @@ void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
|
||||
GL_CALL(Uniform1i(programData->fUniLocations.fStages[s].fSamplerUni, s));
|
||||
}
|
||||
programData->fTextureMatrices[s] = GrMatrix::InvalidMatrix();
|
||||
programData->fRadial2CenterX1[s] = GR_ScalarMax;
|
||||
programData->fRadial2Radius0[s] = -GR_ScalarMax;
|
||||
programData->fTextureWidth[s] = -1;
|
||||
programData->fTextureHeight[s] = -1;
|
||||
programData->fTextureDomain[s].setEmpty();
|
||||
@ -1209,156 +1199,6 @@ void GrGLProgram::getUniformLocationsAndInitCache(const GrGLContextInfo& gl,
|
||||
|
||||
namespace {
|
||||
|
||||
bool isRadialMapping(GrGLProgram::StageDesc::CoordMapping mapping) {
|
||||
return
|
||||
(GrGLProgram::StageDesc::kRadial2Gradient_CoordMapping == mapping ||
|
||||
GrGLProgram::StageDesc::kRadial2GradientDegenerate_CoordMapping == mapping);
|
||||
}
|
||||
|
||||
const GrGLShaderVar* genRadialVS(int stageNum,
|
||||
GrGLShaderBuilder* segments,
|
||||
GrGLProgram::StageUniLocations* locations,
|
||||
const char** radial2VaryingVSName,
|
||||
const char** radial2VaryingFSName,
|
||||
const char* varyingVSName) {
|
||||
GrStringBuilder r2ParamsName;
|
||||
radial2_param_name(stageNum, &r2ParamsName);
|
||||
const GrGLShaderVar* radial2FSParams =
|
||||
&segments->addUniform(GrGLShaderBuilder::kBoth_VariableLifetime,
|
||||
kFloat_GrSLType, r2ParamsName.c_str(), -1, 6);
|
||||
locations->fRadial2Uni = kUseUniform;
|
||||
|
||||
// for radial grads without perspective we can pass the linear
|
||||
// part of the quadratic as a varying.
|
||||
if (segments->fVaryingDims == segments->fCoordDims) {
|
||||
GrAssert(2 == segments->fCoordDims);
|
||||
segments->addVarying(kFloat_GrSLType,
|
||||
"Radial2BCoeff",
|
||||
stageNum,
|
||||
radial2VaryingVSName,
|
||||
radial2VaryingFSName);
|
||||
|
||||
GrStringBuilder radial2p2;
|
||||
GrStringBuilder radial2p3;
|
||||
radial2FSParams->appendArrayAccess(2, &radial2p2);
|
||||
radial2FSParams->appendArrayAccess(3, &radial2p3);
|
||||
|
||||
// r2Var = 2 * (r2Parm[2] * varCoord.x - r2Param[3])
|
||||
const char* r2ParamName = radial2FSParams->getName().c_str();
|
||||
segments->fVSCode.appendf("\t%s = 2.0 *(%s * %s.x - %s);\n",
|
||||
*radial2VaryingVSName, radial2p2.c_str(),
|
||||
varyingVSName, radial2p3.c_str());
|
||||
}
|
||||
|
||||
return radial2FSParams;
|
||||
}
|
||||
|
||||
void genRadial2GradientCoordMapping(int stageNum,
|
||||
GrGLShaderBuilder* segments,
|
||||
const char* radial2VaryingFSName,
|
||||
const GrGLShaderVar* radial2Params) {
|
||||
GrStringBuilder cName("c");
|
||||
GrStringBuilder ac4Name("ac4");
|
||||
GrStringBuilder rootName("root");
|
||||
|
||||
cName.appendS32(stageNum);
|
||||
ac4Name.appendS32(stageNum);
|
||||
rootName.appendS32(stageNum);
|
||||
|
||||
GrStringBuilder radial2p0;
|
||||
GrStringBuilder radial2p1;
|
||||
GrStringBuilder radial2p2;
|
||||
GrStringBuilder radial2p3;
|
||||
GrStringBuilder radial2p4;
|
||||
GrStringBuilder radial2p5;
|
||||
radial2Params->appendArrayAccess(0, &radial2p0);
|
||||
radial2Params->appendArrayAccess(1, &radial2p1);
|
||||
radial2Params->appendArrayAccess(2, &radial2p2);
|
||||
radial2Params->appendArrayAccess(3, &radial2p3);
|
||||
radial2Params->appendArrayAccess(4, &radial2p4);
|
||||
radial2Params->appendArrayAccess(5, &radial2p5);
|
||||
|
||||
// if we were able to interpolate the linear component bVar is the varying
|
||||
// otherwise compute it
|
||||
GrStringBuilder bVar;
|
||||
if (segments->fCoordDims == segments->fVaryingDims) {
|
||||
bVar = radial2VaryingFSName;
|
||||
GrAssert(2 == segments->fVaryingDims);
|
||||
} else {
|
||||
GrAssert(3 == segments->fVaryingDims);
|
||||
bVar = "b";
|
||||
bVar.appendS32(stageNum);
|
||||
segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
|
||||
bVar.c_str(), radial2p2.c_str(),
|
||||
segments->fSampleCoords.c_str(), radial2p3.c_str());
|
||||
}
|
||||
|
||||
// c = (x^2)+(y^2) - params[4]
|
||||
segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s;\n",
|
||||
cName.c_str(), segments->fSampleCoords.c_str(),
|
||||
segments->fSampleCoords.c_str(),
|
||||
radial2p4.c_str());
|
||||
// ac4 = 4.0 * params[0] * c
|
||||
segments->fFSCode.appendf("\tfloat %s = %s * 4.0 * %s;\n",
|
||||
ac4Name.c_str(), radial2p0.c_str(),
|
||||
cName.c_str());
|
||||
|
||||
// root = sqrt(b^2-4ac)
|
||||
// (abs to avoid exception due to fp precision)
|
||||
segments->fFSCode.appendf("\tfloat %s = sqrt(abs(%s*%s - %s));\n",
|
||||
rootName.c_str(), bVar.c_str(), bVar.c_str(),
|
||||
ac4Name.c_str());
|
||||
|
||||
// x coord is: (-b + params[5] * sqrt(b^2-4ac)) * params[1]
|
||||
// y coord is 0.5 (texture is effectively 1D)
|
||||
segments->fSampleCoords.printf("vec2((-%s + %s * %s) * %s, 0.5)",
|
||||
bVar.c_str(), radial2p5.c_str(),
|
||||
rootName.c_str(), radial2p1.c_str());
|
||||
segments->fComplexCoord = true;
|
||||
}
|
||||
|
||||
void genRadial2GradientDegenerateCoordMapping(int stageNum,
|
||||
GrGLShaderBuilder* segments,
|
||||
const char* radial2VaryingFSName,
|
||||
const GrGLShaderVar* radial2Params) {
|
||||
GrStringBuilder cName("c");
|
||||
|
||||
cName.appendS32(stageNum);
|
||||
|
||||
GrStringBuilder radial2p2;
|
||||
GrStringBuilder radial2p3;
|
||||
GrStringBuilder radial2p4;
|
||||
radial2Params->appendArrayAccess(2, &radial2p2);
|
||||
radial2Params->appendArrayAccess(3, &radial2p3);
|
||||
radial2Params->appendArrayAccess(4, &radial2p4);
|
||||
|
||||
// if we were able to interpolate the linear component bVar is the varying
|
||||
// otherwise compute it
|
||||
GrStringBuilder bVar;
|
||||
if (segments->fCoordDims == segments->fVaryingDims) {
|
||||
bVar = radial2VaryingFSName;
|
||||
GrAssert(2 == segments->fVaryingDims);
|
||||
} else {
|
||||
GrAssert(3 == segments->fVaryingDims);
|
||||
bVar = "b";
|
||||
bVar.appendS32(stageNum);
|
||||
segments->fFSCode.appendf("\tfloat %s = 2.0 * (%s * %s.x - %s);\n",
|
||||
bVar.c_str(), radial2p2.c_str(),
|
||||
segments->fSampleCoords.c_str(), radial2p3.c_str());
|
||||
}
|
||||
|
||||
// c = (x^2)+(y^2) - params[4]
|
||||
segments->fFSCode.appendf("\tfloat %s = dot(%s, %s) - %s;\n",
|
||||
cName.c_str(), segments->fSampleCoords.c_str(),
|
||||
segments->fSampleCoords.c_str(),
|
||||
radial2p4.c_str());
|
||||
|
||||
// x coord is: -c/b
|
||||
// y coord is 0.5 (texture is effectively 1D)
|
||||
segments->fSampleCoords.printf("vec2((-%s / %s), 0.5)", cName.c_str(), bVar.c_str());
|
||||
segments->fComplexCoord = true;
|
||||
}
|
||||
|
||||
void gen2x2FS(int stageNum,
|
||||
GrGLShaderBuilder* segments,
|
||||
GrGLProgram::StageUniLocations* locations,
|
||||
@ -1403,10 +1243,6 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
|
||||
GrAssert((desc.fInConfigFlags & StageDesc::kInConfigBitMask) ==
|
||||
desc.fInConfigFlags);
|
||||
|
||||
if (NULL != customStage) {
|
||||
customStage->setupVariables(segments, stageNum);
|
||||
}
|
||||
|
||||
/// Vertex Shader Stuff
|
||||
|
||||
// decide whether we need a matrix to transform texture coords
|
||||
@ -1432,6 +1268,11 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
|
||||
}
|
||||
GrAssert(segments->fVaryingDims > 0);
|
||||
|
||||
// Must setup variables after computing segments->fVaryingDims
|
||||
if (NULL != customStage) {
|
||||
customStage->setupVariables(segments, stageNum);
|
||||
}
|
||||
|
||||
GrStringBuilder samplerName;
|
||||
sampler_name(stageNum, &samplerName);
|
||||
const GrGLShaderVar* sampler = &segments->addUniform(
|
||||
@ -1465,18 +1306,6 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
|
||||
vector_all_coords(segments->fVaryingDims));
|
||||
}
|
||||
|
||||
const GrGLShaderVar* radial2Params = NULL;
|
||||
const char* radial2VaryingVSName = NULL;
|
||||
const char* radial2VaryingFSName = NULL;
|
||||
|
||||
if (isRadialMapping((StageDesc::CoordMapping) desc.fCoordMapping)) {
|
||||
radial2Params = genRadialVS(stageNum, segments,
|
||||
locations,
|
||||
&radial2VaryingVSName,
|
||||
&radial2VaryingFSName,
|
||||
varyingVSName);
|
||||
}
|
||||
|
||||
GrGLShaderVar* kernel = NULL;
|
||||
const char* imageIncrementName = NULL;
|
||||
if (NULL != customStage) {
|
||||
@ -1495,46 +1324,19 @@ void GrGLProgram::genStageCode(const GrGLContextInfo& gl,
|
||||
if (desc.fOptFlags & (StageDesc::kIdentityMatrix_OptFlagBit |
|
||||
StageDesc::kNoPerspective_OptFlagBit)) {
|
||||
sampleMode = GrGLShaderBuilder::kDefault_SamplerMode;
|
||||
} else if (StageDesc::kIdentity_CoordMapping == desc.fCoordMapping &&
|
||||
} else if (NULL == customStage &&
|
||||
StageDesc::kSingle_FetchMode == desc.fFetchMode) {
|
||||
sampleMode = GrGLShaderBuilder::kProj_SamplerMode;
|
||||
}
|
||||
segments->setupTextureAccess(sampleMode, stageNum);
|
||||
|
||||
// NOTE: GrGLProgramStages will soon responsible for mapping
|
||||
//if (NULL == customStage) {
|
||||
switch (desc.fCoordMapping) {
|
||||
case StageDesc::kIdentity_CoordMapping:
|
||||
// Do nothing
|
||||
break;
|
||||
case StageDesc::kSweepGradient_CoordMapping:
|
||||
segments->fSampleCoords.printf("vec2(atan(- %s.y, - %s.x) * 0.1591549430918 + 0.5, 0.5)", segments->fSampleCoords.c_str(), segments->fSampleCoords.c_str());
|
||||
segments->fComplexCoord = true;
|
||||
break;
|
||||
case StageDesc::kRadialGradient_CoordMapping:
|
||||
segments->fSampleCoords.printf("vec2(length(%s.xy), 0.5)", segments->fSampleCoords.c_str());
|
||||
segments->fComplexCoord = true;
|
||||
break;
|
||||
case StageDesc::kRadial2Gradient_CoordMapping:
|
||||
genRadial2GradientCoordMapping(
|
||||
stageNum, segments,
|
||||
radial2VaryingFSName, radial2Params);
|
||||
break;
|
||||
case StageDesc::kRadial2GradientDegenerate_CoordMapping:
|
||||
genRadial2GradientDegenerateCoordMapping(
|
||||
stageNum, segments,
|
||||
radial2VaryingFSName, radial2Params);
|
||||
break;
|
||||
}
|
||||
//}
|
||||
segments->computeSwizzle(desc.fInConfigFlags);
|
||||
segments->computeModulate(fsInColor);
|
||||
|
||||
static const uint32_t kMulByAlphaMask =
|
||||
(StageDesc::kMulRGBByAlpha_RoundUp_InConfigFlag |
|
||||
StageDesc::kMulRGBByAlpha_RoundDown_InConfigFlag);
|
||||
|
||||
segments->computeSwizzle(desc.fInConfigFlags);
|
||||
segments->computeModulate(fsInColor);
|
||||
|
||||
if (desc.fOptFlags & StageDesc::kCustomTextureDomain_OptFlagBit) {
|
||||
GrStringBuilder texDomainName;
|
||||
tex_domain_name(stageNum, &texDomainName);
|
||||
|
@ -162,21 +162,10 @@ public:
|
||||
kInConfigBitMask = (kDummyInConfigFlag-1) |
|
||||
(kDummyInConfigFlag-2)
|
||||
};
|
||||
enum CoordMapping {
|
||||
kIdentity_CoordMapping,
|
||||
kRadialGradient_CoordMapping,
|
||||
kSweepGradient_CoordMapping,
|
||||
kRadial2Gradient_CoordMapping,
|
||||
// need different shader computation when quadratic
|
||||
// eq describing the gradient degenerates to a linear eq.
|
||||
kRadial2GradientDegenerate_CoordMapping,
|
||||
kCoordMappingCnt
|
||||
};
|
||||
|
||||
uint8_t fOptFlags;
|
||||
uint8_t fInConfigFlags; // bitfield of InConfigFlags values
|
||||
uint8_t fFetchMode; // casts to enum FetchMode
|
||||
uint8_t fCoordMapping; // casts to enum CoordMapping
|
||||
|
||||
/** Non-zero if user-supplied code will write the stage's
|
||||
contribution to the fragment shader. */
|
||||
@ -263,13 +252,11 @@ public:
|
||||
GrGLint fTextureMatrixUni;
|
||||
GrGLint fNormalizedTexelSizeUni;
|
||||
GrGLint fSamplerUni;
|
||||
GrGLint fRadial2Uni;
|
||||
GrGLint fTexDomUni;
|
||||
void reset() {
|
||||
fTextureMatrixUni = kUnusedUniform;
|
||||
fNormalizedTexelSizeUni = kUnusedUniform;
|
||||
fSamplerUni = kUnusedUniform;
|
||||
fRadial2Uni = kUnusedUniform;
|
||||
fTexDomUni = kUnusedUniform;
|
||||
}
|
||||
};
|
||||
@ -333,9 +320,6 @@ public:
|
||||
// width and height used for normalized texel size
|
||||
int fTextureWidth[GrDrawState::kNumStages];
|
||||
int fTextureHeight[GrDrawState::kNumStages];
|
||||
GrScalar fRadial2CenterX1[GrDrawState::kNumStages];
|
||||
GrScalar fRadial2Radius0[GrDrawState::kNumStages];
|
||||
bool fRadial2PosRoot[GrDrawState::kNumStages];
|
||||
GrRect fTextureDomain[GrDrawState::kNumStages];
|
||||
// The texture domain and texture matrix sent to GL depend upon the
|
||||
// orientation.
|
||||
|
@ -181,7 +181,6 @@ protected:
|
||||
|
||||
// adjusts texture matrix to account for orientation
|
||||
static void AdjustTextureMatrix(const GrGLTexture* texture,
|
||||
GrSamplerState::SampleMode mode,
|
||||
GrMatrix* matrix);
|
||||
|
||||
// subclass may try to take advantage of identity tex matrices.
|
||||
|
@ -7,6 +7,8 @@
|
||||
|
||||
#include "GrGpuGL.h"
|
||||
|
||||
#include "effects/GrGradientEffects.h"
|
||||
|
||||
#include "GrCustomStage.h"
|
||||
#include "GrGLProgramStage.h"
|
||||
#include "GrGpuVertex.h"
|
||||
@ -148,7 +150,6 @@ void GrGpuGL::flushViewMatrix() {
|
||||
// helpers for texture matrices
|
||||
|
||||
void GrGpuGL::AdjustTextureMatrix(const GrGLTexture* texture,
|
||||
GrSamplerState::SampleMode mode,
|
||||
GrMatrix* matrix) {
|
||||
GrAssert(NULL != texture);
|
||||
GrAssert(NULL != matrix);
|
||||
@ -200,9 +201,7 @@ void GrGpuGL::flushTextureMatrixAndDomain(int s) {
|
||||
(orientationChange || !hwMatrix.cheapEqualTo(samplerMatrix))) {
|
||||
|
||||
GrMatrix m = samplerMatrix;
|
||||
GrSamplerState::SampleMode mode =
|
||||
drawState.getSampler(s).getSampleMode();
|
||||
AdjustTextureMatrix(texture, mode, &m);
|
||||
AdjustTextureMatrix(texture, &m);
|
||||
|
||||
// ES doesn't allow you to pass true to the transpose param,
|
||||
// so do our own transpose
|
||||
@ -251,40 +250,6 @@ void GrGpuGL::flushTextureMatrixAndDomain(int s) {
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuGL::flushRadial2(int s) {
|
||||
|
||||
const int &uni = fProgramData->fUniLocations.fStages[s].fRadial2Uni;
|
||||
const GrSamplerState& sampler = this->getDrawState().getSampler(s);
|
||||
if (GrGLProgram::kUnusedUniform != uni &&
|
||||
(fProgramData->fRadial2CenterX1[s] != sampler.getRadial2CenterX1() ||
|
||||
fProgramData->fRadial2Radius0[s] != sampler.getRadial2Radius0() ||
|
||||
fProgramData->fRadial2PosRoot[s] != sampler.isRadial2PosRoot())) {
|
||||
|
||||
GrScalar centerX1 = sampler.getRadial2CenterX1();
|
||||
GrScalar radius0 = sampler.getRadial2Radius0();
|
||||
|
||||
GrScalar a = GrMul(centerX1, centerX1) - GR_Scalar1;
|
||||
|
||||
// when were in the degenerate (linear) case the second
|
||||
// value will be INF but the program doesn't read it. (We
|
||||
// use the same 6 uniforms even though we don't need them
|
||||
// all in the linear case just to keep the code complexity
|
||||
// down).
|
||||
float values[6] = {
|
||||
GrScalarToFloat(a),
|
||||
1 / (2.f * GrScalarToFloat(a)),
|
||||
GrScalarToFloat(centerX1),
|
||||
GrScalarToFloat(radius0),
|
||||
GrScalarToFloat(GrMul(radius0, radius0)),
|
||||
sampler.isRadial2PosRoot() ? 1.f : -1.f
|
||||
};
|
||||
GL_CALL(Uniform1fv(uni, 6, values));
|
||||
fProgramData->fRadial2CenterX1[s] = sampler.getRadial2CenterX1();
|
||||
fProgramData->fRadial2Radius0[s] = sampler.getRadial2Radius0();
|
||||
fProgramData->fRadial2PosRoot[s] = sampler.isRadial2PosRoot();
|
||||
}
|
||||
}
|
||||
|
||||
void GrGpuGL::flushTexelSize(int s) {
|
||||
const int& uni = fProgramData->fUniLocations.fStages[s].fNormalizedTexelSizeUni;
|
||||
if (GrGLProgram::kUnusedUniform != uni) {
|
||||
@ -475,8 +440,6 @@ bool GrGpuGL::flushGraphicsState(GrPrimitiveType type) {
|
||||
if (this->isStageEnabled(s)) {
|
||||
this->flushTextureMatrixAndDomain(s);
|
||||
|
||||
this->flushRadial2(s);
|
||||
|
||||
this->flushTexelSize(s);
|
||||
|
||||
if (NULL != fProgramData->fCustomStage[s]) {
|
||||
@ -773,29 +736,6 @@ void GrGpuGL::buildProgram(GrPrimitiveType type,
|
||||
} else if (!sampler.getMatrix().hasPerspective()) {
|
||||
stage.fOptFlags |= StageDesc::kNoPerspective_OptFlagBit;
|
||||
}
|
||||
switch (sampler.getSampleMode()) {
|
||||
case GrSamplerState::kNormal_SampleMode:
|
||||
stage.fCoordMapping = StageDesc::kIdentity_CoordMapping;
|
||||
break;
|
||||
case GrSamplerState::kRadial_SampleMode:
|
||||
stage.fCoordMapping = StageDesc::kRadialGradient_CoordMapping;
|
||||
break;
|
||||
case GrSamplerState::kRadial2_SampleMode:
|
||||
if (sampler.radial2IsDegenerate()) {
|
||||
stage.fCoordMapping =
|
||||
StageDesc::kRadial2GradientDegenerate_CoordMapping;
|
||||
} else {
|
||||
stage.fCoordMapping =
|
||||
StageDesc::kRadial2Gradient_CoordMapping;
|
||||
}
|
||||
break;
|
||||
case GrSamplerState::kSweep_SampleMode:
|
||||
stage.fCoordMapping = StageDesc::kSweepGradient_CoordMapping;
|
||||
break;
|
||||
default:
|
||||
GrCrash("Unexpected sample mode!");
|
||||
break;
|
||||
}
|
||||
|
||||
switch (sampler.getFilter()) {
|
||||
// these both can use a regular texture2D()
|
||||
@ -858,7 +798,6 @@ void GrGpuGL::buildProgram(GrPrimitiveType type,
|
||||
|
||||
} else {
|
||||
stage.fOptFlags = 0;
|
||||
stage.fCoordMapping = (StageDesc::CoordMapping) 0;
|
||||
stage.fInConfigFlags = 0;
|
||||
stage.fFetchMode = (StageDesc::FetchMode) 0;
|
||||
stage.fCustomStageKey = 0;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "GrGpuGL.h"
|
||||
|
||||
#include "effects/GrConvolutionEffect.h"
|
||||
#include "effects/GrGradientEffects.h"
|
||||
#include "effects/GrMorphologyEffect.h"
|
||||
#include "GrProgramStageFactory.h"
|
||||
#include "GrRandom.h"
|
||||
@ -32,6 +33,9 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
|
||||
kConvolution_EffectType,
|
||||
kErode_EffectType,
|
||||
kDilate_EffectType,
|
||||
kRadialGradient_EffectType,
|
||||
kRadial2Gradient_EffectType,
|
||||
kSweepGradient_EffectType,
|
||||
|
||||
kEffectCount
|
||||
};
|
||||
@ -85,6 +89,21 @@ GrCustomStage* create_random_effect(StageDesc* stageDesc,
|
||||
kernelRadius,
|
||||
GrContext::kDilate_MorphologyType);
|
||||
}
|
||||
case kRadialGradient_EffectType: {
|
||||
return new GrRadialGradient();
|
||||
}
|
||||
case kRadial2Gradient_EffectType: {
|
||||
float center;
|
||||
do {
|
||||
center = random->nextF();
|
||||
} while (GR_Scalar1 == center);
|
||||
float radius = random->nextF();
|
||||
bool root = random_bool(random);
|
||||
return new GrRadial2Gradient(center, radius, root);
|
||||
}
|
||||
case kSweepGradient_EffectType: {
|
||||
return new GrSweepGradient();
|
||||
}
|
||||
default:
|
||||
GrCrash("Unexpected custom effect type");
|
||||
}
|
||||
@ -99,7 +118,6 @@ bool GrGpuGL::programUnitTest() {
|
||||
static const int STAGE_OPTS[] = {
|
||||
0,
|
||||
StageDesc::kNoPerspective_OptFlagBit,
|
||||
StageDesc::kIdentity_CoordMapping
|
||||
};
|
||||
static const int IN_CONFIG_FLAGS[] = {
|
||||
StageDesc::kNone_InConfigFlag,
|
||||
@ -187,7 +205,6 @@ bool GrGpuGL::programUnitTest() {
|
||||
|
||||
stage.fOptFlags = STAGE_OPTS[random_int(&random, GR_ARRAY_COUNT(STAGE_OPTS))];
|
||||
stage.fInConfigFlags = IN_CONFIG_FLAGS[random_int(&random, GR_ARRAY_COUNT(IN_CONFIG_FLAGS))];
|
||||
stage.fCoordMapping = random_int(&random, StageDesc::kCoordMappingCnt);
|
||||
stage.fFetchMode = random_int(&random, StageDesc::kFetchModeCnt);
|
||||
stage.setEnabled(VertexUsesStage(s, pdesc.fVertexLayout));
|
||||
static const uint32_t kMulByAlphaMask =
|
||||
|
Loading…
Reference in New Issue
Block a user