Swap SkPictureImageFilter's factories over to smart pointers
A trial balloon before converting the rest This requires https://codereview.chromium.org/1836443003/ (add SK_SUPPORT_LEGACY_IMAGEFILTER_PTR flag for future skia CL) to land in Chromium first GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1831323003 Review URL: https://codereview.chromium.org/1831323003
This commit is contained in:
parent
02b2f1900d
commit
5ff17b1352
@ -256,10 +256,10 @@ protected:
|
||||
pic = rec.finishRecordingAsPicture();
|
||||
}
|
||||
|
||||
SkAutoTUnref<SkImageFilter> pif(SkPictureImageFilter::Create(pic.get()));
|
||||
sk_sp<SkImageFilter> pif(SkPictureImageFilter::Make(pic));
|
||||
|
||||
SkTArray<SkPaint> pifPaints;
|
||||
create_paints(pif, &pifPaints);
|
||||
create_paints(pif.get(), &pifPaints);
|
||||
|
||||
//-----------
|
||||
// Paints with a SkImageSource as a source
|
||||
|
@ -12,43 +12,44 @@
|
||||
|
||||
// This GM exercises the SkPictureImageFilter ImageFilter class.
|
||||
|
||||
static void fill_rect_filtered(SkCanvas* canvas,
|
||||
const SkRect& clipRect,
|
||||
sk_sp<SkImageFilter> filter) {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(filter);
|
||||
canvas->save();
|
||||
canvas->clipRect(clipRect);
|
||||
canvas->drawPaint(paint);
|
||||
canvas->restore();
|
||||
}
|
||||
|
||||
static sk_sp<SkPicture> make_picture() {
|
||||
SkPictureRecorder recorder;
|
||||
SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0);
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
sk_tool_utils::set_portable_typeface(&paint);
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
paint.setTextSize(SkIntToScalar(96));
|
||||
const char* str = "e";
|
||||
canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
|
||||
return recorder.finishRecordingAsPicture();
|
||||
}
|
||||
|
||||
class PictureImageFilterGM : public skiagm::GM {
|
||||
public:
|
||||
PictureImageFilterGM() {
|
||||
}
|
||||
PictureImageFilterGM() { }
|
||||
|
||||
protected:
|
||||
SkString onShortName() override {
|
||||
return SkString("pictureimagefilter");
|
||||
}
|
||||
|
||||
void makePicture() {
|
||||
SkPictureRecorder recorder;
|
||||
SkCanvas* canvas = recorder.beginRecording(100, 100, nullptr, 0);
|
||||
canvas->clear(SK_ColorBLACK);
|
||||
SkPaint paint;
|
||||
paint.setAntiAlias(true);
|
||||
sk_tool_utils::set_portable_typeface(&paint);
|
||||
paint.setColor(0xFFFFFFFF);
|
||||
paint.setTextSize(SkIntToScalar(96));
|
||||
const char* str = "e";
|
||||
canvas->drawText(str, strlen(str), SkIntToScalar(20), SkIntToScalar(70), paint);
|
||||
fPicture = recorder.finishRecordingAsPicture();
|
||||
}
|
||||
|
||||
SkISize onISize() override { return SkISize::Make(600, 300); }
|
||||
|
||||
void onOnceBeforeDraw() override {
|
||||
this->makePicture();
|
||||
}
|
||||
|
||||
static void fillRectFiltered(SkCanvas* canvas, const SkRect& clipRect, SkImageFilter* filter) {
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(filter);
|
||||
canvas->save();
|
||||
canvas->clipRect(clipRect);
|
||||
canvas->drawPaint(paint);
|
||||
canvas->restore();
|
||||
fPicture = make_picture();
|
||||
}
|
||||
|
||||
void onDraw(SkCanvas* canvas) override {
|
||||
@ -57,30 +58,31 @@ protected:
|
||||
SkRect srcRect = SkRect::MakeXYWH(20, 20, 30, 30);
|
||||
SkRect emptyRect = SkRect::MakeXYWH(20, 20, 0, 0);
|
||||
SkRect bounds = SkRect::MakeXYWH(0, 0, 100, 100);
|
||||
SkAutoTUnref<SkImageFilter> pictureSource(
|
||||
SkPictureImageFilter::Create(fPicture.get()));
|
||||
SkAutoTUnref<SkImageFilter> pictureSourceSrcRect(
|
||||
SkPictureImageFilter::Create(fPicture.get(), srcRect));
|
||||
SkAutoTUnref<SkImageFilter> pictureSourceEmptyRect(
|
||||
SkPictureImageFilter::Create(fPicture.get(), emptyRect));
|
||||
SkAutoTUnref<SkImageFilter> pictureSourceResampled(
|
||||
SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
|
||||
kLow_SkFilterQuality));
|
||||
SkAutoTUnref<SkImageFilter> pictureSourcePixelated(
|
||||
SkPictureImageFilter::CreateForLocalSpace(fPicture.get(), fPicture->cullRect(),
|
||||
kNone_SkFilterQuality));
|
||||
sk_sp<SkImageFilter> pictureSource(SkPictureImageFilter::Make(fPicture));
|
||||
sk_sp<SkImageFilter> pictureSourceSrcRect(SkPictureImageFilter::Make(fPicture,
|
||||
srcRect));
|
||||
sk_sp<SkImageFilter> pictureSourceEmptyRect(SkPictureImageFilter::Make(fPicture,
|
||||
emptyRect));
|
||||
sk_sp<SkImageFilter> pictureSourceResampled(SkPictureImageFilter::MakeForLocalSpace(
|
||||
fPicture,
|
||||
fPicture->cullRect(),
|
||||
kLow_SkFilterQuality));
|
||||
sk_sp<SkImageFilter> pictureSourcePixelated(SkPictureImageFilter::MakeForLocalSpace(
|
||||
fPicture,
|
||||
fPicture->cullRect(),
|
||||
kNone_SkFilterQuality));
|
||||
|
||||
canvas->save();
|
||||
// Draw the picture unscaled.
|
||||
fillRectFiltered(canvas, bounds, pictureSource);
|
||||
fill_rect_filtered(canvas, bounds, pictureSource);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
// Draw an unscaled subset of the source picture.
|
||||
fillRectFiltered(canvas, bounds, pictureSourceSrcRect);
|
||||
fill_rect_filtered(canvas, bounds, pictureSourceSrcRect);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
// Draw the picture to an empty rect (should draw nothing).
|
||||
fillRectFiltered(canvas, bounds, pictureSourceEmptyRect);
|
||||
fill_rect_filtered(canvas, bounds, pictureSourceEmptyRect);
|
||||
canvas->translate(SkIntToScalar(100), 0);
|
||||
|
||||
canvas->restore();
|
||||
@ -89,20 +91,21 @@ protected:
|
||||
canvas->translate(0, SkIntToScalar(100));
|
||||
canvas->scale(200 / srcRect.width(), 200 / srcRect.height());
|
||||
canvas->translate(-srcRect.fLeft, -srcRect.fTop);
|
||||
fillRectFiltered(canvas, srcRect, pictureSource);
|
||||
fill_rect_filtered(canvas, srcRect, pictureSource);
|
||||
|
||||
// Draw the picture scaled, but rasterized at original resolution
|
||||
canvas->translate(srcRect.width(), 0);
|
||||
fillRectFiltered(canvas, srcRect, pictureSourceResampled);
|
||||
fill_rect_filtered(canvas, srcRect, pictureSourceResampled);
|
||||
|
||||
// Draw the picture scaled, pixelated
|
||||
canvas->translate(srcRect.width(), 0);
|
||||
fillRectFiltered(canvas, srcRect, pictureSourcePixelated);
|
||||
fill_rect_filtered(canvas, srcRect, pictureSourcePixelated);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
sk_sp<SkPicture> fPicture;
|
||||
|
||||
typedef GM INHERITED;
|
||||
};
|
||||
|
||||
|
@ -117,7 +117,7 @@ static void draw_svg_opacity_and_filter_layer_sequence(SkCanvas* canvas, SkColor
|
||||
canvas->save();
|
||||
canvas->clipRect(targetRect);
|
||||
SkPaint drawPaint;
|
||||
drawPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))->unref();
|
||||
drawPaint.setImageFilter(SkPictureImageFilter::Make(shape));
|
||||
installDetector(&drawPaint);
|
||||
canvas->saveLayer(&targetRect, &drawPaint);
|
||||
canvas->restore();
|
||||
|
@ -16,17 +16,19 @@ public:
|
||||
/**
|
||||
* Refs the passed-in picture.
|
||||
*/
|
||||
static SkImageFilter* Create(const SkPicture* picture) {
|
||||
return new SkPictureImageFilter(picture);
|
||||
static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture) {
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Refs the passed-in picture. cropRect can be used to crop or expand the destination rect when
|
||||
* the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.)
|
||||
*/
|
||||
static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) {
|
||||
return new SkPictureImageFilter(picture, cropRect, kDeviceSpace_PictureResolution,
|
||||
kLow_SkFilterQuality);
|
||||
static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture, const SkRect& cropRect) {
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture),
|
||||
cropRect,
|
||||
kDeviceSpace_PictureResolution,
|
||||
kLow_SkFilterQuality));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,13 +38,31 @@ public:
|
||||
* expand the destination rect when the picture is drawn. (No scaling is implied by the
|
||||
* dest rect; only the CTM is applied.)
|
||||
*/
|
||||
static SkImageFilter* CreateForLocalSpace(const SkPicture* picture,
|
||||
const SkRect& cropRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
return new SkPictureImageFilter(picture, cropRect, kLocalSpace_PictureResolution,
|
||||
filterQuality);
|
||||
static sk_sp<SkImageFilter> MakeForLocalSpace(sk_sp<SkPicture> picture,
|
||||
const SkRect& cropRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture),
|
||||
cropRect,
|
||||
kLocalSpace_PictureResolution,
|
||||
filterQuality));
|
||||
}
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkPicture* picture) {
|
||||
return Make(sk_ref_sp(const_cast<SkPicture*>(picture))).release();
|
||||
}
|
||||
static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) {
|
||||
return Make(sk_ref_sp(const_cast<SkPicture*>(picture)), cropRect).release();
|
||||
}
|
||||
static SkImageFilter* CreateForLocalSpace(const SkPicture* picture,
|
||||
const SkRect& cropRect,
|
||||
SkFilterQuality filterQuality) {
|
||||
return MakeForLocalSpace(sk_ref_sp(const_cast<SkPicture*>(picture)),
|
||||
cropRect,
|
||||
filterQuality).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
|
||||
|
||||
@ -52,8 +72,6 @@ protected:
|
||||
kLocalSpace_PictureResolution
|
||||
};
|
||||
|
||||
virtual ~SkPictureImageFilter();
|
||||
|
||||
/* Constructs an SkPictureImageFilter object from an SkReadBuffer.
|
||||
* Note: If the SkPictureImageFilter object construction requires bitmap
|
||||
* decoding, the decoder must be set on the SkReadBuffer parameter by calling
|
||||
@ -65,8 +83,8 @@ protected:
|
||||
SkIPoint* offset) const override;
|
||||
|
||||
private:
|
||||
explicit SkPictureImageFilter(const SkPicture* picture);
|
||||
SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect,
|
||||
explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
|
||||
SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
|
||||
PictureResolution, SkFilterQuality);
|
||||
|
||||
void drawPictureAtDeviceResolution(SkBaseDevice*, const SkIRect& deviceBounds,
|
||||
@ -74,7 +92,7 @@ private:
|
||||
void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds,
|
||||
const Context&) const;
|
||||
|
||||
const SkPicture* fPicture;
|
||||
sk_sp<SkPicture> fPicture;
|
||||
SkRect fCropRect;
|
||||
PictureResolution fPictureResolution;
|
||||
SkFilterQuality fFilterQuality;
|
||||
|
@ -701,7 +701,7 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
&factory, 0);
|
||||
drawSomething(recordingCanvas);
|
||||
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
|
||||
filter = SkPictureImageFilter::Create(pict.get(), make_rect());
|
||||
filter = SkPictureImageFilter::Make(pict, make_rect()).release();
|
||||
}
|
||||
break;
|
||||
case PAINT:
|
||||
|
@ -13,28 +13,24 @@
|
||||
#include "SkWriteBuffer.h"
|
||||
#include "SkValidationUtils.h"
|
||||
|
||||
SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture)
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
|
||||
: INHERITED(0, 0, nullptr)
|
||||
, fPicture(SkSafeRef(picture))
|
||||
, fCropRect(picture ? picture->cullRect() : SkRect::MakeEmpty())
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty())
|
||||
, fPictureResolution(kDeviceSpace_PictureResolution)
|
||||
, fFilterQuality(kLow_SkFilterQuality) {
|
||||
}
|
||||
|
||||
SkPictureImageFilter::SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect,
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
|
||||
PictureResolution pictureResolution,
|
||||
SkFilterQuality filterQuality)
|
||||
: INHERITED(0, 0, nullptr)
|
||||
, fPicture(SkSafeRef(picture))
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(cropRect)
|
||||
, fPictureResolution(pictureResolution)
|
||||
, fFilterQuality(filterQuality) {
|
||||
}
|
||||
|
||||
SkPictureImageFilter::~SkPictureImageFilter() {
|
||||
SkSafeUnref(fPicture);
|
||||
}
|
||||
|
||||
SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
sk_sp<SkPicture> picture;
|
||||
SkRect cropRect;
|
||||
@ -62,9 +58,9 @@ SkFlattenable* SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
} else {
|
||||
filterQuality = (SkFilterQuality)buffer.readInt();
|
||||
}
|
||||
return CreateForLocalSpace(picture.get(), cropRect, filterQuality);
|
||||
return MakeForLocalSpace(picture, cropRect, filterQuality).release();
|
||||
}
|
||||
return Create(picture.get(), cropRect);
|
||||
return Make(picture, cropRect).release();
|
||||
}
|
||||
|
||||
void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -134,7 +134,7 @@ public:
|
||||
greenPaint.setColor(SK_ColorGREEN);
|
||||
recordingCanvas->drawRect(SkRect::Make(SkIRect::MakeXYWH(10, 10, 30, 20)), greenPaint);
|
||||
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
|
||||
SkAutoTUnref<SkImageFilter> pictureFilter(SkPictureImageFilter::Create(picture.get()));
|
||||
sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture));
|
||||
sk_sp<SkShader> shader(SkPerlinNoiseShader::MakeTurbulence(SK_Scalar1, SK_Scalar1, 1, 0));
|
||||
|
||||
SkPaint paint;
|
||||
@ -1024,18 +1024,17 @@ DEF_TEST(ImageFilterCrossProcessPictureImageFilter, reporter) {
|
||||
sk_sp<SkPicture> picture(recorder.finishRecordingAsPicture());
|
||||
|
||||
// Wrap that SkPicture in an SkPictureImageFilter.
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(
|
||||
SkPictureImageFilter::Create(picture.get()));
|
||||
sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture));
|
||||
|
||||
// Check that SkPictureImageFilter successfully serializes its contained
|
||||
// SkPicture when not in cross-process mode.
|
||||
SkPaint paint;
|
||||
paint.setImageFilter(imageFilter.get());
|
||||
paint.setImageFilter(imageFilter);
|
||||
SkPictureRecorder outerRecorder;
|
||||
SkCanvas* outerCanvas = outerRecorder.beginRecording(1, 1, &factory, 0);
|
||||
SkPaint redPaintWithFilter;
|
||||
redPaintWithFilter.setColor(SK_ColorRED);
|
||||
redPaintWithFilter.setImageFilter(imageFilter.get());
|
||||
redPaintWithFilter.setImageFilter(imageFilter);
|
||||
outerCanvas->drawRect(SkRect::Make(SkIRect::MakeWH(1, 1)), redPaintWithFilter);
|
||||
sk_sp<SkPicture> outerPicture(outerRecorder.finishRecordingAsPicture());
|
||||
|
||||
@ -1091,7 +1090,7 @@ static void test_clipped_picture_imagefilter(SkImageFilter::Proxy* proxy,
|
||||
|
||||
sk_sp<SkSpecialImage> srcImg(create_empty_special_image(context, proxy, 2));
|
||||
|
||||
SkAutoTUnref<SkImageFilter> imageFilter(SkPictureImageFilter::Create(picture.get()));
|
||||
sk_sp<SkImageFilter> imageFilter(SkPictureImageFilter::Make(picture));
|
||||
|
||||
SkIPoint offset;
|
||||
SkImageFilter::Context ctx(SkMatrix::I(), SkIRect::MakeXYWH(1, 1, 1, 1), nullptr);
|
||||
@ -1379,8 +1378,7 @@ static void test_composed_imagefilter_bounds(SkImageFilter::Proxy* proxy,
|
||||
recordingCanvas->clipRect(SkRect::MakeXYWH(100, 0, 100, 100));
|
||||
recordingCanvas->clear(SK_ColorGREEN);
|
||||
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
|
||||
sk_sp<SkImageFilter> pictureFilter(
|
||||
SkPictureImageFilter::Create(picture.get()));
|
||||
sk_sp<SkImageFilter> pictureFilter(SkPictureImageFilter::Make(picture));
|
||||
SkImageFilter::CropRect cropRect(SkRect::MakeWH(100, 100));
|
||||
sk_sp<SkImageFilter> offsetFilter(SkOffsetImageFilter::Create(-100, 0, nullptr, &cropRect));
|
||||
sk_sp<SkImageFilter> composedFilter(
|
||||
|
@ -239,7 +239,7 @@ DEF_TEST(RecordOpts_MergeSvgOpacityAndFilterLayers, r) {
|
||||
canvas->drawRect(SkRect::MakeWH(SkIntToScalar(50), SkIntToScalar(50)), shapePaint);
|
||||
shape = recorder.finishRecordingAsPicture();
|
||||
}
|
||||
translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Create(shape.get()))->unref();
|
||||
translucentFilterLayerPaint.setImageFilter(SkPictureImageFilter::Make(shape));
|
||||
|
||||
int index = 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user