aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--include/gpu/GrSurfaceContext.h2
-rw-r--r--include/gpu/SkGr.h10
-rw-r--r--src/gpu/GrSurfaceContext.cpp5
-rw-r--r--src/gpu/SkGr.cpp31
-rw-r--r--src/image/SkSurface_Gpu.cpp7
5 files changed, 35 insertions, 20 deletions
diff --git a/include/gpu/GrSurfaceContext.h b/include/gpu/GrSurfaceContext.h
index 24041e8829..ed049be506 100644
--- a/include/gpu/GrSurfaceContext.h
+++ b/include/gpu/GrSurfaceContext.h
@@ -34,7 +34,7 @@ public:
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
sk_sp<SkColorSpace> refColorSpace() const { return fColorSpace; }
- bool isGammaCorrect() const { return SkToBool(fColorSpace.get()); }
+ bool isGammaCorrect() const;
// TODO: these two calls would be way cooler if this object had a GrSurfaceProxy pointer
int width() const { return this->asSurfaceProxy()->width(); }
diff --git a/include/gpu/SkGr.h b/include/gpu/SkGr.h
index f7ca0c8e4d..02df699ab4 100644
--- a/include/gpu/SkGr.h
+++ b/include/gpu/SkGr.h
@@ -46,11 +46,13 @@ GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace);
GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace);
/**
- * As above, but with explicit control over the linearization and gamut xform steps.
- * Typically used when you have easy access to a pre-computed xform.
+ * As above, but with a caller-supplied color space xform object. Faster for the cases where we
+ * have that cached.
*/
-GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform);
-GrColor4f SkColorToUnpremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform);
+GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
+ GrColorSpaceXform* gamutXform);
+GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
+ GrColorSpaceXform* gamutXform);
static inline GrColor SkColorToOpaqueGrColor(SkColor c) {
unsigned r = SkColorGetR(c);
diff --git a/src/gpu/GrSurfaceContext.cpp b/src/gpu/GrSurfaceContext.cpp
index 7e4d4fb4b5..d3225e3225 100644
--- a/src/gpu/GrSurfaceContext.cpp
+++ b/src/gpu/GrSurfaceContext.cpp
@@ -6,6 +6,7 @@
*/
#include "GrSurfaceContext.h"
+#include "SkColorSpace_Base.h"
#include "../private/GrAuditTrail.h"
@@ -27,3 +28,7 @@ GrSurfaceContext::GrSurfaceContext(GrContext* context,
#endif
, fDrawingManager(drawingMgr) {
}
+
+bool GrSurfaceContext::isGammaCorrect() const {
+ return fColorSpace && !as_CSB(fColorSpace)->nonLinearBlending();
+}
diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp
index c3d197e0a6..69f6061d78 100644
--- a/src/gpu/SkGr.cpp
+++ b/src/gpu/SkGr.cpp
@@ -120,9 +120,10 @@ GrTexture* GrUploadPixmapToTexture(GrContext* ctx, const SkPixmap& pixmap, SkBud
// TODO: We're checking for srgbSupport, but we can then end up picking sBGRA as our pixel
// config (which may not be supported). We need better fallback management here.
+ SkColorSpace* colorSpace = pixmap.colorSpace();
if (caps->srgbSupport() &&
- pixmap.info().colorSpace() && pixmap.info().colorSpace()->gammaCloseToSRGB() &&
+ colorSpace && colorSpace->gammaCloseToSRGB() && !as_CSB(colorSpace)->nonLinearBlending() &&
!GrPixelConfigIsSRGB(desc.fConfig)) {
// We were supplied an sRGB-like color space, but we don't have a suitable pixel config.
// Convert to 8888 sRGB so we can handle the data correctly. The raster backend doesn't
@@ -325,23 +326,25 @@ GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace) {
if (dstColorSpace) {
auto srgbColorSpace = SkColorSpace::MakeSRGB();
auto gamutXform = GrColorSpaceXform::Make(srgbColorSpace.get(), dstColorSpace);
- return SkColorToUnpremulGrColor4f(c, true, gamutXform.get());
+ return SkColorToUnpremulGrColor4f(c, dstColorSpace, gamutXform.get());
} else {
- return SkColorToUnpremulGrColor4f(c, false, nullptr);
+ return SkColorToUnpremulGrColor4f(c, nullptr, nullptr);
}
}
-GrColor4f SkColorToPremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform) {
+GrColor4f SkColorToPremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
+ GrColorSpaceXform* gamutXform) {
// We want to premultiply after linearizing, so this is easy:
- return SkColorToUnpremulGrColor4f(c, gammaCorrect, gamutXform).premul();
+ return SkColorToUnpremulGrColor4f(c, dstColorSpace, gamutXform).premul();
}
-GrColor4f SkColorToUnpremulGrColor4f(SkColor c, bool gammaCorrect, GrColorSpaceXform* gamutXform) {
+GrColor4f SkColorToUnpremulGrColor4f(SkColor c, SkColorSpace* dstColorSpace,
+ GrColorSpaceXform* gamutXform) {
// You can't be color-space aware in legacy mode
- SkASSERT(gammaCorrect || !gamutXform);
+ SkASSERT(dstColorSpace || !gamutXform);
GrColor4f color;
- if (gammaCorrect) {
+ if (dstColorSpace) {
// SkColor4f::FromColor does sRGB -> Linear
color = GrColor4f::FromSkColor4f(SkColor4f::FromColor(c));
} else {
@@ -372,10 +375,12 @@ GrPixelConfig SkImageInfo2GrPixelConfig(const SkImageInfo& info, const GrCaps& c
case kARGB_4444_SkColorType:
return kRGBA_4444_GrPixelConfig;
case kRGBA_8888_SkColorType:
- return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
+ return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB() &&
+ !as_CSB(cs)->nonLinearBlending())
? kSRGBA_8888_GrPixelConfig : kRGBA_8888_GrPixelConfig;
case kBGRA_8888_SkColorType:
- return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB())
+ return (caps.srgbSupport() && cs && cs->gammaCloseToSRGB() &&
+ !as_CSB(cs)->nonLinearBlending())
? kSBGRA_8888_GrPixelConfig : kBGRA_8888_GrPixelConfig;
case kIndex_8_SkColorType:
return kSkia8888_GrPixelConfig;
@@ -428,7 +433,7 @@ bool GrPixelConfigToColorType(GrPixelConfig config, SkColorType* ctOut) {
}
GrPixelConfig GrRenderableConfigForColorSpace(const SkColorSpace* colorSpace) {
- if (!colorSpace) {
+ if (!colorSpace || as_CSB(colorSpace)->nonLinearBlending()) {
return kRGBA_8888_GrPixelConfig;
} else if (colorSpace->gammaIsLinear()) {
return kRGBA_half_GrPixelConfig;
@@ -461,7 +466,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
grPaint->setAllowSRGBInputs(rtc->isGammaCorrect());
// Convert SkPaint color to 4f format, including optional linearizing and gamut conversion.
- GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), rtc->isGammaCorrect(),
+ GrColor4f origColor = SkColorToUnpremulGrColor4f(skPaint.getColor(), rtc->getColorSpace(),
rtc->getColorXformFromSRGB());
// Setup the initial color considering the shader, the SkPaint color, and the presence or not
@@ -567,7 +572,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context,
colorFilter->filterColor4f(origColor.toSkColor4f())).premul());
} else {
grPaint->setColor4f(SkColorToPremulGrColor4f(
- colorFilter->filterColor(skPaint.getColor()), false, nullptr));
+ colorFilter->filterColor(skPaint.getColor()), nullptr, nullptr));
}
} else {
sk_sp<GrFragmentProcessor> cfFP(colorFilter->asFragmentProcessor(context,
diff --git a/src/image/SkSurface_Gpu.cpp b/src/image/SkSurface_Gpu.cpp
index 9fe813f206..85d896a804 100644
--- a/src/image/SkSurface_Gpu.cpp
+++ b/src/image/SkSurface_Gpu.cpp
@@ -10,6 +10,7 @@
#include "GrContextPriv.h"
#include "GrResourceProvider.h"
#include "SkCanvas.h"
+#include "SkColorSpace_Base.h"
#include "SkGpuDevice.h"
#include "SkImage_Base.h"
#include "SkImage_Gpu.h"
@@ -177,13 +178,15 @@ bool SkSurface_Gpu::Valid(GrContext* context, GrPixelConfig config, SkColorSpace
return !colorSpace || colorSpace->gammaIsLinear();
case kSRGBA_8888_GrPixelConfig:
case kSBGRA_8888_GrPixelConfig:
- return context->caps()->srgbSupport() && colorSpace && colorSpace->gammaCloseToSRGB();
+ return context->caps()->srgbSupport() && colorSpace && colorSpace->gammaCloseToSRGB() &&
+ !as_CSB(colorSpace)->nonLinearBlending();
case kRGBA_8888_GrPixelConfig:
case kBGRA_8888_GrPixelConfig:
// If we don't have sRGB support, we may get here with a color space. It still needs
// to be sRGB-like (so that the application will work correctly on sRGB devices.)
return !colorSpace ||
- (!context->caps()->srgbSupport() && colorSpace->gammaCloseToSRGB());
+ (colorSpace->gammaCloseToSRGB() && (!context->caps()->srgbSupport() ||
+ !as_CSB(colorSpace)->nonLinearBlending()));
default:
return !colorSpace;
}