Remove legacy colorfilter flags

Change-Id: I1084a970d901100c6d882aab761360081b46bbb8
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382702
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Mike Reed 2021-03-11 15:57:13 -05:00 committed by Skia Commit-Bot
parent 1f64c80bff
commit 3a94d9285e
8 changed files with 27 additions and 48 deletions

View File

@ -24,9 +24,11 @@ class SkColorMatrix;
*/
class SK_API SkColorFilter : public SkFlattenable {
public:
// DEPRECATED. skbug.com/8941
bool asColorMode(SkColor* color, SkBlendMode* mode) const;
// deprecated, use isAlphaUnchanged()
enum Flags {
kAlphaUnchanged_Flag = 1 << 0,
};
uint32_t getFlags() const { return this->isAlphaUnchanged() ? kAlphaUnchanged_Flag : 0; }
/** If the filter can be represented by a source color plus Mode, this
* returns true, and sets (if not NULL) the color and mode appropriately.
@ -40,13 +42,6 @@ public:
*/
bool asAColorMatrix(float matrix[20]) const;
// deprecated, use isAlphaUnchanged()
enum Flags {
kAlphaUnchanged_Flag = 1 << 0,
};
uint32_t getFlags() const;
// Returns true if the filter is guaranteed to never change the alpha of a color it filters.
bool isAlphaUnchanged() const;

View File

@ -28,10 +28,6 @@
#include "src/gpu/GrFragmentProcessor.h"
#endif
bool SkColorFilter::asColorMode(SkColor* color, SkBlendMode* mode) const {
return as_CFB(this)->onAsAColorMode(color, mode);
}
bool SkColorFilter::asAColorMode(SkColor* color, SkBlendMode* mode) const {
return as_CFB(this)->onAsAColorMode(color, mode);
}
@ -40,10 +36,8 @@ bool SkColorFilter::asAColorMatrix(float matrix[20]) const {
return as_CFB(this)->onAsAColorMatrix(matrix);
}
uint32_t SkColorFilter::getFlags() const { return as_CFB(this)->onGetFlags(); }
bool SkColorFilter::isAlphaUnchanged() const {
return SkToBool(this->getFlags() & kAlphaUnchanged_Flag);
return as_CFB(this)->onIsAlphaUnchanged();
}
//////////////////////////////////////////////////////////////////////////////////////////////////
@ -135,9 +129,9 @@ SkColor4f SkColorFilter::filterColor4f(const SkColor4f& origSrcColor, SkColorSpa
class SkComposeColorFilter : public SkColorFilterBase {
public:
uint32_t onGetFlags() const override {
bool onIsAlphaUnchanged() const override {
// Can only claim alphaunchanged support if both our proxys do.
return fOuter->onGetFlags() & fInner->onGetFlags();
return fOuter->isAlphaUnchanged() & fInner->isAlphaUnchanged();
}
bool onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const override {
@ -381,7 +375,7 @@ struct SkWorkingFormatColorFilter : public SkColorFilterBase {
: c;
}
uint32_t onGetFlags() const override { return fChild->getFlags(); }
bool onIsAlphaUnchanged() const override { return fChild->isAlphaUnchanged(); }
SK_FLATTENABLE_HOOKS(SkWorkingFormatColorFilter)
void flatten(SkWriteBuffer& buffer) const override {

View File

@ -31,7 +31,7 @@ public:
/** Returns the flags for this filter. Override in subclasses to return custom flags.
*/
virtual uint32_t onGetFlags() const { return 0; }
virtual bool onIsAlphaUnchanged() const { return false; }
#if SK_SUPPORT_GPU
/**

View File

@ -20,27 +20,22 @@
#include "src/core/SkVM.h"
#include "src/core/SkWriteBuffer.h"
static uint16_t ComputeFlags(const float matrix[20]) {
static bool is_alpha_unchanged(const float matrix[20]) {
const float* srcA = matrix + 15;
return SkScalarNearlyZero (srcA[0])
&& SkScalarNearlyZero (srcA[1])
&& SkScalarNearlyZero (srcA[2])
&& SkScalarNearlyEqual(srcA[3], 1)
&& SkScalarNearlyZero (srcA[4])
? SkColorFilter::kAlphaUnchanged_Flag : 0;
&& SkScalarNearlyZero (srcA[4]);
}
SkColorFilter_Matrix::SkColorFilter_Matrix(const float array[20], Domain domain)
: fFlags(ComputeFlags(array))
: fAlphaIsUnchanged(is_alpha_unchanged(array))
, fDomain(domain) {
memcpy(fMatrix, array, 20 * sizeof(float));
}
uint32_t SkColorFilter_Matrix::onGetFlags() const {
return this->INHERITED::onGetFlags() | fFlags;
}
void SkColorFilter_Matrix::flatten(SkWriteBuffer& buffer) const {
SkASSERT(sizeof(fMatrix)/sizeof(float) == 20);
buffer.writeScalarArray(fMatrix, 20);
@ -68,7 +63,7 @@ bool SkColorFilter_Matrix::onAsAColorMatrix(float matrix[20]) const {
}
bool SkColorFilter_Matrix::onAppendStages(const SkStageRec& rec, bool shaderIsOpaque) const {
const bool willStayOpaque = shaderIsOpaque && (fFlags & kAlphaUnchanged_Flag),
const bool willStayOpaque = shaderIsOpaque && fAlphaIsUnchanged,
hsla = fDomain == Domain::kHSLA;
SkRasterPipeline* p = rec.fPipeline;

View File

@ -16,7 +16,7 @@ public:
explicit SkColorFilter_Matrix(const float array[20], Domain);
uint32_t onGetFlags() const override;
bool onIsAlphaUnchanged() const override { return fAlphaIsUnchanged; }
#if SK_SUPPORT_GPU
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
@ -36,9 +36,9 @@ private:
SkColorSpace* dstCS,
skvm::Uniforms* uniforms, SkArenaAlloc*) const override;
float fMatrix[20];
uint16_t fFlags;
Domain fDomain;
float fMatrix[20];
bool fAlphaIsUnchanged;
Domain fDomain;
using INHERITED = SkColorFilterBase;
};

View File

@ -38,17 +38,15 @@ bool SkModeColorFilter::onAsAColorMode(SkColor* color, SkBlendMode* mode) const
return true;
}
uint32_t SkModeColorFilter::onGetFlags() const {
uint32_t flags = 0;
bool SkModeColorFilter::onIsAlphaUnchanged() const {
switch (fMode) {
case SkBlendMode::kDst: //!< [Da, Dc]
case SkBlendMode::kSrcATop: //!< [Da, Sc * Da + (1 - Sa) * Dc]
flags |= kAlphaUnchanged_Flag;
break;
return true;
default:
break;
}
return flags;
return false;
}
void SkModeColorFilter::flatten(SkWriteBuffer& buffer) const {

View File

@ -16,7 +16,7 @@ public:
return sk_sp<SkColorFilter>(new SkModeColorFilter(color, mode));
}
uint32_t onGetFlags() const override;
bool onIsAlphaUnchanged() const override;
#if SK_SUPPORT_GPU
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,

View File

@ -429,7 +429,7 @@ public:
: fEffect(std::move(effect))
, fUniforms(std::move(uniforms))
, fChildren(children, children + childCount)
, fFlags(this->computeFlags()) {}
, fIsAlphaUnchanged(this->computeIsAlphaUnchanged()) {}
#if SK_SUPPORT_GPU
GrFPResult asFragmentProcessor(std::unique_ptr<GrFragmentProcessor> inputFP,
@ -500,9 +500,9 @@ public:
/*device=*/zeroCoord, /*local=*/zeroCoord, sampleChild);
}
uint32_t onGetFlags() const override { return fFlags; }
bool onIsAlphaUnchanged() const override { return fIsAlphaUnchanged; }
uint32_t computeFlags() const {
bool computeIsAlphaUnchanged() const {
skvm::Builder p;
SkColorSpace* dstCS = sk_srgb_singleton(); // This _shouldn't_ matter for alpha.
skvm::Uniforms uniforms{p.uniform(), 0};
@ -511,10 +511,7 @@ public:
skvm::Color in = p.load({skvm::PixelFormat::FLOAT, 32,32,32,32, 0,32,64,96}, p.arg(16)),
out = this->onProgram(&p,in,dstCS,&uniforms,&alloc);
if (out.a.id == in.a.id) {
return SkColorFilter::kAlphaUnchanged_Flag;
}
return 0;
return out.a.id == in.a.id;
}
void flatten(SkWriteBuffer& buffer) const override {
@ -536,7 +533,7 @@ private:
sk_sp<SkRuntimeEffect> fEffect;
sk_sp<SkData> fUniforms;
std::vector<sk_sp<SkColorFilter>> fChildren;
const uint32_t fFlags;
const bool fIsAlphaUnchanged;
};
sk_sp<SkFlattenable> SkRuntimeColorFilter::CreateProc(SkReadBuffer& buffer) {