// doesn't set the texture/sampler/matrix state
// caller needs to null out GrPaint's texture if
// non-textured drawing is desired.
+ // Set constantColor to true if a constant color
+ // will be used. This is an optimization, and can
+ // always be set to false. constantColor should
+ // never be true if justAlpha is true.
bool skPaint2GrPaintNoShader(const SkPaint& skPaint,
bool justAlpha,
- GrPaint* grPaint);
+ GrPaint* grPaint,
+ bool constantColor);
// uses the SkShader to setup paint, act used to
// hold lock on cached texture and free it when
// destroyed.
+ // If there is no shader, constantColor will
+ // be passed to skPaint2GrPaintNoShader. Otherwise
+ // it is ignored.
bool skPaint2GrPaintShader(const SkPaint& skPaint,
SkAutoCachedTexture* act,
const SkMatrix& ctm,
- GrPaint* grPaint);
+ GrPaint* grPaint,
+ bool constantColor);
SkDrawProcs* initDrawForText(GrTextContext*);
bool bindDeviceAsTexture(GrPaint* paint);
bool SkGpuDevice::skPaint2GrPaintNoShader(const SkPaint& skPaint,
bool justAlpha,
- GrPaint* grPaint) {
+ GrPaint* grPaint,
+ bool constantColor) {
grPaint->fDither = skPaint.isDither();
grPaint->fAntiAlias = skPaint.isAntiAlias();
if (justAlpha) {
uint8_t alpha = skPaint.getAlpha();
grPaint->fColor = GrColorPackRGBA(alpha, alpha, alpha, alpha);
+ // justAlpha is currently set to true only if there is a texture,
+ // so constantColor should not also be true.
+ GrAssert(!constantColor);
} else {
grPaint->fColor = SkGr::SkColor2GrColor(skPaint.getColor());
grPaint->setTexture(NULL);
SkColor color;
SkXfermode::Mode filterMode;
if (colorFilter != NULL && colorFilter->asColorMode(&color, &filterMode)) {
- grPaint->fColorFilterColor = SkGr::SkColor2GrColor(color);
- grPaint->fColorFilterXfermode = filterMode;
- } else {
- grPaint->resetColorFilter();
+ if (!constantColor) {
+ grPaint->fColorFilterColor = SkGr::SkColor2GrColor(color);
+ grPaint->fColorFilterXfermode = filterMode;
+ return true;
+ }
+ SkColor filtered = colorFilter->filterColor(skPaint.getColor());
+ grPaint->fColor = SkGr::SkColor2GrColor(filtered);
}
+ grPaint->resetColorFilter();
return true;
}
bool SkGpuDevice::skPaint2GrPaintShader(const SkPaint& skPaint,
SkAutoCachedTexture* act,
const SkMatrix& ctm,
- GrPaint* grPaint) {
+ GrPaint* grPaint,
+ bool constantColor) {
SkASSERT(NULL != act);
SkShader* shader = skPaint.getShader();
if (NULL == shader) {
- return this->skPaint2GrPaintNoShader(skPaint, false, grPaint);
- } else if (!this->skPaint2GrPaintNoShader(skPaint, true, grPaint)) {
+ return this->skPaint2GrPaintNoShader(skPaint,
+ false,
+ grPaint,
+ constantColor);
+ } else if (!this->skPaint2GrPaintNoShader(skPaint, true, grPaint, false)) {
return false;
}
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}
fContext->drawRect(grPaint, rect, doStroke ? width : -1);
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}
}
GrPaint grPaint;
- if (!this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+ if (!this->skPaint2GrPaintNoShader(paint, true, &grPaint, false)) {
return;
}
if (paint.isFilterBitmap()) {
}
GrPaint grPaint;
- if(!this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+ if(!this->skPaint2GrPaintNoShader(paint, true, &grPaint, false)) {
return;
}
GrPaint grPaint;
if (!((SkGpuDevice*)dev)->bindDeviceAsTexture(&grPaint) ||
- !this->skPaint2GrPaintNoShader(paint, true, &grPaint)) {
+ !this->skPaint2GrPaintNoShader(paint, true, &grPaint, false)) {
return;
}
SkAutoCachedTexture act;
// we ignore the shader if texs is null.
if (NULL == texs) {
- if (!this->skPaint2GrPaintNoShader(paint, false, &grPaint)) {
+ if (!this->skPaint2GrPaintNoShader(paint,
+ false,
+ &grPaint,
+ NULL == colors)) {
return;
}
} else {
if (!this->skPaint2GrPaintShader(paint, &act,
*draw.fMatrix,
- &grPaint)) {
+ &grPaint,
+ NULL == colors)) {
return;
}
}
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}
GrTextContext context(fContext, grPaint, draw.fExtMatrix);
GrPaint grPaint;
SkAutoCachedTexture act;
- if (!this->skPaint2GrPaintShader(paint, &act, *draw.fMatrix, &grPaint)) {
+ if (!this->skPaint2GrPaintShader(paint,
+ &act,
+ *draw.fMatrix,
+ &grPaint,
+ true)) {
return;
}