From: brianosman Date: Thu, 8 Sep 2016 16:33:50 +0000 (-0700) Subject: Push usage of GrColor4f into OverrideInput X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~106^2~504 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4cea3b9e9d9836c926a8feb55d050993d40b4b5e;p=platform%2Fupstream%2FlibSkiaSharp.git Push usage of GrColor4f into OverrideInput Just a change to preserve precision. BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2324553002 Review-Url: https://codereview.chromium.org/2324553002 --- diff --git a/include/gpu/GrColor.h b/include/gpu/GrColor.h index 911b18f..f526717 100644 --- a/include/gpu/GrColor.h +++ b/include/gpu/GrColor.h @@ -195,6 +195,17 @@ struct GrColor4f { return GrColor4f(color.fR, color.fG, color.fB, color.fA); } + bool operator==(const GrColor4f& other) const { + return + fRGBA[0] == other.fRGBA[0] && + fRGBA[1] == other.fRGBA[1] && + fRGBA[2] == other.fRGBA[2] && + fRGBA[3] == other.fRGBA[3]; + } + bool operator!=(const GrColor4f& other) const { + return !(*this == other); + } + GrColor toGrColor() const { return GrColorPackRGBA( SkTPin(static_cast(fRGBA[0] * 255.0f + 0.5f), 0, 255), diff --git a/include/gpu/GrFragmentProcessor.h b/include/gpu/GrFragmentProcessor.h index ffbf576..f955207 100644 --- a/include/gpu/GrFragmentProcessor.h +++ b/include/gpu/GrFragmentProcessor.h @@ -45,7 +45,7 @@ public: * The parent will ignore its input color and instead feed the passed in color as input to the * child. */ - static sk_sp OverrideInput(sk_sp, GrColor); + static sk_sp OverrideInput(sk_sp, GrColor4f); /** * Returns a fragment processor that premuls the input before calling the passed in fragment diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp index a8a4898..c905fcc 100644 --- a/src/gpu/GrFragmentProcessor.cpp +++ b/src/gpu/GrFragmentProcessor.cpp @@ -259,10 +259,10 @@ sk_sp GrFragmentProcessor::MulOutputByInputUnpremulColor( ////////////////////////////////////////////////////////////////////////////// sk_sp GrFragmentProcessor::OverrideInput(sk_sp fp, - GrColor color) { + GrColor4f color) { class ReplaceInputFragmentProcessor : public GrFragmentProcessor { public: - ReplaceInputFragmentProcessor(sk_sp child, GrColor color) + ReplaceInputFragmentProcessor(sk_sp child, GrColor4f color) : fColor(color) { this->initClassID(); this->registerChildProcessor(std::move(child)); @@ -286,24 +286,17 @@ sk_sp GrFragmentProcessor::OverrideInput(sk_sp().fColor; + GrColor4f color = fp.cast().fColor; if (!fHaveSetColor || color != fPreviousColor) { - static const float scale = 1.f / 255.f; - float floatColor[4] = { - GrColorUnpackR(color) * scale, - GrColorUnpackG(color) * scale, - GrColorUnpackB(color) * scale, - GrColorUnpackA(color) * scale, - }; - pdman.set4fv(fColorUni, 1, floatColor); + pdman.set4fv(fColorUni, 1, color.fRGBA); fPreviousColor = color; fHaveSetColor = true; } } GrGLSLProgramDataManager::UniformHandle fColorUni; - bool fHaveSetColor; - GrColor fPreviousColor; + bool fHaveSetColor; + GrColor4f fPreviousColor; }; return new GLFP; @@ -318,12 +311,12 @@ sk_sp GrFragmentProcessor::OverrideInput(sk_spsetToOther(kRGBA_GrColorComponentFlags, fColor, + inout->setToOther(kRGBA_GrColorComponentFlags, fColor.toGrColor(), GrInvariantOutput::kWillNot_ReadInput); this->childProcessor(0).computeInvariantOutput(inout); } - GrColor fColor; + GrColor4f fColor; }; GrInvariantOutput childOut(0x0, kNone_GrColorComponentFlags, false); diff --git a/src/gpu/SkGr.cpp b/src/gpu/SkGr.cpp index 3d6d4ec..7c0d09b 100644 --- a/src/gpu/SkGr.cpp +++ b/src/gpu/SkGr.cpp @@ -569,9 +569,7 @@ static inline bool skpaint_to_grpaint_impl(GrContext* context, // The geometry processor will insert the primitive color to start the color chain, so // the GrPaint color will be ignored. - GrColor shaderInput = origColor.opaque().toGrColor(); - - // SRGBTODO: Preserve 4f on this code path + GrColor4f shaderInput = origColor.opaque(); shaderFP = GrFragmentProcessor::OverrideInput(shaderFP, shaderInput); if (primitiveIsSrc) { shaderFP = GrXfermodeFragmentProcessor::MakeFromDstProcessor(std::move(shaderFP),