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 SkImageFilter* Create(const SkPicture* picture) { 20 return new 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 SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) { 28 return new SkPictureImageFilter(picture, cropRect, kDeviceSpace_PictureResolution, 29 kLow_SkFilterQuality); 30 } 31 32 /** 33 * Refs the passed-in picture. The picture is rasterized at a resolution that matches the 34 * 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 used to crop or 36 * expand the destination rect when the picture is drawn. (No scaling is implied by the 37 * dest rect; only the CTM is applied.) 38 */ 39 static SkImageFilter* CreateForLocalSpace(const SkPicture* picture, 40 const SkRect& cropRect, 41 SkFilterQuality filterQuality) { 42 return new SkPictureImageFilter(picture, cropRect, kLocalSpace_PictureResolution, 43 filterQuality); 44 } 45 46 SK_TO_STRING_OVERRIDE() 47 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) 48 49 protected: 50 enum PictureResolution { 51 kDeviceSpace_PictureResolution, 52 kLocalSpace_PictureResolution 53 }; 54 55 virtual ~SkPictureImageFilter(); 56 57 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. 58 * Note: If the SkPictureImageFilter object construction requires bitmap 59 * decoding, the decoder must be set on the SkReadBuffer parameter by calling 60 * SkReadBuffer::setBitmapDecoder() before calling this constructor. 61 * @param SkReadBuffer Serialized picture data. 62 */ 63 void flatten(SkWriteBuffer&) const override; 64 bool onFilterImageDeprecated(Proxy*, const SkBitmap& src, const Context&, SkBitmap* result, 65 SkIPoint* offset) const override; 66 67 private: 68 explicit SkPictureImageFilter(const SkPicture* picture); 69 SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect, 70 PictureResolution, SkFilterQuality); 71 72 void drawPictureAtDeviceResolution(SkBaseDevice*, const SkIRect& deviceBounds, 73 const Context&) const; 74 void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& deviceBounds, 75 const Context&) const; 76 77 const SkPicture* fPicture; 78 SkRect fCropRect; 79 PictureResolution fPictureResolution; 80 SkFilterQuality fFilterQuality; 81 82 typedef SkImageFilter INHERITED; 83 }; 84 85 #endif 86