Skia
2DGraphicsLibrary
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
SkPictureImageFilter.h
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:
19  static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture);
20 
25  static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture, const SkRect& cropRect);
26 
34  static sk_sp<SkImageFilter> MakeForLocalSpace(sk_sp<SkPicture> picture,
35  const SkRect& cropRect,
36  SkFilterQuality filterQuality);
37 
38 #ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
39  static SkImageFilter* Create(const SkPicture* picture) {
40  return Make(sk_ref_sp(const_cast<SkPicture*>(picture))).release();
41  }
42  static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) {
43  return Make(sk_ref_sp(const_cast<SkPicture*>(picture)), cropRect).release();
44  }
45  static SkImageFilter* CreateForLocalSpace(const SkPicture* picture,
46  const SkRect& cropRect,
47  SkFilterQuality filterQuality) {
48  return MakeForLocalSpace(sk_ref_sp(const_cast<SkPicture*>(picture)),
49  cropRect,
50  filterQuality).release();
51  }
52 #endif
53 
54  SK_TO_STRING_OVERRIDE()
55  SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
56 
57 protected:
58  enum PictureResolution {
59  kDeviceSpace_PictureResolution,
60  kLocalSpace_PictureResolution
61  };
62 
63  /* Constructs an SkPictureImageFilter object from an SkReadBuffer.
64  * Note: If the SkPictureImageFilter object construction requires bitmap
65  * decoding, the decoder must be set on the SkReadBuffer parameter by calling
66  * SkReadBuffer::setBitmapDecoder() before calling this constructor.
67  * @param SkReadBuffer Serialized picture data.
68  */
69  void flatten(SkWriteBuffer&) const override;
70  sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
71  SkIPoint* offset) const override;
72 
73 private:
74  explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
75  SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
76  PictureResolution, SkFilterQuality);
77 
78  void drawPictureAtDeviceResolution(SkCanvas* canvas,
79  const SkIRect& deviceBounds,
80  const Context&) const;
81  void drawPictureAtLocalResolution(SkSpecialImage* source,
82  SkCanvas*,
83  const SkIRect& deviceBounds,
84  const Context&) const;
85 
86  sk_sp<SkPicture> fPicture;
87  SkRect fCropRect;
88  PictureResolution fPictureResolution;
89  SkFilterQuality fFilterQuality;
90 
91  typedef SkImageFilter INHERITED;
92 };
93 
94 #endif
T *SK_WARN_UNUSED_RESULT release()
Return the bare pointer, and set the internal object pointer to nullptr.
Definition: SkRefCnt.h:363
A Canvas encapsulates all of the state about drawing into a device (bitmap).
Definition: SkCanvas.h:58
Definition: SkPictureImageFilter.h:14
void flatten(SkWriteBuffer &) const override
Override this if your subclass needs to record data that it will need to recreate itself from its Cre...
virtual sk_sp< SkSpecialImage > onFilterImage(SkSpecialImage *src, const Context &, SkIPoint *offset) const =0
This is the virtual which should be overridden by the derived class to perform image filtering...
Definition: SkRefCnt.h:135
An SkPicture records drawing commands made to a canvas to be played back at a later time...
Definition: SkPicture.h:38
Base class for image filters.
Definition: SkImageFilter.h:35
Definition: SkWriteBuffer.h:26
Definition: SkRect.h:390
Definition: SkImageFilter.h:37
SkIRect holds four 32 bit integer coordinates for a rectangle.
Definition: SkRect.h:20
SkIPoint holds two 32 bit integer coordinates.
Definition: SkPoint.h:40