SkXfermodeImageFilter.h revision 4cb543d6057b692e1099e9f115155f0bf323a0c8
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 SkXfermodeImageFilter_DEFINED
9#define SkXfermodeImageFilter_DEFINED
10
11#include "SkImageFilter.h"
12
13class SkBitmap;
14class SkXfermode;
15
16class SK_API SkXfermodeImageFilter : public SkImageFilter {
17    /**
18     * This filter takes an xfermode, and uses it to composite the foreground
19     * over the background.  If foreground or background is NULL, the input
20     * bitmap (src) is used instead.
21      */
22
23public:
24    virtual ~SkXfermodeImageFilter();
25
26    static SkXfermodeImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
27                                         SkImageFilter* foreground = NULL,
28                                         const CropRect* cropRect = NULL) {
29        return SkNEW_ARGS(SkXfermodeImageFilter, (mode, background, foreground, cropRect));
30    }
31
32    SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
33
34    virtual bool onFilterImage(Proxy* proxy,
35                               const SkBitmap& src,
36                               const Context& ctx,
37                               SkBitmap* dst,
38                               SkIPoint* offset) const SK_OVERRIDE;
39#if SK_SUPPORT_GPU
40    virtual bool canFilterImageGPU() const SK_OVERRIDE { return !cropRectIsSet(); }
41    virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
42                                SkBitmap* result, SkIPoint* offset) const SK_OVERRIDE;
43#endif
44
45protected:
46    explicit SkXfermodeImageFilter(SkReadBuffer& buffer);
47    virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
48
49#ifdef SK_SUPPORT_LEGACY_PUBLICEFFECTCONSTRUCTORS
50public:
51#endif
52    SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* background,
53                          SkImageFilter* foreground = NULL, const CropRect* cropRect = NULL);
54
55private:
56    SkXfermode* fMode;
57    typedef SkImageFilter INHERITED;
58};
59
60#endif
61