Just pass the draw context to paint conversion

Concentrate on using draw context functionality to answer gamma and color
related queries in more places.

BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2182603003

Review-Url: https://codereview.chromium.org/2182603003
This commit is contained in:
brianosman 2016-07-25 12:31:51 -07:00 committed by Commit bot
parent 20a272d024
commit 8fe485b793
10 changed files with 83 additions and 135 deletions

View File

@ -100,7 +100,7 @@ protected:
skPaint.setColor(kPaintColors[paintType]);
}
// SRGBTODO: No sRGB inputs allowed here?
SkAssertResult(SkPaintToGrPaint(context, skPaint, viewMatrix, false, nullptr,
SkAssertResult(SkPaintToGrPaint(context, drawContext, skPaint, viewMatrix,
&grPaint));
GrConstColorProcessor::InputMode mode = (GrConstColorProcessor::InputMode) m;

View File

@ -269,6 +269,10 @@ public:
GrPixelConfig config() const { return fRenderTarget->config(); }
int numColorSamples() const { return fRenderTarget->numColorSamples(); }
bool isGammaCorrect() const { return fSurfaceProps.isGammaCorrect(); }
SkSourceGammaTreatment sourceGammaTreatment() const {
return this->isGammaCorrect() ? SkSourceGammaTreatment::kRespect
: SkSourceGammaTreatment::kIgnore;
}
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }

View File

@ -287,8 +287,7 @@ void GrBlurUtils::drawPathWithMaskFilter(GrContext* context,
SkDEBUGCODE(prePathMatrix = (const SkMatrix*)0x50FF8001;)
GrPaint grPaint;
if (!SkPaintToGrPaint(context, paint, viewMatrix, drawContext->isGammaCorrect(),
drawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaint(context, drawContext, paint, viewMatrix, &grPaint)) {
return;
}

View File

@ -309,9 +309,7 @@ void SkGpuDevice::drawPaint(const SkDraw& draw, const SkPaint& paint) {
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawPaint", fContext);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -361,8 +359,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStyle style(paint, SkPaint::kStroke_Style);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return;
}
@ -383,9 +380,7 @@ void SkGpuDevice::drawPoints(const SkDraw& draw, SkCanvas::PointMode mode,
}
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -422,9 +417,7 @@ void SkGpuDevice::drawRect(const SkDraw& draw, const SkRect& rect, const SkPaint
}
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -441,9 +434,7 @@ void SkGpuDevice::drawRRect(const SkDraw& draw, const SkRRect& rect,
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -518,8 +509,7 @@ void SkGpuDevice::drawDRRect(const SkDraw& draw, const SkRRect& outer,
if (stroke.isFillStyle() && !paint.getMaskFilter() && !paint.getPathEffect()) {
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return;
}
@ -564,9 +554,7 @@ void SkGpuDevice::drawOval(const SkDraw& draw, const SkRect& oval, const SkPaint
}
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -622,9 +610,7 @@ void SkGpuDevice::drawStrokedLine(const SkPoint points[2],
m.postConcat(*draw.fMatrix);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), newPaint, m,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), newPaint, m, &grPaint)) {
return;
}
@ -1036,9 +1022,8 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
SkASSERT(bitmap.width() <= fContext->caps()->maxTileSize() &&
bitmap.height() <= fContext->caps()->maxTileSize());
SkSourceGammaTreatment gammaTreatment = this->surfaceProps().isGammaCorrect()
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params, gammaTreatment);
sk_sp<GrTexture> texture = GrMakeCachedBitmapTexture(fContext, bitmap, params,
fDrawContext->sourceGammaTreatment());
if (nullptr == texture) {
return;
}
@ -1105,10 +1090,9 @@ void SkGpuDevice::internalDrawBitmap(const SkBitmap& bitmap,
}
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), paint, viewMatrix, std::move(fp),
kAlpha_8_SkColorType == bitmap.colorType(),
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, viewMatrix,
std::move(fp), kAlpha_8_SkColorType == bitmap.colorType(),
&grPaint)) {
return;
}
@ -1198,9 +1182,8 @@ void SkGpuDevice::drawSpecial(const SkDraw& draw,
} else {
fp = GrFragmentProcessor::MulOutputByInputAlpha(std::move(fp));
}
if (!SkPaintToGrPaintReplaceShader(this->context(), tmpUnfiltered, std::move(fp),
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintReplaceShader(this->context(), fDrawContext.get(), tmpUnfiltered,
std::move(fp), &grPaint)) {
return;
}
@ -1471,18 +1454,15 @@ void SkGpuDevice::drawProducerNine(const SkDraw& draw, GrTextureProducer* produc
}
static const GrTextureParams::FilterMode kMode = GrTextureParams::kNone_FilterMode;
bool gammaCorrect = this->surfaceProps().isGammaCorrect();
SkSourceGammaTreatment gammaTreatment = gammaCorrect
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
sk_sp<GrFragmentProcessor> fp(
producer->createFragmentProcessor(SkMatrix::I(),
SkRect::MakeIWH(producer->width(), producer->height()),
GrTextureProducer::kNo_FilterConstraint, true,
&kMode, fDrawContext->getColorSpace(), gammaTreatment));
&kMode, fDrawContext->getColorSpace(),
fDrawContext->sourceGammaTreatment()));
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(this->context(), paint, *draw.fMatrix, std::move(fp),
producer->isAlphaOnly(), gammaCorrect,
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithTexture(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
std::move(fp), producer->isAlphaOnly(), &grPaint)) {
return;
}
@ -1544,9 +1524,7 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
GrPaint grPaint;
// we ignore the shader if texs is null.
if (!SkPaintToGrPaintNoShader(this->context(), copy,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), copy, &grPaint)) {
return;
}
@ -1617,16 +1595,14 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
} else {
colorMode = SkXfermode::kModulate_Mode;
}
if (!SkPaintToGrPaintWithXfermode(this->context(), paint, *draw.fMatrix, colorMode,
false, this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), paint,
*draw.fMatrix, colorMode, false, &grPaint)) {
return;
}
} else {
// We have a shader, but no colors to blend it against.
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix,
&grPaint)) {
return;
}
}
@ -1634,16 +1610,13 @@ void SkGpuDevice::drawVertices(const SkDraw& draw, SkCanvas::VertexMode vmode,
if (colors) {
// We have colors, but either have no shader or no texture coords (which implies that
// we should ignore the shader).
if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), paint,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithPrimitiveColor(this->context(), fDrawContext.get(), paint,
&grPaint)) {
return;
}
} else {
// No colors and no shaders. Just draw with the paint color.
if (!SkPaintToGrPaintNoShader(this->context(), paint,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintNoShader(this->context(), fDrawContext.get(), paint, &grPaint)) {
return;
}
}
@ -1680,15 +1653,12 @@ void SkGpuDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRS
GrPaint grPaint;
if (colors) {
if (!SkPaintToGrPaintWithXfermode(this->context(), p, *draw.fMatrix, mode, true,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithXfermode(this->context(), fDrawContext.get(), p, *draw.fMatrix,
mode, true, &grPaint)) {
return;
}
} else {
if (!SkPaintToGrPaint(this->context(), p, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(),
fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), p, *draw.fMatrix, &grPaint)) {
return;
}
}
@ -1707,9 +1677,7 @@ void SkGpuDevice::drawText(const SkDraw& draw, const void* text,
GR_CREATE_TRACE_MARKER_CONTEXT("SkGpuDevice", "drawText", fContext);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}
@ -1727,9 +1695,7 @@ void SkGpuDevice::drawPosText(const SkDraw& draw, const void* text, size_t byteL
CHECK_SHOULD_DRAW(draw);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->context(), paint, *draw.fMatrix,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, *draw.fMatrix, &grPaint)) {
return;
}

