Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(290)

Unified Diff: src/gpu/SkGr.cpp

Issue 2182603003: Just pass the draw context to paint conversion (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/gpu/SkGr.cpp
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 51eb91021db9bb5a413fdc7da719e8a138633415..cf36b3a7ccbcccf579465411fdebad0cab234bf7 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -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);
}

Powered by Google App Engine
This is Rietveld 408576698