aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/effects/SkPictureImageFilter.h
blob: 2ca1c5b4fde48fcb96ffc5e3ee6f0555bc8af97f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * Copyright 2013 The Android Open Source Project
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkPictureImageFilter_DEFINED
#define SkPictureImageFilter_DEFINED

#include "SkImageFilter.h"
#include "SkPicture.h"

class SK_API SkPictureImageFilter : public SkImageFilter {
public:
    /**
     *  Refs the passed-in picture.
     */
    static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture);

    /**
     *  Refs the passed-in picture. cropRect can be used to crop or expand the destination rect when
     *  the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.)
     */
    static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture, const SkRect& cropRect);

    /**
     *  Refs the passed-in picture. The picture is rasterized at a resolution that matches the
     *  local coordinate space. If the picture needs to be resampled for drawing it into the
     *  destination canvas, bilinear filtering will be used. cropRect can be used to crop or
     *  expand the destination rect when the picture is drawn. (No scaling is implied by the
     *  dest rect; only the CTM is applied.)
     */
    static sk_sp<SkImageFilter> MakeForLocalSpace(sk_sp<SkPicture> picture,
                                                  const SkRect& cropRect,
                                                  SkFilterQuality filterQuality);

#ifdef SK_SUPPORT_LEGACY_IMAGEFILTER_PTR
    static SkImageFilter* Create(const SkPicture* picture) {
        return Make(sk_ref_sp(const_cast<SkPicture*>(picture))).release();
    }
    static SkImageFilter* Create(const SkPicture* picture, const SkRect& cropRect) {
        return Make(sk_ref_sp(const_cast<SkPicture*>(picture)), cropRect).release();
    }
    static SkImageFilter* CreateForLocalSpace(const SkPicture* picture,
                                              const SkRect& cropRect,
                                              SkFilterQuality filterQuality) {
        return MakeForLocalSpace(sk_ref_sp(const_cast<SkPicture*>(picture)),
                                           cropRect,
                                           filterQuality).release();
    }
#endif

    SK_TO_STRING_OVERRIDE()
    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)

protected:
    enum PictureResolution {
        kDeviceSpace_PictureResolution,
        kLocalSpace_PictureResolution
    };

    /*  Constructs an SkPictureImageFilter object from an SkReadBuffer.
     *  Note: If the SkPictureImageFilter object construction requires bitmap
     *  decoding, the decoder must be set on the SkReadBuffer parameter by calling
     *  SkReadBuffer::setBitmapDecoder() before calling this constructor.
     *  @param SkReadBuffer Serialized picture data.
     */
    void flatten(SkWriteBuffer&) const override;
    sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
                                        SkIPoint* offset) const override;

private:
    explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
    SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
                         PictureResolution, SkFilterQuality);

    void drawPictureAtDeviceResolution(SkCanvas* canvas,
                                       const SkIRect& deviceBounds,
                                       const Context&) const;
    void drawPictureAtLocalResolution(SkSpecialImage* source,
                                      SkCanvas*,
                                      const SkIRect& deviceBounds,
                                      const Context&) const;

    sk_sp<SkPicture>      fPicture;
    SkRect                fCropRect;
    PictureResolution     fPictureResolution;
    SkFilterQuality       fFilterQuality;

    typedef SkImageFilter INHERITED;
};

#endif