View File

@ -201,19 +201,16 @@ void SkGpuDevice::drawTextureProducerImpl(GrTextureProducer* producer,
}
textureMatrix = &tempMatrix;
}
bool gammaCorrect = this->surfaceProps().isGammaCorrect();
SkSourceGammaTreatment gammaTreatment = gammaCorrect
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
sk_sp<GrFragmentProcessor> fp(producer->createFragmentProcessor(
*textureMatrix, clippedSrcRect, constraintMode, coordsAllInsideSrcRect, filterMode,
fDrawContext->getColorSpace(), gammaTreatment));
fDrawContext->getColorSpace(), fDrawContext->sourceGammaTreatment()));
if (!fp) {
return;
}
GrPaint grPaint;
if (!SkPaintToGrPaintWithTexture(fContext, paint, viewMatrix, fp, producer->isAlphaOnly(),
gammaCorrect, fDrawContext->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaintWithTexture(fContext, fDrawContext.get(), paint, viewMatrix, fp,
producer->isAlphaOnly(), &grPaint)) {
return;
}

View File

@ -11,6 +11,7 @@
#include "GrCaps.h"
#include "GrContext.h"
#include "GrDrawContext.h"
#include "GrGpuResourcePriv.h"
#include "GrImageIDTextureAdjuster.h"
#include "GrTextureParamsAdjuster.h"
@ -515,22 +516,21 @@ static inline bool blend_requires_shader(const SkXfermode::Mode mode, bool primi
}
static inline bool skpaint_to_grpaint_impl(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
const SkMatrix& viewM,
sk_sp<GrFragmentProcessor>* shaderProcessor,
SkXfermode::Mode* primColorMode,
bool primitiveIsSrc,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
grPaint->setAntiAlias(skPaint.isAntiAlias());
grPaint->setAllowSRGBInputs(allowSRGBInputs);
grPaint->setAllowSRGBInputs(dc->isGammaCorrect());
// Raw translation of the SkPaint color to our 4f format:
GrColor4f origColor = GrColor4f::FromGrColor(SkColorToUnpremulGrColor(skPaint.getColor()));
// Linearize, if the color is meant to be in sRGB gamma:
if (allowSRGBInputs) {
if (dc->isGammaCorrect()) {
origColor.fRGBA[0] = exact_srgb_to_linear(origColor.fRGBA[0]);
origColor.fRGBA[1] = exact_srgb_to_linear(origColor.fRGBA[1]);
origColor.fRGBA[2] = exact_srgb_to_linear(origColor.fRGBA[2]);
@ -543,12 +543,10 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
if (shaderProcessor) {
shaderFP = *shaderProcessor;
} else if (const SkShader* shader = skPaint.getShader()) {
SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context, &viewM, nullptr,
skPaint.getFilterQuality(),
dstColorSpace,
gammaTreatment));
dc->getColorSpace(),
dc->sourceGammaTreatment()));
if (!shaderFP) {
return false;
}
@ -653,79 +651,72 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
}
#ifndef SK_IGNORE_GPU_DITHER
if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !allowSRGBInputs) {
if (skPaint.isDither() && grPaint->numColorFragmentProcessors() > 0 && !dc->isGammaCorrect()) {
grPaint->addColorFragmentProcessor(GrDitherEffect::Make());
}
#endif
return true;
}
bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
bool allowSRGBInputs, SkColorSpace* dstColorSpace, GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, false,
allowSRGBInputs, dstColorSpace, grPaint);
bool SkPaintToGrPaint(GrContext* context, GrDrawContext* dc, const SkPaint& skPaint,
const SkMatrix& viewM, GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, nullptr, false, grPaint);
}
/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */
bool SkPaintToGrPaintReplaceShader(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
sk_sp<GrFragmentProcessor> shaderFP,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
if (!shaderFP) {
return false;
}
return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
allowSRGBInputs, dstColorSpace, grPaint);
return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
grPaint);
}
/** Ignores the SkShader (if any) on skPaint. */
bool SkPaintToGrPaintNoShader(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
// Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced.
static sk_sp<GrFragmentProcessor> kNullShaderFP(nullptr);
static sk_sp<GrFragmentProcessor>* kIgnoreShader = &kNullShaderFP;
return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShader, nullptr, false,
allowSRGBInputs, dstColorSpace, grPaint);
return skpaint_to_grpaint_impl(context, dc, skPaint, SkMatrix::I(), kIgnoreShader, nullptr,
false, grPaint);
}
/** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must
be setup as a vertex attribute using the specified SkXfermode::Mode. */
bool SkPaintToGrPaintWithXfermode(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
const SkMatrix& viewM,
SkXfermode::Mode primColorMode,
bool primitiveIsSrc,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorMode, primitiveIsSrc,
allowSRGBInputs, dstColorSpace, grPaint);
return skpaint_to_grpaint_impl(context, dc, skPaint, viewM, nullptr, &primColorMode,
primitiveIsSrc, grPaint);
}
bool SkPaintToGrPaintWithTexture(GrContext* context,
GrDrawContext* dc,
const SkPaint& paint,
const SkMatrix& viewM,
sk_sp<GrFragmentProcessor> fp,
bool textureIsAlphaOnly,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
sk_sp<GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
if (const SkShader* shader = paint.getShader()) {
SkSourceGammaTreatment gammaTreatment = allowSRGBInputs
? SkSourceGammaTreatment::kRespect : SkSourceGammaTreatment::kIgnore;
shaderFP = shader->asFragmentProcessor(SkShader::AsFPArgs(context,
&viewM,
nullptr,
paint.getFilterQuality(),
dstColorSpace,
gammaTreatment));
dc->getColorSpace(),
dc->sourceGammaTreatment()));
if (!shaderFP) {
return false;
}
@ -738,8 +729,7 @@ bool SkPaintToGrPaintWithTexture(GrContext* context,
shaderFP = GrFragmentProcessor::MulOutputByInputAlpha(fp);
}
return SkPaintToGrPaintReplaceShader(context, paint, std::move(shaderFP), allowSRGBInputs,
dstColorSpace, grPaint);
return SkPaintToGrPaintReplaceShader(context, dc, paint, std::move(shaderFP), grPaint);
}

