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 SkPictureImageFilter* Create(const SkPicture* picture, int32_t unique
ID = 0) { | 19 static SkPictureImageFilter* Create(const SkPicture* picture, int32_t unique
ID = 0) { |
20 return SkNEW_ARGS(SkPictureImageFilter, (picture, uniqueID)); | 20 return SkNEW_ARGS(SkPictureImageFilter, (picture, uniqueID)); |
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 SkPictureImageFilter* Create(const SkPicture* picture, const SkRect&
cropRect, uint32_t uniqueID = 0) { | 27 static SkPictureImageFilter* Create(const SkPicture* picture, const SkRect&
cropRect, |
28 return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect, uniqueID)); | 28 uint32_t uniqueID = 0) { |
| 29 return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect, uniqueID, |
| 30 kDeviceSpace_PictureResolution)
); |
| 31 } |
| 32 |
| 33 /** |
| 34 * Refs the passed-in picture. The picture is rasterized at a resolution th
at 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 use
d to crop or |
| 37 * expand the destination rect when the picture is drawn. (No scaling is im
plied by the |
| 38 * dest rect; only the CTM is applied.) |
| 39 */ |
| 40 static SkPictureImageFilter* CreateForLocalSpace(const SkPicture* picture, |
| 41 const SkRect& cropRect, |
| 42 uint32_t uniqueID = 0) { |
| 43 return SkNEW_ARGS(SkPictureImageFilter, (picture, cropRect, uniqueID, |
| 44 kLocalSpace_PictureResolution))
; |
29 } | 45 } |
30 | 46 |
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) | 47 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter) |
32 | 48 |
33 protected: | 49 protected: |
| 50 enum PictureResolution { |
| 51 kDeviceSpace_PictureResolution, |
| 52 kLocalSpace_PictureResolution |
| 53 }; |
| 54 |
34 explicit SkPictureImageFilter(const SkPicture* picture, uint32_t uniqueID); | 55 explicit SkPictureImageFilter(const SkPicture* picture, uint32_t uniqueID); |
35 SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect, uint3
2_t uniqueID); | 56 SkPictureImageFilter(const SkPicture* picture, const SkRect& cropRect, uint3
2_t uniqueID, |
| 57 PictureResolution); |
36 virtual ~SkPictureImageFilter(); | 58 virtual ~SkPictureImageFilter(); |
37 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. | 59 /* Constructs an SkPictureImageFilter object from an SkReadBuffer. |
38 * Note: If the SkPictureImageFilter object construction requires bitmap | 60 * Note: If the SkPictureImageFilter object construction requires bitmap |
39 * decoding, the decoder must be set on the SkReadBuffer parameter by calli
ng | 61 * decoding, the decoder must be set on the SkReadBuffer parameter by calli
ng |
40 * SkReadBuffer::setBitmapDecoder() before calling this constructor. | 62 * SkReadBuffer::setBitmapDecoder() before calling this constructor. |
41 * @param SkReadBuffer Serialized picture data. | 63 * @param SkReadBuffer Serialized picture data. |
42 */ | 64 */ |
43 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; | 65 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; |
44 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, | 66 virtual bool onFilterImage(Proxy*, const SkBitmap& src, const Context&, |
45 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; | 67 SkBitmap* result, SkIPoint* offset) const SK_OVER
RIDE; |
46 | 68 |
47 private: | 69 private: |
48 const SkPicture* fPicture; | 70 |
49 SkRect fCropRect; | 71 |
| 72 void drawPictureAtDeviceResolution(Proxy*, SkBaseDevice*, const SkIRect& dev
iceBounds, |
| 73 const Context&) const; |
| 74 void drawPictureAtLocalResolution(Proxy*, SkBaseDevice*, const SkIRect& devi
ceBounds, |
| 75 const Context&) const; |
| 76 |
| 77 const SkPicture* fPicture; |
| 78 SkRect fCropRect; |
| 79 PictureResolution fPictureResolution; |
50 typedef SkImageFilter INHERITED; | 80 typedef SkImageFilter INHERITED; |
51 }; | 81 }; |
52 | 82 |
53 #endif | 83 #endif |
OLD | NEW |