Use half-floats for out-of-gamut color in GrAAFillRRectOp

Bug: skia:
Change-Id: Id093f295708b1f6719bece9899ebadfb9a473e46
Reviewed-on: https://skia-review.googlesource.com/c/192101
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Chris Dalton <csmartdalton@google.com>
This commit is contained in:
Brian Osman 2019-02-13 16:06:14 -05:00 committed by Skia Commit-Bot
parent 9859ef8d20
commit 5105d68f93
2 changed files with 27 additions and 15 deletions

View File

@ -90,8 +90,16 @@ GrProcessorSet::Analysis GrAAFillRRectOp::finalize(const GrCaps& caps, const GrA
&overrideColor); &overrideColor);
// Finish writing the instance attribs. // Finish writing the instance attribs.
this->writeInstanceData( SkPMColor4f finalColor = analysis.inputColorIsOverridden() ? overrideColor : fOriginalColor;
(analysis.inputColorIsOverridden() ? overrideColor : fOriginalColor).toBytes_RGBA()); if (!SkPMColor4fFitsInBytes(finalColor)) {
fFlags |= Flags::kWideColor;
uint32_t halfColor[2];
SkFloatToHalf_finite_ftz(Sk4f::Load(finalColor.vec())).store(&halfColor);
this->writeInstanceData(halfColor[0], halfColor[1]);
} else {
this->writeInstanceData(finalColor.toBytes_RGBA());
}
if (analysis.usesLocalCoords()) { if (analysis.usesLocalCoords()) {
this->writeInstanceData(fLocalRect); this->writeInstanceData(fLocalRect);
fFlags |= Flags::kHasLocalCoords; fFlags |= Flags::kHasLocalCoords;
@ -260,7 +268,14 @@ public:
: GrGeometryProcessor(kGrAAFillRRectOp_Processor_ClassID) : GrGeometryProcessor(kGrAAFillRRectOp_Processor_ClassID)
, fFlags(flags) { , fFlags(flags) {
this->setVertexAttributes(kVertexAttribs, 3); this->setVertexAttributes(kVertexAttribs, 3);
this->setInstanceAttributes(kInstanceAttribs, (flags & Flags::kHasLocalCoords) ? 6 : 5); fInSkew = { "skew", kFloat4_GrVertexAttribType, kFloat4_GrSLType };
fInTranslate = { "translate", kFloat2_GrVertexAttribType, kFloat2_GrSLType };
fInRadiiX = { "radii_x", kFloat4_GrVertexAttribType, kFloat4_GrSLType };
fInRadiiY = { "radii_y", kFloat4_GrVertexAttribType, kFloat4_GrSLType };
fInColor = MakeColorAttribute("color", (flags & Flags::kWideColor));
fInLocalRect = {"local_rect", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
this->setInstanceAttributes(&fInSkew, (flags & Flags::kHasLocalCoords) ? 6 : 5);
SkASSERT(this->vertexStride() == sizeof(Vertex)); SkASSERT(this->vertexStride() == sizeof(Vertex));
} }
@ -278,15 +293,12 @@ private:
{"corner_and_radius_outsets", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, {"corner_and_radius_outsets", kFloat4_GrVertexAttribType, kFloat4_GrSLType},
{"aa_bloat_and_coverage", kFloat4_GrVertexAttribType, kFloat4_GrSLType}}; {"aa_bloat_and_coverage", kFloat4_GrVertexAttribType, kFloat4_GrSLType}};
static constexpr Attribute kInstanceAttribs[] = { Attribute fInSkew;
{"skew", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, Attribute fInTranslate;
{"translate", kFloat2_GrVertexAttribType, kFloat2_GrSLType}, Attribute fInRadiiX;
{"radii_x", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, Attribute fInRadiiY;
{"radii_y", kFloat4_GrVertexAttribType, kFloat4_GrSLType}, Attribute fInColor;
{"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType}, Attribute fInLocalRect; // Conditional.
{"local_rect", kFloat4_GrVertexAttribType, kFloat4_GrSLType}}; // Conditional.
static constexpr int kColorAttribIdx = 4;
const Flags fFlags; const Flags fFlags;
@ -294,7 +306,6 @@ private:
}; };
constexpr GrPrimitiveProcessor::Attribute GrAAFillRRectOp::Processor::kVertexAttribs[]; constexpr GrPrimitiveProcessor::Attribute GrAAFillRRectOp::Processor::kVertexAttribs[];
constexpr GrPrimitiveProcessor::Attribute GrAAFillRRectOp::Processor::kInstanceAttribs[];
class GrAAFillRRectOp::Processor::Impl : public GrGLSLGeometryProcessor { class GrAAFillRRectOp::Processor::Impl : public GrGLSLGeometryProcessor {
public: public:
@ -304,7 +315,7 @@ public:
GrGLSLVaryingHandler* varyings = args.fVaryingHandler; GrGLSLVaryingHandler* varyings = args.fVaryingHandler;
varyings->emitAttributes(proc); varyings->emitAttributes(proc);
varyings->addPassThroughAttribute(proc.kInstanceAttribs[kColorAttribIdx], args.fOutputColor, varyings->addPassThroughAttribute(proc.fInColor, args.fOutputColor,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat); GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Emit the vertex shader. // Emit the vertex shader.

View File

@ -34,7 +34,8 @@ private:
enum class Flags { enum class Flags {
kNone = 0, kNone = 0,
kUseHWDerivatives = 1 << 0, kUseHWDerivatives = 1 << 0,
kHasLocalCoords = 1 << 1 kHasLocalCoords = 1 << 1,
kWideColor = 1 << 2
}; };
GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags); GR_DECL_BITFIELD_CLASS_OPS_FRIENDS(Flags);