hide internals of SkColorMatrix (so we can migrate to col-major)
Change-Id: If0eb6fb2efb6816b92ad7ca7d8caaace71397b7f Reviewed-on: https://skia-review.googlesource.com/c/skia/+/209409 Commit-Queue: Ravi Mistry <rmistry@google.com> Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Reed <reed@google.com> Auto-Submit: Mike Reed <reed@google.com>
This commit is contained in:
parent
731ba99a85
commit
50d79af7b7
@ -29,19 +29,19 @@ static sk_sp<SkColorFilter> make_cf_null() {
|
||||
static sk_sp<SkColorFilter> make_cf0() {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.75f);
|
||||
return SkColorFilters::MatrixRowMajor255(cm.fMat);
|
||||
return SkColorFilters::Matrix(cm);
|
||||
}
|
||||
|
||||
static sk_sp<SkColorFilter> make_cf1() {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.75f);
|
||||
auto a = SkColorFilters::MatrixRowMajor255(cm.fMat);
|
||||
auto a = SkColorFilters::Matrix(cm);
|
||||
// CreateComposedFilter will try to concat these two matrices, resulting in a single
|
||||
// filter (which is good for speed). For this test, we want to force a real compose of
|
||||
// these two, so our inner filter has a scale-up, which disables the optimization of
|
||||
// combining the two matrices.
|
||||
cm.setScale(1.1f, 0.9f, 1);
|
||||
return a->makeComposed(SkColorFilters::MatrixRowMajor255(cm.fMat));
|
||||
return a->makeComposed(SkColorFilters::Matrix(cm));
|
||||
}
|
||||
|
||||
static sk_sp<SkColorFilter> make_cf2() {
|
||||
|
@ -178,7 +178,7 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) {
|
||||
SkAutoCanvasRestore autoCanvasRestore(canvas, false);
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.0f);
|
||||
sk_sp<SkColorFilter> cf(SkColorFilters::MatrixRowMajor255(cm.fMat));
|
||||
sk_sp<SkColorFilter> cf(SkColorFilters::Matrix(cm));
|
||||
SkPaint p;
|
||||
p.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
|
||||
canvas->saveLayer(nullptr, &p);
|
||||
|
@ -14,7 +14,7 @@
|
||||
#define HEIGHT 500
|
||||
|
||||
static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) {
|
||||
paint->setColorFilter(SkColorFilters::MatrixRowMajor255(matrix.fMat));
|
||||
paint->setColorFilter(SkColorFilters::Matrix(matrix));
|
||||
}
|
||||
|
||||
static void set_array(SkPaint* paint, const SkScalar array[]) {
|
||||
|
@ -1006,7 +1006,7 @@ static SkTArray<sk_sp<ClipTileRenderer>> make_filtered_renderers() {
|
||||
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(10);
|
||||
sk_sp<SkColorFilter> colorFilter = SkColorFilters::MatrixRowMajor255(cm.fMat);
|
||||
sk_sp<SkColorFilter> colorFilter = SkColorFilters::Matrix(cm);
|
||||
sk_sp<SkImageFilter> imageFilter = SkDilateImageFilter::Make(8, 8, nullptr);
|
||||
|
||||
static constexpr SkColor kAlphas[] = { SK_ColorTRANSPARENT, SK_ColorBLACK };
|
||||
|
@ -138,7 +138,7 @@ static void draw_set(SkCanvas* canvas, sk_sp<SkImageFilter> filters[], int count
|
||||
DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(10);
|
||||
sk_sp<SkColorFilter> cf(SkColorFilters::MatrixRowMajor255(cm.fMat));
|
||||
sk_sp<SkColorFilter> cf(SkColorFilters::Matrix(cm));
|
||||
const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 };
|
||||
sk_sp<SkImageFilter> filters[] = {
|
||||
SkBlurImageFilter::Make(10, 10, nullptr),
|
||||
|
@ -17,6 +17,7 @@ class GrColorSpaceInfo;
|
||||
class GrFragmentProcessor;
|
||||
class GrRecordingContext;
|
||||
class SkBitmap;
|
||||
class SkColorMatrix;
|
||||
class SkColorSpace;
|
||||
struct SkStageRec;
|
||||
class SkString;
|
||||
@ -136,6 +137,8 @@ public:
|
||||
static sk_sp<SkColorFilter> SRGBToLinearGamma();
|
||||
static sk_sp<SkColorFilter> Lerp(float t, sk_sp<SkColorFilter> dst, sk_sp<SkColorFilter> src);
|
||||
|
||||
static sk_sp<SkColorFilter> Matrix(const SkColorMatrix&);
|
||||
|
||||
private:
|
||||
SkColorFilters() = delete;
|
||||
};
|
||||
|
@ -11,7 +11,9 @@
|
||||
#include "SkScalar.h"
|
||||
|
||||
class SK_API SkColorMatrix {
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORMATRIX_PUBLIC
|
||||
public:
|
||||
#endif
|
||||
enum {
|
||||
kCount = 20
|
||||
};
|
||||
@ -28,12 +30,15 @@ public:
|
||||
kB_Trans = 14,
|
||||
kA_Trans = 19,
|
||||
};
|
||||
void postTranslate(SkScalar rTrans, SkScalar gTrans, SkScalar bTrans,
|
||||
SkScalar aTrans = 0);
|
||||
static bool NeedsClamping(const SkScalar[20]);
|
||||
static void SetConcat(SkScalar result[20], const SkScalar outer[20], const SkScalar inner[20]);
|
||||
|
||||
public:
|
||||
void setIdentity();
|
||||
void setScale(SkScalar rScale, SkScalar gScale, SkScalar bScale,
|
||||
SkScalar aScale = SK_Scalar1);
|
||||
void postTranslate(SkScalar rTrans, SkScalar gTrans, SkScalar bTrans,
|
||||
SkScalar aTrans = 0);
|
||||
|
||||
enum Axis {
|
||||
kR_Axis = 0,
|
||||
@ -53,14 +58,18 @@ public:
|
||||
void setRGB2YUV();
|
||||
void setYUV2RGB();
|
||||
|
||||
void postTranslate255(SkScalar r, SkScalar g, SkScalar b, SkScalar a = 0) {
|
||||
this->postTranslate(r, g, b, a);
|
||||
}
|
||||
|
||||
bool operator==(const SkColorMatrix& other) const {
|
||||
return 0 == memcmp(fMat, other.fMat, sizeof(fMat));
|
||||
}
|
||||
|
||||
bool operator!=(const SkColorMatrix& other) const { return !((*this) == other); }
|
||||
|
||||
static bool NeedsClamping(const SkScalar[20]);
|
||||
static void SetConcat(SkScalar result[20], const SkScalar outer[20], const SkScalar inner[20]);
|
||||
private:
|
||||
friend class SkColorFilters;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
#include "SkColorMatrixFilterRowMajor255.h"
|
||||
#include "SkColorData.h"
|
||||
#include "SkColorMatrix.h"
|
||||
#include "SkNx.h"
|
||||
#include "SkRasterPipeline.h"
|
||||
#include "SkReadBuffer.h"
|
||||
@ -202,6 +203,10 @@ std::unique_ptr<GrFragmentProcessor> SkColorMatrixFilterRowMajor255::asFragmentP
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkColorFilter> SkColorFilters::Matrix(const SkColorMatrix& cm) {
|
||||
return MatrixRowMajor255(cm.fMat);
|
||||
}
|
||||
|
||||
sk_sp<SkColorFilter> SkColorFilters::MatrixRowMajor255(const float array[20]) {
|
||||
if (!SkScalarsAreFinite(array, 20)) {
|
||||
return nullptr;
|
||||
|
@ -28,9 +28,9 @@ sk_sp<SkColorFilter> SkColorMatrixFilter::MakeLightingFilter(SkColor mul, SkColo
|
||||
byte_to_scale(SkColorGetG(mul)),
|
||||
byte_to_scale(SkColorGetB(mul)),
|
||||
1);
|
||||
matrix.postTranslate(SkIntToScalar(SkColorGetR(add)),
|
||||
matrix.postTranslate255(SkIntToScalar(SkColorGetR(add)),
|
||||
SkIntToScalar(SkColorGetG(add)),
|
||||
SkIntToScalar(SkColorGetB(add)),
|
||||
0);
|
||||
return SkColorFilters::MatrixRowMajor255(matrix.fMat);
|
||||
return SkColorFilters::Matrix(matrix);
|
||||
}
|
||||
|
@ -236,11 +236,11 @@ DEF_TEST(Paint_nothingToDraw, r) {
|
||||
|
||||
SkColorMatrix cm;
|
||||
cm.setIdentity(); // does not change alpha
|
||||
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(cm.fMat));
|
||||
paint.setColorFilter(SkColorFilters::Matrix(cm));
|
||||
REPORTER_ASSERT(r, paint.nothingToDraw());
|
||||
|
||||
cm.postTranslate(0, 0, 0, 1); // wacks alpha
|
||||
paint.setColorFilter(SkColorFilters::MatrixRowMajor255(cm.fMat));
|
||||
cm.postTranslate255(0, 0, 0, 1); // wacks alpha
|
||||
paint.setColorFilter(SkColorFilters::Matrix(cm));
|
||||
REPORTER_ASSERT(r, !paint.nothingToDraw());
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user