Reland of [2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #1 id:1 of https://codereview.chromium.org/1821103004/ )
Reason for revert:
guard has now landed in chrome
Original issue's description:
> Revert of Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.o… (patchset #3 id:40001 of https://codereview.chromium.org/1825073002/ )
>
> Reason for revert:
> CreateModeFilter not compiling
>
> Original issue's description:
> > Revert[2] of "switch colorfilters to sk_sp (patchset #11 id:200001 of https://codereview.chromium.org/1822623002/ )"
> >
> > Fixed legacy withColorFilter to call new(er) make method
> >
> > This reverts commit 1eb81db650
.
> >
> > BUG=skia:
> > GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1825073002
> >
> > TBR=
> >
> > Committed: https://skia.googlesource.com/skia/+/4c9776b046dd5e9e46e2d1ce35154855c8fcb381
>
> TBR=
> # Skipping CQ checks because original CL landed less than 1 days ago.
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=skia:
>
> Committed: https://skia.googlesource.com/skia/+/d6889293dd0942f27f9593f679722c956831f2c4
TBR=
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=skia:
Review URL: https://codereview.chromium.org/1827433002
This commit is contained in:
parent
d25d06bf5f
commit
d053ce9c54
@ -54,9 +54,8 @@ public:
|
||||
SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
|
||||
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
||||
paint->setMaskFilter(maskFilter)->unref();
|
||||
SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(SK_ColorLTGRAY,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
paint->setColorFilter(colorFilter)->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorLTGRAY,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
paint->setColor(SK_ColorGRAY);
|
||||
}
|
||||
{
|
||||
|
@ -13,20 +13,14 @@
|
||||
class ColorCubeBench : public Benchmark {
|
||||
SkISize fSize;
|
||||
int fCubeDimension;
|
||||
SkData* fCubeData;
|
||||
sk_sp<SkData> fCubeData;
|
||||
SkBitmap fBitmap;
|
||||
|
||||
public:
|
||||
ColorCubeBench()
|
||||
: fCubeDimension(0)
|
||||
, fCubeData(nullptr) {
|
||||
ColorCubeBench() : fCubeDimension(0) {
|
||||
fSize = SkISize::Make(2880, 1800); // 2014 Macbook Pro resolution
|
||||
}
|
||||
|
||||
~ColorCubeBench() {
|
||||
SkSafeUnref(fCubeData);
|
||||
}
|
||||
|
||||
protected:
|
||||
const char* onGetName() override {
|
||||
return "colorcube";
|
||||
@ -71,7 +65,7 @@ private:
|
||||
|
||||
void makeCubeData() {
|
||||
fCubeDimension = 32;
|
||||
fCubeData = SkData::NewUninitialized(sizeof(SkColor) *
|
||||
fCubeData = SkData::MakeUninitialized(sizeof(SkColor) *
|
||||
fCubeDimension * fCubeDimension * fCubeDimension);
|
||||
SkColor* pixels = (SkColor*)(fCubeData->writable_data());
|
||||
SkAutoTMalloc<uint8_t> lutMemory(fCubeDimension);
|
||||
@ -95,9 +89,7 @@ private:
|
||||
void test(int loops, SkCanvas* canvas) {
|
||||
SkPaint paint;
|
||||
for (int i = 0; i < loops; i++) {
|
||||
SkAutoTUnref<SkColorFilter> colorCube(
|
||||
SkColorCubeFilter::Create(fCubeData, fCubeDimension));
|
||||
paint.setColorFilter(colorCube);
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(fCubeData, fCubeDimension));
|
||||
canvas->drawBitmap(fBitmap, 0, 0, &paint);
|
||||
}
|
||||
}
|
||||
|
@ -34,8 +34,8 @@ protected:
|
||||
0, 1, 0, 0, amount255,
|
||||
0, 0, 1, 0, amount255,
|
||||
0, 0, 0, 1, 0 };
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
|
||||
@ -45,14 +45,13 @@ protected:
|
||||
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
|
||||
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
|
||||
matrix[18] = 1.0f;
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
|
||||
SkAutoTUnref<SkColorFilter> filter(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input);
|
||||
}
|
||||
|
||||
inline bool isSmall() const { return fIsSmall; }
|
||||
|
@ -28,12 +28,12 @@ public:
|
||||
}
|
||||
|
||||
protected:
|
||||
void doPreDraw(SkColorFilter* colorFilters[], int nFilters) {
|
||||
void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
|
||||
// Create a chain of ImageFilters from colorFilters
|
||||
fImageFilter = nullptr;
|
||||
for(int i = nFilters; i --> 0;) {
|
||||
SkAutoTUnref<SkImageFilter> filter(
|
||||
SkColorFilterImageFilter::Create(colorFilters[i], fImageFilter, nullptr)
|
||||
SkColorFilterImageFilter::Create(colorFilters[i].get(), fImageFilter, nullptr)
|
||||
);
|
||||
SkRefCnt_SafeAssign(fImageFilter, filter.get());
|
||||
}
|
||||
@ -73,15 +73,12 @@ private:
|
||||
};
|
||||
|
||||
class TableCollapseBench: public BaseImageFilterCollapseBench {
|
||||
public:
|
||||
virtual ~TableCollapseBench() {}
|
||||
|
||||
protected:
|
||||
virtual const char* onGetName() override {
|
||||
const char* onGetName() override {
|
||||
return "image_filter_collapse_table";
|
||||
}
|
||||
|
||||
virtual void onDelayedSetup() override {
|
||||
void onDelayedSetup() override {
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
int n = i >> 5;
|
||||
table1[i] = (n << 5) | (n << 2) | (n >> 1);
|
||||
@ -92,63 +89,52 @@ protected:
|
||||
table3[i] = static_cast<uint8_t>(sqrtf(fi) * 255);
|
||||
}
|
||||
|
||||
SkColorFilter* colorFilters[] = {
|
||||
SkTableColorFilter::Create(table1),
|
||||
SkTableColorFilter::Create(table2),
|
||||
SkTableColorFilter::Create(table3),
|
||||
sk_sp<SkColorFilter> colorFilters[] = {
|
||||
SkTableColorFilter::Make(table1),
|
||||
SkTableColorFilter::Make(table2),
|
||||
SkTableColorFilter::Make(table3),
|
||||
};
|
||||
|
||||
doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
|
||||
|
||||
for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
|
||||
colorFilters[i]->unref();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
uint8_t table1[256], table2[256], table3[256];
|
||||
};
|
||||
|
||||
static SkColorFilter* make_brightness(float amount) {
|
||||
static sk_sp<SkColorFilter> make_brightness(float amount) {
|
||||
SkScalar amount255 = SkScalarMul(amount, SkIntToScalar(255));
|
||||
SkScalar matrix[20] = { 1, 0, 0, 0, amount255,
|
||||
0, 1, 0, 0, amount255,
|
||||
0, 0, 1, 0, amount255,
|
||||
0, 0, 0, 1, 0 };
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_grayscale() {
|
||||
static sk_sp<SkColorFilter> make_grayscale() {
|
||||
SkScalar matrix[20];
|
||||
memset(matrix, 0, 20 * sizeof(SkScalar));
|
||||
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
|
||||
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
|
||||
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
|
||||
matrix[18] = 1.0f;
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
|
||||
class MatrixCollapseBench: public BaseImageFilterCollapseBench {
|
||||
public:
|
||||
virtual ~MatrixCollapseBench() {}
|
||||
|
||||
protected:
|
||||
virtual const char* onGetName() override {
|
||||
const char* onGetName() override {
|
||||
return "image_filter_collapse_matrix";
|
||||
}
|
||||
|
||||
virtual void onDelayedSetup() override {
|
||||
SkColorFilter* colorFilters[] = {
|
||||
void onDelayedSetup() override {
|
||||
sk_sp<SkColorFilter> colorFilters[] = {
|
||||
make_brightness(0.1f),
|
||||
make_grayscale(),
|
||||
make_brightness(-0.1f),
|
||||
};
|
||||
|
||||
doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
|
||||
|
||||
for(unsigned i = 0; i < SK_ARRAY_COUNT(colorFilters); i++) {
|
||||
colorFilters[i]->unref();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -67,9 +67,9 @@ protected:
|
||||
kNormal_SkBlurStyle,
|
||||
1.366025f,
|
||||
SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
|
||||
paint.setColorFilter(SkColorFilter::CreateModeFilter(
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(
|
||||
SK_ColorRED,
|
||||
SkXfermode::kSrcIn_Mode))->unref();
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
canvas->drawRRect(rr, paint);
|
||||
|
@ -60,10 +60,9 @@ public:
|
||||
SkBlurMask::ConvertRadiusToSigma(SK_ScalarHalf),
|
||||
SkBlurMaskFilter::kHighQuality_BlurFlag);
|
||||
paint->setMaskFilter(maskFilter)->unref();
|
||||
SkColorFilter* colorFilter = SkColorFilter::CreateModeFilter(
|
||||
paint->setColorFilter(SkColorFilter::MakeModeFilter(
|
||||
sk_tool_utils::color_to_565(SK_ColorLTGRAY),
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
paint->setColorFilter(colorFilter)->unref();
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
paint->setColor(sk_tool_utils::color_to_565(SK_ColorGRAY));
|
||||
}
|
||||
{
|
||||
|
@ -22,43 +22,43 @@ static sk_sp<SkShader> make_alpha_color() {
|
||||
return SkShader::MakeColorShader(0x80FF0000);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf_null() {
|
||||
static sk_sp<SkColorFilter> make_cf_null() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf0() {
|
||||
static sk_sp<SkColorFilter> make_cf0() {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.75f);
|
||||
return SkColorMatrixFilter::Create(cm);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf1() {
|
||||
static sk_sp<SkColorFilter> make_cf1() {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.75f);
|
||||
SkAutoTUnref<SkColorFilter> a(SkColorMatrixFilter::Create(cm));
|
||||
auto a(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
// 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);
|
||||
SkAutoTUnref<SkColorFilter> b(SkColorMatrixFilter::Create(cm));
|
||||
return SkColorFilter::CreateComposeFilter(a, b);
|
||||
auto b(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
return SkColorFilter::MakeComposeFilter(a, b);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf2() {
|
||||
return SkColorFilter::CreateModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode);
|
||||
static sk_sp<SkColorFilter> make_cf2() {
|
||||
return SkColorFilter::MakeModeFilter(0x8044CC88, SkXfermode::kSrcATop_Mode);
|
||||
}
|
||||
|
||||
static void draw_into_canvas(SkCanvas* canvas) {
|
||||
const SkRect r = SkRect::MakeWH(50, 100);
|
||||
sk_sp<SkShader> (*shaders[])() { make_opaque_color, make_alpha_color };
|
||||
SkColorFilter* (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
|
||||
sk_sp<SkColorFilter> (*filters[])() { make_cf_null, make_cf0, make_cf1, make_cf2 };
|
||||
|
||||
SkPaint paint;
|
||||
for (auto shProc : shaders) {
|
||||
paint.setShader(shProc());
|
||||
for (auto cfProc : filters) {
|
||||
SkSafeUnref(paint.setColorFilter(cfProc()));
|
||||
paint.setColorFilter(cfProc());
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->translate(60, 0);
|
||||
}
|
||||
|
@ -25,27 +25,12 @@ static sk_sp<SkShader> MakeLinear() {
|
||||
|
||||
class ColorCubeGM : public GM {
|
||||
public:
|
||||
ColorCubeGM()
|
||||
: fInitialized(false)
|
||||
, f3DLut4(nullptr)
|
||||
, f3DLut8(nullptr)
|
||||
, f3DLut16(nullptr)
|
||||
, f3DLut32(nullptr)
|
||||
, f3DLut64(nullptr)
|
||||
{
|
||||
ColorCubeGM() : fInitialized(false) {
|
||||
this->setBGColor(0xFF000000);
|
||||
}
|
||||
|
||||
~ColorCubeGM() {
|
||||
SkSafeUnref(f3DLut4);
|
||||
SkSafeUnref(f3DLut8);
|
||||
SkSafeUnref(f3DLut16);
|
||||
SkSafeUnref(f3DLut32);
|
||||
SkSafeUnref(f3DLut64);
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual SkString onShortName() {
|
||||
SkString onShortName() override {
|
||||
return SkString("colorcube");
|
||||
}
|
||||
|
||||
@ -67,8 +52,8 @@ protected:
|
||||
canvas.drawRect(SkRect::MakeWH(80, 80), paint);
|
||||
}
|
||||
|
||||
void make_3Dlut(SkData** data, int size, bool invR, bool invG, bool invB) {
|
||||
*data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
|
||||
void make_3Dlut(sk_sp<SkData>* data, int size, bool invR, bool invG, bool invB) {
|
||||
*data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size);
|
||||
SkColor* pixels = (SkColor*)((*data)->writable_data());
|
||||
SkAutoTMalloc<uint8_t> lutMemory(size);
|
||||
SkAutoTMalloc<uint8_t> invLutMemory(size);
|
||||
@ -92,11 +77,11 @@ protected:
|
||||
}
|
||||
}
|
||||
|
||||
virtual SkISize onISize() {
|
||||
SkISize onISize() override {
|
||||
return SkISize::Make(500, 100);
|
||||
}
|
||||
|
||||
virtual void onDraw(SkCanvas* canvas) {
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
if (!fInitialized) {
|
||||
this->make_bitmap();
|
||||
this->make_3Dluts();
|
||||
@ -104,19 +89,19 @@ protected:
|
||||
}
|
||||
canvas->clear(0x00000000);
|
||||
SkPaint paint;
|
||||
paint.setColorFilter(SkColorCubeFilter::Create(f3DLut4, 4))->unref();
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(f3DLut4, 4));
|
||||
canvas->drawBitmap(fBitmap, 10, 10, &paint);
|
||||
|
||||
paint.setColorFilter(SkColorCubeFilter::Create(f3DLut8, 8))->unref();
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(f3DLut8, 8));
|
||||
canvas->drawBitmap(fBitmap, 110, 10, &paint);
|
||||
|
||||
paint.setColorFilter(SkColorCubeFilter::Create(f3DLut16, 16))->unref();
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(f3DLut16, 16));
|
||||
canvas->drawBitmap(fBitmap, 210, 10, &paint);
|
||||
|
||||
paint.setColorFilter(SkColorCubeFilter::Create(f3DLut32, 32))->unref();
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(f3DLut32, 32));
|
||||
canvas->drawBitmap(fBitmap, 310, 10, &paint);
|
||||
|
||||
paint.setColorFilter(SkColorCubeFilter::Create(f3DLut64, 64))->unref();
|
||||
paint.setColorFilter(SkColorCubeFilter::Make(f3DLut64, 64));
|
||||
canvas->drawBitmap(fBitmap, 410, 10, &paint);
|
||||
}
|
||||
|
||||
@ -124,11 +109,11 @@ private:
|
||||
typedef GM INHERITED;
|
||||
bool fInitialized;
|
||||
SkBitmap fBitmap;
|
||||
SkData* f3DLut4;
|
||||
SkData* f3DLut8;
|
||||
SkData* f3DLut16;
|
||||
SkData* f3DLut32;
|
||||
SkData* f3DLut64;
|
||||
sk_sp<SkData> f3DLut4;
|
||||
sk_sp<SkData> f3DLut8;
|
||||
sk_sp<SkData> f3DLut16;
|
||||
sk_sp<SkData> f3DLut32;
|
||||
sk_sp<SkData> f3DLut64;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -34,8 +34,8 @@ static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
|
||||
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
|
||||
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
|
||||
matrix[18] = 1.0f;
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) {
|
||||
|
@ -18,34 +18,34 @@
|
||||
#define FILTER_HEIGHT SkIntToScalar(30)
|
||||
#define MARGIN SkIntToScalar(10)
|
||||
|
||||
static SkColorFilter* cf_make_brightness(float brightness) {
|
||||
static sk_sp<SkColorFilter> cf_make_brightness(float brightness) {
|
||||
SkScalar amount255 = SkScalarMul(brightness, SkIntToScalar(255));
|
||||
SkScalar matrix[20] = {
|
||||
1, 0, 0, 0, amount255,
|
||||
0, 1, 0, 0, amount255,
|
||||
0, 0, 1, 0, amount255,
|
||||
0, 0, 0, 1, 0 };
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
|
||||
static SkColorFilter* cf_make_grayscale() {
|
||||
static sk_sp<SkColorFilter> cf_make_grayscale() {
|
||||
SkScalar matrix[20];
|
||||
memset(matrix, 0, 20 * sizeof(SkScalar));
|
||||
matrix[0] = matrix[5] = matrix[10] = 0.2126f;
|
||||
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
|
||||
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
|
||||
matrix[18] = 1.0f;
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
|
||||
static SkColorFilter* cf_make_colorize(SkColor color) {
|
||||
return SkColorFilter::CreateModeFilter(color, SkXfermode::kSrc_Mode);
|
||||
static sk_sp<SkColorFilter> cf_make_colorize(SkColor color) {
|
||||
return SkColorFilter::MakeModeFilter(color, SkXfermode::kSrc_Mode);
|
||||
}
|
||||
|
||||
static void sk_gm_get_colorfilters(SkTDArray<SkColorFilter*>* array) {
|
||||
*array->append() = cf_make_brightness(0.5f);
|
||||
*array->append() = cf_make_grayscale();
|
||||
*array->append() = cf_make_colorize(SK_ColorBLUE);
|
||||
static void sk_gm_get_colorfilters(SkTArray<sk_sp<SkColorFilter>>* array) {
|
||||
array->push_back(cf_make_brightness(0.5f));
|
||||
array->push_back(cf_make_grayscale());
|
||||
array->push_back(cf_make_colorize(SK_ColorBLUE));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -92,18 +92,15 @@ static SkImageFilter* make_blur(float amount, SkImageFilter* input = nullptr) {
|
||||
}
|
||||
|
||||
static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) {
|
||||
SkAutoTUnref<SkColorFilter> filter(cf_make_brightness(amount));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
return SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
|
||||
SkAutoTUnref<SkColorFilter> filter(cf_make_grayscale());
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
return SkColorFilterImageFilter::Create(cf_make_grayscale().get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
|
||||
SkAutoTUnref<SkColorFilter> filter(cf_make_colorize(SK_ColorBLUE));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
return SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(), input);
|
||||
}
|
||||
|
||||
static void drawClippedRect(SkCanvas* canvas,
|
||||
@ -179,8 +176,8 @@ DEF_SIMPLE_GM(colorfilterimagefilter_layer, canvas, 32, 32) {
|
||||
SkAutoCanvasRestore autoCanvasRestore(canvas, false);
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(0.0f);
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm));
|
||||
SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf));
|
||||
auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
SkAutoTUnref<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf.get()));
|
||||
SkPaint p;
|
||||
p.setImageFilter(imf);
|
||||
canvas->saveLayer(NULL, &p);
|
||||
@ -195,7 +192,7 @@ public:
|
||||
};
|
||||
|
||||
DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
|
||||
SkTRefArray<SkColorFilter*> filters;
|
||||
SkTArray<sk_sp<SkColorFilter>> filters;
|
||||
sk_gm_get_colorfilters(&filters);
|
||||
|
||||
SkTRefArray<SkShader*> shaders;
|
||||
@ -210,7 +207,7 @@ DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
|
||||
|
||||
canvas->save();
|
||||
for (int x = -1; x < filters.count(); ++x) {
|
||||
SkColorFilter* filter = x >= 0 ? filters[x] : nullptr;
|
||||
sk_sp<SkColorFilter> filter = x >= 0 ? filters[x] : nullptr;
|
||||
|
||||
paint.setShader(shader->makeWithColorFilter(filter));
|
||||
canvas->drawRect(r, paint);
|
||||
|
@ -30,7 +30,7 @@ static void install_nothing(SkPaint* paint, uint32_t, uint32_t) {
|
||||
}
|
||||
|
||||
static void install_lighting(SkPaint* paint, uint32_t mul, uint32_t add) {
|
||||
paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(mul, add))->unref();
|
||||
paint->setColorFilter(SkColorMatrixFilter::MakeLightingFilter(mul, add));
|
||||
}
|
||||
|
||||
class ColorFiltersGM : public skiagm::GM {
|
||||
|
@ -14,11 +14,11 @@
|
||||
#define HEIGHT 500
|
||||
|
||||
static void set_color_matrix(SkPaint* paint, const SkColorMatrix& matrix) {
|
||||
paint->setColorFilter(SkColorMatrixFilter::Create(matrix))->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat));
|
||||
}
|
||||
|
||||
static void set_array(SkPaint* paint, const SkScalar array[]) {
|
||||
paint->setColorFilter(SkColorMatrixFilter::Create(array))->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(array));
|
||||
}
|
||||
|
||||
class ColorMatrixGM : public skiagm::GM {
|
||||
|
@ -93,8 +93,7 @@ protected:
|
||||
draw_bitmap, draw_path, draw_paint, draw_text
|
||||
};
|
||||
|
||||
SkAutoTUnref<SkColorFilter> cf(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
|
||||
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
|
||||
SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
|
||||
SkImageFilter::CropRect::kHasAll_CropEdge);
|
||||
|
@ -49,7 +49,7 @@ protected:
|
||||
|
||||
// this combination of emboss+colorfilter used to crash -- so we exercise it to
|
||||
// confirm that we have a fix.
|
||||
paint.setColorFilter(SkColorFilter::CreateModeFilter(0xFFFF0000, SkXfermode::kSrcATop_Mode))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(0xFFFF0000, SkXfermode::kSrcATop_Mode));
|
||||
canvas->translate(bm.width() + SkIntToScalar(10), 0);
|
||||
canvas->drawBitmap(bm, 10, 10, &paint);
|
||||
}
|
||||
|
@ -15,10 +15,8 @@ DEF_SIMPLE_GM(fadefilter, canvas, 256, 256) {
|
||||
0, 1, 0, 0, 128.0f,
|
||||
0, 0, 1, 0, 128.0f,
|
||||
0, 0, 0, 1, 0 };
|
||||
SkAutoTUnref<SkColorFilter> colorFilter(
|
||||
SkColorMatrixFilter::Create(matrix));
|
||||
SkAutoTUnref<SkImageFilter> filter(
|
||||
SkColorFilterImageFilter::Create(colorFilter));
|
||||
auto colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(colorFilter.get()));
|
||||
SkPaint layerPaint;
|
||||
layerPaint.setImageFilter(filter);
|
||||
canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint);
|
||||
|
@ -140,7 +140,7 @@ static void draw_set(SkCanvas* canvas, SkImageFilter* filters[], int count) {
|
||||
DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
|
||||
SkColorMatrix cm;
|
||||
cm.setSaturation(10);
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(cm));
|
||||
auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
const SkScalar kernel[] = { 4, 0, 4, 0, -15, 0, 4, 0, 4 };
|
||||
SkImageFilter* filters[] = {
|
||||
SkBlurImageFilter::Create(10, 10),
|
||||
@ -148,7 +148,7 @@ DEF_SIMPLE_GM(savelayer_with_backdrop, canvas, 830, 550) {
|
||||
SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
|
||||
SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
|
||||
true),
|
||||
SkColorFilterImageFilter::Create(cf),
|
||||
SkColorFilterImageFilter::Create(cf.get()),
|
||||
};
|
||||
|
||||
const struct {
|
||||
|
@ -192,18 +192,16 @@ protected:
|
||||
draw_bitmap,
|
||||
};
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorRED,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode);
|
||||
SkImageFilter* filters[] = {
|
||||
nullptr,
|
||||
IdentityImageFilter::Create(),
|
||||
FailImageFilter::Create(),
|
||||
SkColorFilterImageFilter::Create(cf),
|
||||
SkColorFilterImageFilter::Create(cf.get()),
|
||||
SkBlurImageFilter::Create(12.0f, 0.0f),
|
||||
SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
|
||||
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
|
||||
};
|
||||
cf->unref();
|
||||
|
||||
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
|
||||
SkScalar MARGIN = SkIntToScalar(16);
|
||||
@ -320,7 +318,7 @@ public:
|
||||
ImageFiltersText_CF() : ImageFiltersTextBaseGM("color") {}
|
||||
|
||||
void installFilter(SkPaint* paint) override {
|
||||
paint->setColorFilter(SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode))->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
}
|
||||
};
|
||||
DEF_GM( return new ImageFiltersText_CF; )
|
||||
|
@ -40,8 +40,6 @@ protected:
|
||||
SkISize onISize() override { return SkISize::Make(730, 650); }
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
SkAutoTUnref<SkColorFilter> cf(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
SkImageFilter::CropRect cropRect(
|
||||
SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)),
|
||||
SkImageFilter::CropRect::kHasAll_CropEdge);
|
||||
@ -59,7 +57,7 @@ protected:
|
||||
0, 1, 0, 0, sk255,
|
||||
0, 0, 1, 0, 0,
|
||||
0, 0, 0, 0, sk255 };
|
||||
SkAutoTUnref<SkColorFilter> cfAlphaTrans(SkColorMatrixFilter::Create(matrix));
|
||||
auto cfAlphaTrans(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
|
||||
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
|
||||
SkScalar MARGIN = SkIntToScalar(12);
|
||||
@ -80,7 +78,7 @@ protected:
|
||||
SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
|
||||
|
||||
Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Create(
|
||||
cfAlphaTrans, noopCropped.get(), &bigRect));
|
||||
cfAlphaTrans.get(), noopCropped.get(), &bigRect));
|
||||
|
||||
Draw(canvas, checkerboard, rect, SkBlurImageFilter::Create(
|
||||
0.3f, 0.3f, noopCropped.get(), &bigRect));
|
||||
|
@ -115,8 +115,7 @@ protected:
|
||||
draw_bitmap, draw_path, draw_paint, draw_text
|
||||
};
|
||||
|
||||
SkAutoTUnref<SkColorFilter> cf(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
SkImageFilter::CropRect cropRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 44, 44)), SkImageFilter::CropRect::kHasAll_CropEdge);
|
||||
SkImageFilter::CropRect bogusRect(SkRect::Make(SkIRect::MakeXYWH(-100, -100, 10, 10)), SkImageFilter::CropRect::kHasAll_CropEdge);
|
||||
|
||||
|
@ -119,11 +119,10 @@ protected:
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
{
|
||||
SkAutoTUnref<SkImageFilter> bitmapSource(SkImageSource::Create(fImage.get()));
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
|
||||
SkAutoTUnref<SkImageFilter> blur(SkBlurImageFilter::Create(4.0f, 4.0f, bitmapSource));
|
||||
SkAutoTUnref<SkImageFilter> erode(SkErodeImageFilter::Create(4, 4, blur));
|
||||
SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(cf, erode));
|
||||
SkAutoTUnref<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode));
|
||||
SkAutoTUnref<SkImageFilter> merge(SkMergeImageFilter::Create(blur, color));
|
||||
|
||||
SkPaint paint;
|
||||
@ -139,8 +138,8 @@ protected:
|
||||
0, 0, SK_Scalar1, 0, 0,
|
||||
0, 0, 0, 0.5f, 0 };
|
||||
|
||||
SkAutoTUnref<SkColorFilter> matrixFilter(SkColorMatrixFilter::Create(matrix));
|
||||
SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter, morph));
|
||||
auto matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
SkAutoTUnref<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(), morph));
|
||||
SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
|
||||
SkAutoTUnref<SkImageFilter> blendColor(SkXfermodeImageFilter::Create(mode, colorMorph));
|
||||
|
||||
@ -154,8 +153,8 @@ protected:
|
||||
0, SK_Scalar1, 0, 0, 0,
|
||||
0, 0, SK_Scalar1, 0, 0,
|
||||
0, 0, 0, 0.5f, 0 };
|
||||
SkAutoTUnref<SkColorFilter> matrixCF(SkColorMatrixFilter::Create(matrix));
|
||||
SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF));
|
||||
auto matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
SkAutoTUnref<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
|
||||
SkAutoTUnref<SkImageFilter> offsetFilter(
|
||||
SimpleOffsetFilter::Create(10.0f, 10.f, matrixFilter));
|
||||
|
||||
@ -218,16 +217,14 @@ protected:
|
||||
}
|
||||
{
|
||||
// Test that crop offsets are absolute, not relative to the parent's crop rect.
|
||||
SkAutoTUnref<SkColorFilter> cf1(SkColorFilter::CreateModeFilter(SK_ColorBLUE,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
SkAutoTUnref<SkColorFilter> cf2(SkColorFilter::CreateModeFilter(SK_ColorGREEN,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
|
||||
SkImageFilter::CropRect outerRect(SkRect::MakeXYWH(SkIntToScalar(10), SkIntToScalar(10),
|
||||
SkIntToScalar(80), SkIntToScalar(80)));
|
||||
SkImageFilter::CropRect innerRect(SkRect::MakeXYWH(SkIntToScalar(20), SkIntToScalar(20),
|
||||
SkIntToScalar(60), SkIntToScalar(60)));
|
||||
SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1, nullptr, &outerRect));
|
||||
SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2, color1, &innerRect));
|
||||
SkAutoTUnref<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(), nullptr, &outerRect));
|
||||
SkAutoTUnref<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(), color1, &innerRect));
|
||||
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(color2);
|
||||
|
@ -26,7 +26,7 @@ static void draw_label(SkCanvas* canvas, const char* label,
|
||||
paint);
|
||||
}
|
||||
|
||||
static void draw_scene(SkCanvas* canvas, SkColorFilter* filter, SkXfermode::Mode mode,
|
||||
static void draw_scene(SkCanvas* canvas, const sk_sp<SkColorFilter>& filter, SkXfermode::Mode mode,
|
||||
const sk_sp<SkShader>& s1, const sk_sp<SkShader>& s2) {
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
@ -83,7 +83,7 @@ public:
|
||||
SkPoint g2Points[] = { { 0, 0 }, { kSize, 0 } };
|
||||
SkScalar pos[] = { 0.2f, 1.0f };
|
||||
|
||||
fFilter.reset(SkLumaColorFilter::Create());
|
||||
fFilter = SkLumaColorFilter::Make();
|
||||
fGr1 = SkGradientShader::MakeLinear(g1Points, g1Colors, pos, SK_ARRAY_COUNT(g1Colors),
|
||||
SkShader::kClamp_TileMode);
|
||||
fGr2 = SkGradientShader::MakeLinear(g2Points, g2Colors, pos, SK_ARRAY_COUNT(g2Colors),
|
||||
@ -137,7 +137,7 @@ protected:
|
||||
}
|
||||
|
||||
private:
|
||||
SkAutoTUnref<SkColorFilter> fFilter;
|
||||
sk_sp<SkColorFilter> fFilter;
|
||||
sk_sp<SkShader> fGr1, fGr2;
|
||||
|
||||
typedef skiagm::GM INHERITED;
|
||||
|
@ -175,8 +175,7 @@ private:
|
||||
|
||||
paint->setMaskFilter(this->createBlur())->unref();
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcIn_Mode);
|
||||
paint->setColorFilter(cf)->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeModeFilter(color, SkXfermode::kSrcIn_Mode));
|
||||
|
||||
return looperBuilder.detach();
|
||||
}
|
||||
@ -222,8 +221,8 @@ private:
|
||||
|
||||
paint->setMaskFilter(this->createBlur())->unref();
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(gColors[i], SkXfermode::kSrcIn_Mode);
|
||||
paint->setColorFilter(cf)->unref();
|
||||
paint->setColorFilter(SkColorFilter::MakeModeFilter(gColors[i],
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
}
|
||||
|
||||
return looperBuilder.detach();
|
||||
|
@ -121,9 +121,7 @@ protected:
|
||||
static const int kRectsPerRow = SkMax32(this->getISize().fWidth / kRectWidth, 1);
|
||||
for (size_t cfm = 0; cfm < SK_ARRAY_COUNT(modes); ++cfm) {
|
||||
for (size_t cfc = 0; cfc < SK_ARRAY_COUNT(colors); ++cfc) {
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[cfc],
|
||||
modes[cfm]));
|
||||
paint.setColorFilter(cf);
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(colors[cfc], modes[cfm]));
|
||||
for (size_t s = 0; s < SK_ARRAY_COUNT(shaders); ++s) {
|
||||
paint.setShader(shaders[s]);
|
||||
bool hasShader = nullptr == paint.getShader();
|
||||
|
@ -420,7 +420,7 @@ static void tiled(SkCanvas* finalCanvas, SkMultiPictureDraw* mpd,
|
||||
step.fY = SkIntToScalar(y*kTileHeight);
|
||||
step.fPaint = new SkPaint;
|
||||
step.fPaint->setColorFilter(
|
||||
SkColorFilter::CreateModeFilter(colors[x][y], SkXfermode::kModulate_Mode))->unref();
|
||||
SkColorFilter::MakeModeFilter(colors[x][y], SkXfermode::kModulate_Mode));
|
||||
|
||||
step.fSurf = create_compat_surface(finalCanvas, kTileWidth, kTileHeight);
|
||||
|
||||
|
@ -22,26 +22,26 @@ static const int kDetectorGreenValue = 50;
|
||||
// kDetectorGreenValue and then the incorrect value is observable by some part of the drawing
|
||||
// pipeline, that pixel will remain empty.
|
||||
|
||||
static SkColorFilter* make_detector_color_filter() {
|
||||
static sk_sp<SkColorFilter> make_detector_color_filter() {
|
||||
uint8_t tableA[256] = { 0, };
|
||||
uint8_t tableR[256] = { 0, };
|
||||
uint8_t tableG[256] = { 0, };
|
||||
uint8_t tableB[256] = { 0, };
|
||||
tableA[255] = 255;
|
||||
tableG[kDetectorGreenValue] = 255;
|
||||
return SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
|
||||
return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
|
||||
}
|
||||
|
||||
// This detector detects that color filter phase of the pixel pipeline receives the correct value.
|
||||
static void install_detector_color_filter(SkPaint* drawPaint) {
|
||||
drawPaint->setColorFilter(make_detector_color_filter())->unref();
|
||||
drawPaint->setColorFilter(make_detector_color_filter());
|
||||
}
|
||||
|
||||
// This detector detects that image filter phase of the pixel pipeline receives the correct value.
|
||||
static void install_detector_image_filter(SkPaint* drawPaint) {
|
||||
SkAutoTUnref<SkColorFilter> colorFilter(make_detector_color_filter());
|
||||
auto colorFilter(make_detector_color_filter());
|
||||
SkImageFilter* imageFilter =
|
||||
SkColorFilterImageFilter::Create(colorFilter, drawPaint->getImageFilter());
|
||||
SkColorFilterImageFilter::Create(colorFilter.get(), drawPaint->getImageFilter());
|
||||
drawPaint->setImageFilter(imageFilter)->unref();
|
||||
}
|
||||
|
||||
|
@ -64,8 +64,7 @@ DEF_SIMPLE_GM_BG(skbug1719, canvas, 300, 100,
|
||||
SkBlurMaskFilter::Create(kNormal_SkBlurStyle,
|
||||
0.78867501f,
|
||||
SkBlurMaskFilter::kHighQuality_BlurFlag))->unref();
|
||||
paint.setColorFilter(
|
||||
SkColorFilter::CreateModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(0xBFFFFFFF, SkXfermode::kSrcIn_Mode));
|
||||
|
||||
canvas->clipPath(clipPath, SkRegion::kIntersect_Op, true);
|
||||
canvas->drawPath(drawPath, paint);
|
||||
|
@ -73,27 +73,27 @@ static void make_table2(uint8_t table[]) {
|
||||
}
|
||||
}
|
||||
|
||||
static SkColorFilter* make_null_cf() {
|
||||
static sk_sp<SkColorFilter> make_null_cf() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf0() {
|
||||
static sk_sp<SkColorFilter> make_cf0() {
|
||||
uint8_t table[256]; make_table0(table);
|
||||
return SkTableColorFilter::Create(table);
|
||||
return SkTableColorFilter::Make(table);
|
||||
}
|
||||
static SkColorFilter* make_cf1() {
|
||||
static sk_sp<SkColorFilter> make_cf1() {
|
||||
uint8_t table[256]; make_table1(table);
|
||||
return SkTableColorFilter::Create(table);
|
||||
return SkTableColorFilter::Make(table);
|
||||
}
|
||||
static SkColorFilter* make_cf2() {
|
||||
static sk_sp<SkColorFilter> make_cf2() {
|
||||
uint8_t table[256]; make_table2(table);
|
||||
return SkTableColorFilter::Create(table);
|
||||
return SkTableColorFilter::Make(table);
|
||||
}
|
||||
static SkColorFilter* make_cf3() {
|
||||
static sk_sp<SkColorFilter> make_cf3() {
|
||||
uint8_t table0[256]; make_table0(table0);
|
||||
uint8_t table1[256]; make_table1(table1);
|
||||
uint8_t table2[256]; make_table2(table2);
|
||||
return SkTableColorFilter::CreateARGB(nullptr, table0, table1, table2);
|
||||
return SkTableColorFilter::MakeARGB(nullptr, table0, table1, table2);
|
||||
}
|
||||
|
||||
class TableColorFilterGM : public skiagm::GM {
|
||||
@ -114,8 +114,9 @@ protected:
|
||||
canvas->translate(20, 20);
|
||||
|
||||
|
||||
static SkColorFilter* (*gColorFilterMakers[])() = { make_null_cf, make_cf0, make_cf1,
|
||||
make_cf2, make_cf3 };
|
||||
static sk_sp<SkColorFilter> (*gColorFilterMakers[])() = {
|
||||
make_null_cf, make_cf0, make_cf1, make_cf2, make_cf3
|
||||
};
|
||||
static void (*gBitmapMakers[])(SkBitmap*) = { make_bm0, make_bm1 };
|
||||
|
||||
// This test will be done once for each bitmap with the results stacked vertically.
|
||||
@ -155,25 +156,25 @@ protected:
|
||||
// each draw being at xOffset of the previous one
|
||||
for (unsigned i = 1; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
|
||||
x += xOffset;
|
||||
paint.setColorFilter(gColorFilterMakers[i]())->unref();
|
||||
paint.setColorFilter(gColorFilterMakers[i]());
|
||||
canvas->drawBitmap(bm, x, y, &paint);
|
||||
}
|
||||
|
||||
paint.setColorFilter(nullptr);
|
||||
|
||||
for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
|
||||
SkAutoTUnref<SkColorFilter> colorFilter1(gColorFilterMakers[i]());
|
||||
auto colorFilter1(gColorFilterMakers[i]());
|
||||
SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create(
|
||||
colorFilter1, nullptr, nullptr));
|
||||
colorFilter1.get(), nullptr, nullptr));
|
||||
|
||||
// Move down to the next line and draw it
|
||||
// each draw being at xOffset of the previous one
|
||||
y += yOffset;
|
||||
x = 0;
|
||||
for (unsigned j = 1; j < SK_ARRAY_COUNT(gColorFilterMakers); ++j) {
|
||||
SkAutoTUnref<SkColorFilter> colorFilter2(gColorFilterMakers[j]());
|
||||
auto colorFilter2(gColorFilterMakers[j]());
|
||||
SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Create(
|
||||
colorFilter2, imageFilter1, nullptr));
|
||||
colorFilter2.get(), imageFilter1, nullptr));
|
||||
paint.setImageFilter(imageFilter2);
|
||||
canvas->drawBitmap(bm, x, y, &paint);
|
||||
x += xOffset;
|
||||
@ -225,11 +226,11 @@ protected:
|
||||
canvas->drawColor(sk_tool_utils::color_to_565(0xFFDDDDDD));
|
||||
|
||||
const int MODES = MODE_COUNT * COLOR_COUNT;
|
||||
SkAutoTUnref<SkColorFilter> filters[MODES];
|
||||
sk_sp<SkColorFilter> filters[MODES];
|
||||
int index = 0;
|
||||
for (int i = 0; i < MODE_COUNT; ++i) {
|
||||
for (int j = 0; j < COLOR_COUNT; ++j) {
|
||||
filters[index++].reset(SkColorFilter::CreateModeFilter(fColors[j], fModes[i]));
|
||||
filters[index++] = SkColorFilter::MakeModeFilter(fColors[j], fModes[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -261,9 +262,7 @@ protected:
|
||||
for (int y = 0; y < MODES; ++y) {
|
||||
canvas->save();
|
||||
for (int x = 0; x < MODES; ++x) {
|
||||
SkAutoTUnref<SkColorFilter> compose(SkColorFilter::CreateComposeFilter(filters[y],
|
||||
filters[x]));
|
||||
paint.setColorFilter(compose);
|
||||
paint.setColorFilter(SkColorFilter::MakeComposeFilter(filters[y], filters[x]));
|
||||
canvas->drawRect(r, paint);
|
||||
canvas->translate(r.width() + spacer, 0);
|
||||
}
|
||||
|
@ -24,10 +24,8 @@
|
||||
static SkImageFilter* make0() { return SkDownSampleImageFilter::Create(SK_Scalar1 / 5); }
|
||||
static SkImageFilter* make1() { return SkOffsetImageFilter::Create(SkIntToScalar(16), SkIntToScalar(16)); }
|
||||
static SkImageFilter* make2() {
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(SK_ColorBLUE,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
SkAutoUnref aur(cf);
|
||||
return SkColorFilterImageFilter::Create(cf);
|
||||
auto cf = SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode);
|
||||
return SkColorFilterImageFilter::Create(cf.get());
|
||||
}
|
||||
static SkImageFilter* make3() {
|
||||
return SkBlurImageFilter::Create(8, 0);
|
||||
@ -56,10 +54,8 @@ static SkImageFilter* make6() {
|
||||
SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
|
||||
SkAutoUnref aur2(compose);
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
SkAutoUnref aur3(cf);
|
||||
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
|
||||
auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode);
|
||||
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get());
|
||||
SkAutoUnref aur4(blue);
|
||||
|
||||
return SkMergeImageFilter::Create(compose, blue);
|
||||
@ -73,10 +69,8 @@ static SkImageFilter* make7() {
|
||||
SkImageFilter* compose = SkComposeImageFilter::Create(outer, inner);
|
||||
SkAutoUnref aur2(compose);
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(0x880000FF,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
SkAutoUnref aur3(cf);
|
||||
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf);
|
||||
auto cf = SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode);
|
||||
SkImageFilter* blue = SkColorFilterImageFilter::Create(cf.get());
|
||||
SkAutoUnref aur4(blue);
|
||||
|
||||
return SkMergeImageFilter::Create(compose, blue);
|
||||
|
@ -97,7 +97,7 @@ static void color_filter(SkPaint* paint) {
|
||||
SkRect r;
|
||||
r.setWH(SkIntToScalar(kWidth), 50);
|
||||
paint->setShader(make_shader(r));
|
||||
paint->setColorFilter(SkColorMatrixFilter::CreateLightingFilter(0xF0F0F0, 0))->unref();
|
||||
paint->setColorFilter(SkColorMatrixFilter::MakeLightingFilter(0xF0F0F0, 0));
|
||||
}
|
||||
|
||||
static void kitchen_sink(SkPaint* paint) {
|
||||
|
@ -93,9 +93,9 @@ protected:
|
||||
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
|
||||
SkIntToScalar(fBitmap->height() * 2));
|
||||
SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorMatrixFilter::Create(matrix));
|
||||
auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
|
||||
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf, tile.get()));
|
||||
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get()));
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(cfif);
|
||||
canvas->save();
|
||||
|
@ -26,8 +26,8 @@ static sk_sp<SkShader> make_shader2() {
|
||||
return SkShader::MakeColorShader(SK_ColorBLUE);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_color_filter() {
|
||||
return SkColorFilter::CreateModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
|
||||
static sk_sp<SkColorFilter> make_color_filter() {
|
||||
return SkColorFilter::MakeModeFilter(0xFFAABBCC, SkXfermode::kDarken_Mode);
|
||||
}
|
||||
|
||||
class VerticesGM : public skiagm::GM {
|
||||
@ -36,7 +36,7 @@ class VerticesGM : public skiagm::GM {
|
||||
SkColor fColors[9];
|
||||
sk_sp<SkShader> fShader1;
|
||||
sk_sp<SkShader> fShader2;
|
||||
SkAutoTUnref<SkColorFilter> fColorFilter;
|
||||
sk_sp<SkColorFilter> fColorFilter;
|
||||
|
||||
public:
|
||||
VerticesGM() {}
|
||||
@ -60,7 +60,7 @@ protected:
|
||||
|
||||
fShader1 = make_shader1(w, h);
|
||||
fShader2 = make_shader2();
|
||||
fColorFilter.reset(make_color_filter());
|
||||
fColorFilter = make_color_filter();
|
||||
|
||||
SkRandom rand;
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(fColors); ++i) {
|
||||
@ -88,7 +88,7 @@ protected:
|
||||
const SkColor* fColors;
|
||||
const SkPoint* fTexs;
|
||||
const sk_sp<SkShader>& fShader;
|
||||
SkColorFilter* fColorFilter;
|
||||
const sk_sp<SkColorFilter>& fColorFilter;
|
||||
uint8_t fAlpha;
|
||||
} rec[] = {
|
||||
{ fColors, nullptr, fShader1, nullptr , 0xFF },
|
||||
|
@ -16,6 +16,7 @@
|
||||
'SK_SUPPORT_LEGACY_UNBALANCED_PIXELREF_LOCKCOUNT',
|
||||
# Needed until we fix https://bug.skia.org/2440 .
|
||||
'SK_SUPPORT_LEGACY_CLIPTOLAYERFLAG',
|
||||
'SK_SUPPORT_LEGACY_COLORFILTER_PTR',
|
||||
'SK_IGNORE_LINEONLY_AA_CONVEX_PATH_OPTS',
|
||||
'SK_SUPPORT_LEGACY_MINOR_EFFECT_PTR',
|
||||
'SK_SUPPORT_LEGACY_GRADIENT_DITHERING',
|
||||
|
@ -86,7 +86,7 @@ public:
|
||||
*
|
||||
* e.g. result(color) == this_filter(inner(color))
|
||||
*/
|
||||
virtual SkColorFilter* newComposed(const SkColorFilter* /*inner*/) const { return NULL; }
|
||||
virtual sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const { return nullptr; }
|
||||
|
||||
/**
|
||||
* Apply this colorfilter to the specified SkColor. This routine handles
|
||||
@ -110,7 +110,7 @@ public:
|
||||
@return colorfilter object that applies the src color and mode,
|
||||
or NULL if the mode will have no effect.
|
||||
*/
|
||||
static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode);
|
||||
static sk_sp<SkColorFilter> MakeModeFilter(SkColor c, SkXfermode::Mode mode);
|
||||
|
||||
/** Construct a colorfilter whose effect is to first apply the inner filter and then apply
|
||||
* the outer filter to the result of the inner's.
|
||||
@ -119,12 +119,28 @@ public:
|
||||
* Due to internal limits, it is possible that this will return NULL, so the caller must
|
||||
* always check.
|
||||
*/
|
||||
static SkColorFilter* CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner);
|
||||
static sk_sp<SkColorFilter> MakeComposeFilter(sk_sp<SkColorFilter> outer,
|
||||
sk_sp<SkColorFilter> inner);
|
||||
|
||||
/** Construct a color filter that transforms a color by a 4x5 matrix. The matrix is in row-
|
||||
* major order and the translation column is specified in unnormalized, 0...255, space.
|
||||
*/
|
||||
static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]);
|
||||
static sk_sp<SkColorFilter> MakeMatrixFilterRowMajor255(const SkScalar array[20]);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* CreateModeFilter(SkColor c, SkXfermode::Mode mode) {
|
||||
return MakeModeFilter(c, mode).release();
|
||||
}
|
||||
static SkColorFilter* CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
|
||||
return MakeComposeFilter(sk_ref_sp(outer), sk_ref_sp(inner)).release();
|
||||
}
|
||||
static SkColorFilter* CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
|
||||
return MakeMatrixFilterRowMajor255(array).release();
|
||||
}
|
||||
virtual SkColorFilter* newComposed(const SkColorFilter* inner) const {
|
||||
return this->makeComposed(sk_ref_sp(const_cast<SkColorFilter*>(inner))).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A subclass may implement this factory function to work with the GPU backend. It returns
|
||||
|
@ -515,7 +515,9 @@ public:
|
||||
@param filter May be NULL. The filter to be installed in the paint
|
||||
@return filter
|
||||
*/
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
SkColorFilter* setColorFilter(SkColorFilter* filter);
|
||||
#endif
|
||||
void setColorFilter(sk_sp<SkColorFilter>);
|
||||
|
||||
/** Get the paint's xfermode object.
|
||||
|
@ -359,7 +359,7 @@ public:
|
||||
* Create a new shader that produces the same colors as invoking this shader and then applying
|
||||
* the colorfilter.
|
||||
*/
|
||||
sk_sp<SkShader> makeWithColorFilter(SkColorFilter*) const;
|
||||
sk_sp<SkShader> makeWithColorFilter(sk_sp<SkColorFilter>) const;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// Factory methods for stock shaders
|
||||
@ -393,9 +393,7 @@ public:
|
||||
SkShader* newWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
return this->makeWithLocalMatrix(matrix).release();
|
||||
}
|
||||
SkShader* newWithColorFilter(SkColorFilter* filter) const {
|
||||
return this->makeWithColorFilter(filter).release();
|
||||
}
|
||||
SkShader* newWithColorFilter(SkColorFilter* filter) const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
|
@ -65,7 +65,7 @@ protected:
|
||||
|
||||
private:
|
||||
SkMaskFilter* fBlur;
|
||||
SkColorFilter* fColorFilter;
|
||||
sk_sp<SkColorFilter> fColorFilter;
|
||||
SkScalar fDx, fDy, fSigma;
|
||||
SkColor fBlurColor;
|
||||
uint32_t fBlurFlags;
|
||||
|
@ -20,7 +20,11 @@ public:
|
||||
* This cube contains a transform where (x,y,z) maps to the (r,g,b).
|
||||
* The alpha components of the colors must be 0xFF.
|
||||
*/
|
||||
static sk_sp<SkColorFilter> Make(sk_sp<SkData> cubeData, int cubeDimension);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
uint32_t getFlags() const override;
|
||||
@ -33,7 +37,7 @@ public:
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
|
||||
|
||||
protected:
|
||||
SkColorCubeFilter(SkData* cubeData, int cubeDimension);
|
||||
SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension);
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
private:
|
||||
|
@ -31,9 +31,8 @@ private:
|
||||
SkColorFilterImageFilter(SkColorFilter* cf,
|
||||
SkImageFilter* input,
|
||||
const CropRect* cropRect);
|
||||
virtual ~SkColorFilterImageFilter();
|
||||
|
||||
SkColorFilter* fColorFilter;
|
||||
sk_sp<SkColorFilter> fColorFilter;
|
||||
|
||||
typedef SkImageFilter INHERITED;
|
||||
};
|
||||
|
@ -13,20 +13,25 @@
|
||||
|
||||
class SK_API SkColorMatrixFilter : public SkColorFilter {
|
||||
public:
|
||||
static SkColorFilter* Create(const SkColorMatrix& cm) {
|
||||
return SkColorFilter::CreateMatrixFilterRowMajor255(cm.fMat);
|
||||
}
|
||||
static SkColorFilter* Create(const SkScalar array[20]) {
|
||||
return SkColorFilter::CreateMatrixFilterRowMajor255(array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a colorfilter that multiplies the RGB channels by one color, and
|
||||
* then adds a second color, pinning the result for each component to
|
||||
* [0..255]. The alpha components of the mul and add arguments
|
||||
* are ignored.
|
||||
*/
|
||||
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add);
|
||||
static sk_sp<SkColorFilter> MakeLightingFilter(SkColor mul, SkColor add);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(const SkColorMatrix& cm) {
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat).release();
|
||||
}
|
||||
static SkColorFilter* Create(const SkScalar array[20]) {
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(array).release();
|
||||
}
|
||||
static SkColorFilter* CreateLightingFilter(SkColor mul, SkColor add) {
|
||||
return MakeLightingFilter(mul, add).release();
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,11 @@
|
||||
*/
|
||||
class SK_API SkLumaColorFilter : public SkColorFilter {
|
||||
public:
|
||||
static SkColorFilter* Create();
|
||||
static sk_sp<SkColorFilter> Make();
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create() { return Make().release(); }
|
||||
#endif
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
|
||||
|
@ -23,7 +23,7 @@ public:
|
||||
* colors are premultiplied, they are temporarily unpremultiplied, then
|
||||
* the table is applied, and then the result is remultiplied.
|
||||
*/
|
||||
static SkColorFilter* Create(const uint8_t table[256]);
|
||||
static sk_sp<SkColorFilter> Make(const uint8_t table[256]);
|
||||
|
||||
/**
|
||||
* Create a table colorfilter, with a different table for each
|
||||
@ -31,11 +31,23 @@ public:
|
||||
* treated as identity, with the component left unchanged. If a table
|
||||
* is not null, then its contents are copied into the filter.
|
||||
*/
|
||||
static SkColorFilter* CreateARGB(const uint8_t tableA[256],
|
||||
static sk_sp<SkColorFilter> MakeARGB(const uint8_t tableA[256],
|
||||
const uint8_t tableR[256],
|
||||
const uint8_t tableG[256],
|
||||
const uint8_t tableB[256]);
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(const uint8_t table[256]) {
|
||||
return Make(table).release();
|
||||
}
|
||||
static SkColorFilter* CreateARGB(const uint8_t tableA[256],
|
||||
const uint8_t tableR[256],
|
||||
const uint8_t tableG[256],
|
||||
const uint8_t tableB[256]) {
|
||||
return MakeARGB(tableA, tableR, tableG, tableB).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
|
||||
};
|
||||
|
||||
|
@ -501,7 +501,6 @@ DEFINES_UNIX = [
|
||||
"SK_CODEC_DECODES_PNG",
|
||||
"SK_CODEC_DECODES_RAW",
|
||||
"SK_CODEC_DECODES_WEBP",
|
||||
"SK_SUPPORT_LEGACY_CREATESHADER_PTR",
|
||||
]
|
||||
|
||||
DEFINES_ANDROID = [
|
||||
@ -527,6 +526,9 @@ DEFINES_ALL = [
|
||||
"SK_SUPPORT_LEGACY_PATHEFFECT_PTR",
|
||||
# Turn on a few Google3-specific build fixes.
|
||||
"GOOGLE3",
|
||||
# Staging flags for API changes
|
||||
"SK_SUPPORT_LEGACY_COLORFILTER_PTR",
|
||||
"SK_SUPPORT_LEGACY_CREATESHADER_PTR",
|
||||
]
|
||||
|
||||
################################################################################
|
||||
|
@ -384,7 +384,7 @@ protected:
|
||||
SkMaskFilter* embossFilter = SkEmbossMaskFilter::Create(sigma, light);
|
||||
|
||||
SkXfermode* xfermode = SkXfermode::Create(SkXfermode::kXor_Mode);
|
||||
SkColorFilter* lightingFilter = SkColorMatrixFilter::CreateLightingFilter(
|
||||
auto lightingFilter = SkColorMatrixFilter::MakeLightingFilter(
|
||||
0xff89bc45, 0xff112233);
|
||||
|
||||
canvas->save();
|
||||
@ -406,7 +406,7 @@ protected:
|
||||
paint.setStrokeWidth(SkIntToScalar(10));
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
paint.setXfermode(xfermode)->unref();
|
||||
paint.setColorFilter(lightingFilter)->unref();
|
||||
paint.setColorFilter(lightingFilter);
|
||||
canvas->drawLine(start.fX, start.fY, stop.fX, stop.fY, paint); // should not be green
|
||||
paint.setXfermode(nullptr);
|
||||
paint.setColorFilter(nullptr);
|
||||
@ -543,9 +543,9 @@ protected:
|
||||
|
||||
#if 01
|
||||
int index = i % SK_ARRAY_COUNT(gLightingColors);
|
||||
paint.setColorFilter(SkColorMatrixFilter::CreateLightingFilter(
|
||||
paint.setColorFilter(SkColorMatrixFilter::MakeLightingFilter(
|
||||
gLightingColors[index].fMul,
|
||||
gLightingColors[index].fAdd))->unref();
|
||||
gLightingColors[index].fAdd));
|
||||
#endif
|
||||
|
||||
canvas->drawText(str.c_str(), str.size(), x, y, paint);
|
||||
|
@ -184,8 +184,7 @@ protected:
|
||||
|
||||
for (size_t y = 0; y < SK_ARRAY_COUNT(gColors); y++) {
|
||||
for (size_t x = 0; x < SK_ARRAY_COUNT(gModes); x++) {
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(gColors[y], gModes[x]);
|
||||
SkSafeUnref(paint.setColorFilter(cf));
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(gColors[y], gModes[x]));
|
||||
canvas->drawBitmap(fBitmap, x * N * 1.25f, y * N * scale, &paint);
|
||||
}
|
||||
}
|
||||
|
@ -298,9 +298,9 @@ static const SkBitmap& make_bitmap() {
|
||||
return bitmap[R(2)];
|
||||
}
|
||||
|
||||
static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
|
||||
static sk_sp<SkData> make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
|
||||
int size = 4 << R(5);
|
||||
SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size);
|
||||
auto data = SkData::MakeUninitialized(sizeof(SkColor) * size * size * size);
|
||||
SkColor* pixels = (SkColor*)(data->writable_data());
|
||||
SkAutoTMalloc<uint8_t> lutMemory(size);
|
||||
SkAutoTMalloc<uint8_t> invLutMemory(size);
|
||||
@ -350,20 +350,17 @@ static void rand_color_table(uint8_t* table) {
|
||||
}
|
||||
}
|
||||
|
||||
static SkColorFilter* make_color_filter() {
|
||||
SkColorFilter* colorFilter;
|
||||
static sk_sp<SkColorFilter> make_color_filter() {
|
||||
switch (R(6)) {
|
||||
case 0: {
|
||||
SkScalar array[20];
|
||||
for (int i = 0; i < 20; ++i) {
|
||||
array[i] = make_scalar();
|
||||
}
|
||||
colorFilter = SkColorMatrixFilter::Create(array);
|
||||
break;
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(array);
|
||||
}
|
||||
case 1:
|
||||
colorFilter = SkLumaColorFilter::Create();
|
||||
break;
|
||||
return SkLumaColorFilter::Make();
|
||||
case 2: {
|
||||
uint8_t tableA[256];
|
||||
uint8_t tableR[256];
|
||||
@ -373,21 +370,17 @@ static SkColorFilter* make_color_filter() {
|
||||
rand_color_table(tableR);
|
||||
rand_color_table(tableG);
|
||||
rand_color_table(tableB);
|
||||
colorFilter = SkTableColorFilter::CreateARGB(tableA, tableR, tableG, tableB);
|
||||
break;
|
||||
return SkTableColorFilter::MakeARGB(tableA, tableR, tableG, tableB);
|
||||
}
|
||||
case 3:
|
||||
colorFilter = SkColorFilter::CreateModeFilter(make_color(), make_xfermode());
|
||||
break;
|
||||
return SkColorFilter::MakeModeFilter(make_color(), make_xfermode());
|
||||
case 4:
|
||||
colorFilter = SkColorMatrixFilter::CreateLightingFilter(make_color(), make_color());
|
||||
break;
|
||||
return SkColorMatrixFilter::MakeLightingFilter(make_color(), make_color());
|
||||
case 5:
|
||||
default:
|
||||
colorFilter = nullptr;
|
||||
break;
|
||||
}
|
||||
return colorFilter;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static SkPath make_path() {
|
||||
@ -538,7 +531,7 @@ static SkPaint make_paint() {
|
||||
rasterizerBuilder.addLayer(paintForRasterizer);
|
||||
paint.setRasterizer(rasterizerBuilder.detach());
|
||||
paint.setImageFilter(make_image_filter());
|
||||
SkAutoDataUnref data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
|
||||
sk_sp<SkData> data(make_3Dlut(nullptr, make_bool(), make_bool(), make_bool()));
|
||||
paint.setTextAlign(make_paint_align());
|
||||
paint.setTextSize(make_scalar());
|
||||
paint.setTextScaleX(make_scalar());
|
||||
@ -567,16 +560,16 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
break;
|
||||
case COLOR:
|
||||
{
|
||||
SkAutoTUnref<SkColorFilter> cf(make_color_filter());
|
||||
filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0;
|
||||
sk_sp<SkColorFilter> cf(make_color_filter());
|
||||
filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
|
||||
}
|
||||
break;
|
||||
case LUT3D:
|
||||
{
|
||||
int cubeDimension;
|
||||
SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDimension));
|
||||
filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0;
|
||||
sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
|
||||
sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
|
||||
filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
|
||||
}
|
||||
break;
|
||||
case BLUR:
|
||||
|
@ -844,7 +844,8 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
|
||||
if (SkXfermode::IsMode(mode, SkXfermode::kClear_Mode)) {
|
||||
SkPaint* p = paint.writable();
|
||||
shader = p->setShader(nullptr);
|
||||
cf = p->setColorFilter(nullptr);
|
||||
p->setColorFilter(nullptr);
|
||||
cf = nullptr;
|
||||
mode = p->setXfermodeMode(SkXfermode::kSrc_Mode);
|
||||
p->setColor(0);
|
||||
}
|
||||
@ -867,7 +868,7 @@ SkBlitter* SkBlitter::Choose(const SkPixmap& device,
|
||||
|
||||
if (cf) {
|
||||
SkASSERT(shader);
|
||||
paint.writable()->setShader(shader->makeWithColorFilter(cf));
|
||||
paint.writable()->setShader(shader->makeWithColorFilter(sk_ref_sp(cf)));
|
||||
shader = paint->getShader();
|
||||
// blitters should ignore the presence/absence of a filter, since
|
||||
// if there is one, the shader will take care of it.
|
||||
|
@ -391,16 +391,17 @@ static SkPaint* set_if_needed(SkLazyPaint* lazy, const SkPaint& orig) {
|
||||
* If the paint has an imagefilter, but it can be simplified to just a colorfilter, return that
|
||||
* colorfilter, else return nullptr.
|
||||
*/
|
||||
static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
|
||||
static sk_sp<SkColorFilter> image_to_color_filter(const SkPaint& paint) {
|
||||
SkImageFilter* imgf = paint.getImageFilter();
|
||||
if (!imgf) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SkColorFilter* imgCF;
|
||||
if (!imgf->asAColorFilter(&imgCF)) {
|
||||
SkColorFilter* imgCFPtr;
|
||||
if (!imgf->asAColorFilter(&imgCFPtr)) {
|
||||
return nullptr;
|
||||
}
|
||||
sk_sp<SkColorFilter> imgCF(imgCFPtr);
|
||||
|
||||
SkColorFilter* paintCF = paint.getColorFilter();
|
||||
if (nullptr == paintCF) {
|
||||
@ -410,8 +411,7 @@ static SkColorFilter* image_to_color_filter(const SkPaint& paint) {
|
||||
|
||||
// The paint has both a colorfilter(paintCF) and an imagefilter-which-is-a-colorfilter(imgCF)
|
||||
// and we need to combine them into a single colorfilter.
|
||||
SkAutoTUnref<SkColorFilter> autoImgCF(imgCF);
|
||||
return SkColorFilter::CreateComposeFilter(imgCF, paintCF);
|
||||
return SkColorFilter::MakeComposeFilter(std::move(imgCF), sk_ref_sp(paintCF));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -455,10 +455,10 @@ public:
|
||||
fTempLayerForImageFilter = false;
|
||||
fDone = false;
|
||||
|
||||
SkColorFilter* simplifiedCF = image_to_color_filter(fOrigPaint);
|
||||
auto simplifiedCF = image_to_color_filter(fOrigPaint);
|
||||
if (simplifiedCF) {
|
||||
SkPaint* paint = set_if_needed(&fLazyPaintInit, fOrigPaint);
|
||||
paint->setColorFilter(simplifiedCF)->unref();
|
||||
paint->setColorFilter(std::move(simplifiedCF));
|
||||
paint->setImageFilter(nullptr);
|
||||
fPaint = paint;
|
||||
}
|
||||
|
@ -114,14 +114,15 @@ public:
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer& buffer) const override {
|
||||
buffer.writeFlattenable(fOuter);
|
||||
buffer.writeFlattenable(fInner);
|
||||
buffer.writeFlattenable(fOuter.get());
|
||||
buffer.writeFlattenable(fInner.get());
|
||||
}
|
||||
|
||||
private:
|
||||
SkComposeColorFilter(SkColorFilter* outer, SkColorFilter* inner, int composedFilterCount)
|
||||
: fOuter(SkRef(outer))
|
||||
, fInner(SkRef(inner))
|
||||
SkComposeColorFilter(sk_sp<SkColorFilter> outer, sk_sp<SkColorFilter> inner,
|
||||
int composedFilterCount)
|
||||
: fOuter(std::move(outer))
|
||||
, fInner(std::move(inner))
|
||||
, fComposedFilterCount(composedFilterCount)
|
||||
{
|
||||
SkASSERT(composedFilterCount >= 2);
|
||||
@ -132,8 +133,8 @@ private:
|
||||
return fComposedFilterCount;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkColorFilter> fOuter;
|
||||
SkAutoTUnref<SkColorFilter> fInner;
|
||||
sk_sp<SkColorFilter> fOuter;
|
||||
sk_sp<SkColorFilter> fInner;
|
||||
const int fComposedFilterCount;
|
||||
|
||||
friend class SkColorFilter;
|
||||
@ -142,23 +143,24 @@ private:
|
||||
};
|
||||
|
||||
SkFlattenable* SkComposeColorFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkAutoTUnref<SkColorFilter> outer(buffer.readColorFilter());
|
||||
SkAutoTUnref<SkColorFilter> inner(buffer.readColorFilter());
|
||||
return CreateComposeFilter(outer, inner);
|
||||
sk_sp<SkColorFilter> outer(buffer.readColorFilter());
|
||||
sk_sp<SkColorFilter> inner(buffer.readColorFilter());
|
||||
return MakeComposeFilter(std::move(outer), std::move(inner)).release();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorFilter* inner) {
|
||||
sk_sp<SkColorFilter> SkColorFilter::MakeComposeFilter(sk_sp<SkColorFilter> outer,
|
||||
sk_sp<SkColorFilter> inner) {
|
||||
if (!outer) {
|
||||
return SkSafeRef(inner);
|
||||
return inner;
|
||||
}
|
||||
if (!inner) {
|
||||
return SkSafeRef(outer);
|
||||
return outer;
|
||||
}
|
||||
|
||||
// Give the subclass a shot at a more optimal composition...
|
||||
SkColorFilter* composition = outer->newComposed(inner);
|
||||
auto composition = outer->makeComposed(inner);
|
||||
if (composition) {
|
||||
return composition;
|
||||
}
|
||||
@ -167,7 +169,7 @@ SkColorFilter* SkColorFilter::CreateComposeFilter(SkColorFilter* outer, SkColorF
|
||||
if (count > SK_MAX_COMPOSE_COLORFILTER_COUNT) {
|
||||
return nullptr;
|
||||
}
|
||||
return new SkComposeColorFilter(outer, inner, count);
|
||||
return sk_sp<SkColorFilter>(new SkComposeColorFilter(std::move(outer), std::move(inner),count));
|
||||
}
|
||||
|
||||
#include "SkModeColorFilter.h"
|
||||
|
@ -15,26 +15,26 @@
|
||||
#include "GrFragmentProcessor.h"
|
||||
#endif
|
||||
|
||||
SkColorFilterShader::SkColorFilterShader(SkShader* shader, SkColorFilter* filter)
|
||||
: fShader(SkRef(shader))
|
||||
, fFilter(SkRef(filter))
|
||||
SkColorFilterShader::SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter)
|
||||
: fShader(std::move(shader))
|
||||
, fFilter(std::move(filter))
|
||||
{
|
||||
SkASSERT(shader);
|
||||
SkASSERT(filter);
|
||||
SkASSERT(fShader);
|
||||
SkASSERT(fFilter);
|
||||
}
|
||||
|
||||
SkFlattenable* SkColorFilterShader::CreateProc(SkReadBuffer& buffer) {
|
||||
auto shader = buffer.readShader();
|
||||
SkAutoTUnref<SkColorFilter> filter(buffer.readColorFilter());
|
||||
if (!shader || !filter.get()) {
|
||||
auto filter = buffer.readColorFilter();
|
||||
if (!shader || !filter) {
|
||||
return nullptr;
|
||||
}
|
||||
return new SkColorFilterShader(shader.get(), filter);
|
||||
return new SkColorFilterShader(shader, filter);
|
||||
}
|
||||
|
||||
void SkColorFilterShader::flatten(SkWriteBuffer& buffer) const {
|
||||
buffer.writeFlattenable(fShader);
|
||||
buffer.writeFlattenable(fFilter);
|
||||
buffer.writeFlattenable(fShader.get());
|
||||
buffer.writeFlattenable(fFilter.get());
|
||||
}
|
||||
|
||||
uint32_t SkColorFilterShader::FilterShaderContext::getFlags() const {
|
||||
@ -137,10 +137,10 @@ void SkColorFilterShader::toString(SkString* str) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
sk_sp<SkShader> SkShader::makeWithColorFilter(SkColorFilter* filter) const {
|
||||
sk_sp<SkShader> SkShader::makeWithColorFilter(sk_sp<SkColorFilter> filter) const {
|
||||
SkShader* base = const_cast<SkShader*>(this);
|
||||
if (!filter) {
|
||||
return sk_ref_sp(base);
|
||||
}
|
||||
return sk_make_sp<SkColorFilterShader>(base, filter);
|
||||
return sk_make_sp<SkColorFilterShader>(sk_ref_sp(base), filter);
|
||||
}
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
class SkColorFilterShader : public SkShader {
|
||||
public:
|
||||
SkColorFilterShader(SkShader* shader, SkColorFilter* filter);
|
||||
SkColorFilterShader(sk_sp<SkShader> shader, sk_sp<SkColorFilter> filter);
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
const GrFragmentProcessor* asFragmentProcessor(GrContext*,
|
||||
@ -53,8 +53,8 @@ protected:
|
||||
Context* onCreateContext(const ContextRec&, void* storage) const override;
|
||||
|
||||
private:
|
||||
SkAutoTUnref<SkShader> fShader;
|
||||
SkAutoTUnref<SkColorFilter> fFilter;
|
||||
sk_sp<SkShader> fShader;
|
||||
sk_sp<SkColorFilter> fFilter;
|
||||
|
||||
typedef SkShader INHERITED;
|
||||
};
|
||||
|
@ -226,12 +226,13 @@ static void set_concat(SkScalar result[20], const SkScalar outer[20], const SkSc
|
||||
// End duplication
|
||||
//////
|
||||
|
||||
SkColorFilter* SkColorMatrixFilterRowMajor255::newComposed(const SkColorFilter* innerFilter) const {
|
||||
sk_sp<SkColorFilter>
|
||||
SkColorMatrixFilterRowMajor255::makeComposed(sk_sp<SkColorFilter> innerFilter) const {
|
||||
SkScalar innerMatrix[20];
|
||||
if (innerFilter->asColorMatrix(innerMatrix) && !needs_clamping(innerMatrix)) {
|
||||
SkScalar concat[20];
|
||||
set_concat(concat, fMatrix, innerMatrix);
|
||||
return new SkColorMatrixFilterRowMajor255(concat);
|
||||
return sk_make_sp<SkColorMatrixFilterRowMajor255>(concat);
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
@ -417,15 +418,16 @@ void SkColorMatrixFilterRowMajor255::toString(SkString* str) const {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkColorFilter* SkColorFilter::CreateMatrixFilterRowMajor255(const SkScalar array[20]) {
|
||||
return new SkColorMatrixFilterRowMajor255(array);
|
||||
sk_sp<SkColorFilter> SkColorFilter::MakeMatrixFilterRowMajor255(const SkScalar array[20]) {
|
||||
return sk_sp<SkColorFilter>(new SkColorMatrixFilterRowMajor255(array));
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkColorFilter* SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(const SkScalar row[5]) {
|
||||
sk_sp<SkColorFilter>
|
||||
SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(const SkScalar row[5]) {
|
||||
SkASSERT(row);
|
||||
SkColorMatrixFilterRowMajor255* cf = new SkColorMatrixFilterRowMajor255();
|
||||
auto cf = sk_make_sp<SkColorMatrixFilterRowMajor255>();
|
||||
static_assert(sizeof(SkScalar) * 5 * 4 == sizeof(cf->fMatrix), "sizes don't match");
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
memcpy(cf->fMatrix + 5 * i, row, sizeof(SkScalar) * 5);
|
||||
|
@ -12,16 +12,17 @@
|
||||
|
||||
class SK_API SkColorMatrixFilterRowMajor255 : public SkColorFilter {
|
||||
public:
|
||||
SkColorMatrixFilterRowMajor255() {};
|
||||
explicit SkColorMatrixFilterRowMajor255(const SkScalar array[20]);
|
||||
|
||||
/** Creates a color matrix filter that returns the same value in all four channels. */
|
||||
static SkColorFilter* CreateSingleChannelOutput(const SkScalar row[5]);
|
||||
static sk_sp<SkColorFilter> MakeSingleChannelOutput(const SkScalar row[5]);
|
||||
|
||||
void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
|
||||
void filterSpan4f(const SkPM4f src[], int count, SkPM4f[]) const override;
|
||||
uint32_t getFlags() const override;
|
||||
bool asColorMatrix(SkScalar matrix[20]) const override;
|
||||
SkColorFilter* newComposed(const SkColorFilter*) const override;
|
||||
sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter>) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override;
|
||||
@ -35,8 +36,6 @@ protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
|
||||
private:
|
||||
SkColorMatrixFilterRowMajor255() {};
|
||||
|
||||
SkScalar fMatrix[20];
|
||||
float fTranspose[20]; // for Sk4s
|
||||
uint32_t fFlags;
|
||||
|
@ -207,8 +207,7 @@ void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkR
|
||||
pnt.setShader(std::move(shader));
|
||||
|
||||
if (colors) {
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[i], mode));
|
||||
pnt.setColorFilter(cf);
|
||||
pnt.setColorFilter(SkColorFilter::MakeModeFilter(colors[i], mode));
|
||||
}
|
||||
|
||||
path.rewind();
|
||||
|
@ -80,7 +80,7 @@ void SkModeColorFilter::updateCache() {
|
||||
SkFlattenable* SkModeColorFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SkColor color = buffer.readColor();
|
||||
SkXfermode::Mode mode = (SkXfermode::Mode)buffer.readUInt();
|
||||
return SkColorFilter::CreateModeFilter(color, mode);
|
||||
return SkColorFilter::MakeModeFilter(color, mode).release();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -148,7 +148,7 @@ private:
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode mode) {
|
||||
sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkXfermode::Mode mode) {
|
||||
if (!SkIsValidMode(mode)) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -183,10 +183,10 @@ SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode m
|
||||
|
||||
switch (mode) {
|
||||
case SkXfermode::kSrc_Mode:
|
||||
return new Src_SkModeColorFilter(color);
|
||||
return sk_make_sp<Src_SkModeColorFilter>(color);
|
||||
case SkXfermode::kSrcOver_Mode:
|
||||
return new SrcOver_SkModeColorFilter(color);
|
||||
return sk_make_sp<SrcOver_SkModeColorFilter>(color);
|
||||
default:
|
||||
return SkModeColorFilter::Create(color, mode);
|
||||
return SkModeColorFilter::Make(color, mode);
|
||||
}
|
||||
}
|
||||
|
@ -13,9 +13,14 @@
|
||||
|
||||
class SkModeColorFilter : public SkColorFilter {
|
||||
public:
|
||||
static SkColorFilter* Create(SkColor color, SkXfermode::Mode mode) {
|
||||
return new SkModeColorFilter(color, mode);
|
||||
static sk_sp<SkColorFilter> Make(SkColor color, SkXfermode::Mode mode) {
|
||||
return sk_sp<SkColorFilter>(new SkModeColorFilter(color, mode));
|
||||
}
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
static SkColorFilter* Create(SkColor color, SkXfermode::Mode mode) {
|
||||
return Make(color, mode).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SkColor getColor() const { return fColor; }
|
||||
SkXfermode::Mode getMode() const { return fMode; }
|
||||
|
@ -375,7 +375,9 @@ SET_PTR(Rasterizer)
|
||||
#endif
|
||||
SET_PTR(ImageFilter)
|
||||
SET_PTR(Shader)
|
||||
#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
|
||||
SET_PTR(ColorFilter)
|
||||
#endif
|
||||
SET_PTR(Xfermode)
|
||||
#ifdef SK_SUPPORT_LEGACY_PATHEFFECT_PTR
|
||||
SET_PTR(PathEffect)
|
||||
@ -1940,7 +1942,7 @@ void SkPaint::unflatten(SkReadBuffer& buffer) {
|
||||
this->setShader(buffer.readShader());
|
||||
SkSafeUnref(this->setXfermode(buffer.readXfermode()));
|
||||
SkSafeUnref(this->setMaskFilter(buffer.readMaskFilter()));
|
||||
SkSafeUnref(this->setColorFilter(buffer.readColorFilter()));
|
||||
this->setColorFilter(buffer.readColorFilter());
|
||||
this->setRasterizer(buffer.readRasterizer());
|
||||
this->setLooper(buffer.readDrawLooper());
|
||||
SkSafeUnref(this->setImageFilter(buffer.readImageFilter()));
|
||||
|
@ -130,7 +130,9 @@ public:
|
||||
template <typename T> T* readFlattenable() {
|
||||
return (T*) this->readFlattenable(T::GetFlattenableType());
|
||||
}
|
||||
SkColorFilter* readColorFilter() { return this->readFlattenable<SkColorFilter>(); }
|
||||
sk_sp<SkColorFilter> readColorFilter() {
|
||||
return sk_sp<SkColorFilter>(this->readFlattenable<SkColorFilter>());
|
||||
}
|
||||
sk_sp<SkDrawLooper> readDrawLooper() {
|
||||
return sk_sp<SkDrawLooper>(this->readFlattenable<SkDrawLooper>());
|
||||
}
|
||||
|
@ -449,4 +449,7 @@ SkShader* SkShader::CreatePictureShader(const SkPicture* src, TileMode tmx, Tile
|
||||
return MakePictureShader(sk_ref_sp(const_cast<SkPicture*>(src)), tmx, tmy,
|
||||
localMatrix, tile).release();
|
||||
}
|
||||
SkShader* SkShader::newWithColorFilter(SkColorFilter* filter) const {
|
||||
return this->makeWithColorFilter(sk_ref_sp(filter)).release();
|
||||
}
|
||||
#endif
|
||||
|
@ -44,8 +44,7 @@ void SkBlurDrawLooper::initEffects() {
|
||||
// be baked into the blurred mask.
|
||||
SkColor opaqueColor = SkColorSetA(fBlurColor, 255);
|
||||
//The SrcIn xfer mode will multiply 'color' by the incoming alpha
|
||||
fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor,
|
||||
SkXfermode::kSrcIn_Mode);
|
||||
fColorFilter = SkColorFilter::MakeModeFilter(opaqueColor, SkXfermode::kSrcIn_Mode);
|
||||
} else {
|
||||
fColorFilter = nullptr;
|
||||
}
|
||||
@ -81,7 +80,6 @@ void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
|
||||
|
||||
SkBlurDrawLooper::~SkBlurDrawLooper() {
|
||||
SkSafeUnref(fBlur);
|
||||
SkSafeUnref(fColorFilter);
|
||||
}
|
||||
|
||||
bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
|
||||
|
@ -48,19 +48,19 @@ static bool is_valid_3D_lut(SkData* cubeData, int cubeDimension) {
|
||||
(nullptr != cubeData) && (cubeData->size() >= minMemorySize);
|
||||
}
|
||||
|
||||
SkColorFilter* SkColorCubeFilter::Create(SkData* cubeData, int cubeDimension) {
|
||||
if (!is_valid_3D_lut(cubeData, cubeDimension)) {
|
||||
sk_sp<SkColorFilter> SkColorCubeFilter::Make(sk_sp<SkData> cubeData, int cubeDimension) {
|
||||
if (!is_valid_3D_lut(cubeData.get(), cubeDimension)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return new SkColorCubeFilter(cubeData, cubeDimension);
|
||||
return sk_sp<SkColorFilter>(new SkColorCubeFilter(std::move(cubeData), cubeDimension));
|
||||
}
|
||||
|
||||
SkColorCubeFilter::SkColorCubeFilter(SkData* cubeData, int cubeDimension)
|
||||
: fCubeData(SkRef(cubeData))
|
||||
SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension)
|
||||
: fCubeData(std::move(cubeData))
|
||||
, fUniqueID(SkNextColorCubeUniqueID())
|
||||
, fCache(cubeDimension) {
|
||||
}
|
||||
, fCache(cubeDimension)
|
||||
{}
|
||||
|
||||
uint32_t SkColorCubeFilter::getFlags() const {
|
||||
return this->INHERITED::getFlags() | kAlphaUnchanged_Flag;
|
||||
@ -142,7 +142,7 @@ SkFlattenable* SkColorCubeFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
if (!buffer.validate(is_valid_3D_lut(cubeData.get(), cubeDimension))) {
|
||||
return nullptr;
|
||||
}
|
||||
return Create(cubeData.get(), cubeDimension);
|
||||
return Make(std::move(cubeData), cubeDimension).release();
|
||||
}
|
||||
|
||||
void SkColorCubeFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -25,10 +25,10 @@ SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter
|
||||
if (input && input->isColorFilterNode(&inputCF)) {
|
||||
// This is an optimization, as it collapses the hierarchy by just combining the two
|
||||
// colorfilters into a single one, which the new imagefilter will wrap.
|
||||
SkAutoUnref autoUnref(inputCF);
|
||||
SkAutoTUnref<SkColorFilter> newCF(SkColorFilter::CreateComposeFilter(cf, inputCF));
|
||||
sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf),
|
||||
sk_sp<SkColorFilter>(inputCF)));
|
||||
if (newCF) {
|
||||
return new SkColorFilterImageFilter(newCF, input->getInput(0), cropRect);
|
||||
return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect);
|
||||
}
|
||||
}
|
||||
|
||||
@ -42,17 +42,13 @@ SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
|
||||
|
||||
SkFlattenable* SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
|
||||
SkAutoTUnref<SkColorFilter> cf(buffer.readColorFilter());
|
||||
return Create(cf, common.getInput(0), &common.cropRect());
|
||||
sk_sp<SkColorFilter> cf(buffer.readColorFilter());
|
||||
return Create(cf.get(), common.getInput(0), &common.cropRect());
|
||||
}
|
||||
|
||||
void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
this->INHERITED::flatten(buffer);
|
||||
buffer.writeFlattenable(fColorFilter);
|
||||
}
|
||||
|
||||
SkColorFilterImageFilter::~SkColorFilterImageFilter() {
|
||||
fColorFilter->unref();
|
||||
buffer.writeFlattenable(fColorFilter.get());
|
||||
}
|
||||
|
||||
bool SkColorFilterImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitmap& source,
|
||||
@ -94,7 +90,7 @@ bool SkColorFilterImageFilter::onIsColorFilterNode(SkColorFilter** filter) const
|
||||
SkASSERT(1 == this->countInputs());
|
||||
if (!this->cropRectIsSet()) {
|
||||
if (filter) {
|
||||
*filter = SkRef(fColorFilter);
|
||||
*filter = SkRef(fColorFilter.get());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ static SkScalar byte_to_scale(U8CPU byte) {
|
||||
}
|
||||
}
|
||||
|
||||
SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor add) {
|
||||
sk_sp<SkColorFilter> SkColorMatrixFilter::MakeLightingFilter(SkColor mul, SkColor add) {
|
||||
SkColorMatrix matrix;
|
||||
matrix.setScale(byte_to_scale(SkColorGetR(mul)),
|
||||
byte_to_scale(SkColorGetG(mul)),
|
||||
@ -26,5 +26,5 @@ SkColorFilter* SkColorMatrixFilter::CreateLightingFilter(SkColor mul, SkColor ad
|
||||
SkIntToScalar(SkColorGetG(add)),
|
||||
SkIntToScalar(SkColorGetB(add)),
|
||||
0);
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat);
|
||||
}
|
||||
|
@ -79,11 +79,9 @@ bool SkDropShadowImageFilter::onFilterImageDeprecated(Proxy* proxy, const SkBitm
|
||||
sigma.fX = SkMaxScalar(0, sigma.fX);
|
||||
sigma.fY = SkMaxScalar(0, sigma.fY);
|
||||
SkAutoTUnref<SkImageFilter> blurFilter(SkBlurImageFilter::Create(sigma.fX, sigma.fY));
|
||||
SkAutoTUnref<SkColorFilter> colorFilter(
|
||||
SkColorFilter::CreateModeFilter(fColor, SkXfermode::kSrcIn_Mode));
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(blurFilter.get());
|
||||
paint.setColorFilter(colorFilter.get());
|
||||
paint.setColorFilter(SkColorFilter::MakeModeFilter(fColor, SkXfermode::kSrcIn_Mode));
|
||||
paint.setXfermodeMode(SkXfermode::kSrcOver_Mode);
|
||||
SkVector offsetVec = SkVector::Make(fDx, fDy);
|
||||
ctx.ctm().mapVectors(&offsetVec, 1);
|
||||
|
@ -102,7 +102,7 @@ void SkLayerDrawLooper::LayerDrawLooperContext::ApplyInfo(
|
||||
dst->setShader(src.getShader());
|
||||
}
|
||||
if (bits & kColorFilter_Bit) {
|
||||
dst->setColorFilter(src.getColorFilter());
|
||||
dst->setColorFilter(sk_ref_sp(src.getColorFilter()));
|
||||
}
|
||||
if (bits & kXfermode_Bit) {
|
||||
dst->setXfermode(src.getXfermode());
|
||||
|
@ -37,7 +37,9 @@ void SkLumaColorFilter::filterSpan(const SkPMColor src[], int count,
|
||||
}
|
||||
}
|
||||
|
||||
SkColorFilter* SkLumaColorFilter::Create() { return new SkLumaColorFilter; }
|
||||
sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
|
||||
return sk_sp<SkColorFilter>(new SkLumaColorFilter);
|
||||
}
|
||||
|
||||
SkLumaColorFilter::SkLumaColorFilter() : INHERITED() {}
|
||||
|
||||
|
@ -46,7 +46,7 @@ public:
|
||||
virtual ~SkTable_ColorFilter() { delete fBitmap; }
|
||||
|
||||
bool asComponentTable(SkBitmap* table) const override;
|
||||
SkColorFilter* newComposed(const SkColorFilter* inner) const override;
|
||||
sk_sp<SkColorFilter> makeComposed(sk_sp<SkColorFilter> inner) const override;
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
const GrFragmentProcessor* asFragmentProcessor(GrContext*) const override;
|
||||
@ -251,7 +251,7 @@ SkFlattenable* SkTable_ColorFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
b = ptr;
|
||||
ptr += 256;
|
||||
}
|
||||
return SkTableColorFilter::CreateARGB(a, r, g, b);
|
||||
return SkTableColorFilter::MakeARGB(a, r, g, b).release();
|
||||
}
|
||||
|
||||
bool SkTable_ColorFilter::asComponentTable(SkBitmap* table) const {
|
||||
@ -287,7 +287,7 @@ static void combine_tables(uint8_t res[256], const uint8_t outer[256], const uin
|
||||
}
|
||||
}
|
||||
|
||||
SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter) const {
|
||||
sk_sp<SkColorFilter> SkTable_ColorFilter::makeComposed(sk_sp<SkColorFilter> innerFilter) const {
|
||||
SkBitmap innerBM;
|
||||
if (!innerFilter->asComponentTable(&innerBM)) {
|
||||
return nullptr;
|
||||
@ -326,7 +326,7 @@ SkColorFilter* SkTable_ColorFilter::newComposed(const SkColorFilter* innerFilter
|
||||
combine_tables(concatG, tableG, innerBM.getAddr8(0, 2));
|
||||
combine_tables(concatB, tableB, innerBM.getAddr8(0, 3));
|
||||
|
||||
return SkTableColorFilter::CreateARGB(concatA, concatR, concatG, concatB);
|
||||
return SkTableColorFilter::MakeARGB(concatA, concatR, concatG, concatB);
|
||||
}
|
||||
|
||||
#if SK_SUPPORT_GPU
|
||||
@ -554,7 +554,7 @@ const GrFragmentProcessor* ColorTableEffect::TestCreate(GrProcessorTestData* d)
|
||||
}
|
||||
}
|
||||
}
|
||||
SkAutoTUnref<SkColorFilter> filter(SkTableColorFilter::CreateARGB(
|
||||
auto filter(SkTableColorFilter::MakeARGB(
|
||||
(flags & (1 << 0)) ? luts[0] : nullptr,
|
||||
(flags & (1 << 1)) ? luts[1] : nullptr,
|
||||
(flags & (1 << 2)) ? luts[2] : nullptr,
|
||||
@ -587,15 +587,15 @@ const GrFragmentProcessor* SkTable_ColorFilter::asFragmentProcessor(GrContext* c
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkColorFilter* SkTableColorFilter::Create(const uint8_t table[256]) {
|
||||
return new SkTable_ColorFilter(table, table, table, table);
|
||||
sk_sp<SkColorFilter> SkTableColorFilter::Make(const uint8_t table[256]) {
|
||||
return sk_make_sp<SkTable_ColorFilter>(table, table, table, table);
|
||||
}
|
||||
|
||||
SkColorFilter* SkTableColorFilter::CreateARGB(const uint8_t tableA[256],
|
||||
sk_sp<SkColorFilter> SkTableColorFilter::MakeARGB(const uint8_t tableA[256],
|
||||
const uint8_t tableR[256],
|
||||
const uint8_t tableG[256],
|
||||
const uint8_t tableB[256]) {
|
||||
return new SkTable_ColorFilter(tableA, tableR, tableG, tableB);
|
||||
return sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB);
|
||||
}
|
||||
|
||||
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
|
||||
|
@ -2114,8 +2114,7 @@ static SkSize rect_to_size(const SkRect& r) {
|
||||
return SkSize::Make(r.width(), r.height());
|
||||
}
|
||||
|
||||
static const SkImage* color_filter(const SkImage* image,
|
||||
SkColorFilter* colorFilter) {
|
||||
static const SkImage* color_filter(const SkImage* image, SkColorFilter* colorFilter) {
|
||||
sk_sp<SkSurface> surface(SkSurface::NewRaster(
|
||||
SkImageInfo::MakeN32Premul(image->dimensions())));
|
||||
if (!surface) {
|
||||
@ -2124,7 +2123,7 @@ static const SkImage* color_filter(const SkImage* image,
|
||||
SkCanvas* canvas = surface->getCanvas();
|
||||
canvas->clear(SK_ColorTRANSPARENT);
|
||||
SkPaint paint;
|
||||
paint.setColorFilter(colorFilter);
|
||||
paint.setColorFilter(sk_ref_sp(colorFilter));
|
||||
canvas->drawImage(image, 0, 0, &paint);
|
||||
canvas->flush();
|
||||
return surface->makeImageSnapshot().release();
|
||||
|
@ -1114,7 +1114,7 @@ static int lpaint_getColorFilter(lua_State* L) {
|
||||
|
||||
static int lpaint_setColorFilter(lua_State* L) {
|
||||
SkPaint* paint = get_obj<SkPaint>(L, 1);
|
||||
paint->setColorFilter(get_ref<SkColorFilter>(L, 2));
|
||||
paint->setColorFilter(sk_ref_sp(get_ref<SkColorFilter>(L, 2)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -49,7 +49,7 @@ bool SkRGBAToYUV(const SkImage* image, const SkISize sizes[3], void* const plane
|
||||
int rowStartIdx = 5 * i;
|
||||
const SkScalar* row = kYUVColorSpaceInvMatrices[colorSpace] + rowStartIdx;
|
||||
paint.setColorFilter(
|
||||
SkColorMatrixFilterRowMajor255::CreateSingleChannelOutput(row))->unref();
|
||||
SkColorMatrixFilterRowMajor255::MakeSingleChannelOutput(row));
|
||||
surface->getCanvas()->drawImageRect(image, SkIRect::MakeWH(image->width(), image->height()),
|
||||
SkRect::MakeIWH(surface->width(), surface->height()),
|
||||
&paint);
|
||||
|
@ -15,7 +15,7 @@
|
||||
#include "SkXfermode.h"
|
||||
#include "Test.h"
|
||||
|
||||
static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
|
||||
static sk_sp<SkColorFilter> reincarnate_colorfilter(SkFlattenable* obj) {
|
||||
SkWriteBuffer wb;
|
||||
wb.writeFlattenable(obj);
|
||||
|
||||
@ -30,18 +30,18 @@ static SkColorFilter* reincarnate_colorfilter(SkFlattenable* obj) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkColorFilter* make_filter() {
|
||||
static sk_sp<SkColorFilter> make_filter() {
|
||||
// pick a filter that cannot compose with itself via newComposed()
|
||||
return SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kColorBurn_Mode);
|
||||
return SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kColorBurn_Mode);
|
||||
}
|
||||
|
||||
static void test_composecolorfilter_limit(skiatest::Reporter* reporter) {
|
||||
// Test that CreateComposeFilter() has some finite limit (i.e. that the factory can return null)
|
||||
const int way_too_many = 100;
|
||||
SkAutoTUnref<SkColorFilter> parent(make_filter());
|
||||
auto parent(make_filter());
|
||||
for (int i = 2; i < way_too_many; ++i) {
|
||||
SkAutoTUnref<SkColorFilter> filter(make_filter());
|
||||
parent.reset(SkColorFilter::CreateComposeFilter(parent, filter));
|
||||
auto filter(make_filter());
|
||||
parent = SkColorFilter::MakeComposeFilter(parent, filter);
|
||||
if (nullptr == parent) {
|
||||
REPORTER_ASSERT(reporter, i > 2); // we need to have succeeded at least once!
|
||||
return;
|
||||
@ -62,15 +62,13 @@ DEF_TEST(ColorFilter, reporter) {
|
||||
// special case that would return nullptr (if color's alpha is 0 or 0xFF)
|
||||
color = SkColorSetA(color, 0x7F);
|
||||
|
||||
SkColorFilter* cf = SkColorFilter::CreateModeFilter(color,
|
||||
(SkXfermode::Mode)mode);
|
||||
auto cf = SkColorFilter::MakeModeFilter(color, (SkXfermode::Mode)mode);
|
||||
|
||||
// allow for no filter if we're in Dst mode (its a no op)
|
||||
if (SkXfermode::kDst_Mode == mode && nullptr == cf) {
|
||||
continue;
|
||||
}
|
||||
|
||||
SkAutoUnref aur(cf);
|
||||
REPORTER_ASSERT(reporter, cf);
|
||||
|
||||
SkColor c = ~color;
|
||||
@ -98,8 +96,7 @@ DEF_TEST(ColorFilter, reporter) {
|
||||
REPORTER_ASSERT(reporter, m == expectedMode);
|
||||
|
||||
{
|
||||
SkColorFilter* cf2 = reincarnate_colorfilter(cf);
|
||||
SkAutoUnref aur2(cf2);
|
||||
auto cf2 = reincarnate_colorfilter(cf.get());
|
||||
REPORTER_ASSERT(reporter, cf2);
|
||||
|
||||
SkColor c2 = ~color;
|
||||
@ -117,7 +114,7 @@ DEF_TEST(ColorFilter, reporter) {
|
||||
|
||||
DEF_TEST(LumaColorFilter, reporter) {
|
||||
SkPMColor in, out;
|
||||
SkAutoTUnref<SkColorFilter> lf(SkLumaColorFilter::Create());
|
||||
auto lf(SkLumaColorFilter::Make());
|
||||
|
||||
// Applying luma to white produces black with the same transparency.
|
||||
for (unsigned i = 0; i < 256; ++i) {
|
||||
@ -183,31 +180,31 @@ static void get_grayscale_matrix(float amount, float matrix[20]) {
|
||||
matrix[18] = 1.f;
|
||||
}
|
||||
|
||||
static SkColorFilter* make_cf0() {
|
||||
static sk_sp<SkColorFilter> make_cf0() {
|
||||
SkScalar matrix[20];
|
||||
get_brightness_matrix(0.5f, matrix);
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
static SkColorFilter* make_cf1() {
|
||||
static sk_sp<SkColorFilter> make_cf1() {
|
||||
SkScalar matrix[20];
|
||||
get_grayscale_matrix(1, matrix);
|
||||
return SkColorMatrixFilter::Create(matrix);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(matrix);
|
||||
}
|
||||
static SkColorFilter* make_cf2() {
|
||||
static sk_sp<SkColorFilter> make_cf2() {
|
||||
SkColorMatrix m0, m1;
|
||||
get_brightness_matrix(0.5f, m0.fMat);
|
||||
get_grayscale_matrix(1, m1.fMat);
|
||||
m0.preConcat(m1);
|
||||
return SkColorMatrixFilter::Create(m0);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(m0.fMat);
|
||||
}
|
||||
static SkColorFilter* make_cf3() {
|
||||
static sk_sp<SkColorFilter> make_cf3() {
|
||||
SkColorMatrix m0, m1;
|
||||
get_brightness_matrix(0.5f, m0.fMat);
|
||||
get_grayscale_matrix(1, m1.fMat);
|
||||
m0.postConcat(m1);
|
||||
return SkColorMatrixFilter::Create(m0);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(m0.fMat);
|
||||
}
|
||||
typedef SkColorFilter* (*CFProc)();
|
||||
typedef sk_sp<SkColorFilter> (*CFProc)();
|
||||
|
||||
// Test that a colormatrix that "should" preserve opaquness actually does.
|
||||
DEF_TEST(ColorMatrixFilter, reporter) {
|
||||
@ -216,7 +213,7 @@ DEF_TEST(ColorMatrixFilter, reporter) {
|
||||
};
|
||||
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
|
||||
SkAutoTUnref<SkColorFilter> cf(procs[i]());
|
||||
auto cf(procs[i]());
|
||||
|
||||
// generate all possible r,g,b triples
|
||||
for (int r = 0; r < 256; ++r) {
|
||||
|
@ -45,7 +45,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
|
||||
0.0f, 1.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 0.0f,
|
||||
0.0f, 0.0f, 0.0f, 1.0f, 0.0f };
|
||||
paint.setColorFilter(SkColorMatrixFilter::Create(blueToCyan))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(blueToCyan));
|
||||
|
||||
paint.setColor(SK_ColorBLUE);
|
||||
canvas.drawPoint(0, 0, paint);
|
||||
@ -70,7 +70,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
|
||||
0.0f, 0.0f, 1.0f, 0.0f, 64.0f,
|
||||
-0.5f, 0.0f, 0.0f, 1.0f, 0.0f
|
||||
};
|
||||
paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
|
||||
bitmap.eraseColor(SK_ColorTRANSPARENT);
|
||||
|
||||
paint.setColor(SK_ColorRED);
|
||||
@ -91,7 +91,7 @@ static inline void test_colorMatrixCTS(skiatest::Reporter* reporter) {
|
||||
assert_color(reporter, SK_ColorCYAN, bitmap.getColor(0, 0));
|
||||
|
||||
// create a new filter with the changed matrix
|
||||
paint.setColorFilter(SkColorMatrixFilter::Create(transparentRedAddBlue))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(transparentRedAddBlue));
|
||||
canvas.drawPoint(0, 0, paint);
|
||||
assert_color(reporter, SK_ColorBLUE, bitmap.getColor(0, 0));
|
||||
}
|
||||
|
@ -99,8 +99,7 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(GpuColorFilter, reporter, context) {
|
||||
GrPaint paint;
|
||||
for (size_t i = 0; i < SK_ARRAY_COUNT(filterTests); ++i) {
|
||||
const GetConstantComponentTestCase& test = filterTests[i];
|
||||
SkAutoTUnref<SkColorFilter> cf(
|
||||
SkColorFilter::CreateModeFilter(test.filterColor, test.filterMode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(test.filterColor, test.filterMode));
|
||||
SkAutoTUnref<const GrFragmentProcessor> fp( cf->asFragmentProcessor(context));
|
||||
REPORTER_ASSERT(reporter, fp);
|
||||
GrInvariantOutput inout(test.inputColor,
|
||||
|
@ -137,8 +137,8 @@ static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
|
||||
0, s, 0, 0, 0,
|
||||
0, 0, s, 0, 0,
|
||||
0, 0, 0, s, 0 };
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter, input);
|
||||
auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
|
||||
@ -148,14 +148,13 @@ static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::
|
||||
matrix[1] = matrix[6] = matrix[11] = 0.7152f;
|
||||
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
|
||||
matrix[18] = 1.0f;
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorMatrixFilter::Create(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter, input, cropRect);
|
||||
auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
|
||||
}
|
||||
|
||||
static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
|
||||
SkAutoTUnref<SkColorFilter> filter(SkColorFilter::CreateModeFilter(SK_ColorBLUE,
|
||||
SkXfermode::kSrcIn_Mode));
|
||||
return SkColorFilterImageFilter::Create(filter, input, cropRect);
|
||||
auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
|
||||
return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
|
||||
}
|
||||
|
||||
static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
|
||||
@ -258,9 +257,9 @@ DEF_TEST(ImageFilter, reporter) {
|
||||
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
|
||||
SkScalar redToGreenMatrix[20] = { 0 };
|
||||
redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
|
||||
SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedMatrix));
|
||||
auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
|
||||
SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blueToRed.get()));
|
||||
SkAutoTUnref<SkColorFilter> redToGreen(SkColorMatrixFilter::Create(redToGreenMatrix));
|
||||
auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
|
||||
SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get()));
|
||||
|
||||
SkBitmap result;
|
||||
@ -320,7 +319,7 @@ static void test_crop_rects(SkImageFilter::Proxy* proxy,
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(20, 30, 60, 60));
|
||||
SkAutoTUnref<SkImageFilter> input(make_grayscale(nullptr, &inputCropRect));
|
||||
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
|
||||
SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
|
||||
SkScalar kernel[9] = {
|
||||
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
|
||||
@ -564,7 +563,7 @@ DEF_TEST(ImageFilterDrawTiled, reporter) {
|
||||
// match the same filters drawn with a single full-canvas bitmap draw.
|
||||
// Tests pass by not asserting.
|
||||
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode));
|
||||
SkPoint3 location = SkPoint3::Make(0, 0, SK_Scalar1);
|
||||
SkScalar kernel[9] = {
|
||||
SkIntToScalar( 1), SkIntToScalar( 1), SkIntToScalar( 1),
|
||||
@ -693,7 +692,7 @@ static void draw_saveLayer_picture(int width, int height, int tileSize,
|
||||
SkMatrix matrix;
|
||||
matrix.setTranslate(SkIntToScalar(50), 0);
|
||||
|
||||
SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
|
||||
auto cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
|
||||
SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix, kNone_SkFilterQuality, cfif.get()));
|
||||
|
||||
@ -1122,14 +1121,13 @@ DEF_TEST(ImageFilterEmptySaveLayer, reporter) {
|
||||
SkRTreeFactory factory;
|
||||
SkPictureRecorder recorder;
|
||||
|
||||
SkAutoTUnref<SkColorFilter> green(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
|
||||
auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(
|
||||
SkColorFilterImageFilter::Create(green.get()));
|
||||
SkPaint imageFilterPaint;
|
||||
imageFilterPaint.setImageFilter(imageFilter.get());
|
||||
SkPaint colorFilterPaint;
|
||||
colorFilterPaint.setColorFilter(green.get());
|
||||
colorFilterPaint.setColorFilter(green);
|
||||
|
||||
SkRect bounds = SkRect::MakeWH(10, 10);
|
||||
|
||||
@ -1245,8 +1243,7 @@ static void test_xfermode_cropped_input(SkCanvas* canvas, skiatest::Reporter* re
|
||||
bitmap.allocN32Pixels(1, 1);
|
||||
bitmap.eraseARGB(255, 255, 255, 255);
|
||||
|
||||
SkAutoTUnref<SkColorFilter> green(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
|
||||
auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
|
||||
SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get()));
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
|
||||
SkAutoTUnref<SkImageFilter> croppedOut(
|
||||
@ -1467,8 +1464,8 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
|
||||
0, 0, 0, 0, 1,
|
||||
0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 1 };
|
||||
SkAutoTUnref<SkColorFilter> greenCF(SkColorMatrixFilter::Create(greenMatrix));
|
||||
SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF));
|
||||
auto greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
|
||||
SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get()));
|
||||
|
||||
REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
|
||||
REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
|
||||
@ -1482,14 +1479,12 @@ DEF_TEST(ImageFilterCanComputeFastBounds, reporter) {
|
||||
allOne[i] = 255;
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkColorFilter> identityCF(
|
||||
SkTableColorFilter::CreateARGB(identity, identity, identity, allOne));
|
||||
auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne));
|
||||
SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(identityCF.get()));
|
||||
REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
|
||||
REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
|
||||
|
||||
SkAutoTUnref<SkColorFilter> forceOpaqueCF(
|
||||
SkTableColorFilter::CreateARGB(allOne, identity, identity, identity));
|
||||
auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity));
|
||||
SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get()));
|
||||
REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
|
||||
REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
|
||||
|
@ -360,11 +360,11 @@ DEF_TEST(Paint_nothingToDraw, r) {
|
||||
|
||||
SkColorMatrix cm;
|
||||
cm.setIdentity(); // does not change alpha
|
||||
paint.setColorFilter(SkColorMatrixFilter::Create(cm))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
REPORTER_ASSERT(r, paint.nothingToDraw());
|
||||
|
||||
cm.postTranslate(0, 0, 0, 1); // wacks alpha
|
||||
paint.setColorFilter(SkColorMatrixFilter::Create(cm))->unref();
|
||||
paint.setColorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
|
||||
REPORTER_ASSERT(r, !paint.nothingToDraw());
|
||||
}
|
||||
|
||||
|
@ -278,7 +278,7 @@ static void test_savelayer_extraction(skiatest::Reporter* reporter) {
|
||||
// optimize away
|
||||
SkScalar blueToRedMatrix[20] = { 0 };
|
||||
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
|
||||
SkAutoTUnref<SkColorFilter> blueToRed(SkColorMatrixFilter::Create(blueToRedMatrix));
|
||||
auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
|
||||
SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRed.get()));
|
||||
|
||||
SkPaint complexPaint;
|
||||
|
@ -224,7 +224,7 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
|
||||
xfermodePaint.setXfermodeMode(SkXfermode::kDstIn_Mode);
|
||||
SkPaint colorFilterPaint;
|
||||
colorFilterPaint.setColorFilter(
|
||||
SkColorFilter::CreateModeFilter(SK_ColorLTGRAY, SkXfermode::kSrcIn_Mode))->unref();
|
||||
SkColorFilter::MakeModeFilter(SK_ColorLTGRAY, SkXfermode::kSrcIn_Mode));
|
||||
|
||||
SkPaint opaqueFilterLayerPaint;
|
||||
opaqueFilterLayerPaint.setColor(0xFF020202); // Opaque.
|
||||
|
@ -286,7 +286,7 @@ static void TestColorFilterSerialization(skiatest::Reporter* reporter) {
|
||||
for (int i = 0; i < 256; ++i) {
|
||||
table[i] = (i * 41) % 256;
|
||||
}
|
||||
SkAutoTUnref<SkColorFilter> colorFilter(SkTableColorFilter::Create(table));
|
||||
auto colorFilter(SkTableColorFilter::Make(table));
|
||||
SkAutoTUnref<SkColorFilter> copy(
|
||||
TestFlattenableSerialization<SkColorFilter>(colorFilter.get(), true, reporter));
|
||||
}
|
||||
|
@ -78,24 +78,22 @@ DEF_TEST(Color4f_premul, reporter) {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static SkColorFilter* make_mode_cf() {
|
||||
return SkColorFilter::CreateModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
|
||||
static sk_sp<SkColorFilter> make_mode_cf() {
|
||||
return SkColorFilter::MakeModeFilter(0xFFBB8855, SkXfermode::kPlus_Mode);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_mx_cf() {
|
||||
static sk_sp<SkColorFilter> make_mx_cf() {
|
||||
const float mx[] = {
|
||||
0.5f, 0, 0, 0, 0.1f,
|
||||
0, 0.5f, 0, 0, 0.2f,
|
||||
0, 0, 1, 0, -0.1f,
|
||||
0, 0, 0, 1, 0,
|
||||
};
|
||||
return SkColorMatrixFilter::Create(mx);
|
||||
return SkColorFilter::MakeMatrixFilterRowMajor255(mx);
|
||||
}
|
||||
|
||||
static SkColorFilter* make_compose_cf() {
|
||||
SkAutoTUnref<SkColorFilter> cf0(make_mode_cf());
|
||||
SkAutoTUnref<SkColorFilter> cf1(make_mx_cf());
|
||||
return SkColorFilter::CreateComposeFilter(cf0, cf1);
|
||||
static sk_sp<SkColorFilter> make_compose_cf() {
|
||||
return SkColorFilter::MakeComposeFilter(make_mode_cf(), make_mx_cf());
|
||||
}
|
||||
|
||||
static sk_sp<SkShader> make_color_sh() { return SkShader::MakeColorShader(0xFFBB8855); }
|
||||
@ -124,8 +122,7 @@ static sk_sp<SkShader> make_grad_sh() {
|
||||
}
|
||||
|
||||
static sk_sp<SkShader> make_cf_sh() {
|
||||
SkAutoTUnref<SkColorFilter> filter(make_mx_cf());
|
||||
return make_color_sh()->makeWithColorFilter(filter);
|
||||
return make_color_sh()->makeWithColorFilter(make_mx_cf());
|
||||
}
|
||||
|
||||
static bool compare_spans(const SkPM4f span4f[], const SkPMColor span4b[], int count,
|
||||
@ -178,7 +175,7 @@ DEF_TEST(Color4f_shader, reporter) {
|
||||
|
||||
DEF_TEST(Color4f_colorfilter, reporter) {
|
||||
struct {
|
||||
SkColorFilter* (*fFact)();
|
||||
sk_sp<SkColorFilter> (*fFact)();
|
||||
bool fSupports4f;
|
||||
const char* fName;
|
||||
} recs[] = {
|
||||
@ -200,7 +197,7 @@ DEF_TEST(Color4f_colorfilter, reporter) {
|
||||
REPORTER_ASSERT(reporter, compare_spans(src4f, src4b, N));
|
||||
|
||||
for (const auto& rec : recs) {
|
||||
SkAutoTUnref<SkColorFilter> filter(rec.fFact());
|
||||
auto filter(rec.fFact());
|
||||
SkPMColor dst4b[N];
|
||||
filter->filterSpan(src4b, N, dst4b);
|
||||
SkPM4f dst4f[N];
|
||||
|
@ -69,7 +69,7 @@ void Filter(SkPaint* paint) {
|
||||
bool isMode = cf->asColorMode(&color, &mode);
|
||||
if (isMode && mode > SkXfermode::kLighten_Mode) {
|
||||
paint->setColorFilter(
|
||||
SkColorFilter::CreateModeFilter(color, SkXfermode::kSrcOver_Mode));
|
||||
SkColorFilter::MakeModeFilter(color, SkXfermode::kSrcOver_Mode));
|
||||
} else if (!isMode && !cf->asColorMatrix(srcColorMatrix)) {
|
||||
paint->setColorFilter(nullptr);
|
||||
}
|
||||
|
@ -1159,11 +1159,10 @@ static void extract_json_paint_colorfilter(Json::Value& jsonPaint, UrlDataManage
|
||||
SkPaint* target) {
|
||||
if (jsonPaint.isMember(SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER)) {
|
||||
Json::Value jsonColorFilter = jsonPaint[SKDEBUGCANVAS_ATTRIBUTE_COLORFILTER];
|
||||
SkColorFilter* colorFilter = (SkColorFilter*) load_flattenable(jsonColorFilter,
|
||||
urlDataManager);
|
||||
sk_sp<SkColorFilter> colorFilter((SkColorFilter*)load_flattenable(jsonColorFilter,
|
||||
urlDataManager));
|
||||
if (colorFilter != nullptr) {
|
||||
target->setColorFilter(colorFilter);
|
||||
colorFilter->unref();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user