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 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:
     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     /**
     28      *  Refs the passed-in picture. The picture is rasterized at a resolution that matches the
     29      *  local coordinate space. If the picture needs to be resampled for drawing it into the
     30      *  destination canvas, bilinear filtering will be used. cropRect can be used to crop or
     31      *  expand the destination rect when the picture is drawn. (No scaling is implied by the
     32      *  dest rect; only the CTM is applied.)
     33      */
     34     static sk_sp<SkImageFilter> MakeForLocalSpace(sk_sp<SkPicture> picture,
     35                                                   const SkRect& cropRect,
     36                                                   SkFilterQuality filterQuality);
     37 
     38     SK_TO_STRING_OVERRIDE()
     39     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkPictureImageFilter)
     40 
     41 protected:
     42     enum PictureResolution {
     43         kDeviceSpace_PictureResolution,
     44         kLocalSpace_PictureResolution
     45     };
     46 
     47     /*  Constructs an SkPictureImageFilter object from an SkReadBuffer.
     48      *  Note: If the SkPictureImageFilter object construction requires bitmap
     49      *  decoding, the decoder must be set on the SkReadBuffer parameter by calling
     50      *  SkReadBuffer::setBitmapDecoder() before calling this constructor.
     51      *  @param SkReadBuffer Serialized picture data.
     52      */
     53     void flatten(SkWriteBuffer&) const override;
     54     sk_sp<SkSpecialImage> onFilterImage(SkSpecialImage* source, const Context&,
     55                                         SkIPoint* offset) const override;
     56     sk_sp<SkImageFilter> onMakeColorSpace(SkColorSpaceXformer*) const override;
     57 
     58 private:
     59     explicit SkPictureImageFilter(sk_sp<SkPicture> picture);
     60     SkPictureImageFilter(sk_sp<SkPicture> picture, const SkRect& cropRect,
     61                          PictureResolution, SkFilterQuality, sk_sp<SkColorSpace>);
     62 
     63     void drawPictureAtDeviceResolution(SkCanvas* canvas,
     64                                        const SkIRect& deviceBounds,
     65                                        const Context&) const;
     66     void drawPictureAtLocalResolution(SkSpecialImage* source,
     67                                       SkCanvas*,
     68                                       const SkIRect& deviceBounds,
     69                                       const Context&) const;
     70 
     71     sk_sp<SkPicture>      fPicture;
     72     SkRect                fCropRect;
     73     PictureResolution     fPictureResolution;
     74     SkFilterQuality       fFilterQuality;
     75 
     76     // Should never be set by a public constructor.  This is only used when onMakeColorSpace()
     77     // forces a deferred color space xform.
     78     sk_sp<SkColorSpace>   fColorSpace;
     79 
     80     typedef SkImageFilter INHERITED;
     81 };
     82 
     83 #endif
     84