Home | History | Annotate | Download | only in effects
      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 
     13 class SkBitmap;
     14 class SkXfermode;
     15 
     16 class 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 
     23 public:
     24     virtual ~SkXfermodeImageFilter();
     25 
     26     static SkXfermodeImageFilter* Create(SkXfermode* mode, SkImageFilter* background,
     27                                          SkImageFilter* foreground = NULL,
     28                                          const CropRect* cropRect = NULL) {
     29         SkImageFilter* inputs[2] = { background, foreground };
     30         return SkNEW_ARGS(SkXfermodeImageFilter, (mode, inputs, cropRect));
     31     }
     32 
     33     SK_TO_STRING_OVERRIDE()
     34     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkXfermodeImageFilter)
     35 
     36     virtual bool onFilterImage(Proxy* proxy,
     37                                const SkBitmap& src,
     38                                const Context& ctx,
     39                                SkBitmap* dst,
     40                                SkIPoint* offset) const override;
     41 #if SK_SUPPORT_GPU
     42     bool canFilterImageGPU() const override;
     43     virtual bool filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
     44                                 SkBitmap* result, SkIPoint* offset) const override;
     45 #endif
     46 
     47 protected:
     48     SkXfermodeImageFilter(SkXfermode* mode, SkImageFilter* inputs[2],
     49                           const CropRect* cropRect);
     50     void flatten(SkWriteBuffer&) const override;
     51 
     52 private:
     53     SkXfermode* fMode;
     54     typedef SkImageFilter INHERITED;
     55 };
     56 
     57 #endif
     58