View File

@ -16,6 +16,7 @@
class GrCaps;
class GrContext;
class GrDrawContext;
class GrFragmentProcessor;
class GrPaint;
class GrTexture;
@ -46,27 +47,24 @@ void GrInstallBitmapUniqueKeyInvalidator(const GrUniqueKey& key, SkPixelRef* pix
/** Converts an SkPaint to a GrPaint for a given GrContext. The matrix is required in order
to convert the SkShader (if any) on the SkPaint. The primitive itself has no color. */
bool SkPaintToGrPaint(GrContext*,
GrDrawContext*,
const SkPaint& skPaint,
const SkMatrix& viewM,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint);
/** Same as above but ignores the SkShader (if any) on skPaint. */
bool SkPaintToGrPaintNoShader(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint);
/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. The processor
should expect an unpremul input color and produce a premultiplied output color. There is
no primitive color. */
bool SkPaintToGrPaintReplaceShader(GrContext*,
GrDrawContext*,
const SkPaint& skPaint,
sk_sp<GrFragmentProcessor> shaderFP,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint);
/** Blends the SkPaint's shader (or color if no shader) with the color which specified via a
@ -74,34 +72,31 @@ bool SkPaintToGrPaintReplaceShader(GrContext*,
primitive color is the dst or src color to the blend in order to work around differences between
drawVertices and drawAtlas. */
bool SkPaintToGrPaintWithXfermode(GrContext* context,
GrDrawContext* dc,
const SkPaint& skPaint,
const SkMatrix& viewM,
SkXfermode::Mode primColorMode,
bool primitiveIsSrc,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint);
/** This is used when there is a primitive color, but the shader should be ignored. Currently,
the expectation is that the primitive color will be premultiplied, though it really should be
unpremultiplied so that interpolation is done in unpremul space. The paint's alpha will be
applied to the primitive color after interpolation. */
inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, const SkPaint& skPaint,
bool allowSRGBInputs, SkColorSpace* dstColorSpace,
GrPaint* grPaint) {
return SkPaintToGrPaintWithXfermode(context, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode,
false, allowSRGBInputs, dstColorSpace, grPaint);
inline bool SkPaintToGrPaintWithPrimitiveColor(GrContext* context, GrDrawContext* dc,
const SkPaint& skPaint, GrPaint* grPaint) {
return SkPaintToGrPaintWithXfermode(context, dc, skPaint, SkMatrix::I(), SkXfermode::kDst_Mode,
false, grPaint);
}
/** This is used when there may or may not be a shader, and the caller wants to plugin a texture
lookup. If there is a shader, then its output will only be used if the texture is alpha8. */
bool SkPaintToGrPaintWithTexture(GrContext* context,
GrDrawContext* dc,
const SkPaint& paint,
const SkMatrix& viewM,
sk_sp<GrFragmentProcessor> fp,
bool textureIsAlphaOnly,
bool allowSRGBInputs,
SkColorSpace* dstColorSpace,
GrPaint* grPaint);
//////////////////////////////////////////////////////////////////////////////

View File

@ -124,8 +124,7 @@ void GrAtlasTextContext::drawTextBlob(GrContext* context, GrDrawContext* dc,
// Though for the time being runs in the textblob can override the paint, they only touch font
// info.
GrPaint grPaint;
if (!SkPaintToGrPaint(context, skPaint, viewMatrix, props.isGammaCorrect(), dc->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &grPaint)) {
return;
}
@ -389,7 +388,10 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
gTextContext = GrAtlasTextContext::Create();
}
// Setup dummy SkPaint / GrPaint
// Setup dummy SkPaint / GrPaint / GrDrawContext
sk_sp<GrDrawContext> drawContext(context->newDrawContext(SkBackingFit::kApprox, 1024, 1024,
kSkia8888_GrPixelConfig, nullptr));
GrColor color = GrRandomColor(random);
SkMatrix viewMatrix = GrTest::TestMatrixInvertible(random);
SkPaint skPaint;
@ -399,8 +401,7 @@ DRAW_BATCH_TEST_DEFINE(TextBlobBatch) {
skPaint.setSubpixelText(random->nextBool());
GrPaint grPaint;
if (!SkPaintToGrPaint(context, skPaint, viewMatrix, gSurfaceProps.isGammaCorrect(), nullptr,
&grPaint)) {
if (!SkPaintToGrPaint(context, drawContext.get(), skPaint, viewMatrix, &grPaint)) {
SkFAIL("couldn't convert paint\n");
}

View File

@ -165,8 +165,7 @@ void GrStencilAndCoverTextContext::uncachedDrawTextBlob(GrContext* context,
runPaint.setFlags(GrTextUtils::FilterTextFlags(props, runPaint));
GrPaint grPaint;
if (!SkPaintToGrPaint(context, runPaint, viewMatrix, dc->isGammaCorrect(),
dc->getColorSpace(), &grPaint)) {
if (!SkPaintToGrPaint(context, dc, runPaint, viewMatrix, &grPaint)) {
return;
}
@ -221,8 +220,7 @@ void GrStencilAndCoverTextContext::drawTextBlob(GrContext* context, GrDrawContex
}
GrPaint paint;
if (!SkPaintToGrPaint(context, skPaint, viewMatrix, dc->isGammaCorrect(), dc->getColorSpace(),
&paint)) {
if (!SkPaintToGrPaint(context, dc, skPaint, viewMatrix, &paint)) {
return;
}

View File

@ -139,9 +139,7 @@ void SkGpuDevice::drawTexture(GrTexture* tex, const SkRect& dst, const SkPaint&
GrPaint grPaint;
SkMatrix mat;
mat.reset();
if (!SkPaintToGrPaint(this->context(), paint, mat,
this->surfaceProps().isGammaCorrect(), fDrawContext->getColorSpace(),
&grPaint)) {
if (!SkPaintToGrPaint(this->context(), fDrawContext.get(), paint, mat, &grPaint)) {
return;
}
SkMatrix textureMat;