Conversion from sRGB to destination gamut is going to be very common,
so I'm caching that xform (if there is one) on the draw context.
Results verified in the gamut GM (two more boxes correct).
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=
2330553003
Review-Url: https://codereview.chromium.org/
2330553003
#ifndef GrColorSpaceXform_DEFINED
#define GrColorSpaceXform_DEFINED
+#include "GrColor.h"
#include "SkMatrix44.h"
#include "SkRefCnt.h"
return SkToBool(xform) ? 1 : 0;
}
+ GrColor4f apply(const GrColor4f& srcColor);
+
private:
SkMatrix44 fSrcToDst;
};
}
const SkSurfaceProps& surfaceProps() const { return fSurfaceProps; }
SkColorSpace* getColorSpace() const { return fColorSpace.get(); }
+ GrColorSpaceXform* getColorXformFromSRGB() const { return fColorXformFromSRGB.get(); }
GrSurfaceOrigin origin() const { return fRenderTarget->origin(); }
bool wasAbandoned() const;
GrInstancedPipelineInfo fInstancedPipelineInfo;
sk_sp<SkColorSpace> fColorSpace;
+ sk_sp<GrColorSpaceXform> fColorXformFromSRGB;
SkSurfaceProps fSurfaceProps;
GrAuditTrail* fAuditTrail;
return sk_make_sp<GrColorSpaceXform>(srcToDst);
}
+
+GrColor4f GrColorSpaceXform::apply(const GrColor4f& srcColor) {
+ GrColor4f result;
+ fSrcToDst.mapScalars(srcColor.fRGBA, result.fRGBA);
+ return result;
+}
, fContext(context)
, fInstancedPipelineInfo(fRenderTarget.get())
, fColorSpace(std::move(colorSpace))
+ , fColorXformFromSRGB(nullptr)
, fSurfaceProps(SkSurfacePropsCopyOrDefault(surfaceProps))
, fAuditTrail(auditTrail)
#ifdef SK_DEBUG
, fSingleOwner(singleOwner)
#endif
{
+ if (fColorSpace) {
+ // sRGB sources are very common (SkColor, etc...), so we cache that gamut transformation
+ auto srgbColorSpace = SkColorSpace::NewNamed(SkColorSpace::kSRGB_Named);
+ fColorXformFromSRGB = GrColorSpaceXform::Make(srgbColorSpace.get(), fColorSpace.get());
+ }
SkDEBUGCODE(this->validate();)
}
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]);
+
+ if (dc->getColorXformFromSRGB()) {
+ origColor = dc->getColorXformFromSRGB()->apply(origColor);
+ }
}
// Setup the initial color considering the shader, the SkPaint color, and the presence or not