From 0d8766c84c80537f323947089cc196c3cca106f4 Mon Sep 17 00:00:00 2001 From: Mike Reed Date: Thu, 9 Nov 2017 11:32:12 -0500 Subject: [PATCH] Remove MakeForLocalSpace since picture image is sufficient Bug: skia: Change-Id: If38e702c418e93141311490edf447d1f09ed4434 Reviewed-on: https://skia-review.googlesource.com/68640 Commit-Queue: Mike Reed Reviewed-by: Florin Malita --- fuzz/FuzzCanvas.cpp | 10 +------ gm/pictureimagefilter.cpp | 28 ++++++++++--------- include/core/SkPicture.h | 3 ++- include/effects/SkPictureImageFilter.h | 11 -------- src/core/SkReadBuffer.h | 1 + src/effects/SkPictureImageFilter.cpp | 37 ++++++++++++-------------- 6 files changed, 37 insertions(+), 53 deletions(-) diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp index 3b3715fe8a..064d38aa72 100644 --- a/fuzz/FuzzCanvas.cpp +++ b/fuzz/FuzzCanvas.cpp @@ -920,20 +920,12 @@ static sk_sp make_fuzz_imageFilter(Fuzz* fuzz, int depth) { return SkPictureImageFilter::Make(std::move(picture), cropRect); } case 22: { - SkRect cropRect; - SkFilterQuality filterQuality; - fuzz->next(&cropRect, &filterQuality); - sk_sp picture = make_fuzz_picture(fuzz, depth - 1); - return SkPictureImageFilter::MakeForLocalSpace(std::move(picture), cropRect, - filterQuality); - } - case 23: { SkRect src, dst; fuzz->next(&src, &dst); sk_sp input = make_fuzz_imageFilter(fuzz, depth - 1); return SkTileImageFilter::Make(src, dst, std::move(input)); } - case 24: { + case 23: { SkBlendMode blendMode; bool useCropRect; fuzz->next(&useCropRect, &blendMode); diff --git a/gm/pictureimagefilter.cpp b/gm/pictureimagefilter.cpp index 587ed3733b..c9a0d393be 100644 --- a/gm/pictureimagefilter.cpp +++ b/gm/pictureimagefilter.cpp @@ -11,6 +11,9 @@ #include "SkPictureImageFilter.h" #include "SkPictureRecorder.h" +#include "SkImage.h" +#include "SkImageSource.h" + // This GM exercises the SkPictureImageFilter ImageFilter class. static void fill_rect_filtered(SkCanvas* canvas, @@ -70,6 +73,16 @@ protected: fLCDPicture = make_LCD_picture(); } + sk_sp make(sk_sp pic, SkRect r, SkFilterQuality fq) { + SkISize dim = { SkScalarRoundToInt(r.width()), SkScalarRoundToInt(r.height()) }; + auto img = SkImage::MakeFromPicture(pic, dim, nullptr, nullptr, + SkImage::BitDepth::kU8, SkColorSpace::MakeSRGB()); + return SkImageSource::Make(img, r, r, fq); + } + sk_sp make(SkFilterQuality fq) { + return make(fPicture, fPicture->cullRect(), fq); + } + void onDraw(SkCanvas* canvas) override { canvas->clear(SK_ColorGRAY); { @@ -81,14 +94,8 @@ protected: srcRect)); sk_sp pictureSourceEmptyRect(SkPictureImageFilter::Make(fPicture, emptyRect)); - sk_sp pictureSourceResampled(SkPictureImageFilter::MakeForLocalSpace( - fPicture, - fPicture->cullRect(), - kLow_SkFilterQuality)); - sk_sp pictureSourcePixelated(SkPictureImageFilter::MakeForLocalSpace( - fPicture, - fPicture->cullRect(), - kNone_SkFilterQuality)); + sk_sp pictureSourceResampled = make(kLow_SkFilterQuality); + sk_sp pictureSourcePixelated = make(kNone_SkFilterQuality); canvas->save(); // Draw the picture unscaled. @@ -111,10 +118,7 @@ protected: canvas->drawRect(bounds, stroke); SkPaint paint; - paint.setImageFilter(SkPictureImageFilter::MakeForLocalSpace( - fLCDPicture, - fPicture->cullRect(), - kNone_SkFilterQuality)); + paint.setImageFilter(make(fLCDPicture, fPicture->cullRect(), kNone_SkFilterQuality)); canvas->scale(4, 4); canvas->translate(-0.9f*srcRect.fLeft, -2.45f*srcRect.fTop); diff --git a/include/core/SkPicture.h b/include/core/SkPicture.h index a5f2047e84..b3bc96bb88 100644 --- a/include/core/SkPicture.h +++ b/include/core/SkPicture.h @@ -201,10 +201,11 @@ private: // V56: Add TileMode in SkBlurImageFilter. // V57: Sweep tiling info. // V58: No more 2pt conical flipping. + // V59: No more LocalSpace option on PictureImageFilter // Only SKPs within the min/current picture version range (inclusive) can be read. static const uint32_t MIN_PICTURE_VERSION = 51; // Produced by Chrome ~M56. - static const uint32_t CURRENT_PICTURE_VERSION = 58; + static const uint32_t CURRENT_PICTURE_VERSION = 59; static bool IsValidPictInfo(const SkPictInfo& info); static sk_sp Forwardport(const SkPictInfo&, diff --git a/include/effects/SkPictureImageFilter.h b/include/effects/SkPictureImageFilter.h index 13bf66aac7..76e7b63e3e 100644 --- a/include/effects/SkPictureImageFilter.h +++ b/include/effects/SkPictureImageFilter.h @@ -24,17 +24,6 @@ public: */ static sk_sp Make(sk_sp picture, const SkRect& cropRect); - /** - * Refs the passed-in picture. The picture is rasterized at a resolution that matches the - * local coordinate space. If the picture needs to be resampled for drawing it into the - * destination canvas, bilinear filtering will be used. 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 sk_sp MakeForLocalSpace(sk_sp picture, - const SkRect& cropRect, - SkFilterQuality filterQuality); - SK_TO_STRING_OVERRIDE() SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) diff --git a/src/core/SkReadBuffer.h b/src/core/SkReadBuffer.h index ab9ec7fedb..f7b724d588 100644 --- a/src/core/SkReadBuffer.h +++ b/src/core/SkReadBuffer.h @@ -76,6 +76,7 @@ public: kTileModeInBlurImageFilter_Version = 56, kTileInfoInSweepGradient_Version = 57, k2PtConicalNoFlip_Version = 58, + kRemovePictureImageFilterLocalSpace = 59, }; /** diff --git a/src/effects/SkPictureImageFilter.cpp b/src/effects/SkPictureImageFilter.cpp index c335474200..5611900e7e 100644 --- a/src/effects/SkPictureImageFilter.cpp +++ b/src/effects/SkPictureImageFilter.cpp @@ -29,16 +29,6 @@ sk_sp SkPictureImageFilter::Make(sk_sp picture, nullptr)); } -sk_sp SkPictureImageFilter::MakeForLocalSpace(sk_sp picture, - const SkRect& cropRect, - SkFilterQuality filterQuality) { - return sk_sp(new SkPictureImageFilter(std::move(picture), - cropRect, - kLocalSpace_PictureResolution, - filterQuality, - nullptr)); -} - SkPictureImageFilter::SkPictureImageFilter(sk_sp picture) : INHERITED(nullptr, 0, nullptr) , fPicture(std::move(picture)) @@ -71,14 +61,25 @@ sk_sp SkPictureImageFilter::CreateProc(SkReadBuffer& buffer) { } } buffer.readRect(&cropRect); - PictureResolution pictureResolution = (PictureResolution)buffer.readInt(); - if (kLocalSpace_PictureResolution == pictureResolution) { - //filterLevel is only serialized if pictureResolution is LocalSpace - SkFilterQuality filterQuality = (SkFilterQuality)buffer.readInt(); - return MakeForLocalSpace(picture, cropRect, filterQuality); + // NOTE: these two fields can be removed from the class once we have out-lived the need + // to load pictures older than SkReadBuffer::kRemovePictureImageFilterLocalSpace + // + PictureResolution pictureResolution = kDeviceSpace_PictureResolution; + SkFilterQuality filterQuality = kNone_SkFilterQuality; + + if (buffer.isVersionLT(SkReadBuffer::kRemovePictureImageFilterLocalSpace)) { + pictureResolution = (PictureResolution)buffer.readInt(); + if (kLocalSpace_PictureResolution == pictureResolution) { + //filterLevel is only serialized if pictureResolution is LocalSpace + filterQuality = (SkFilterQuality)buffer.readInt(); + } } - return Make(picture, cropRect); + return sk_sp(new SkPictureImageFilter(picture, + cropRect, + pictureResolution, + filterQuality, + nullptr)); } void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { @@ -92,10 +93,6 @@ void SkPictureImageFilter::flatten(SkWriteBuffer& buffer) const { } } buffer.writeRect(fCropRect); - buffer.writeInt(fPictureResolution); - if (kLocalSpace_PictureResolution == fPictureResolution) { - buffer.writeInt(fFilterQuality); - } } sk_sp SkPictureImageFilter::onFilterImage(SkSpecialImage* source,