Move WithWorkingFormat to SkColorFilterPriv

It's a performance foot-gun today (disables raster pipeline), and will
hopefully be unnecessary in the future.

Change-Id: I241484286388e4bd2a429a6d22e3b96ecf975cec
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/467456
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Derek Sollenberger <djsollen@google.com>
This commit is contained in:
Brian Osman 2021-11-03 14:12:01 -04:00 committed by SkCQ
parent dfeced7059
commit 37459e71a5
6 changed files with 34 additions and 29 deletions

View File

@ -26,6 +26,7 @@
#include "include/effects/SkGradientShader.h"
#include "include/effects/SkLumaColorFilter.h"
#include "include/effects/SkRuntimeEffect.h"
#include "src/core/SkColorFilterPriv.h"
#include "tools/Resources.h"
#include "tools/ToolUtils.h"
@ -193,9 +194,9 @@ DEF_SIMPLE_GM(AlternateLuma, canvas, 384,128) {
SkASSERT(filter);
SkAlphaType unpremul = kUnpremul_SkAlphaType;
paint.setColorFilter(SkColorFilters::WithWorkingFormat(std::move(filter),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kXYZ,
&unpremul));
paint.setColorFilter(SkColorFilterPriv::WithWorkingFormat(std::move(filter),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kXYZ,
&unpremul));
canvas->drawImage(img, 0,0, SkSamplingOptions{}, &paint);
}

View File

@ -83,14 +83,6 @@ public:
static sk_sp<SkColorFilter> SRGBToLinearGamma();
static sk_sp<SkColorFilter> Lerp(float t, sk_sp<SkColorFilter> dst, sk_sp<SkColorFilter> src);
// Runs the child filter in a different working color format than usual (premul in
// destination surface's color space), with all inputs and outputs expressed in this format.
// Each non-null {tf,gamut,at} parameter overrides that particular aspect of the color format.
static sk_sp<SkColorFilter> WithWorkingFormat(sk_sp<SkColorFilter> child,
const skcms_TransferFunction* tf,
const skcms_Matrix3x3* gamut,
const SkAlphaType* at);
private:
SkColorFilters() = delete;
};

View File

@ -13,6 +13,7 @@
#include "include/private/SkTDArray.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkColorFilterBase.h"
#include "src/core/SkColorFilterPriv.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkMatrixProvider.h"
@ -435,16 +436,16 @@ sk_sp<SkFlattenable> SkWorkingFormatColorFilter::CreateProc(SkReadBuffer& buffer
if (!useDstGamut) { buffer.readScalarArray(&gamut.vals[0][0], 9); }
if (!useDstAT) { at = buffer.read32LE(kLastEnum_SkAlphaType); }
return SkColorFilters::WithWorkingFormat(std::move(child),
useDstTF ? nullptr : &tf,
useDstGamut ? nullptr : &gamut,
useDstAT ? nullptr : &at);
return SkColorFilterPriv::WithWorkingFormat(std::move(child),
useDstTF ? nullptr : &tf,
useDstGamut ? nullptr : &gamut,
useDstAT ? nullptr : &at);
}
sk_sp<SkColorFilter> SkColorFilters::WithWorkingFormat(sk_sp<SkColorFilter> child,
const skcms_TransferFunction* tf,
const skcms_Matrix3x3* gamut,
const SkAlphaType* at) {
sk_sp<SkColorFilter> SkColorFilterPriv::WithWorkingFormat(sk_sp<SkColorFilter> child,
const skcms_TransferFunction* tf,
const skcms_Matrix3x3* gamut,
const SkAlphaType* at) {
return sk_make_sp<SkWorkingFormatColorFilter>(std::move(child), tf, gamut, at);
}

View File

@ -13,6 +13,15 @@
class SkColorFilterPriv {
public:
static sk_sp<SkColorFilter> MakeGaussian();
// Runs the child filter in a different working color format than usual (premul in
// destination surface's color space), with all inputs and outputs expressed in this format.
// Each non-null {tf,gamut,at} parameter overrides that particular aspect of the color format.
static sk_sp<SkColorFilter> WithWorkingFormat(sk_sp<SkColorFilter> child,
const skcms_TransferFunction* tf,
const skcms_Matrix3x3* gamut,
const SkAlphaType* at);
};
#endif

View File

@ -9,6 +9,7 @@
#include "include/effects/SkHighContrastFilter.h"
#include "include/effects/SkRuntimeEffect.h"
#include "include/private/SkTPin.h"
#include "src/core/SkColorFilterPriv.h"
#include "src/core/SkRuntimeEffectPriv.h"
sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& config) {
@ -60,7 +61,7 @@ sk_sp<SkColorFilter> SkHighContrastFilter::Make(const SkHighContrastConfig& conf
skcms_TransferFunction linear = SkNamedTransferFn::kLinear;
SkAlphaType unpremul = kUnpremul_SkAlphaType;
return SkColorFilters::WithWorkingFormat(
return SkColorFilterPriv::WithWorkingFormat(
effect->makeColorFilter(SkData::MakeWithCopy(&uniforms,sizeof(uniforms))),
&linear, nullptr/*use dst gamut*/, &unpremul);
#else

View File

@ -14,6 +14,7 @@
#include "include/effects/SkColorMatrix.h"
#include "include/utils/SkRandom.h"
#include "src/core/SkAutoMalloc.h"
#include "src/core/SkColorFilterPriv.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
#include "tests/Test.h"
@ -104,10 +105,10 @@ DEF_TEST(WorkingFormatFilterFlags, r) {
// No working format change will itself change alpha.
SkAlphaType unpremul = kUnpremul_SkAlphaType;
cf = SkColorFilters::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
cf = SkColorFilterPriv::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
REPORTER_ASSERT(r, cf->isAlphaUnchanged());
}
@ -120,10 +121,10 @@ DEF_TEST(WorkingFormatFilterFlags, r) {
REPORTER_ASSERT(r, !cf->isAlphaUnchanged());
SkAlphaType unpremul = kUnpremul_SkAlphaType;
cf = SkColorFilters::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
cf = SkColorFilterPriv::WithWorkingFormat(std::move(cf),
&SkNamedTransferFn::kLinear,
&SkNamedGamut::kDisplayP3,
&unpremul);
REPORTER_ASSERT(r, !cf->isAlphaUnchanged());
}
}