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
14class SK_API SkPictureImageFilter : public SkImageFilter {
15public:
16    /**
17     *  Refs the passed-in picture.
18     */
19    static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture);
20
21    /**
22     *  Refs the passed-in picture. cropRect can be used to crop or expand the destination rect when
23     *  the picture is drawn. (No scaling is implied by the dest rect; only the CTM is applied.)
24     */
25    static sk_sp<SkImageFilter> Make(sk_sp<SkPicture> picture, const SkRect& cropRect);
26
27    SK_TO_STRING_OVERRIDE()
28    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
29
30protected:
31    /*  Constructs an SkPictureImageFilter object from an SkReadBuffer.
32     *  Note: If the SkPictureImageFilter object construction requires bitmap
33     *  decoding, the decoder must be set on the SkReadBuffer parameter by calling
34     *  SkReadBuffer::setBitmapDecoder() before calling this constructor.
35     *  @param SkReadBuffer Serialized picture data.
36     */
37    void flatten(SkWriteBuffer&) const override;
38    sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
39                                        SkIPoint* offset) const override;
40    sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
41
42private:
43    explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
44    SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect, sk_sp<SkColorSpace>);
45
46    sk_sp<SkPicture>    fPicture;
47    SkRect              fCropRect;
48
49    // Should never be set by a public constructor.  This is only used when onMakeColorSpace()
50    // forces a deferred color space xform.
51    sk_sp<SkColorSpace>   fColorSpace;
52
53    typedef SkImageFilter INHERITED;
54};
55
56#endif
57