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);
}
{
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";
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);
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);
}
}
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) {
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; }
}
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());
}
};
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);
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();
- }
}
};
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);
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));
}
{
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);
}
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");
}
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);
}
}
- 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();
}
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);
}
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;
};
//////////////////////////////////////////////////////////////////////////////
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) {
#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));
}
///////////////////////////////////////////////////////////////////////////////////////////////////
}
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,
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);
};
DEF_SIMPLE_GM(colorfiltershader, canvas, 800, 800) {
- SkTRefArray<SkColorFilter*> filters;
+ SkTArray<sk_sp<SkColorFilter>> filters;
sk_gm_get_colorfilters(&filters);
SkTRefArray<SkShader*> shaders;
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);
}
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 {
#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 {
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);
// 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);
}
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);
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),
SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
true),
- SkColorFilterImageFilter::Create(cf),
+ SkColorFilterImageFilter::Create(cf.get()),
};
const struct {
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);
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; )
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);
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);
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));
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);
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;
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));
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));
}
{
// 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);
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);
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),
}
private:
- SkAutoTUnref<SkColorFilter> fFilter;
- sk_sp<SkShader> fGr1, fGr2;
+ sk_sp<SkColorFilter> fFilter;
+ sk_sp<SkShader> fGr1, fGr2;
typedef skiagm::GM INHERITED;
};
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();
}
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();
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();
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);
// 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();
}
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);
}
}
-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 {
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.
// 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;
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]);
}
}
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);
}
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);
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);
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);
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) {
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();
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 {
- SkPoint fPts[9];
- SkPoint fTexs[9];
- SkColor fColors[9];
- sk_sp<SkShader> fShader1;
- sk_sp<SkShader> fShader2;
- SkAutoTUnref<SkColorFilter> fColorFilter;
+ SkPoint fPts[9];
+ SkPoint fTexs[9];
+ SkColor fColors[9];
+ sk_sp<SkShader> fShader1;
+ sk_sp<SkShader> fShader2;
+ sk_sp<SkColorFilter> fColorFilter;
public:
VerticesGM() {}
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) {
};
const struct {
- const SkColor* fColors;
- const SkPoint* fTexs;
- const sk_sp<SkShader>& fShader;
- SkColorFilter* fColorFilter;
- uint8_t fAlpha;
+ const SkColor* fColors;
+ const SkPoint* fTexs;
+ const sk_sp<SkShader>& fShader;
+ const sk_sp<SkColorFilter>& fColorFilter;
+ uint8_t fAlpha;
} rec[] = {
{ fColors, nullptr, fShader1, nullptr , 0xFF },
{ nullptr, fTexs , fShader1, nullptr , 0xFF },
'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',
*
* 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
@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.
* 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
@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.
* 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
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
/**
private:
SkMaskFilter* fBlur;
- SkColorFilter* fColorFilter;
+ sk_sp<SkColorFilter> fColorFilter;
SkScalar fDx, fDy, fSigma;
SkColor fBlurColor;
uint32_t fBlurFlags;
* 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;
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:
SkColorFilterImageFilter(SkColorFilter* cf,
SkImageFilter* input,
const CropRect* cropRect);
- virtual ~SkColorFilterImageFilter();
- SkColorFilter* fColorFilter;
+ sk_sp<SkColorFilter> fColorFilter;
typedef SkImageFilter INHERITED;
};
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
*/
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;
* 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
* treated as identity, with the component left unchanged. If a table
* is not null, then its contents are copied into the filter.
*/
+ 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]);
-
+ const uint8_t tableB[256]) {
+ return MakeARGB(tableA, tableR, tableG, tableB).release();
+ }
+#endif
+
SK_DECLARE_FLATTENABLE_REGISTRAR_GROUP()
};
"SK_CODEC_DECODES_PNG",
"SK_CODEC_DECODES_RAW",
"SK_CODEC_DECODES_WEBP",
- "SK_SUPPORT_LEGACY_CREATESHADER_PTR",
]
DEFINES_ANDROID = [
"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",
]
################################################################################
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();
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);
#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);
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);
}
}
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);
}
}
-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];
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() {
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());
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:
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);
}
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.
* 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) {
// 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));
}
/**
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;
}
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);
return fComposedFilterCount;
}
- SkAutoTUnref<SkColorFilter> fOuter;
- SkAutoTUnref<SkColorFilter> fInner;
- const int fComposedFilterCount;
+ sk_sp<SkColorFilter> fOuter;
+ sk_sp<SkColorFilter> fInner;
+ const int fComposedFilterCount;
friend class SkColorFilter;
};
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;
}
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"
#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 {
///////////////////////////////////////////////////////////////////////////////////////////////////
-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);
}
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*,
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;
};
// 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;
}
///////////////////////////////////////////////////////////////////////////////
-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);
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;
void flatten(SkWriteBuffer&) const override;
private:
- SkColorMatrixFilterRowMajor255() {};
-
SkScalar fMatrix[20];
float fTranspose[20]; // for Sk4s
uint32_t fFlags;
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();
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();
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-SkColorFilter* SkColorFilter::CreateModeFilter(SkColor color, SkXfermode::Mode mode) {
+sk_sp<SkColorFilter> SkColorFilter::MakeModeFilter(SkColor color, SkXfermode::Mode mode) {
if (!SkIsValidMode(mode)) {
return nullptr;
}
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);
}
}
class SkModeColorFilter : public SkColorFilter {
public:
+ 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 new SkModeColorFilter(color, mode);
+ return Make(color, mode).release();
}
+#endif
SkColor getColor() const { return fColor; }
SkXfermode::Mode getMode() const { return fMode; }
#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)
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()));
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>());
}
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
// 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;
}
SkBlurDrawLooper::~SkBlurDrawLooper() {
SkSafeUnref(fBlur);
- SkSafeUnref(fColorFilter);
}
bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
(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))
- , fUniqueID(SkNextColorCubeUniqueID())
- , fCache(cubeDimension) {
-}
+SkColorCubeFilter::SkColorCubeFilter(sk_sp<SkData> cubeData, int cubeDimension)
+ : fCubeData(std::move(cubeData))
+ , fUniqueID(SkNextColorCubeUniqueID())
+ , fCache(cubeDimension)
+{}
uint32_t SkColorCubeFilter::getFlags() const {
return this->INHERITED::getFlags() | kAlphaUnchanged_Flag;
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 {
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);
}
}
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,
SkASSERT(1 == this->countInputs());
if (!this->cropRectIsSet()) {
if (filter) {
- *filter = SkRef(fColorFilter);
+ *filter = SkRef(fColorFilter.get());
}
return true;
}
}
}
-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)),
SkIntToScalar(SkColorGetG(add)),
SkIntToScalar(SkColorGetB(add)),
0);
- return SkColorMatrixFilter::Create(matrix);
+ return SkColorFilter::MakeMatrixFilterRowMajor255(matrix.fMat);
}
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);
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());
}
}
-SkColorFilter* SkLumaColorFilter::Create() { return new SkLumaColorFilter; }
+sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
+ return sk_sp<SkColorFilter>(new SkLumaColorFilter);
+}
SkLumaColorFilter::SkLumaColorFilter() : INHERITED() {}
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;
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 {
}
}
-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;
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
}
}
}
- 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,
///////////////////////////////////////////////////////////////////////////////
-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],
- const uint8_t tableR[256],
- const uint8_t tableG[256],
- const uint8_t tableB[256]) {
- return new SkTable_ColorFilter(tableA, tableR, tableG, tableB);
+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 sk_make_sp<SkTable_ColorFilter>(tableA, tableR, tableG, tableB);
}
SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkTableColorFilter)
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) {
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();
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;
}
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);
#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);
///////////////////////////////////////////////////////////////////////////////
-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;
// 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;
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;
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) {
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) {
};
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) {
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);
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);
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));
}
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,
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) {
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,
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;
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),
// 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),
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()));
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);
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(
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());
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());
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());
}
// 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;
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.
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));
}
//////////////////////////////////////////////////////////////////////////////////////////////////
-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); }
}
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,
DEF_TEST(Color4f_colorfilter, reporter) {
struct {
- SkColorFilter* (*fFact)();
- bool fSupports4f;
- const char* fName;
+ sk_sp<SkColorFilter> (*fFact)();
+ bool fSupports4f;
+ const char* fName;
} recs[] = {
{ make_mode_cf, true, "mode" },
{ make_mx_cf, true, "matrix" },
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];
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);
}
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();
}
}
}