// in fPath since that path may have resulted from a SkStrokeRec::applyToPath call.
uint32_t fGenID;
SkStrokeRec fStroke;
+ GrColor fColor;
bool fAntiAlias;
};
- static GrDrawBatch* Create(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix,
+ static GrDrawBatch* Create(const Geometry& geometry, const SkMatrix& viewMatrix,
GrBatchAtlas* atlas, PathCache* pathCache, PathDataList* pathList) {
- return new AADistanceFieldPathBatch(geometry, color, viewMatrix, atlas, pathCache,
- pathList);
+ return new AADistanceFieldPathBatch(geometry, viewMatrix, atlas, pathCache, pathList);
}
const char* name() const override { return "AADistanceFieldPathBatch"; }
void computePipelineOptimizations(GrInitInvariantOutput* color,
GrInitInvariantOutput* coverage,
GrBatchToXPOverrides* overrides) const override {
- color->setKnownFourComponents(fBatch.fColor);
+ color->setKnownFourComponents(fGeoData[0].fColor);
coverage->setUnknownSingleComponent();
overrides->fUsePLSDstRead = false;
}
void initBatchTracker(const GrXPOverridesForBatch& overrides) override {
// Handle any color overrides
if (!overrides.readsColor()) {
- fBatch.fColor = GrColor_ILLEGAL;
+ fGeoData[0].fColor = GrColor_ILLEGAL;
}
- overrides.getOverrideColorIfSet(&fBatch.fColor);
+ overrides.getOverrideColorIfSet(&fGeoData[0].fColor);
// setup batch properties
fBatch.fColorIgnored = !overrides.readsColor();
// allocate vertices
size_t vertexStride = dfProcessor->getVertexStride();
- SkASSERT(vertexStride == 2 * sizeof(SkPoint));
+ SkASSERT(vertexStride == 2 * sizeof(SkPoint) + sizeof(GrColor));
const GrVertexBuffer* vertexBuffer;
void* vertices = target->makeVertexSpace(vertexStride,
// Now set vertices
intptr_t offset = reinterpret_cast<intptr_t>(vertices);
offset += i * kVerticesPerQuad * vertexStride;
- SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
this->writePathVertices(target,
atlas,
this->pipeline(),
dfProcessor,
- positions,
+ offset,
+ args.fColor,
vertexStride,
this->viewMatrix(),
args.fPath,
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
- AADistanceFieldPathBatch(const Geometry& geometry, GrColor color, const SkMatrix& viewMatrix,
+ AADistanceFieldPathBatch(const Geometry& geometry,
+ const SkMatrix& viewMatrix,
GrBatchAtlas* atlas,
PathCache* pathCache, PathDataList* pathList)
: INHERITED(ClassID()) {
- fBatch.fColor = color;
fBatch.fViewMatrix = viewMatrix;
fGeoData.push_back(geometry);
GrBatchAtlas* atlas,
const GrPipeline* pipeline,
const GrGeometryProcessor* gp,
- SkPoint* positions,
+ intptr_t offset,
+ GrColor color,
size_t vertexStride,
const SkMatrix& viewMatrix,
const SkPath& path,
SkFixed tw = SkScalarToFixed(pathData->fBounds.width());
SkFixed th = SkScalarToFixed(pathData->fBounds.height());
+ SkPoint* positions = reinterpret_cast<SkPoint*>(offset);
+
// vertex positions
// TODO make the vertex attributes a struct
SkRect r = SkRect::MakeXYWH(dx, dy, width, height);
positions->setRectFan(r.left(), r.top(), r.right(), r.bottom(), vertexStride);
+ // colors
+ for (int i = 0; i < kVerticesPerQuad; i++) {
+ GrColor* colorPtr = (GrColor*)(offset + sizeof(SkPoint) + i * vertexStride);
+ *colorPtr = color;
+ }
+
// vertex texture coords
- SkPoint* textureCoords = positions + 1;
+ SkPoint* textureCoords = (SkPoint*)(offset + sizeof(SkPoint) + sizeof(GrColor));
textureCoords->setRectFan(SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx)),
SkFixedToFloat(texture->texturePriv().normalizeFixedY(ty)),
SkFixedToFloat(texture->texturePriv().normalizeFixedX(tx + tw)),
flushInfo->fInstancesToFlush = 0;
}
- GrColor color() const { return fBatch.fColor; }
+ GrColor color() const { return fGeoData[0].fColor; }
const SkMatrix& viewMatrix() const { return fBatch.fViewMatrix; }
bool usesLocalCoords() const { return fBatch.fUsesLocalCoords; }
return false;
}
- // TODO we could actually probably do a bunch of this work on the CPU, ie map viewMatrix,
- // maybe upload color via attribute
- if (this->color() != that->color()) {
- return false;
- }
-
+ // TODO We can position on the cpu
if (!this->viewMatrix().cheapEqualTo(that->viewMatrix())) {
return false;
}
}
struct BatchTracker {
- GrColor fColor;
SkMatrix fViewMatrix;
bool fUsesLocalCoords;
bool fColorIgnored;
} else {
args.fStroke->applyToPath(&geometry.fPath, *args.fPath);
}
+ geometry.fColor = args.fColor;
geometry.fAntiAlias = args.fAntiAlias;
// Note: this is the generation ID of the _original_ path. When a new path is
// generated due to stroking it is important that the original path's id is used
// for caching.
geometry.fGenID = args.fPath->getGenerationID();
- SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry, args.fColor,
+ SkAutoTUnref<GrDrawBatch> batch(AADistanceFieldPathBatch::Create(geometry,
*args.fViewMatrix, fAtlas,
&fPathCache, &fPathList));
args.fTarget->drawBatch(*args.fPipelineBuilder, batch);
GrColor color = GrRandomColor(random);
AADistanceFieldPathBatch::Geometry geometry(GrTest::TestStrokeRec(random));
+ geometry.fColor = color;
geometry.fPath = GrTest::TestPath(random);
geometry.fAntiAlias = random->nextBool();
geometry.fGenID = random->nextU();
- return AADistanceFieldPathBatch::Create(geometry, color, viewMatrix,
+ return AADistanceFieldPathBatch::Create(geometry, viewMatrix,
gTestStruct.fAtlas,
&gTestStruct.fPathCache,
&gTestStruct.fPathList);
flags |= kUseLCD_DistanceFieldEffectFlag;
flags |= viewMatrix.rectStaysRect() ? kRectToRect_DistanceFieldEffectFlag : 0;
flags |= fUseBGR ? kBGR_DistanceFieldEffectFlag : 0;
- flags |= kColorAttr_DistanceFieldEffectFlag;
GrColor colorNoPreMul = skcolor_to_grcolor_nopremultiply(filteredColor);
flags,
this->usesLocalCoords());
} else {
- flags |= kColorAttr_DistanceFieldEffectFlag;
#ifdef SK_GAMMA_APPLY_TO_A8
U8CPU lum = SkColorSpaceLuminance::computeLuminance(SK_GAMMA_EXPONENT, filteredColor);
float correction = (*fDistanceAdjustTable)[lum >> kDistanceAdjustLumShift];
public:
GrGLDistanceFieldA8TextGeoProc()
: fViewMatrix(SkMatrix::InvalidMatrix())
- , fColor(GrColor_ILLEGAL)
#ifdef SK_GAMMA_APPLY_TO_A8
, fDistanceAdjust(-1.0f)
#endif
// Setup pass through color
if (!dfTexEffect.colorIgnored()) {
- if (dfTexEffect.hasVertexColor()) {
- varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
- } else {
- this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
- &fColorUniform);
- }
+ varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
}
// Setup position
GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix);
pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
}
-
- if (dfa8gp.color() != fColor && !dfa8gp.hasVertexColor()) {
- float c[4];
- GrColorToRGBAFloat(dfa8gp.color(), c);
- pdman.set4fv(fColorUniform, 1, c);
- fColor = dfa8gp.color();
- }
}
static inline void GenKey(const GrGeometryProcessor& gp,
GrProcessorKeyBuilder* b) {
const GrDistanceFieldA8TextGeoProc& dfTexEffect = gp.cast<GrDistanceFieldA8TextGeoProc>();
uint32_t key = dfTexEffect.getFlags();
- key |= dfTexEffect.hasVertexColor() << 16;
- key |= dfTexEffect.colorIgnored() << 17;
+ key |= dfTexEffect.colorIgnored() << 16;
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25;
b->add32(key);
private:
SkMatrix fViewMatrix;
- GrColor fColor;
- UniformHandle fColorUniform;
UniformHandle fViewMatrixUniform;
#ifdef SK_GAMMA_APPLY_TO_A8
float fDistanceAdjust;
this->initClassID<GrDistanceFieldA8TextGeoProc>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType,
kHigh_GrSLPrecision));
- if (flags & kColorAttr_DistanceFieldEffectFlag) {
- fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
- }
+ fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
kVec2s_GrVertexAttribType));
this->addTextureAccess(&fTextureAccess);
public:
GrGLDistanceFieldPathGeoProc()
: fViewMatrix(SkMatrix::InvalidMatrix())
- , fColor(GrColor_ILLEGAL)
, fTextureSize(SkISize::Make(-1, -1)) {}
void onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) override{
// setup pass through color
if (!dfTexEffect.colorIgnored()) {
- if (dfTexEffect.hasVertexColor()) {
- varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
- } else {
- this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
- &fColorUniform);
- }
+ varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
}
vertBuilder->codeAppendf("%s = %s;", v.vsOut(), dfTexEffect.inTextureCoords()->fName);
GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix);
pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
}
-
- if (dfpgp.color() != fColor && !dfpgp.hasVertexColor()) {
- float c[4];
- GrColorToRGBAFloat(dfpgp.color(), c);
- pdman.set4fv(fColorUniform, 1, c);
- fColor = dfpgp.color();
- }
}
static inline void GenKey(const GrGeometryProcessor& gp,
uint32_t key = dfTexEffect.getFlags();
key |= dfTexEffect.colorIgnored() << 16;
- key |= dfTexEffect.hasVertexColor() << 17;
key |= ComputePosKey(dfTexEffect.viewMatrix()) << 25;
b->add32(key);
}
private:
- UniformHandle fColorUniform;
UniformHandle fTextureSizeUni;
UniformHandle fViewMatrixUniform;
SkMatrix fViewMatrix;
- GrColor fColor;
SkISize fTextureSize;
typedef GrGLSLGeometryProcessor INHERITED;
this->initClassID<GrDistanceFieldPathGeoProc>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType,
kHigh_GrSLPrecision));
- if (flags & kColorAttr_DistanceFieldEffectFlag) {
- fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
- }
+ fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
kVec2f_GrVertexAttribType));
this->addTextureAccess(&fTextureAccess);
class GrGLDistanceFieldLCDTextGeoProc : public GrGLSLGeometryProcessor {
public:
GrGLDistanceFieldLCDTextGeoProc()
- : fViewMatrix(SkMatrix::InvalidMatrix()), fColor(GrColor_ILLEGAL) {
+ : fViewMatrix(SkMatrix::InvalidMatrix()) {
fDistanceAdjust = GrDistanceFieldLCDTextGeoProc::DistanceAdjust::Make(1.0f, 1.0f, 1.0f);
}
// setup pass through color
if (!dfTexEffect.colorIgnored()) {
- if (dfTexEffect.hasVertexColor()) {
- varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
- } else {
- this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor,
- &fColorUniform);
- }
+ varyingHandler->addPassThroughAttribute(dfTexEffect.inColor(), args.fOutputColor);
}
// Setup position
GrGLSLGetMatrix<3>(viewMatrix, fViewMatrix);
pdman.setMatrix3f(fViewMatrixUniform, viewMatrix);
}
-
- if (dflcd.color() != fColor && !dflcd.hasVertexColor()) {
- float c[4];
- GrColorToRGBAFloat(dflcd.color(), c);
- pdman.set4fv(fColorUniform, 1, c);
- fColor = dflcd.color();
- }
}
static inline void GenKey(const GrGeometryProcessor& gp,
private:
SkMatrix fViewMatrix;
- GrColor fColor;
UniformHandle fViewMatrixUniform;
UniformHandle fColorUniform;
GrDistanceFieldLCDTextGeoProc::DistanceAdjust fDistanceAdjust;
this->initClassID<GrDistanceFieldLCDTextGeoProc>();
fInPosition = &this->addVertexAttrib(Attribute("inPosition", kVec2f_GrVertexAttribType,
kHigh_GrSLPrecision));
- if (flags & kColorAttr_DistanceFieldEffectFlag) {
- fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
- }
+ fInColor = &this->addVertexAttrib(Attribute("inColor", kVec4ub_GrVertexAttribType));
fInTextureCoords = &this->addVertexAttrib(Attribute("inTextureCoords",
kVec2s_GrVertexAttribType));
this->addTextureAccess(&fTextureAccess);
kUseLCD_DistanceFieldEffectFlag = 0x04, // use lcd text
kBGR_DistanceFieldEffectFlag = 0x08, // lcd display has bgr order
kPortrait_DistanceFieldEffectFlag = 0x10, // lcd display is in portrait mode (not used yet)
- kColorAttr_DistanceFieldEffectFlag = 0x20, // color vertex attribute
kInvalid_DistanceFieldEffectFlag = 0x80, // invalid state (for initialization)
kUniformScale_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
kRectToRect_DistanceFieldEffectFlag,
// The subset of the flags relevant to GrDistanceFieldA8TextGeoProc
- kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
- kColorAttr_DistanceFieldEffectFlag,
+ kNonLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag,
// The subset of the flags relevant to GrDistanceFieldLCDTextGeoProc
kLCD_DistanceFieldEffectMask = kSimilarity_DistanceFieldEffectFlag |
kRectToRect_DistanceFieldEffectFlag |
kUseLCD_DistanceFieldEffectFlag |
- kBGR_DistanceFieldEffectFlag |
- kColorAttr_DistanceFieldEffectFlag,
+ kBGR_DistanceFieldEffectFlag,
};
/**
const Attribute* inTextureCoords() const { return fInTextureCoords; }
GrColor color() const { return fColor; }
bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
- bool hasVertexColor() const { return SkToBool(fInColor); }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
#ifdef SK_GAMMA_APPLY_TO_A8
const Attribute* inTextureCoords() const { return fInTextureCoords; }
GrColor color() const { return fColor; }
bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
- bool hasVertexColor() const { return SkToBool(fInColor); }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
uint32_t getFlags() const { return fFlags; }
bool usesLocalCoords() const { return fUsesLocalCoords; }
DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
GrColor color() const { return fColor; }
bool colorIgnored() const { return GrColor_ILLEGAL == fColor; }
- bool hasVertexColor() const { return SkToBool(fInColor); }
const SkMatrix& viewMatrix() const { return fViewMatrix; }
uint32_t getFlags() const { return fFlags; }
bool usesLocalCoords() const { return fUsesLocalCoords; }