Revert "SkColorfilters::HSLAMatrix"

This reverts commit f4c5f63ab9.

Reason for revert: trying to revert my earlier CL.  Sorry!  I'll let you reland this one first and I'll rebase next time.

Original change's description:
> SkColorfilters::HSLAMatrix
> 
> Introduce an SkColorFilter_Matrix flavor operating in HSLA space.
> 
> (CPU-only for now)
> 
> Change-Id: If081de062b9e920c3365bd7b281e45bb069c3d1a
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231259
> Commit-Queue: Florin Malita <fmalita@chromium.org>
> Reviewed-by: Mike Reed <reed@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>

TBR=mtklein@google.com,brianosman@google.com,fmalita@chromium.org,reed@google.com

Change-Id: I6a4e85d3810e2ca30d072937c035c929917d36c9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231678
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Klein 2019-08-01 21:10:21 +00:00 committed by Skia Commit-Bot
parent f77c1460f8
commit 44d095fe18
6 changed files with 43 additions and 185 deletions

View File

@ -8,11 +8,9 @@ Milestone 78
* Added RELEASE_NOTES.txt file
* SkDrawLooper is no longer supported in SkPaint or SkCanvas.
SkDrawLooper is no longer supported in SkPaint or SkCanvas.
* SkImageFilter API refactor started:
- Consolidated enum types to use SkTileMode and SkColorChannel
- Hide filter implementation classes
- Bumps SkPicture version number
* SkColorFilters::HSLAMatrix - new matrix color filter operating in HSLA space.
SkImageFilter API refactor started:
- Consolidated enum types to use SkTileMode and SkColorChannel
- Hide filter implementation classes
- Bumps SkPicture version number

View File

