Switch SkLocalMatrixImageFilter and SkPaintImageFilter over to sk_sp
TBR=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1842793002 Committed: https://skia.googlesource.com/skia/+/a33cf07a2273315363c0b6fb5d3ce811742f5a85 Review URL: https://codereview.chromium.org/1842793002
This commit is contained in:
parent
2e77ddbb5e
commit
372177ee11
@ -138,11 +138,11 @@ protected:
|
||||
|
||||
SkPaint noisePaint;
|
||||
noisePaint.setShader(noise);
|
||||
SkAutoTUnref<SkImageFilter> rectFilter(SkPaintImageFilter::Create(noisePaint));
|
||||
sk_sp<SkImageFilter> rectFilter(SkPaintImageFilter::Make(noisePaint));
|
||||
canvas->translate(SK_ARRAY_COUNT(filters)*(r.width() + margin), 0);
|
||||
for (int xOffset = 0; xOffset < 80; xOffset += 16) {
|
||||
bounds.fLeft = SkIntToScalar(xOffset);
|
||||
draw_clipped_filter(canvas, rectFilter, 0, r, bounds);
|
||||
draw_clipped_filter(canvas, rectFilter.get(), 0, r, bounds);
|
||||
canvas->translate(0, r.height() + margin);
|
||||
}
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ protected:
|
||||
SkErodeImageFilter::Create(1, 1, checkerboard.get()),
|
||||
SkOffsetImageFilter::Create(SkIntToScalar(32), 0),
|
||||
SkImageFilter::CreateMatrixFilter(resizeMatrix, kNone_SkFilterQuality),
|
||||
SkPaintImageFilter::Create(noisePaint),
|
||||
SkPaintImageFilter::Make(noisePaint).release(),
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(pointLocation, white, surfaceScale, kd),
|
||||
SkLightingImageFilter::CreateSpotLitDiffuse(spotLocation, spotTarget, spotExponent,
|
||||
cutoffAngle, white, surfaceScale, kd),
|
||||
|
@ -49,7 +49,7 @@ protected:
|
||||
return SkISize::Make(640, 640);
|
||||
}
|
||||
|
||||
static void show_image(SkCanvas* canvas, SkImage* image, SkImageFilter* filter) {
|
||||
static void show_image(SkCanvas* canvas, SkImage* image, sk_sp<SkImageFilter> filter) {
|
||||
SkPaint paint;
|
||||
paint.setStyle(SkPaint::kStroke_Style);
|
||||
SkRect r = SkRect::MakeIWH(image->width(), image->height()).makeOutset(SK_ScalarHalf,
|
||||
@ -81,14 +81,14 @@ protected:
|
||||
|
||||
canvas->translate(40, 40);
|
||||
for (auto&& factory : factories) {
|
||||
SkAutoTUnref<SkImageFilter> filter(factory());
|
||||
sk_sp<SkImageFilter> filter(factory());
|
||||
|
||||
canvas->save();
|
||||
show_image(canvas, image0.get(), filter);
|
||||
for (const auto& matrix : matrices) {
|
||||
SkAutoTUnref<SkImageFilter> localFilter(filter->newWithLocalMatrix(matrix));
|
||||
sk_sp<SkImageFilter> localFilter(filter->makeWithLocalMatrix(matrix));
|
||||
canvas->translate(spacer, 0);
|
||||
show_image(canvas, image0.get(), localFilter);
|
||||
show_image(canvas, image0.get(), std::move(localFilter));
|
||||
}
|
||||
canvas->restore();
|
||||
canvas->translate(0, spacer);
|
||||
|
@ -255,7 +255,13 @@ public:
|
||||
* If this filter can be represented by another filter + a localMatrix, return that filter,
|
||||
* else return null.
|
||||
*/
|
||||
SkImageFilter* newWithLocalMatrix(const SkMatrix& matrix) const;
|
||||
sk_sp<SkImageFilter> makeWithLocalMatrix(const SkMatrix&) const;
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
SkImageFilter* newWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
return this->makeWithLocalMatrix(matrix).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Create an SkMatrixImageFilter, which transforms its input by the given matrix.
|
||||
@ -320,7 +326,9 @@ protected:
|
||||
void allocInputs(int count);
|
||||
};
|
||||
|
||||
SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = NULL);
|
||||
SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect = nullptr);
|
||||
|
||||
SkImageFilter(sk_sp<SkImageFilter>* inputs, int inputCount, const CropRect* cropRect);
|
||||
|
||||
virtual ~SkImageFilter();
|
||||
|
||||
|
@ -22,13 +22,21 @@ public:
|
||||
* not specified, the source primitive's bounds are used
|
||||
* instead.
|
||||
*/
|
||||
static SkImageFilter* Create(const SkPaint& paint, const CropRect* rect = NULL);
|
||||
static sk_sp<SkImageFilter> Make(const SkPaint& paint, const CropRect* cropRect = nullptr) {
|
||||
return sk_sp<SkImageFilter>(new SkPaintImageFilter(paint, cropRect));
|
||||
}
|
||||
|
||||
bool canComputeFastBounds() const override;
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPaintImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkPaint& paint, const CropRect* rect = nullptr) {
|
||||
return Make(paint, rect).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
|
@ -487,7 +487,7 @@ static SkMaskFilter* make_mask_filter() {
|
||||
return maskFilter;
|
||||
}
|
||||
|
||||
static SkImageFilter* make_image_filter(bool canBeNull = true);
|
||||
static sk_sp<SkImageFilter> make_image_filter(bool canBeNull = true);
|
||||
|
||||
static SkPaint make_paint() {
|
||||
SkPaint paint;
|
||||
@ -540,11 +540,13 @@ static SkPaint make_paint() {
|
||||
return paint;
|
||||
}
|
||||
|
||||
static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
SkImageFilter* filter = 0;
|
||||
static sk_sp<SkImageFilter> make_image_filter(bool canBeNull) {
|
||||
sk_sp<SkImageFilter> filter;
|
||||
|
||||
// Add a 1 in 3 chance to get a nullptr input
|
||||
if (canBeNull && (R(3) == 1)) { return filter; }
|
||||
if (canBeNull && (R(3) == 1)) {
|
||||
return filter;
|
||||
}
|
||||
|
||||
enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
|
||||
DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
|
||||
@ -553,49 +555,73 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
|
||||
switch (R(NUM_FILTERS)) {
|
||||
case ALPHA_THRESHOLD:
|
||||
filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), make_scalar());
|
||||
filter = sk_sp<SkImageFilter>(SkAlphaThresholdFilter::Create(make_region(),
|
||||
make_scalar(),
|
||||
make_scalar()));
|
||||
break;
|
||||
case MERGE:
|
||||
filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filter(), make_xfermode());
|
||||
case MERGE: {
|
||||
sk_sp<SkImageFilter> subFilter1(make_image_filter());
|
||||
sk_sp<SkImageFilter> subFilter2(make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkMergeImageFilter::Create(subFilter1.get(),
|
||||
subFilter2.get(),
|
||||
make_xfermode()));
|
||||
break;
|
||||
case COLOR:
|
||||
{
|
||||
sk_sp<SkColorFilter> cf(make_color_filter());
|
||||
filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
|
||||
}
|
||||
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()))
|
||||
: nullptr;
|
||||
break;
|
||||
case LUT3D:
|
||||
{
|
||||
}
|
||||
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));
|
||||
filter = cf ? SkColorFilterImageFilter::Create(cf.get(), make_image_filter()) : 0;
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
filter = cf ? sk_sp<SkImageFilter>(SkColorFilterImageFilter::Create(cf.get(),
|
||||
subFilter.get()))
|
||||
: nullptr;
|
||||
break;
|
||||
}
|
||||
case BLUR: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkBlurImageFilter::Create(make_scalar(true),
|
||||
make_scalar(true),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case BLUR:
|
||||
filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
|
||||
break;
|
||||
}
|
||||
case MAGNIFIER:
|
||||
filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
|
||||
filter = sk_sp<SkImageFilter>(SkMagnifierImageFilter::Create(make_rect(),
|
||||
make_scalar(true)));
|
||||
break;
|
||||
case DOWN_SAMPLE:
|
||||
filter = SkDownSampleImageFilter::Create(make_scalar());
|
||||
filter = sk_sp<SkImageFilter>(SkDownSampleImageFilter::Create(make_scalar()));
|
||||
break;
|
||||
case XFERMODE:
|
||||
case XFERMODE: {
|
||||
sk_sp<SkImageFilter> subFilter1(make_image_filter());
|
||||
sk_sp<SkImageFilter> subFilter2(make_image_filter());
|
||||
filter = SkXfermodeImageFilter::Make(SkXfermode::Make(make_xfermode()),
|
||||
make_image_filter(), make_image_filter(),
|
||||
nullptr).release();
|
||||
subFilter1.get(),
|
||||
subFilter2.get(),
|
||||
nullptr);
|
||||
break;
|
||||
case OFFSET:
|
||||
filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_image_filter());
|
||||
}
|
||||
case OFFSET: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkOffsetImageFilter::Create(make_scalar(), make_scalar(),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case MATRIX:
|
||||
filter = SkImageFilter::CreateMatrixFilter(make_matrix(),
|
||||
(SkFilterQuality)R(4),
|
||||
make_image_filter());
|
||||
}
|
||||
case MATRIX: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkImageFilter::CreateMatrixFilter(make_matrix(),
|
||||
(SkFilterQuality)R(4),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case MATRIX_CONVOLUTION:
|
||||
{
|
||||
}
|
||||
case MATRIX_CONVOLUTION: {
|
||||
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
|
||||
SkIntToScalar(kBitmapSize)));
|
||||
SkISize size = SkISize::Make(R(10)+1, R(10)+1);
|
||||
@ -606,47 +632,68 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
}
|
||||
SkIPoint kernelOffset = SkIPoint::Make(R(SkIntToScalar(size.width())),
|
||||
R(SkIntToScalar(size.height())));
|
||||
filter = SkMatrixConvolutionImageFilter::Create(size,
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
filter = sk_sp<SkImageFilter>(SkMatrixConvolutionImageFilter::Create(
|
||||
size,
|
||||
kernel.begin(),
|
||||
make_scalar(),
|
||||
make_scalar(),
|
||||
kernelOffset,
|
||||
(SkMatrixConvolutionImageFilter::TileMode)R(3),
|
||||
R(2) == 1,
|
||||
make_image_filter(),
|
||||
&cropR);
|
||||
subFilter.get(),
|
||||
&cropR));
|
||||
break;
|
||||
}
|
||||
case COMPOSE: {
|
||||
sk_sp<SkImageFilter> subFilter1(make_image_filter());
|
||||
sk_sp<SkImageFilter> subFilter2(make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkComposeImageFilter::Create(subFilter1.get(),
|
||||
subFilter2.get()));
|
||||
break;
|
||||
case COMPOSE:
|
||||
filter = SkComposeImageFilter::Create(make_image_filter(), make_image_filter());
|
||||
}
|
||||
case DISTANT_LIGHT: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
filter = (R(2) == 1)
|
||||
? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(),
|
||||
subFilter.get()))
|
||||
: sk_sp<SkImageFilter>(SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
|
||||
make_color(), make_scalar(),
|
||||
make_scalar(), SkIntToScalar(R(10)),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case DISTANT_LIGHT:
|
||||
filter = (R(2) == 1) ?
|
||||
SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(), make_image_filter()) :
|
||||
SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)),
|
||||
make_image_filter());
|
||||
}
|
||||
case POINT_LIGHT: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
filter = (R(2) == 1)
|
||||
? sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(),
|
||||
subFilter.get()))
|
||||
: sk_sp<SkImageFilter>(SkLightingImageFilter::CreatePointLitSpecular(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(),
|
||||
SkIntToScalar(R(10)),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case POINT_LIGHT:
|
||||
filter = (R(2) == 1) ?
|
||||
SkLightingImageFilter::CreatePointLitDiffuse(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(), make_image_filter()) :
|
||||
SkLightingImageFilter::CreatePointLitSpecular(make_point(),
|
||||
make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10)),
|
||||
make_image_filter());
|
||||
}
|
||||
case SPOT_LIGHT: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
filter = (R(2) == 1)
|
||||
? sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
|
||||
make_point(), make_scalar(), make_scalar(),
|
||||
make_color(), make_scalar(), make_scalar(),
|
||||
subFilter.get()))
|
||||
: sk_sp<SkImageFilter>(SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
|
||||
make_point(), make_scalar(), make_scalar(),
|
||||
make_color(), make_scalar(), make_scalar(),
|
||||
SkIntToScalar(R(10)), subFilter.get()));
|
||||
break;
|
||||
case SPOT_LIGHT:
|
||||
filter = (R(2) == 1) ?
|
||||
SkLightingImageFilter::CreateSpotLitDiffuse(SkPoint3::Make(0, 0, 0),
|
||||
make_point(), make_scalar(), make_scalar(), make_color(),
|
||||
make_scalar(), make_scalar(), make_image_filter()) :
|
||||
SkLightingImageFilter::CreateSpotLitSpecular(SkPoint3::Make(0, 0, 0),
|
||||
make_point(), make_scalar(), make_scalar(), make_color(),
|
||||
make_scalar(), make_scalar(), SkIntToScalar(R(10)), make_image_filter());
|
||||
break;
|
||||
case NOISE:
|
||||
{
|
||||
}
|
||||
case NOISE: {
|
||||
sk_sp<SkShader> shader((R(2) == 1) ?
|
||||
SkPerlinNoiseShader::MakeFractalNoise(
|
||||
make_scalar(true), make_scalar(true), R(10.0f), make_scalar()) :
|
||||
@ -656,43 +703,68 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
paint.setShader(shader);
|
||||
SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
|
||||
SkIntToScalar(kBitmapSize)));
|
||||
filter = SkPaintImageFilter::Create(paint, &cropR);
|
||||
filter = SkPaintImageFilter::Make(paint, &cropR);
|
||||
break;
|
||||
}
|
||||
case DROP_SHADOW: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
filter = sk_sp<SkImageFilter>(SkDropShadowImageFilter::Create(make_scalar(),
|
||||
make_scalar(),
|
||||
make_scalar(true),
|
||||
make_scalar(true),
|
||||
make_color(),
|
||||
make_shadow_mode(),
|
||||
subFilter.get(),
|
||||
nullptr));
|
||||
break;
|
||||
case DROP_SHADOW:
|
||||
filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), make_scalar(true),
|
||||
make_scalar(true), make_color(), make_shadow_mode(), make_image_filter(),
|
||||
nullptr);
|
||||
break;
|
||||
case MORPHOLOGY:
|
||||
}
|
||||
case MORPHOLOGY: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter());
|
||||
|
||||
if (R(2) == 1) {
|
||||
filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
|
||||
R(static_cast<float>(kBitmapSize)), make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSize)),
|
||||
R(static_cast<float>(kBitmapSize)),
|
||||
subFilter.get()));
|
||||
} else {
|
||||
filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
|
||||
R(static_cast<float>(kBitmapSize)), make_image_filter());
|
||||
filter = sk_sp<SkImageFilter>(SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize)),
|
||||
R(static_cast<float>(kBitmapSize)),
|
||||
subFilter.get()));
|
||||
}
|
||||
break;
|
||||
case BITMAP:
|
||||
{
|
||||
}
|
||||
case BITMAP: {
|
||||
sk_sp<SkImage> image(SkImage::MakeFromBitmap(make_bitmap()));
|
||||
if (R(2) == 1) {
|
||||
filter = SkImageSource::Create(image.get(), make_rect(), make_rect(), kHigh_SkFilterQuality);
|
||||
filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get(),
|
||||
make_rect(),
|
||||
make_rect(),
|
||||
kHigh_SkFilterQuality));
|
||||
} else {
|
||||
filter = SkImageSource::Create(image.get());
|
||||
filter = sk_sp<SkImageFilter>(SkImageSource::Create(image.get()));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case DISPLACE: {
|
||||
sk_sp<SkImageFilter> subFilter1(make_image_filter(false));
|
||||
sk_sp<SkImageFilter> subFilter2(make_image_filter());
|
||||
|
||||
filter = sk_sp<SkImageFilter>(SkDisplacementMapEffect::Create(make_channel_selector_type(),
|
||||
make_channel_selector_type(),
|
||||
make_scalar(),
|
||||
subFilter1.get(),
|
||||
subFilter2.get()));
|
||||
break;
|
||||
case DISPLACE:
|
||||
filter = SkDisplacementMapEffect::Create(make_channel_selector_type(),
|
||||
make_channel_selector_type(), make_scalar(),
|
||||
make_image_filter(false), make_image_filter());
|
||||
}
|
||||
case TILE: {
|
||||
sk_sp<SkImageFilter> subFilter(make_image_filter(false));
|
||||
|
||||
filter = sk_sp<SkImageFilter>(SkTileImageFilter::Create(make_rect(),
|
||||
make_rect(),
|
||||
subFilter.get()));
|
||||
break;
|
||||
case TILE:
|
||||
filter = SkTileImageFilter::Create(make_rect(), make_rect(), make_image_filter(false));
|
||||
break;
|
||||
case PICTURE:
|
||||
{
|
||||
}
|
||||
case PICTURE: {
|
||||
SkRTreeFactory factory;
|
||||
SkPictureRecorder recorder;
|
||||
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(kBitmapSize),
|
||||
@ -700,13 +772,13 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
&factory, 0);
|
||||
drawSomething(recordingCanvas);
|
||||
sk_sp<SkPicture> pict(recorder.finishRecordingAsPicture());
|
||||
filter = SkPictureImageFilter::Make(pict, make_rect()).release();
|
||||
}
|
||||
filter = SkPictureImageFilter::Make(pict, make_rect());
|
||||
break;
|
||||
case PAINT:
|
||||
{
|
||||
}
|
||||
case PAINT: {
|
||||
SkImageFilter::CropRect cropR(make_rect());
|
||||
filter = SkPaintImageFilter::Create(make_paint(), &cropR);
|
||||
filter = SkPaintImageFilter::Make(make_paint(), &cropR);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
@ -715,8 +787,8 @@ static SkImageFilter* make_image_filter(bool canBeNull) {
|
||||
}
|
||||
|
||||
static SkImageFilter* make_serialized_image_filter() {
|
||||
SkAutoTUnref<SkImageFilter> filter(make_image_filter(false));
|
||||
SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
|
||||
sk_sp<SkImageFilter> filter(make_image_filter(false));
|
||||
SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter.get()));
|
||||
const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
|
||||
size_t len = data->size();
|
||||
#ifdef SK_ADD_RANDOM_BIT_FLIPS
|
||||
|
@ -1161,9 +1161,8 @@ static void draw_filter_into_device(SkBaseDevice* src, const SkImageFilter* filt
|
||||
|
||||
SkCanvas c(dst);
|
||||
|
||||
SkAutoTUnref<SkImageFilter> localF(filter->newWithLocalMatrix(ctm));
|
||||
SkPaint p;
|
||||
p.setImageFilter(localF);
|
||||
p.setImageFilter(filter->makeWithLocalMatrix(ctm));
|
||||
const SkScalar x = SkIntToScalar(src->getOrigin().x());
|
||||
const SkScalar y = SkIntToScalar(src->getOrigin().y());
|
||||
c.drawBitmap(srcBM, x, y, &p);
|
||||
|
@ -158,6 +158,22 @@ bool SkImageFilter::Common::unflatten(SkReadBuffer& buffer, int expectedCount) {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
SkImageFilter::SkImageFilter(sk_sp<SkImageFilter>* inputs,
|
||||
int inputCount,
|
||||
const CropRect* cropRect)
|
||||
: fInputCount(inputCount),
|
||||
fInputs(new SkImageFilter*[inputCount]),
|
||||
fUsesSrcInput(false),
|
||||
fCropRect(cropRect ? *cropRect : CropRect(SkRect(), 0x0)),
|
||||
fUniqueID(next_image_filter_unique_id()) {
|
||||
for (int i = 0; i < inputCount; ++i) {
|
||||
if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
|
||||
fUsesSrcInput = true;
|
||||
}
|
||||
fInputs[i] = SkSafeRef(inputs[i].get());
|
||||
}
|
||||
}
|
||||
|
||||
SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropRect* cropRect)
|
||||
: fInputCount(inputCount),
|
||||
fInputs(new SkImageFilter*[inputCount]),
|
||||
@ -168,8 +184,7 @@ SkImageFilter::SkImageFilter(int inputCount, SkImageFilter** inputs, const CropR
|
||||
if (nullptr == inputs[i] || inputs[i]->usesSrcInput()) {
|
||||
fUsesSrcInput = true;
|
||||
}
|
||||
fInputs[i] = inputs[i];
|
||||
SkSafeRef(fInputs[i]);
|
||||
fInputs[i] = SkSafeRef(inputs[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -556,11 +571,12 @@ SkImageFilter* SkImageFilter::CreateMatrixFilter(const SkMatrix& matrix,
|
||||
return SkMatrixImageFilter::Create(matrix, filterQuality, input);
|
||||
}
|
||||
|
||||
SkImageFilter* SkImageFilter::newWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
sk_sp<SkImageFilter> SkImageFilter::makeWithLocalMatrix(const SkMatrix& matrix) const {
|
||||
// SkLocalMatrixImageFilter takes SkImage* in its factory, but logically that parameter
|
||||
// is *always* treated as a const ptr. Hence the const-cast here.
|
||||
//
|
||||
return SkLocalMatrixImageFilter::Create(matrix, const_cast<SkImageFilter*>(this));
|
||||
SkImageFilter* nonConstThis = const_cast<SkImageFilter*>(this);
|
||||
return SkLocalMatrixImageFilter::Make(matrix, sk_ref_sp<SkImageFilter>(nonConstThis));
|
||||
}
|
||||
|
||||
sk_sp<SkSpecialImage> SkImageFilter::filterInput(int index,
|
||||
|
@ -10,21 +10,9 @@
|
||||
#include "SkSpecialImage.h"
|
||||
#include "SkString.h"
|
||||
|
||||
SkImageFilter* SkLocalMatrixImageFilter::Create(const SkMatrix& localM, SkImageFilter* input) {
|
||||
if (!input) {
|
||||
return nullptr;
|
||||
}
|
||||
if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (localM.isIdentity()) {
|
||||
return SkRef(input);
|
||||
}
|
||||
return new SkLocalMatrixImageFilter(localM, input);
|
||||
}
|
||||
|
||||
SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input)
|
||||
: INHERITED(1, &input)
|
||||
SkLocalMatrixImageFilter::SkLocalMatrixImageFilter(const SkMatrix& localM,
|
||||
sk_sp<SkImageFilter> input)
|
||||
: INHERITED(&input, 1, nullptr)
|
||||
, fLocalM(localM) {
|
||||
}
|
||||
|
||||
@ -32,7 +20,8 @@ SkFlattenable* SkLocalMatrixImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 1);
|
||||
SkMatrix lm;
|
||||
buffer.readMatrix(&lm);
|
||||
return SkLocalMatrixImageFilter::Create(lm, common.getInput(0));
|
||||
return SkLocalMatrixImageFilter::Make(lm,
|
||||
sk_ref_sp<SkImageFilter>(common.getInput(0))).release();
|
||||
}
|
||||
|
||||
void SkLocalMatrixImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
|
@ -16,11 +16,28 @@
|
||||
*/
|
||||
class SkLocalMatrixImageFilter : public SkImageFilter {
|
||||
public:
|
||||
static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input);
|
||||
static sk_sp<SkImageFilter> Make(const SkMatrix& localM, sk_sp<SkImageFilter> input) {
|
||||
if (!input) {
|
||||
return nullptr;
|
||||
}
|
||||
if (localM.getType() & (SkMatrix::kAffine_Mask | SkMatrix::kPerspective_Mask)) {
|
||||
return nullptr;
|
||||
}
|
||||
if (localM.isIdentity()) {
|
||||
return input;
|
||||
}
|
||||
return sk_sp<SkImageFilter>(new SkLocalMatrixImageFilter(localM, input));
|
||||
}
|
||||
|
||||
SK_TO_STRING_OVERRIDE()
|
||||
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLocalMatrixImageFilter)
|
||||
|
||||
#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
|
||||
static SkImageFilter* Create(const SkMatrix& localM, SkImageFilter* input) {
|
||||
return Make(localM, sk_sp<SkImageFilter>(SkSafeRef(input))).release();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void flatten(SkWriteBuffer&) const override;
|
||||
sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
|
||||
@ -28,7 +45,7 @@ protected:
|
||||
SkIRect onFilterBounds(const SkIRect& src, const SkMatrix&, MapDirection) const override;
|
||||
|
||||
private:
|
||||
SkLocalMatrixImageFilter(const SkMatrix& localM, SkImageFilter* input);
|
||||
SkLocalMatrixImageFilter(const SkMatrix& localM, sk_sp<SkImageFilter> input);
|
||||
|
||||
SkMatrix fLocalM;
|
||||
|
||||
|
@ -12,20 +12,16 @@
|
||||
#include "SkSpecialSurface.h"
|
||||
#include "SkWriteBuffer.h"
|
||||
|
||||
SkImageFilter* SkPaintImageFilter::Create(const SkPaint& paint, const CropRect* cropRect) {
|
||||
return new SkPaintImageFilter(paint, cropRect);
|
||||
}
|
||||
|
||||
SkPaintImageFilter::SkPaintImageFilter(const SkPaint& paint, const CropRect* cropRect)
|
||||
: INHERITED(0, nullptr, cropRect)
|
||||
, fPaint(paint) {
|
||||
: INHERITED(nullptr, 0, cropRect)
|
||||
, fPaint(paint) {
|
||||
}
|
||||
|
||||
SkFlattenable* SkPaintImageFilter::CreateProc(SkReadBuffer& buffer) {
|
||||
SK_IMAGEFILTER_UNFLATTEN_COMMON(common, 0);
|
||||
SkPaint paint;
|
||||
buffer.readPaint(&paint);
|
||||
return Create(paint, &common.cropRect());
|
||||
return SkPaintImageFilter::Make(paint, &common.cropRect()).release();
|
||||
}
|
||||
|
||||
void SkPaintImageFilter::flatten(SkWriteBuffer& buffer) const {
|
||||
@ -80,6 +76,7 @@ bool SkPaintImageFilter::canComputeFastBounds() const {
|
||||
#ifndef SK_IGNORE_TO_STRING
|
||||
void SkPaintImageFilter::toString(SkString* str) const {
|
||||
str->appendf("SkPaintImageFilter: (");
|
||||
fPaint.toString(str);
|
||||
str->append(")");
|
||||
}
|
||||
#endif
|
||||
|
@ -14,7 +14,7 @@
|
||||
#include "SkValidationUtils.h"
|
||||
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
|
||||
: INHERITED(0, 0, nullptr)
|
||||
: INHERITED(nullptr, 0, nullptr)
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(fPicture ? fPicture->cullRect() : SkRect::MakeEmpty())
|
||||
, fPictureResolution(kDeviceSpace_PictureResolution)
|
||||
@ -24,7 +24,7 @@ SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture)
|
||||
SkPictureImageFilter::SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
|
||||
PictureResolution pictureResolution,
|
||||
SkFilterQuality filterQuality)
|
||||
: INHERITED(0, 0, nullptr)
|
||||
: INHERITED(nullptr, 0, nullptr)
|
||||
, fPicture(std::move(picture))
|
||||
, fCropRect(cropRect)
|
||||
, fPictureResolution(pictureResolution)
|
||||
|
@ -138,17 +138,17 @@ public:
|
||||
|
||||
SkPaint paint;
|
||||
paint.setShader(shader);
|
||||
SkAutoTUnref<SkImageFilter> paintFilter(SkPaintImageFilter::Create(paint));
|
||||
sk_sp<SkImageFilter> paintFilter(SkPaintImageFilter::Make(paint));
|
||||
|
||||
sk_sp<SkShader> greenColorShader(SkShader::MakeColorShader(SK_ColorGREEN));
|
||||
SkPaint greenColorShaderPaint;
|
||||
greenColorShaderPaint.setShader(greenColorShader);
|
||||
SkImageFilter::CropRect leftSideCropRect(SkRect::MakeXYWH(0, 0, 32, 64));
|
||||
SkAutoTUnref<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Create(
|
||||
greenColorShaderPaint, &leftSideCropRect));
|
||||
sk_sp<SkImageFilter> paintFilterLeft(SkPaintImageFilter::Make(greenColorShaderPaint,
|
||||
&leftSideCropRect));
|
||||
SkImageFilter::CropRect rightSideCropRect(SkRect::MakeXYWH(32, 0, 32, 64));
|
||||
SkAutoTUnref<SkImageFilter> paintFilterRight(SkPaintImageFilter::Create(
|
||||
greenColorShaderPaint, &rightSideCropRect));
|
||||
sk_sp<SkImageFilter> paintFilterRight(SkPaintImageFilter::Make(greenColorShaderPaint,
|
||||
&rightSideCropRect));
|
||||
|
||||
this->addFilter("color filter",
|
||||
SkColorFilterImageFilter::Create(cf.get(), input, cropRect));
|
||||
@ -172,7 +172,8 @@ public:
|
||||
this->addFilter("merge", SkMergeImageFilter::Create(input, input, SkXfermode::kSrcOver_Mode,
|
||||
cropRect));
|
||||
this->addFilter("merge with disjoint inputs", SkMergeImageFilter::Create(
|
||||
paintFilterLeft, paintFilterRight, SkXfermode::kSrcOver_Mode, cropRect));
|
||||
paintFilterLeft.get(), paintFilterRight.get(),
|
||||
SkXfermode::kSrcOver_Mode, cropRect));
|
||||
this->addFilter("offset",
|
||||
SkOffsetImageFilter::Create(SK_Scalar1, SK_Scalar1, input, cropRect));
|
||||
this->addFilter("dilate", SkDilateImageFilter::Create(3, 2, input, cropRect));
|
||||
|
@ -38,7 +38,7 @@ static void test_unscaled(skiatest::Reporter* reporter) {
|
||||
{
|
||||
SkPaint paint;
|
||||
SkImageFilter::CropRect cr(r);
|
||||
paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->unref();
|
||||
paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
|
||||
canvasFilter.drawRect(r, paint);
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ static void test_scaled(skiatest::Reporter* reporter) {
|
||||
{
|
||||
SkPaint paint;
|
||||
SkImageFilter::CropRect cr(r);
|
||||
paint.setImageFilter(SkPaintImageFilter::Create(gradientPaint, &cr))->unref();
|
||||
paint.setImageFilter(SkPaintImageFilter::Make(gradientPaint, &cr));
|
||||
canvasFilter.scale(SkIntToScalar(2), SkIntToScalar(2));
|
||||
canvasFilter.drawRect(r, paint);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user