impl WorkingFormatCF::getFlags()

The only color filter flag is isAlphaUnchanged(), so since alpha is
unchanged through any working format transformation, we can just return
whatever flags the child filter claims.

Add a simple test.

Change-Id: I2ce0300d9db55f953660ed157510070755c4c677
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/370824
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2021-02-16 11:59:00 -06:00 committed by Skia Commit-Bot
parent 4635b5dad0
commit 6bba1bcdc1
2 changed files with 39 additions and 0 deletions

View File

@ -380,6 +380,8 @@ struct SkWorkingFormatColorFilter : public SkColorFilterBase {
: c;
}
uint32_t onGetFlags() const override { return fChild->getFlags(); }
SK_FLATTENABLE_HOOKS(SkWorkingFormatColorFilter)
void flatten(SkWriteBuffer& buffer) const override {
buffer.writeFlattenable(fChild.get());

View File

@ -8,8 +8,10 @@
#include "include/core/SkBlendMode.h"
#include "include/core/SkColor.h"
#include "include/core/SkColorFilter.h"
#include "include/core/SkColorSpace.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkColorMatrix.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkReadBuffer.h"
@ -90,3 +92,38 @@ DEF_TEST(ColorFilter, reporter) {
}
}
}
DEF_TEST(WorkingFormatFilterFlags, r) {
{
// A matrix with final row 0,0,0,1,0 shouldn't change alpha.
sk_sp<SkColorFilter> cf = SkColorFilters::Matrix({1,0,0,0,0,
0,1,0,0,0,
0,0,1,0,0,
0,0,0,1,0});
REPORTER_ASSERT(r, cf->isAlphaUnchanged());
// No working format change will itself change alpha.
SkAlphaType unpremul = kUnpremul_SkAlphaType;
cf = SkColorFilters::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
REPORTER_ASSERT(r, cf->isAlphaUnchanged());
}
{
// Here's a matrix that definitely does change alpha.
sk_sp<SkColorFilter> cf = SkColorFilters::Matrix({1,0,0,0,0,
0,1,0,0,0,
0,0,1,0,0,
0,0,0,0,1});
REPORTER_ASSERT(r, !cf->isAlphaUnchanged());
SkAlphaType unpremul = kUnpremul_SkAlphaType;
cf = SkColorFilters::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
REPORTER_ASSERT(r, !cf->isAlphaUnchanged());
}
}