Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 The Android Open Source Project | 2 * Copyright 2013 The Android Open Source Project |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkPictureImageFilter_DEFINED | 8 #ifndef SkPictureImageFilter_DEFINED |
| 9 #define SkPictureImageFilter_DEFINED | 9 #define SkPictureImageFilter_DEFINED |
| 10 | 10 |
| 11 #include "SkImageFilter.h" | 11 #include "SkImageFilter.h" |
| 12 #include "SkPicture.h" | 12 #include "SkPicture.h" |
| 13 | 13 |
| 14 class SK_API SkPictureImageFilter : public SkImageFilter { | 14 class SK_API SkPictureImageFilter : public SkImageFilter { |
| 15 public: | 15 public: |
| 16 /** | 16 /** |
| 17 * Refs the passed-in picture. | 17 * Refs the passed-in picture. |
| 18 */ | 18 */ |
| 19 static SkImageFilter* Create(const SkPicture* picture) { | 19 static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture) { |
|
reed1
2016/03/25 19:32:36
This style is fine.
However, at some point, I'd l
robertphillips
2016/03/28 12:02:22
The picture image filter is actually defined to wo
f(malita)
2016/03/28 13:00:08
I don't recall the image filter specifics, but tha
| |
| 20 return new SkPictureImageFilter(picture); | 20 return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture)) ); |
| 21 } | 21 } |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * Refs the passed-in picture. cropRect can be used to crop or expand the d estination rect when | 24 * Refs the passed-in picture. cropRect can be used to crop or expand the d estination rect when |
| 25 * the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.) | 25 * the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.) |
| 26 */ | 26 */ |
| 27 static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRec t) { | 27 static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture, const SkRect& cro pRect) { |
| 28 return new SkPictureImageFilter(picture, cropRect, kDeviceSpace_PictureR esolution, | 28 return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture), |
| 29 kLow_SkFilterQuality); | 29 cropRect, |
| 30 kDeviceSpace_Pictur eResolution, | |
| 31 kLow_SkFilterQualit y)); | |
| 30 } | 32 } |
| 31 | 33 |
| 32 /** | 34 /** |
| 33 * Refs the passed-in picture. The picture is rasterized at a resolution th at matches the | 35 * Refs the passed-in picture. The picture is rasterized at a resolution th at matches the |
| 34 * local coordinate space. If the picture needs to be resampled for drawing it into the | 36 * local coordinate space. If the picture needs to be resampled for drawing it into the |
| 35 * destination canvas, bilinear filtering will be used. cropRect can be use d to crop or | 37 * destination canvas, bilinear filtering will be used. cropRect can be use d to crop or |
| 36 * expand the destination rect when the picture is drawn. (No scaling is im plied by the | 38 * expand the destination rect when the picture is drawn. (No scaling is im plied by the |
| 37 * dest rect; only the CTM is applied.) | 39 * dest rect; only the CTM is applied.) |
| 38 */ | 40 */ |
| 41 static sk_sp<SkImageFilter> MakeForLocalSpace(sk_sp<SkPicture> picture, | |
| 42 const SkRect& cropRect, | |
| 43 SkFilterQuality filterQuality) { | |
| 44 return sk_sp<SkImageFilter>(new SkPictureImageFilter(std::move(picture), | |
| 45 cropRect, | |
| 46 kLocalSpace_Picture Resolution, | |
| 47 filterQuality)); | |
| 48 } | |
| 49 | |
| 50 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR | |
| 51 static SkImageFilter* Create(const SkPicture* picture) { | |
| 52 return Make(sk_ref_sp(const_cast<SkPicture*>(picture))).release(); | |
| 53 } | |
| 54 static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRec t) { | |
| 55 return Make(sk_ref_sp(const_cast<SkPicture*>(picture)), cropRect).releas e(); | |
| 56 } | |
| 39 static SkImageFilter* CreateForLocalSpace(const SkPicture* picture, | 57 static SkImageFilter* CreateForLocalSpace(const SkPicture* picture, |
| 40 const SkRect& cropRect, | 58 const SkRect& cropRect, |
| 41 SkFilterQuality filterQuali ty) { | 59 SkFilterQuality filterQuality) { |
| 42 return new SkPictureImageFilter(picture, cropRect, kLocalSpace_PictureRe solution, | 60 return MakeForLocalSpace(sk_ref_sp(const_cast<SkPicture*>(picture)), |
| 43 filterQuality); | 61 cropRect, |
| 62 filterQuality).release(); | |
| 44 } | 63 } |
| 64 #endif | |
| 45 | 65 |
| 46 SK_TO_STRING_OVERRIDE() | 66 SK_TO_STRING_OVERRIDE() |
| 47 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) | 67 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) |
| 48 | 68 |
| 49 protected: | 69 protected: |
| 50 enum PictureResolution { | 70 enum PictureResolution { |
| 51 kDeviceSpace_PictureResolution, | 71 kDeviceSpace_PictureResolution, |
| 52 kLocalSpace_PictureResolution | 72 kLocalSpace_PictureResolution |
| 53 }; | 73 }; |
| 54 | 74 |
| 55 virtual ~SkPictureImageFilter(); | |
| 56 | |
| 57 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. | 75 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. |
| 58 * Note: If the SkPictureImageFilter object construction requires bitmap | 76 * Note: If the SkPictureImageFilter object construction requires bitmap |
| 59 * decoding, the decoder must be set on the SkReadBuffer parameter by calli ng | 77 * decoding, the decoder must be set on the SkReadBuffer parameter by calli ng |
| 60 * SkReadBuffer::setBitmapDecoder() before calling this constructor. | 78 * SkReadBuffer::setBitmapDecoder() before calling this constructor. |
| 61 * @param SkReadBuffer Serialized picture data. | 79 * @param SkReadBuffer Serialized picture data. |
| 62 */ | 80 */ |
| 63 void flatten(SkWriteBuffer&) const override; | 81 void flatten(SkWriteBuffer&) const override; |
| 64 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, Sk Bitmap* result, | 82 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, Sk Bitmap* result, |
| 65 SkIPoint* offset) const override; | 83 SkIPoint* offset) const override; |
| 66 | 84 |
| 67 private: | 85 private: |
| 68 explicit SkPictureImageFilter(const SkPicture* picture); | 86 explicit SkPictureImageFilter(sk_sp<SkPicture> picture); |
| 69 SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect, | 87 SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect, |
| 70 PictureResolution, SkFilterQuality); | 88 PictureResolution, SkFilterQuality); |
| 71 | 89 |
| 72 void drawPictureAtDeviceResolution(SkBaseDevice*, const SkIRect& deviceBound s, | 90 void drawPictureAtDeviceResolution(SkBaseDevice*, const SkIRect& deviceBound s, |
| 73 const Context&) const; | 91 const Context&) const; |
| 74 void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& devi ceBounds, | 92 void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& devi ceBounds, |
| 75 const Context&) const; | 93 const Context&) const; |
| 76 | 94 |
| 77 const SkPicture* fPicture; | 95 sk_sp<SkPicture> fPicture; |
| 78 SkRect fCropRect; | 96 SkRect fCropRect; |
| 79 PictureResolution fPictureResolution; | 97 PictureResolution fPictureResolution; |
| 80 SkFilterQuality fFilterQuality; | 98 SkFilterQuality fFilterQuality; |
| 81 | 99 |
| 82 typedef SkImageFilter INHERITED; | 100 typedef SkImageFilter INHERITED; |
| 83 }; | 101 }; |
| 84 | 102 |
| 85 #endif | 103 #endif |
| OLD | NEW |