1 /* 2 * Copyright 2013 The Android Open Source Project 3 * 4 * Use of this source code is governed by a BSD-style license that can be 5 * found in the LICENSE file. 6 */ 7 8 #ifndef SkPictureImageFilter_DEFINED 9 #define SkPictureImageFilter_DEFINED 10 11 #include "SkImageFilter.h" 12 #include "SkPicture.h" 13 14 class SK_API SkPictureImageFilter : public SkImageFilter { 15 public: 16 /** 17 * Refs the passed-in picture. 18 */ 19 static SkPictureImageFilter* Create(const SkPicture* picture) { 20 return SkNEW_ARGS(SkPictureImageFilter, (picture)); 21 } 22 23 /** 24 * Refs the passed-in picture. cropRect can be used to crop or expand the destination rect when 25 * the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.) 26 */ 27 static SkPictureImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) { 28 return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect, 29 kDeviceSpace_PictureResolution, 30 kLow_SkFilterQuality)); 31 } 32 33 /** 34 * Refs the passed-in picture. The picture is rasterized at a resolution that matches the 35 * local coordinate space. If the picture needs to be resampled for drawing it into the 36 * destination canvas, bilinear filtering will be used. cropRect can be used to crop or 37 * expand the destination rect when the picture is drawn. (No scaling is implied by the 38 * dest rect; only the CTM is applied.) 39 */ 40 static SkPictureImageFilter* CreateForLocalSpace(const SkPicture* picture, 41 const SkRect& cropRect, 42 SkFilterQuality filterQuality) { 43 return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect, 44 kLocalSpace_PictureResolution, filterQuality)); 45 } 46 #ifdef SK_SUPPORT_LEGACY_FILTERLEVEL_ENUM 47 static SkPictureImageFilter* CreateForLocalSpace(const SkPicture* picture, 48 const SkRect& cropRect, 49 SkPaint::FilterLevel filterLevel) { 50 return CreateForLocalSpace(picture, cropRect, (SkFilterQuality)filterLevel); 51 } 52 #endif 53 SK_TO_STRING_OVERRIDE() 54 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) 55 56 protected: 57 enum PictureResolution { 58 kDeviceSpace_PictureResolution, 59 kLocalSpace_PictureResolution 60 }; 61 62 explicit SkPictureImageFilter(const SkPicture* picture); 63 SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect, 64 PictureResolution, SkFilterQuality); 65 virtual ~SkPictureImageFilter(); 66 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. 67 * Note: If the SkPictureImageFilter object construction requires bitmap 68 * decoding, the decoder must be set on the SkReadBuffer parameter by calling 69 * SkReadBuffer::setBitmapDecoder() before calling this constructor. 70 * @param SkReadBuffer Serialized picture data. 71 */ 72 void flatten(SkWriteBuffer&) const override; 73 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, 74 SkBitmap* result, SkIPoint* offset) const override; 75 76 private: 77 78 79 void drawPictureAtDeviceResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds, 80 const Context&) const; 81 void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds, 82 const Context&) const; 83 84 const SkPicture* fPicture; 85 SkRect fCropRect; 86 PictureResolution fPictureResolution; 87 SkFilterQuality fFilterQuality; 88 typedef SkImageFilter INHERITED; 89 }; 90 91 #endif 92