@ -20,10 +20,6 @@
#include "include/core/SkTypes.h"
#include "include/effects/SkColorMatrixFilter.h"
#include "include/effects/SkGradientShader.h"
#include "tools/Resources.h"
#include <vector>
#include <tuple>
static sk_sp<SkShader> make_shader(const SkRect& bounds) {
const SkPoint pts[] = {
@ -82,104 +78,3 @@ class ColorFiltersGM : public skiagm::GM {
};
DEF_GM(return new ColorFiltersGM;)
class HSLColorFilterGM : public skiagm::GM {
protected:
SkString onShortName() override { return SkString("hslcolorfilter"); }
SkISize onISize() override { return { 840, 1100 }; }
void onOnceBeforeDraw() override {
sk_sp<SkImage> mandrill = GetResourceAsImage("images/mandrill_256.png");
const auto lm = SkMatrix::MakeRectToRect(SkRect::MakeWH(mandrill->width(),
mandrill->height()),
SkRect::MakeWH(kWheelSize, kWheelSize),
SkMatrix::kFill_ScaleToFit);
fShaders.push_back(mandrill->makeShader(&lm));
static constexpr SkColor gGrads[][4] = {
{ 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffff0000 },
{ 0xdfc08040, 0xdf8040c0, 0xdf40c080, 0xdfc08040 },
};
for (const auto& cols : gGrads) {
fShaders.push_back(SkGradientShader::MakeSweep(kWheelSize / 2, kWheelSize / 2,
cols, nullptr, SK_ARRAY_COUNT(cols),
SkTileMode::kRepeat, -90, 270, 0,
nullptr));
}
}
void onDraw(SkCanvas* canvas) override {
using std::make_tuple;
static constexpr struct {
std::tuple<float, float> h, s, l;
} gTests[] = {
{ make_tuple(-0.5f, 0.5f), make_tuple( 0.0f, 0.0f), make_tuple( 0.0f, 0.0f) },
{ make_tuple( 0.0f, 0.0f), make_tuple(-1.0f, 1.0f), make_tuple( 0.0f, 0.0f) },
{ make_tuple( 0.0f, 0.0f), make_tuple( 0.0f, 0.0f), make_tuple(-1.0f, 1.0f) },
};
const auto rect = SkRect::MakeWH(kWheelSize, kWheelSize);
canvas->drawColor(0xffcccccc);
SkPaint paint;
for (const auto& shader : fShaders) {
paint.setShader(shader);
for (const auto& tst: gTests) {
canvas->translate(0, kWheelSize * 0.1f);
const auto dh = (std::get<1>(tst.h) - std::get<0>(tst.h)) / (kSteps - 1),
ds = (std::get<1>(tst.s) - std::get<0>(tst.s)) / (kSteps - 1),
dl = (std::get<1>(tst.l) - std::get<0>(tst.l)) / (kSteps - 1);
auto h = std::get<0>(tst.h),
s = std::get<0>(tst.s),
l = std::get<0>(tst.l);
{
SkAutoCanvasRestore acr(canvas, true);
for (size_t i = 0; i < kSteps; ++i) {
paint.setColorFilter(make_filter(h, s, l));
canvas->translate(kWheelSize * 0.1f, 0);
canvas->drawRect(rect, paint);
canvas->translate(kWheelSize * 1.1f, 0);
h += dh;
s += ds;
l += dl;
}
}
canvas->translate(0, kWheelSize * 1.1f);
}
canvas->translate(0, kWheelSize * 0.1f);
}
}
private:
static constexpr SkScalar kWheelSize = 100;
static constexpr size_t kSteps = 7;
static sk_sp<SkColorFilter> make_filter(float h, float s, float l) {
// These are roughly AE semantics.
const auto h_bias = h,
h_scale = 1.0f,
s_bias = std::max(s, 0.0f),
s_scale = 1 - std::abs(s),
l_bias = std::max(l, 0.0f),
l_scale = 1 - std::abs(l);
const float cm[20] = {
h_scale, 0, 0, 0, h_bias,
0, s_scale, 0, 0, s_bias,
0, 0, l_scale, 0, l_bias,
0, 0, 0, 1, 0,
};
return SkColorFilters::HSLAMatrix(cm);
}
std::vector<sk_sp<SkShader>> fShaders;
};
DEF_GM(return new HSLColorFilterGM;)

View File

@ -149,10 +149,6 @@ public:
static sk_sp<SkColorFilter> Matrix(const SkColorMatrix&);
static sk_sp<SkColorFilter> Matrix(const float rowMajor[20]);
// A version of Matrix which operates in HSLA space instead of RGBA.
// I.e. HSLA-to-RGBA(Matrix(RGBA-to-HSLA(input))).
static sk_sp<SkColorFilter> HSLAMatrix(const float rowMajor[20]);
static sk_sp<SkColorFilter> LinearToSRGBGamma();
static sk_sp<SkColorFilter> SRGBToLinearGamma();
static sk_sp<SkColorFilter> Lerp(float t, sk_sp<SkColorFilter> dst, sk_sp<SkColorFilter> src);

View File

@ -16,21 +16,15 @@
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
static uint16_t ComputeFlags(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;
void SkColorFilter_Matrix::initState() {
const float* srcA = fMatrix + 15;
fFlags = (srcA[0] == 0 && srcA[1] == 0 && srcA[2] == 0 && srcA[3] == 1 && srcA[4] == 0)
? kAlphaUnchanged_Flag : 0;
}
SkColorFilter_Matrix::SkColorFilter_Matrix(const float array[20], Domain domain)
: fFlags(ComputeFlags(array))
, fDomain(domain) {
SkColorFilter_Matrix::SkColorFilter_Matrix(const float array[20]) {
memcpy(fMatrix, array, 20 * sizeof(float));
this->initState();
}
uint32_t SkColorFilter_Matrix::getFlags() const {
@ -40,21 +34,14 @@ uint32_t SkColorFilter_Matrix::getFlags() const {
void SkColorFilter_Matrix::flatten(SkWriteBuffer& buffer) const {
SkASSERT(sizeof(fMatrix)/sizeof(float) == 20);
buffer.writeScalarArray(fMatrix, 20);
// RGBA flag
buffer.writeBool(fDomain == Domain::kRGBA);
}
sk_sp<SkFlattenable> SkColorFilter_Matrix::CreateProc(SkReadBuffer& buffer) {
float matrix[20];
if (!buffer.readScalarArray(matrix, 20)) {
return nullptr;
if (buffer.readScalarArray(matrix, 20)) {
return SkColorFilters::Matrix(matrix);
}
auto is_rgba = buffer.isVersionLT(SkPicturePriv::kMatrixColorFilterDomain_Version) ||
buffer.readBool();
return is_rgba ? SkColorFilters::Matrix(matrix)
: SkColorFilters::HSLAMatrix(matrix);
return nullptr;
}
bool SkColorFilter_Matrix::onAsAColorMatrix(float matrix[20]) const {
@ -66,14 +53,10 @@ bool SkColorFilter_Matrix::onAsAColorMatrix(float matrix[20]) const {
bool SkColorFilter_Matrix::onAppendStages(const SkStageRec& rec,
bool /*shaderIsOpaque*/) const {
const bool hsla = fDomain == Domain::kHSLA;
SkRasterPipeline* p = rec.fPipeline;
if (hsla) { p->append(SkRasterPipeline::rgb_to_hsl); }
p->append(SkRasterPipeline::matrix_4x5, fMatrix);
if (hsla) { p->append(SkRasterPipeline::hsl_to_rgb); }
p->append(SkRasterPipeline::clamp_0);
p->append(SkRasterPipeline::clamp_1);
p->append(SkRasterPipeline::matrix_4x5, fMatrix);
p->append(SkRasterPipeline::clamp_0);
p->append(SkRasterPipeline::clamp_1);
return true;
}
@ -81,10 +64,6 @@ bool SkColorFilter_Matrix::onAppendStages(const SkStageRec& rec,
#include "src/gpu/effects/generated/GrColorMatrixFragmentProcessor.h"
std::unique_ptr<GrFragmentProcessor> SkColorFilter_Matrix::asFragmentProcessor(
GrRecordingContext*, const GrColorSpaceInfo&) const {
if (fDomain == Domain::kHSLA) {
// TODO
return nullptr;
}
return GrColorMatrixFragmentProcessor::Make(fMatrix,
/* premulInput = */ true,
/* clampRGBOutput = */ true,
@ -95,23 +74,15 @@ std::unique_ptr<GrFragmentProcessor> SkColorFilter_Matrix::asFragmentProcessor(
///////////////////////////////////////////////////////////////////////////////
static sk_sp<SkColorFilter> MakeMatrix(const float array[20],
SkColorFilter_Matrix::Domain domain) {
return sk_floats_are_finite(array, 20)
? sk_make_sp<SkColorFilter_Matrix>(array, domain)
: nullptr;
}
sk_sp<SkColorFilter> SkColorFilters::Matrix(const float array[20]) {
return MakeMatrix(array, SkColorFilter_Matrix::Domain::kRGBA);
if (!sk_floats_are_finite(array, 20)) {
return nullptr;
}
return sk_sp<SkColorFilter>(new SkColorFilter_Matrix(array));
}
sk_sp<SkColorFilter> SkColorFilters::Matrix(const SkColorMatrix& cm) {
return MakeMatrix(cm.fMat, SkColorFilter_Matrix::Domain::kRGBA);
}
sk_sp<SkColorFilter> SkColorFilters::HSLAMatrix(const float array[20]) {
return MakeMatrix(array, SkColorFilter_Matrix::Domain::kHSLA);
return Matrix(cm.fMat);
}
void SkColorFilter_Matrix::RegisterFlattenables() {

View File

@ -13,9 +13,8 @@
class SkColorFilter_Matrix : public SkColorFilter {
public:
enum class Domain : uint8_t { kRGBA, kHSLA };
explicit SkColorFilter_Matrix(const float array[20], Domain);
SkColorFilter_Matrix() {}
explicit SkColorFilter_Matrix(const float array[20]);
uint32_t getFlags() const override;
@ -35,8 +34,9 @@ private:
SkAlphaType onAlphaType() const override { return kUnpremul_SkAlphaType; }
float fMatrix[20];
uint16_t fFlags;
Domain fDomain;
uint32_t fFlags;
void initState();
typedef SkColorFilter INHERITED;
};

View File

@ -72,29 +72,27 @@ public:
// V69: Clean up duplicated and redundant SkImageFilter related enums
// V70: Image filters definitions hidden, registered names updated to include "Impl"
// V71: Unify erode and dilate image filters
// V72: SkColorFilter_Matrix domain (rgba vs. hsla)
enum Version {
kTileModeInBlurImageFilter_Version = 56,
kTileInfoInSweepGradient_Version = 57,
k2PtConicalNoFlip_Version = 58,
kTileModeInBlurImageFilter_Version = 56,
kTileInfoInSweepGradient_Version = 57,
k2PtConicalNoFlip_Version = 58,
kRemovePictureImageFilterLocalSpace = 59,
kRemoveHeaderFlags_Version = 60,
kTwoColorDrawShadow_Version = 61,
kDontNegateImageSize_Version = 62,
kStoreImageBounds_Version = 63,
kRemoveOccluderFromBlurMaskFilter = 64,
kFloat4PaintColor_Version = 65,
kSaveBehind_Version = 66,
kSerializeFonts_Version = 67,
kPaintDoesntSerializeFonts_Version = 68,
kCleanupImageFilterEnums_Version = 69,
kHideImageFilterImpls_Version = 70,
kUnifyErodeDilateImpls_Version = 71,
kMatrixColorFilterDomain_Version = 72,
kRemoveHeaderFlags_Version = 60,
kTwoColorDrawShadow_Version = 61,
kDontNegateImageSize_Version = 62,
kStoreImageBounds_Version = 63,
kRemoveOccluderFromBlurMaskFilter = 64,
kFloat4PaintColor_Version = 65,
kSaveBehind_Version = 66,
kSerializeFonts_Version = 67,
kPaintDoesntSerializeFonts_Version = 68,
kCleanupImageFilterEnums_Version = 69,
kHideImageFilterImpls_Version = 70,
kUnifyErodeDilateImpls_Version = 71,
// Only SKPs within the min/current picture version range (inclusive) can be read.
kMin_Version = kTileModeInBlurImageFilter_Version,
kCurrent_Version = kMatrixColorFilterDomain_Version
kCurrent_Version = kUnifyErodeDilateImpls_Version
};
static_assert(kMin_Version <= 62, "Remove kFontAxes_bad from SkFontDescriptor.cpp");