Revert "Use float colors for blend constant"
This reverts commit 52065473ee15568c24af17584748d53cdaa60e82.
Reason for revert: Typo messed up LCD blending
Original change's description:
> Use float colors for blend constant
>
> Bug: skia:
> Change-Id: Ie2a4b341a5e7762c3e8031fbd0f0d8b1ebae27f1
> Reviewed-on: https://skia-review.googlesource.com/c/168268
> Commit-Queue: Brian Osman <brianosman@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>
TBR=egdaniel@google.com,mtklein@google.com,bsalomon@google.com,brianosman@google.com
Change-Id: Ieaad5724099e18727296ce312d728a1a9ed45c4b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/168362
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrProcessorAnalysis.h b/src/gpu/GrProcessorAnalysis.h
index e8c7458..28e6731 100644
--- a/src/gpu/GrProcessorAnalysis.h
+++ b/src/gpu/GrProcessorAnalysis.h
@@ -8,6 +8,7 @@
#ifndef GrProcessorAnalysis_DEFINED
#define GrProcessorAnalysis_DEFINED
+#include "GrColor.h"
#include "SkColorData.h"
class GrDrawOp;
@@ -41,6 +42,16 @@
bool isOpaque() const { return SkToBool(kIsOpaque_Flag & fFlags); }
+ bool isConstant(GrColor* color) const {
+ if (kColorIsKnown_Flag & fFlags) {
+ if (color) {
+ *color = fColor.toBytes_RGBA();
+ }
+ return true;
+ }
+ return false;
+ }
+
bool isConstant(SkPMColor4f* color = nullptr) const {
if (kColorIsKnown_Flag & fFlags) {
if (color) {
diff --git a/src/gpu/GrSwizzle.h b/src/gpu/GrSwizzle.h
index 51e01ef..2d900e3 100644
--- a/src/gpu/GrSwizzle.h
+++ b/src/gpu/GrSwizzle.h
@@ -57,6 +57,25 @@
}
/** Applies this swizzle to the input color and returns the swizzled color. */
+ GrColor applyTo(GrColor color) const {
+ int idx;
+ uint32_t key = fKey;
+ // Index of the input color that should be mapped to output r.
+ idx = (key & 3);
+ uint32_t outR = (color >> idx * 8) & 0xFF;
+ key >>= 2;
+ idx = (key & 3);
+ uint32_t outG = (color >> idx * 8) & 0xFF;
+ key >>= 2;
+ idx = (key & 3);
+ uint32_t outB = (color >> idx * 8) & 0xFF;
+ key >>= 2;
+ idx = (key & 3);
+ uint32_t outA = (color >> idx * 8) & 0xFF;
+ return GrColorPackRGBA(outR, outG, outB, outA);
+ }
+
+ /** Applies this swizzle to the input color and returns the swizzled color. */
SkPMColor4f applyTo(const SkPMColor4f& color) const {
int idx;
uint32_t key = fKey;
diff --git a/src/gpu/GrXferProcessor.cpp b/src/gpu/GrXferProcessor.cpp
index b32f25f..a008e98 100644
--- a/src/gpu/GrXferProcessor.cpp
+++ b/src/gpu/GrXferProcessor.cpp
@@ -149,7 +149,7 @@
SkString out;
out.printf("write_color(%d) equation(%s) src_coeff(%s) dst_coeff:(%s) const(0x%08x)",
fWriteColor, equation_string(fEquation), coeff_string(fSrcBlend),
- coeff_string(fDstBlend), fBlendConstant.toBytes_RGBA());
+ coeff_string(fDstBlend), fBlendConstant);
return out;
}
#endif
diff --git a/src/gpu/GrXferProcessor.h b/src/gpu/GrXferProcessor.h
index 3d42dfd..6d80333 100644
--- a/src/gpu/GrXferProcessor.h
+++ b/src/gpu/GrXferProcessor.h
@@ -9,6 +9,7 @@
#define GrXferProcessor_DEFINED
#include "GrBlend.h"
+#include "GrColor.h"
#include "GrNonAtomicRef.h"
#include "GrProcessor.h"
#include "GrProcessorAnalysis.h"
@@ -131,7 +132,7 @@
fEquation = kAdd_GrBlendEquation;
fSrcBlend = kOne_GrBlendCoeff;
fDstBlend = kZero_GrBlendCoeff;
- fBlendConstant = SK_PMColor4fTRANSPARENT;
+ fBlendConstant = 0;
fWriteColor = true;
}
@@ -140,7 +141,7 @@
GrBlendEquation fEquation;
GrBlendCoeff fSrcBlend;
GrBlendCoeff fDstBlend;
- SkPMColor4f fBlendConstant;
+ GrColor fBlendConstant;
bool fWriteColor;
};
diff --git a/src/gpu/effects/GrCoverageSetOpXP.cpp b/src/gpu/effects/GrCoverageSetOpXP.cpp
index 8e1dbbb..e7ac874 100644
--- a/src/gpu/effects/GrCoverageSetOpXP.cpp
+++ b/src/gpu/effects/GrCoverageSetOpXP.cpp
@@ -117,7 +117,7 @@
blendInfo->fDstBlend = kZero_GrBlendCoeff;
break;
}
- blendInfo->fBlendConstant = SK_PMColor4fTRANSPARENT;
+ blendInfo->fBlendConstant = 0;
}
///////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrPorterDuffXferProcessor.cpp b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
index aca1e05..89f61ec 100644
--- a/src/gpu/effects/GrPorterDuffXferProcessor.cpp
+++ b/src/gpu/effects/GrPorterDuffXferProcessor.cpp
@@ -588,10 +588,10 @@
GrGLSLXferProcessor* createGLSLInstance() const override;
- float alpha() const { return fAlpha; }
+ uint8_t alpha() const { return fAlpha; }
private:
- PDLCDXferProcessor(const SkPMColor4f& blendConstant, float alpha);
+ PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha);
void onGetGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override;
@@ -609,8 +609,8 @@
return true;
}
- SkPMColor4f fBlendConstant;
- float fAlpha;
+ GrColor fBlendConstant;
+ uint8_t fAlpha;
typedef GrXferProcessor INHERITED;
};
@@ -619,7 +619,7 @@
class GLPDLCDXferProcessor : public GrGLSLXferProcessor {
public:
- GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(SK_FloatNaN) {}
+ GLPDLCDXferProcessor(const GrProcessor&) : fLastAlpha(UINT32_MAX) {}
~GLPDLCDXferProcessor() override {}
@@ -641,21 +641,21 @@
}
void onSetData(const GrGLSLProgramDataManager& pdm, const GrXferProcessor& xp) override {
- float alpha = xp.cast<PDLCDXferProcessor>().alpha();
+ uint32_t alpha = SkToU32(xp.cast<PDLCDXferProcessor>().alpha());
if (fLastAlpha != alpha) {
- pdm.set1f(fAlphaUniform, alpha);
+ pdm.set1f(fAlphaUniform, alpha / 255.f);
fLastAlpha = alpha;
}
}
GrGLSLUniformHandler::UniformHandle fAlphaUniform;
- float fLastAlpha;
+ uint32_t fLastAlpha;
typedef GrGLSLXferProcessor INHERITED;
};
///////////////////////////////////////////////////////////////////////////////
-PDLCDXferProcessor::PDLCDXferProcessor(const SkPMColor4f& blendConstant, float alpha)
+PDLCDXferProcessor::PDLCDXferProcessor(GrColor blendConstant, uint8_t alpha)
: INHERITED(kPDLCDXferProcessor_ClassID, false, false, GrProcessorAnalysisCoverage::kLCD)
, fBlendConstant(blendConstant)
, fAlpha(alpha) {
@@ -666,14 +666,14 @@
if (SkBlendMode::kSrcOver != mode) {
return nullptr;
}
- SkPMColor4f blendConstantPM;
- if (!color.isConstant(&blendConstantPM)) {
+ GrColor blendConstant;
+ if (!color.isConstant(&blendConstant)) {
return nullptr;
}
- SkColor4f blendConstantUPM = blendConstantPM.unpremul();
- float alpha = blendConstantUPM.fA;
- blendConstantPM = { blendConstantUPM.fR, blendConstantUPM.fG, blendConstantUPM.fG, 1 };
- return sk_sp<GrXferProcessor>(new PDLCDXferProcessor(blendConstantPM, alpha));
+ blendConstant = GrUnpremulColor(blendConstant);
+ uint8_t alpha = GrColorUnpackA(blendConstant);
+ blendConstant |= (0xff << GrColor_SHIFT_A);
+ return sk_sp<GrXferProcessor>(new PDLCDXferProcessor(blendConstant, alpha));
}
PDLCDXferProcessor::~PDLCDXferProcessor() {
diff --git a/src/gpu/gl/GrGLGpu.cpp b/src/gpu/gl/GrGLGpu.cpp
index f9b6217..902509d 100644
--- a/src/gpu/gl/GrGLGpu.cpp
+++ b/src/gpu/gl/GrGLGpu.cpp
@@ -2795,9 +2795,12 @@
}
if ((BlendCoeffReferencesConstant(srcCoeff) || BlendCoeffReferencesConstant(dstCoeff))) {
- SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
+ GrColor blendConst = blendInfo.fBlendConstant;
+ blendConst = swizzle.applyTo(blendConst);
if (!fHWBlendState.fConstColorValid || fHWBlendState.fConstColor != blendConst) {
- GL_CALL(BlendColor(blendConst.fR, blendConst.fG, blendConst.fB, blendConst.fA));
+ GrGLfloat c[4];
+ GrColorToRGBAFloat(blendConst, c);
+ GL_CALL(BlendColor(c[0], c[1], c[2], c[3]));
fHWBlendState.fConstColor = blendConst;
fHWBlendState.fConstColorValid = true;
}
diff --git a/src/gpu/gl/GrGLGpu.h b/src/gpu/gl/GrGLGpu.h
index 270e28a..8812a02 100644
--- a/src/gpu/gl/GrGLGpu.h
+++ b/src/gpu/gl/GrGLGpu.h
@@ -561,7 +561,7 @@
GrBlendEquation fEquation;
GrBlendCoeff fSrcCoeff;
GrBlendCoeff fDstCoeff;
- SkPMColor4f fConstColor;
+ GrColor fConstColor;
bool fConstColorValid;
TriState fEnabled;
diff --git a/src/gpu/mtl/GrMtlPipelineState.mm b/src/gpu/mtl/GrMtlPipelineState.mm
index 1d9562e..590eff6 100644
--- a/src/gpu/mtl/GrMtlPipelineState.mm
+++ b/src/gpu/mtl/GrMtlPipelineState.mm
@@ -185,14 +185,16 @@
GrBlendCoeff srcCoeff = blendInfo.fSrcBlend;
GrBlendCoeff dstCoeff = blendInfo.fDstBlend;
if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoeff)) {
+ float floatColors[4];
// Swizzle the blend to match what the shader will output.
const GrSwizzle& swizzle = fGpu->caps()->shaderCaps()->configOutputSwizzle(config);
- SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
+ GrColor blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
+ GrColorToRGBAFloat(blendConst, floatColors);
- [renderCmdEncoder setBlendColorRed: blendConst.fR
- green: blendConst.fG
- blue: blendConst.fB
- alpha: blendConst.fA];
+ [renderCmdEncoder setBlendColorRed: floatColors[0]
+ green: floatColors[1]
+ blue: floatColors[2]
+ alpha: floatColors[3]];
}
}
diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp
index e0ede4c..15832cc 100644
--- a/src/gpu/vk/GrVkPipeline.cpp
+++ b/src/gpu/vk/GrVkPipeline.cpp
@@ -624,11 +624,8 @@
if (blend_coeff_refs_constant(srcCoeff) || blend_coeff_refs_constant(dstCoeff)) {
// Swizzle the blend to match what the shader will output.
const GrSwizzle& swizzle = gpu->caps()->shaderCaps()->configOutputSwizzle(pixelConfig);
- SkPMColor4f blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
- floatColors[0] = blendConst.fR;
- floatColors[1] = blendConst.fG;
- floatColors[2] = blendConst.fB;
- floatColors[3] = blendConst.fA;
+ GrColor blendConst = swizzle.applyTo(blendInfo.fBlendConstant);
+ GrColorToRGBAFloat(blendConst, floatColors);
} else {
memset(floatColors, 0, 4 * sizeof(float));
}