#include "SkCanvas.h"
#include "SkColorFilterImageFilter.h"
#include "SkColorMatrixFilter.h"
-#include "SkLumaColorFilter.h"
-#include "SkTableColorFilter.h"
#define FILTER_WIDTH_SMALL SkIntToScalar(32)
#define FILTER_HEIGHT_SMALL SkIntToScalar(32)
#define FILTER_WIDTH_LARGE SkIntToScalar(256)
#define FILTER_HEIGHT_LARGE SkIntToScalar(256)
+static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) {
+ 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 };
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
+ 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;
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
+static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+ SkXfermode::kSrcIn_Mode));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
+}
+
class ColorFilterBaseBench : public Benchmark {
public:
protected:
SkRect getFilterRect() const {
- return isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
- SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
- }
-
- static SkImageFilter* make_brightness(float amount, SkImageFilter* input = nullptr) {
- 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 };
- auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Create(filter.get(), input);
- }
-
- static SkImageFilter* make_grayscale(SkImageFilter* input = nullptr) {
- 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;
- auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Create(filter.get(), input);
- }
-
- static SkImageFilter* make_mode_blue(SkImageFilter* input = nullptr) {
- auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- return SkColorFilterImageFilter::Create(filter.get(), input);
+ return this->isSmall() ? SkRect::MakeWH(FILTER_WIDTH_SMALL, FILTER_HEIGHT_SMALL) :
+ SkRect::MakeWH(FILTER_WIDTH_LARGE, FILTER_HEIGHT_LARGE);
}
inline bool isSmall() const { return fIsSmall; }
class ColorFilterDimBrightBench : public ColorFilterBaseBench {
public:
- ColorFilterDimBrightBench(bool small) : INHERITED(small) {
- }
+ ColorFilterDimBrightBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large";
+ return this->isSmall() ? "colorfilter_dim_bright_small" : "colorfilter_dim_bright_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
for (float brightness = -1.0f; brightness <= 1.0f; brightness += 0.4f) {
- SkAutoTUnref<SkImageFilter> dim(make_brightness(-brightness));
- SkAutoTUnref<SkImageFilter> bright(make_brightness(brightness, dim));
- paint.setImageFilter(bright);
+ sk_sp<SkImageFilter> dim(make_brightness(-brightness, nullptr));
+ paint.setImageFilter(make_brightness(brightness, std::move(dim)));
canvas->drawRect(r, paint);
}
}
class ColorFilterBrightGrayBench : public ColorFilterBaseBench {
public:
- ColorFilterBrightGrayBench(bool small) : INHERITED(small) {
- }
+ ColorFilterBrightGrayBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large";
+ return this->isSmall() ? "colorfilter_bright_gray_small" : "colorfilter_bright_gray_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f));
- SkAutoTUnref<SkImageFilter> grayscale(make_grayscale(brightness));
- paint.setImageFilter(grayscale);
+ sk_sp<SkImageFilter> brightness(make_brightness(0.9f, nullptr));
+ paint.setImageFilter(make_grayscale(std::move(brightness)));
canvas->drawRect(r, paint);
}
}
class ColorFilterGrayBrightBench : public ColorFilterBaseBench {
public:
- ColorFilterGrayBrightBench(bool small) : INHERITED(small) {
- }
+ ColorFilterGrayBrightBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large";
+ return this->isSmall() ? "colorfilter_gray_bright_small" : "colorfilter_gray_bright_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(0.9f, grayscale));
- paint.setImageFilter(brightness);
+ sk_sp<SkImageFilter> grayscale(make_grayscale(nullptr));
+ paint.setImageFilter(make_brightness(0.9f, std::move(grayscale)));
canvas->drawRect(r, paint);
}
}
class ColorFilterBlueBrightBench : public ColorFilterBaseBench {
public:
- ColorFilterBlueBrightBench(bool small) : INHERITED(small) {
- }
+ ColorFilterBlueBrightBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large";
+ return this->isSmall() ? "colorfilter_blue_bright_small" : "colorfilter_blue_bright_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f, blue));
- paint.setImageFilter(brightness);
+ sk_sp<SkImageFilter> blue(make_mode_blue(nullptr));
+ paint.setImageFilter(make_brightness(1.0f, std::move(blue)));
canvas->drawRect(r, paint);
}
}
class ColorFilterBrightBlueBench : public ColorFilterBaseBench {
public:
- ColorFilterBrightBlueBench(bool small) : INHERITED(small) {
- }
+ ColorFilterBrightBlueBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large";
+ return this->isSmall() ? "colorfilter_bright_blue_small" : "colorfilter_bright_blue_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
- SkAutoTUnref<SkImageFilter> blue(make_mode_blue(brightness));
- paint.setImageFilter(blue);
+ sk_sp<SkImageFilter> brightness(make_brightness(1.0f, nullptr));
+ paint.setImageFilter(make_mode_blue(std::move(brightness)));
canvas->drawRect(r, paint);
}
}
class ColorFilterBrightBench : public ColorFilterBaseBench {
public:
- ColorFilterBrightBench(bool small) : INHERITED(small) {
- }
+ ColorFilterBrightBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large";
+ return this->isSmall() ? "colorfilter_bright_small" : "colorfilter_bright_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> brightness(make_brightness(1.0f));
- paint.setImageFilter(brightness);
+ paint.setImageFilter(make_brightness(1.0f, nullptr));
canvas->drawRect(r, paint);
}
}
class ColorFilterBlueBench : public ColorFilterBaseBench {
public:
- ColorFilterBlueBench(bool small) : INHERITED(small) {
- }
+ ColorFilterBlueBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large";
+ return this->isSmall() ? "colorfilter_blue_small" : "colorfilter_blue_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> blue(make_mode_blue());
- paint.setImageFilter(blue);
+ paint.setImageFilter(make_mode_blue(nullptr));
canvas->drawRect(r, paint);
}
}
class ColorFilterGrayBench : public ColorFilterBaseBench {
public:
- ColorFilterGrayBench(bool small) : INHERITED(small) {}
+ ColorFilterGrayBench(bool small) : INHERITED(small) { }
protected:
const char* onGetName() override {
- return isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large";
+ return this->isSmall() ? "colorfilter_gray_small" : "colorfilter_gray_large";
}
void onDraw(int loops, SkCanvas* canvas) override {
- SkRect r = getFilterRect();
+ SkRect r = this->getFilterRect();
SkPaint paint;
paint.setColor(SK_ColorRED);
for (int i = 0; i < loops; i++) {
- SkAutoTUnref<SkImageFilter> grayscale(make_grayscale());
- paint.setImageFilter(grayscale);
+ paint.setImageFilter(make_grayscale(nullptr));
canvas->drawRect(r, paint);
}
}
class BaseImageFilterCollapseBench : public Benchmark {
public:
- BaseImageFilterCollapseBench(): fImageFilter(nullptr) {}
- ~BaseImageFilterCollapseBench() {
- SkSafeUnref(fImageFilter);
- }
+ BaseImageFilterCollapseBench() {}
protected:
void doPreDraw(sk_sp<SkColorFilter> colorFilters[], int nFilters) {
+ SkASSERT(!fImageFilter);
+
// Create a chain of ImageFilters from colorFilters
- fImageFilter = nullptr;
for(int i = nFilters; i --> 0;) {
- SkAutoTUnref<SkImageFilter> filter(
- SkColorFilterImageFilter::Create(colorFilters[i].get(), fImageFilter, nullptr)
- );
- SkRefCnt_SafeAssign(fImageFilter, filter.get());
+ fImageFilter = SkColorFilterImageFilter::Make(colorFilters[i], fImageFilter);
}
}
}
private:
- SkImageFilter* fImageFilter;
+ sk_sp<SkImageFilter> fImageFilter;
SkBitmap fBitmap;
void makeBitmap() {
SkTableColorFilter::Make(table3),
};
- doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
+ this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
}
private:
make_brightness(-0.1f),
};
- doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
+ this->doPreDraw(colorFilters, SK_ARRAY_COUNT(colorFilters));
}
};
matrix[2] = matrix[7] = matrix[12] = 0.0722f;
matrix[18] = 1.0f;
sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(filter.get(), input.get()));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}
static sk_sp<SkImageFilter> make_blur(float amount, sk_sp<SkImageFilter> input) {
}
static sk_sp<SkImageFilter> make_brightness(float amount, sk_sp<SkImageFilter> input) {
- return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_brightness(amount).get(),
- input.get()));
+ return SkColorFilterImageFilter::Make(cf_make_brightness(amount), std::move(input));
}
static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input) {
- return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_grayscale().get(),
- input.get()));
+ return SkColorFilterImageFilter::Make(cf_make_grayscale(), std::move(input));
}
static sk_sp<SkImageFilter> make_mode_blue(sk_sp<SkImageFilter> input) {
- return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf_make_colorize(SK_ColorBLUE).get(),
- input.get()));
+ return SkColorFilterImageFilter::Make(cf_make_colorize(SK_ColorBLUE), std::move(input));
}
static void draw_clipped_rect(SkCanvas* canvas,
const SkRect& r,
const SkPaint& paint,
float outset = 0.0f) {
- canvas->save();
- SkRect clip(r);
- clip.outset(outset, outset);
- canvas->clipRect(clip);
- canvas->drawRect(r, paint);
- canvas->restore();
+ canvas->save();
+ SkRect clip(r);
+ clip.outset(outset, outset);
+ canvas->clipRect(clip);
+ canvas->drawRect(r, paint);
+ canvas->restore();
}
DEF_SIMPLE_GM(colorfilterimagefilter, canvas, 400, 100){
SkAutoCanvasRestore autoCanvasRestore(canvas, false);
SkColorMatrix cm;
cm.setSaturation(0.0f);
- auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
- sk_sp<SkImageFilter> imf(SkColorFilterImageFilter::Create(cf.get()));
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(cm.fMat));
SkPaint p;
- p.setImageFilter(std::move(imf));
+ p.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
canvas->saveLayer(NULL, &p);
canvas->clear(SK_ColorRED);
}
draw_bitmap, draw_path, draw_paint, draw_text
};
- auto cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA, SkXfermode::kSrcIn_Mode));
- SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get()));
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorMAGENTA,
+ SkXfermode::kSrcIn_Mode));
+ sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
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)),
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
- SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif, nullptr),
+ SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, cfif.get(), nullptr),
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode, nullptr, &cropRect),
SkDropShadowImageFilter::Create(7.0f, 7.0f, 3.0f, 3.0f, SK_ColorBLUE,
0, 1, 0, 0, 128.0f,
0, 0, 1, 0, 128.0f,
0, 0, 0, 1, 0 };
- auto colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(colorFilter.get()));
+ sk_sp<SkColorFilter> colorFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
SkPaint layerPaint;
- layerPaint.setImageFilter(filter);
+ layerPaint.setImageFilter(SkColorFilterImageFilter::Make(std::move(colorFilter), nullptr));
canvas->drawRect(SkRect::MakeLTRB(64, 64, 192, 192), layerPaint);
}
SkMatrixConvolutionImageFilter::Create({ 3, 3 }, kernel, 1, 0, { 0, 0 },
SkMatrixConvolutionImageFilter::kClampToBlack_TileMode,
true),
- SkColorFilterImageFilter::Create(cf.get()),
+ SkColorFilterImageFilter::Make(std::move(cf), nullptr).release(),
};
const struct {
///////////////////////////////////////////////////////////////////////////////
-static void draw_paint(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_paint(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
paint.setColor(SK_ColorGREEN);
canvas->save();
canvas->clipRect(r);
canvas->restore();
}
-static void draw_line(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_line(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setColor(SK_ColorBLUE);
paint.setImageFilter(imf);
canvas->drawLine(r.fLeft, r.fTop, r.fRight, r.fBottom, paint);
}
-static void draw_rect(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_rect(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setColor(SK_ColorYELLOW);
paint.setImageFilter(imf);
canvas->drawRect(rr, paint);
}
-static void draw_path(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_path(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setColor(SK_ColorMAGENTA);
paint.setImageFilter(imf);
canvas->drawCircle(r.centerX(), r.centerY(), r.width()*2/5, paint);
}
-static void draw_text(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_text(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
paint.setImageFilter(imf);
paint.setColor(SK_ColorCYAN);
canvas->drawText("Text", 4, r.centerX(), r.centerY(), paint);
}
-static void draw_bitmap(SkCanvas* canvas, const SkRect& r, SkImageFilter* imf) {
+static void draw_bitmap(SkCanvas* canvas, const SkRect& r, sk_sp<SkImageFilter> imf) {
SkPaint paint;
- paint.setImageFilter(imf);
+ paint.setImageFilter(std::move(imf));
SkIRect bounds;
r.roundOut(&bounds);
}
void onDraw(SkCanvas* canvas) override {
- void (*drawProc[])(SkCanvas*, const SkRect&, SkImageFilter*) = {
+ void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
draw_paint,
draw_line, draw_rect, draw_path, draw_text,
draw_bitmap,
};
auto cf = SkColorFilter::MakeModeFilter(SK_ColorRED, SkXfermode::kSrcIn_Mode);
- SkImageFilter* filters[] = {
+ sk_sp<SkImageFilter> filters[] = {
nullptr,
- IdentityImageFilter::Make(nullptr).release(),
- FailImageFilter::Make().release(),
- SkColorFilterImageFilter::Create(cf.get()),
- SkBlurImageFilter::Make(12.0f, 0.0f, nullptr).release(),
- SkDropShadowImageFilter::Create(10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
- SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode),
+ IdentityImageFilter::Make(nullptr),
+ FailImageFilter::Make(),
+ SkColorFilterImageFilter::Make(std::move(cf), nullptr),
+ SkBlurImageFilter::Make(12.0f, 0.0f, nullptr),
+ sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(
+ 10.0f, 5.0f, 3.0f, 3.0f, SK_ColorBLUE,
+ SkDropShadowImageFilter::kDrawShadowAndForeground_ShadowMode)),
};
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
canvas->restore();
canvas->translate(DX, 0);
}
-
- for(size_t j = 0; j < SK_ARRAY_COUNT(filters); ++j) {
- SkSafeUnref(filters[j]);
- }
}
private:
SkIntToScalar(outset));
SkImageFilter::CropRect bigRect(rect, SkImageFilter::CropRect::kHasAll_CropEdge);
- Draw(canvas, checkerboard, rect,
- sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cfAlphaTrans.get(),
- noopCropped.get(),
- &bigRect)));
+ Draw(canvas, checkerboard, rect, SkColorFilterImageFilter::Make(cfAlphaTrans,
+ noopCropped,
+ &bigRect));
Draw(canvas, checkerboard, rect, SkBlurImageFilter::Make(0.3f, 0.3f,
noopCropped,
canvas->drawRect(r, paint);
}
- virtual void onOnceBeforeDraw() override{
+ void onOnceBeforeDraw() override{
make_checkerboard();
}
- virtual void onDraw(SkCanvas* canvas) override {
+ void onDraw(SkCanvas* canvas) override {
void (*drawProc[])(SkCanvas*, const SkRect&, sk_sp<SkImageFilter>) = {
draw_bitmap, draw_path, draw_paint, draw_text
};
SkIntToScalar(-10),
nullptr));
- sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Create(cf.get(), offset.get()));
+ sk_sp<SkImageFilter> cfOffset(SkColorFilterImageFilter::Make(cf, std::move(offset)));
sk_sp<SkImageFilter> erodeX(SkErodeImageFilter::Make(8, 0, nullptr, &cropRect));
sk_sp<SkImageFilter> erodeY(SkErodeImageFilter::Make(0, 8, nullptr, &cropRect));
sk_sp<SkImageFilter> filters[] = {
nullptr,
- sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &cropRect)),
+ SkColorFilterImageFilter::Make(cf, nullptr, &cropRect),
SkBlurImageFilter::Make(0.0f, 0.0f, nullptr, &cropRect),
SkBlurImageFilter::Make(1.0f, 1.0f, nullptr, &cropRect),
SkBlurImageFilter::Make(8.0f, 0.0f, nullptr, &cropRect),
SkXfermode::kSrcOver_Mode,
&cropRect),
SkBlurImageFilter::Make(8.0f, 8.0f, nullptr, &bogusRect),
- sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(), nullptr, &bogusRect)),
+ SkColorFilterImageFilter::Make(cf, nullptr, &bogusRect),
};
SkRect r = SkRect::MakeWH(SkIntToScalar(64), SkIntToScalar(64));
SkXfermode::kSrcIn_Mode));
sk_sp<SkImageFilter> blur(SkBlurImageFilter::Make(4.0f, 4.0f, std::move(bitmapSource)));
sk_sp<SkImageFilter> erode(SkErodeImageFilter::Make(4, 4, blur));
- sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Create(cf.get(), erode.get()));
+ sk_sp<SkImageFilter> color(SkColorFilterImageFilter::Make(std::move(cf),
+ std::move(erode)));
sk_sp<SkImageFilter> merge(SkMergeImageFilter::Make(blur, color));
SkPaint paint;
0, 0, 0, 0.5f, 0 };
sk_sp<SkColorFilter> matrixFilter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Create(matrixFilter.get(),
- morph.get()));
+ sk_sp<SkImageFilter> colorMorph(SkColorFilterImageFilter::Make(std::move(matrixFilter),
+ std::move(morph)));
SkPaint paint;
paint.setImageFilter(SkXfermodeImageFilter::Make(
SkXfermode::Make(SkXfermode::kSrcOver_Mode),
0, 0, SK_Scalar1, 0, 0,
0, 0, 0, 0.5f, 0 };
sk_sp<SkColorFilter> matrixCF(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Create(matrixCF.get()));
+ sk_sp<SkImageFilter> matrixFilter(SkColorFilterImageFilter::Make(std::move(matrixCF),
+ nullptr));
sk_sp<SkImageFilter> offsetFilter(SimpleOffsetFilter::Make(10.0f, 10.f, matrixFilter));
SkPaint paint;
}
{
// Test that crop offsets are absolute, not relative to the parent's crop rect.
- auto cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- auto cf2(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
+ sk_sp<SkColorFilter> cf1(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+ SkXfermode::kSrcIn_Mode));
+ sk_sp<SkColorFilter> 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)));
- sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Create(cf1.get(),
- nullptr,
- &outerRect));
- sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Create(cf2.get(),
- color1.get(),
- &innerRect));
+ sk_sp<SkImageFilter> color1(SkColorFilterImageFilter::Make(std::move(cf1),
+ nullptr,
+ &outerRect));
+ sk_sp<SkImageFilter> color2(SkColorFilterImageFilter::Make(std::move(cf2),
+ std::move(color1),
+ &innerRect));
SkPaint paint;
paint.setImageFilter(std::move(color2));
// This detector detects that image filter phase of the pixel pipeline receives the correct value.
static void install_detector_image_filter(SkPaint* drawPaint) {
- auto colorFilter(make_detector_color_filter());
- SkImageFilter* imageFilter =
- SkColorFilterImageFilter::Create(colorFilter.get(), drawPaint->getImageFilter());
- drawPaint->setImageFilter(imageFilter)->unref();
+ sk_sp<SkColorFilter> colorFilter(make_detector_color_filter());
+ sk_sp<SkImageFilter> imageFilter(
+ SkColorFilterImageFilter::Make(std::move(colorFilter),
+ sk_ref_sp(drawPaint->getImageFilter())));
+ drawPaint->setImageFilter(std::move(imageFilter));
}
static void no_detector_install(SkPaint*) {
paint.setColorFilter(nullptr);
for (unsigned i = 0; i < SK_ARRAY_COUNT(gColorFilterMakers); ++i) {
- auto colorFilter1(gColorFilterMakers[i]());
- SkAutoTUnref<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Create(
- colorFilter1.get(), nullptr, nullptr));
+ sk_sp<SkColorFilter> colorFilter1(gColorFilterMakers[i]());
+ sk_sp<SkImageFilter> imageFilter1(SkColorFilterImageFilter::Make(
+ std::move(colorFilter1), 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) {
- auto colorFilter2(gColorFilterMakers[j]());
- SkAutoTUnref<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Create(
- colorFilter2.get(), imageFilter1, nullptr));
- paint.setImageFilter(imageFilter2);
+ sk_sp<SkColorFilter> colorFilter2(gColorFilterMakers[j]());
+ sk_sp<SkImageFilter> imageFilter2(SkColorFilterImageFilter::Make(
+ std::move(colorFilter2), imageFilter1, nullptr));
+ paint.setImageFilter(std::move(imageFilter2));
canvas->drawBitmap(bm, x, y, &paint);
x += xOffset;
}
static sk_sp<SkImageFilter> make2() {
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- return sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get()));
+ return SkColorFilterImageFilter::Make(std::move(cf), nullptr);
}
static sk_sp<SkImageFilter> make3() {
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
- sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
+ sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
}
sk_sp<SkImageFilter> compose(SkComposeImageFilter::Make(std::move(outer), std::move(inner)));
sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(0x880000FF, SkXfermode::kSrcIn_Mode));
- sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Create(cf.get()));
+ sk_sp<SkImageFilter> blue(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
return SkMergeImageFilter::Make(std::move(compose), std::move(blue));
}
SkIntToScalar(fBitmap->height()));
SkRect dstRect = SkRect::MakeWH(SkIntToScalar(fBitmap->width() * 2),
SkIntToScalar(fBitmap->height() * 2));
- SkAutoTUnref<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
- auto cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ sk_sp<SkImageFilter> tile(SkTileImageFilter::Create(srcRect, dstRect, nullptr));
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- SkAutoTUnref<SkImageFilter> cfif(SkColorFilterImageFilter::Create(cf.get(), tile.get()));
SkPaint paint;
- paint.setImageFilter(cfif);
+ paint.setImageFilter(SkColorFilterImageFilter::Make(std::move(cf), std::move(tile)));
canvas->save();
canvas->translate(SkIntToScalar(x), SkIntToScalar(y));
canvas->clipRect(dstRect);
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(5, 5, 40, 40));
sk_sp<SkColorFilter> greenCF = SkColorFilter::MakeModeFilter(SK_ColorGREEN,
SkXfermode::kSrc_Mode);
- SkAutoTUnref<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get(), nullptr,
- &cropRect));
- tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green));
+ sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(std::move(greenCF),
+ nullptr,
+ &cropRect));
+ tile.reset(SkTileImageFilter::Create(srcRect, dstRect, green.get()));
paint.setColor(SK_ColorRED);
- paint.setImageFilter(tile);
+ paint.setImageFilter(std::move(tile));
canvas->drawRect(dstRect, paint);
}
private:
class SK_API SkColorFilterImageFilter : public SkImageFilter {
public:
- static SkImageFilter* Create(SkColorFilter* cf, SkImageFilter* input = NULL,
- const CropRect* cropRect = NULL);
+ static sk_sp<SkImageFilter> Make(sk_sp<SkColorFilter> cf,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect = NULL);
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorFilterImageFilter)
+#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
+ static SkImageFilter* Create(SkColorFilter* cf,
+ SkImageFilter* input = NULL,
+ const CropRect* cropRect = NULL) {
+ return Make(sk_ref_sp<SkColorFilter>(cf),
+ sk_ref_sp<SkImageFilter>(input),
+ cropRect).release();
+ }
+#endif
+
protected:
void flatten(SkWriteBuffer&) const override;
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
bool affectsTransparentBlack() const override;
private:
- SkColorFilterImageFilter(SkColorFilter* cf,
- SkImageFilter* input,
+ SkColorFilterImageFilter(sk_sp<SkColorFilter> cf,
+ sk_sp<SkImageFilter> input,
const CropRect* cropRect);
sk_sp<SkColorFilter> fColorFilter;
break;
case COLOR: {
sk_sp<SkColorFilter> cf(make_color_filter());
- sk_sp<SkImageFilter> subFilter(make_image_filter());
- filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
- subFilter.get()))
+ filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter())
: nullptr;
break;
}
case LUT3D: {
int cubeDimension;
sk_sp<SkData> lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1)));
- sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(lut3D, cubeDimension));
- sk_sp<SkImageFilter> subFilter(make_image_filter());
- filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
- subFilter.get()))
+ sk_sp<SkColorFilter> cf(SkColorCubeFilter::Make(std::move(lut3D), cubeDimension));
+ filter = cf ? SkColorFilterImageFilter::Make(std::move(cf), make_image_filter())
: nullptr;
break;
}
#include "SkSpecialSurface.h"
#include "SkWriteBuffer.h"
-SkImageFilter* SkColorFilterImageFilter::Create(SkColorFilter* cf, SkImageFilter* input,
- const CropRect* cropRect) {
+sk_sp<SkImageFilter> SkColorFilterImageFilter::Make(sk_sp<SkColorFilter> cf,
+ sk_sp<SkImageFilter> input,
+ const CropRect* cropRect) {
if (!cf) {
return nullptr;
}
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.
- sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(sk_ref_sp(cf),
+ sk_sp<SkColorFilter> newCF(SkColorFilter::MakeComposeFilter(cf,// can't move bc of fallthru
sk_sp<SkColorFilter>(inputCF)));
if (newCF) {
- return new SkColorFilterImageFilter(newCF.get(), input->getInput(0), cropRect);
+ return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(newCF),
+ sk_ref_sp(input->getInput(0)),
+ cropRect));
}
}
- return new SkColorFilterImageFilter(cf, input, cropRect);
+ return sk_sp<SkImageFilter>(new SkColorFilterImageFilter(std::move(cf),
+ std::move(input),
+ cropRect));
}
-SkColorFilterImageFilter::SkColorFilterImageFilter(SkColorFilter* cf,
- SkImageFilter* input,
+SkColorFilterImageFilter::SkColorFilterImageFilter(sk_sp<SkColorFilter> cf,
+ sk_sp<SkImageFilter> input,
const CropRect* cropRect)
- : INHERITED(1, &input, cropRect)
- , fColorFilter(SkRef(cf)) {
+ : INHERITED(&input, 1, cropRect)
+ , fColorFilter(std::move(cf)) {
}
sk_sp<SkFlattenable> SkColorFilterImageFilter::CreateProc(SkReadBuffer& buffer) {
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
sk_sp<SkColorFilter> cf(buffer.readColorFilter());
- return sk_sp<SkFlattenable>(Create(cf.get(), common.getInput(0).get(), &common.cropRect()));
+ return Make(std::move(cf), common.getInput(0), &common.cropRect());
}
void SkColorFilterImageFilter::flatten(SkWriteBuffer& buffer) const {
SkXfermode::kSrcIn_Mode));
this->addFilter("color filter",
- SkColorFilterImageFilter::Create(cf.get(), input.get(), cropRect));
+ SkColorFilterImageFilter::Make(cf, input, cropRect).release());
}
{
return surface->makeImageSnapshot();
}
-static SkImageFilter* make_scale(float amount, SkImageFilter* input = nullptr) {
+static sk_sp<SkImageFilter> make_scale(float amount, sk_sp<SkImageFilter> input) {
SkScalar s = amount;
SkScalar matrix[20] = { s, 0, 0, 0, 0,
0, s, 0, 0, 0,
0, 0, s, 0, 0,
0, 0, 0, s, 0 };
- auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Create(filter.get(), input);
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input));
}
-static SkImageFilter* make_grayscale(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
+static sk_sp<SkImageFilter> make_grayscale(sk_sp<SkImageFilter> input,
+ const SkImageFilter::CropRect* cropRect) {
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;
- auto filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
- return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeMatrixFilterRowMajor255(matrix));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
}
-static SkImageFilter* make_blue(SkImageFilter* input, const SkImageFilter::CropRect* cropRect) {
- auto filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE, SkXfermode::kSrcIn_Mode));
- return SkColorFilterImageFilter::Create(filter.get(), input, cropRect);
+static sk_sp<SkImageFilter> make_blue(sk_sp<SkImageFilter> input,
+ const SkImageFilter::CropRect* cropRect) {
+ sk_sp<SkColorFilter> filter(SkColorFilter::MakeModeFilter(SK_ColorBLUE,
+ SkXfermode::kSrcIn_Mode));
+ return SkColorFilterImageFilter::Make(std::move(filter), std::move(input), cropRect);
}
static sk_sp<SkSpecialSurface> create_empty_special_surface(GrContext* context,
DEF_TEST(ImageFilter, reporter) {
{
// Check that two non-clipping color-matrice-filters concatenate into a single filter.
- SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f));
- SkAutoTUnref<SkImageFilter> quarterBrightness(make_scale(0.5f, halfBrightness));
+ sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, nullptr));
+ sk_sp<SkImageFilter> quarterBrightness(make_scale(0.5f, std::move(halfBrightness)));
REPORTER_ASSERT(reporter, nullptr == quarterBrightness->getInput(0));
SkColorFilter* cf;
REPORTER_ASSERT(reporter, quarterBrightness->asColorFilter(&cf));
{
// Check that a clipping color-matrice-filter followed by a color-matrice-filters
// concatenates into a single filter, but not a matrixfilter (due to clamping).
- SkAutoTUnref<SkImageFilter> doubleBrightness(make_scale(2.0f));
- SkAutoTUnref<SkImageFilter> halfBrightness(make_scale(0.5f, doubleBrightness));
+ sk_sp<SkImageFilter> doubleBrightness(make_scale(2.0f, nullptr));
+ sk_sp<SkImageFilter> halfBrightness(make_scale(0.5f, std::move(doubleBrightness)));
REPORTER_ASSERT(reporter, nullptr == halfBrightness->getInput(0));
SkColorFilter* cf;
REPORTER_ASSERT(reporter, halfBrightness->asColorFilter(&cf));
{
// Check that a color filter image filter without a crop rect can be
// expressed as a color filter.
- SkAutoTUnref<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
+ sk_sp<SkImageFilter> gray(make_grayscale(nullptr, nullptr));
REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
}
{
// Check that a colorfilterimage filter without a crop rect but with an input
// that is another colorfilterimage can be expressed as a colorfilter (composed).
- SkAutoTUnref<SkImageFilter> mode(make_blue(nullptr, nullptr));
- SkAutoTUnref<SkImageFilter> gray(make_grayscale(mode, nullptr));
+ sk_sp<SkImageFilter> mode(make_blue(nullptr, nullptr));
+ sk_sp<SkImageFilter> gray(make_grayscale(std::move(mode), nullptr));
REPORTER_ASSERT(reporter, true == gray->asColorFilter(nullptr));
}
{
// Test that if we exceed the limit of what ComposeColorFilter can combine, we still
// can build the DAG and won't assert if we call asColorFilter.
- SkAutoTUnref<SkImageFilter> filter(make_blue(nullptr, nullptr));
+ sk_sp<SkImageFilter> filter(make_blue(nullptr, nullptr));
const int kWayTooManyForComposeColorFilter = 100;
for (int i = 0; i < kWayTooManyForComposeColorFilter; ++i) {
- filter.reset(make_blue(filter, nullptr));
+ filter = make_blue(filter, nullptr);
// the first few of these will succeed, but after we hit the internal limit,
// it will then return false.
(void)filter->asColorFilter(nullptr);
// Check that a color filter image filter with a crop rect cannot
// be expressed as a color filter.
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(0, 0, 100, 100));
- SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
+ sk_sp<SkImageFilter> grayWithCrop(make_grayscale(nullptr, &cropRect));
REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(nullptr));
}
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
SkScalar redToGreenMatrix[20] = { 0 };
redToGreenMatrix[5] = redToGreenMatrix[18] = SK_Scalar1;
- auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
- SkAutoTUnref<SkImageFilter> filter1(SkColorFilterImageFilter::Create(blueToRed.get()));
- auto redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
- SkAutoTUnref<SkImageFilter> filter2(SkColorFilterImageFilter::Create(redToGreen.get(), filter1.get()));
+ sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
+ sk_sp<SkImageFilter> filter1(SkColorFilterImageFilter::Make(std::move(blueToRed),
+ nullptr));
+ sk_sp<SkColorFilter> redToGreen(SkColorFilter::MakeMatrixFilterRowMajor255(redToGreenMatrix));
+ sk_sp<SkImageFilter> filter2(SkColorFilterImageFilter::Make(std::move(redToGreen),
+ std::move(filter1)));
SkBitmap result;
result.allocN32Pixels(kBitmapSize, kBitmapSize);
SkPaint paint;
paint.setColor(SK_ColorBLUE);
- paint.setImageFilter(filter2.get());
+ paint.setImageFilter(std::move(filter2));
SkCanvas canvas(result);
canvas.clear(0x0);
SkRect rect = SkRect::Make(SkIRect::MakeWH(kBitmapSize, kBitmapSize));
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(0, 0, 1, 1), nullptr);
sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
SkASSERT(green->affectsTransparentBlack());
- sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get(),
- failFilter.get()));
+ sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(std::move(green),
+ std::move(failFilter)));
SkIPoint offset;
sk_sp<SkSpecialImage> result(greenFilter->filterImage(source.get(), ctx, &offset));
REPORTER_ASSERT(reporter, nullptr != result.get());
SkMatrix matrix;
matrix.setTranslate(SkIntToScalar(50), 0);
- 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()));
+ sk_sp<SkColorFilter> cf(SkColorFilter::MakeModeFilter(SK_ColorWHITE, SkXfermode::kSrc_Mode));
+ sk_sp<SkImageFilter> cfif(SkColorFilterImageFilter::Make(std::move(cf), nullptr));
+ sk_sp<SkImageFilter> imageFilter(SkImageFilter::CreateMatrixFilter(matrix,
+ kNone_SkFilterQuality,
+ cfif.get()));
SkPaint paint;
- paint.setImageFilter(imageFilter.get());
+ paint.setImageFilter(std::move(imageFilter));
SkPictureRecorder recorder;
SkRect bounds = SkRect::Make(SkIRect::MakeXYWH(0, 0, 50, 50));
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
SkRTreeFactory factory;
SkPictureRecorder recorder;
- auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrc_Mode));
- SkAutoTUnref<SkImageFilter> imageFilter(
- SkColorFilterImageFilter::Create(green.get()));
+ sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
+ SkXfermode::kSrc_Mode));
+ sk_sp<SkImageFilter> imageFilter(SkColorFilterImageFilter::Make(green, nullptr));
SkPaint imageFilterPaint;
- imageFilterPaint.setImageFilter(imageFilter.get());
+ imageFilterPaint.setImageFilter(std::move(imageFilter));
SkPaint colorFilterPaint;
colorFilterPaint.setColorFilter(green);
bitmap.allocN32Pixels(1, 1);
bitmap.eraseARGB(255, 255, 255, 255);
- auto green(SkColorFilter::MakeModeFilter(SK_ColorGREEN, SkXfermode::kSrcIn_Mode));
- SkAutoTUnref<SkImageFilter> greenFilter(SkColorFilterImageFilter::Create(green.get()));
+ sk_sp<SkColorFilter> green(SkColorFilter::MakeModeFilter(SK_ColorGREEN,
+ SkXfermode::kSrcIn_Mode));
+ sk_sp<SkImageFilter> greenFilter(SkColorFilterImageFilter::Make(green, nullptr));
SkImageFilter::CropRect cropRect(SkRect::MakeEmpty());
- SkAutoTUnref<SkImageFilter> croppedOut(
- SkColorFilterImageFilter::Create(green.get(), nullptr, &cropRect));
+ sk_sp<SkImageFilter> croppedOut(SkColorFilterImageFilter::Make(green, nullptr, &cropRect));
// Check that an xfermode image filter whose input has been cropped out still draws the other
// input. Also check that drawing with both inputs cropped out doesn't cause a GPU warning.
auto mode = SkXfermode::Make(SkXfermode::kSrcOver_Mode);
- auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode, greenFilter, croppedOut, nullptr));
- auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, greenFilter, nullptr));
- auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode, croppedOut, croppedOut, nullptr));
+ auto xfermodeNoFg(SkXfermodeImageFilter::Make(mode,
+ greenFilter.get(), croppedOut.get(), nullptr));
+ auto xfermodeNoBg(SkXfermodeImageFilter::Make(mode,
+ croppedOut.get(), greenFilter.get(), nullptr));
+ auto xfermodeNoFgNoBg(SkXfermodeImageFilter::Make(mode,
+ croppedOut.get(),
+ croppedOut.get(), nullptr));
SkPaint paint;
paint.setImageFilter(xfermodeNoFg);
SkImageFilter::CropRect cropRect(SkRect::MakeXYWH(100, 0, 20, 30),
SkImageFilter::CropRect::kHasWidth_CropEdge | SkImageFilter::CropRect::kHasHeight_CropEdge);
- SkAutoTUnref<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
+ sk_sp<SkImageFilter> filter(make_grayscale(nullptr, &cropRect));
SkIPoint offset;
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeWH(100, 100), nullptr);
0, 0, 0, 0, 0,
0, 0, 0, 0, 1 };
sk_sp<SkColorFilter> greenCF(SkColorFilter::MakeMatrixFilterRowMajor255(greenMatrix));
- sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Create(greenCF.get()));
+ sk_sp<SkImageFilter> green(SkColorFilterImageFilter::Make(greenCF, nullptr));
REPORTER_ASSERT(reporter, greenCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, !green->canComputeFastBounds());
allOne[i] = 255;
}
- auto identityCF(SkTableColorFilter::MakeARGB(identity, identity, identity, allOne));
- SkAutoTUnref<SkImageFilter> identityFilter(SkColorFilterImageFilter::Create(identityCF.get()));
+ sk_sp<SkColorFilter> identityCF(SkTableColorFilter::MakeARGB(identity, identity,
+ identity, allOne));
+ sk_sp<SkImageFilter> identityFilter(SkColorFilterImageFilter::Make(identityCF, nullptr));
REPORTER_ASSERT(reporter, !identityCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, identityFilter->canComputeFastBounds());
- auto forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity, identity, identity));
- SkAutoTUnref<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Create(forceOpaqueCF.get()));
+ sk_sp<SkColorFilter> forceOpaqueCF(SkTableColorFilter::MakeARGB(allOne, identity,
+ identity, identity));
+ sk_sp<SkImageFilter> forceOpaque(SkColorFilterImageFilter::Make(forceOpaqueCF, nullptr));
REPORTER_ASSERT(reporter, forceOpaqueCF->affectsTransparentBlack());
REPORTER_ASSERT(reporter, !forceOpaque->canComputeFastBounds());
}
// optimize away
SkScalar blueToRedMatrix[20] = { 0 };
blueToRedMatrix[2] = blueToRedMatrix[18] = SK_Scalar1;
- auto blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
- SkAutoTUnref<SkImageFilter> filter(SkColorFilterImageFilter::Create(blueToRed.get()));
+ sk_sp<SkColorFilter> blueToRed(SkColorFilter::MakeMatrixFilterRowMajor255(blueToRedMatrix));
+ sk_sp<SkImageFilter> filter(SkColorFilterImageFilter::Make(std::move(blueToRed), nullptr));
SkPaint complexPaint;
- complexPaint.setImageFilter(filter);
+ complexPaint.setImageFilter(std::move(filter));
sk_sp<SkPicture> pict, child;
SkRTreeFactory bbhFactory;