SkSurfaceProps now has a gamma-correct ("AllowSRGBInputs") flag. That's propagated in a few places so that the backend can do the right thing for L32 vs S32 mode.
Also added SkSurfaceProps to SkSpecialImage, so that Image -> Surface conversion can preserve the desired behavior during filtering.
Many small changes, including a bunch of comments about places where we may be losing information right now. My approach was to ensure that if anything fails, it will always fall back to "legacy" mode - gamma-correctness is opt-in, so I'll just have to feed things through as missing cases are exposed.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1838953007
Review URL: https://codereview.chromium.org/1845283003
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index 905af81..7169091 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -495,8 +495,10 @@
const GrFragmentProcessor** shaderProcessor,
SkXfermode::Mode* primColorMode,
bool primitiveIsSrc,
+ bool allowSRGBInputs,
GrPaint* grPaint) {
grPaint->setAntiAlias(skPaint.isAntiAlias());
+ grPaint->setAllowSRGBInputs(allowSRGBInputs);
// Setup the initial color considering the shader, the SkPaint color, and the presence or not
// of per-vertex colors.
@@ -623,31 +625,34 @@
}
bool SkPaintToGrPaint(GrContext* context, const SkPaint& skPaint, const SkMatrix& viewM,
- GrPaint* grPaint) {
- return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, false, grPaint);
+ bool allowSRGBInputs, GrPaint* grPaint) {
+ return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, nullptr, false,
+ allowSRGBInputs, grPaint);
}
/** Replaces the SkShader (if any) on skPaint with the passed in GrFragmentProcessor. */
bool SkPaintToGrPaintReplaceShader(GrContext* context,
const SkPaint& skPaint,
const GrFragmentProcessor* shaderFP,
+ bool allowSRGBInputs,
GrPaint* grPaint) {
if (!shaderFP) {
return false;
}
return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), &shaderFP, nullptr, false,
- grPaint);
+ allowSRGBInputs, grPaint);
}
/** Ignores the SkShader (if any) on skPaint. */
bool SkPaintToGrPaintNoShader(GrContext* context,
const SkPaint& skPaint,
+ bool allowSRGBInputs,
GrPaint* grPaint) {
// Use a ptr to a nullptr to to indicate that the SkShader is ignored and not replaced.
static const GrFragmentProcessor* kNullShaderFP = nullptr;
static const GrFragmentProcessor** kIgnoreShader = &kNullShaderFP;
return skpaint_to_grpaint_impl(context, skPaint, SkMatrix::I(), kIgnoreShader, nullptr, false,
- grPaint);
+ allowSRGBInputs, grPaint);
}
/** Blends the SkPaint's shader (or color if no shader) with a per-primitive color which must
@@ -657,9 +662,10 @@
const SkMatrix& viewM,
SkXfermode::Mode primColorMode,
bool primitiveIsSrc,
+ bool allowSRGBInputs,
GrPaint* grPaint) {
return skpaint_to_grpaint_impl(context, skPaint, viewM, nullptr, &primColorMode, primitiveIsSrc,
- grPaint);
+ allowSRGBInputs, grPaint);
}
bool SkPaintToGrPaintWithTexture(GrContext* context,
@@ -667,6 +673,7 @@
const SkMatrix& viewM,
const GrFragmentProcessor* fp,
bool textureIsAlphaOnly,
+ bool allowSRGBInputs,
GrPaint* grPaint) {
SkAutoTUnref<const GrFragmentProcessor> shaderFP;
if (textureIsAlphaOnly) {
@@ -687,7 +694,7 @@
shaderFP.reset(GrFragmentProcessor::MulOutputByInputAlpha(fp));
}
- return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), grPaint);
+ return SkPaintToGrPaintReplaceShader(context, paint, shaderFP.get(), allowSRGBInputs, grPaint);
}