Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright 2008 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 
      9 #ifndef SkBlurDrawLooper_DEFINED
     10 #define SkBlurDrawLooper_DEFINED
     11 
     12 #include "SkDrawLooper.h"
     13 #include "SkColor.h"
     14 
     15 class SkMaskFilter;
     16 class SkColorFilter;
     17 
     18 /** \class SkBlurDrawLooper
     19     This class draws a shadow of the object (possibly offset), and then draws
     20     the original object in its original position.
     21     should there be an option to just draw the shadow/blur layer? webkit?
     22 */
     23 class SK_API SkBlurDrawLooper : public SkDrawLooper {
     24 public:
     25     enum BlurFlags {
     26         kNone_BlurFlag = 0x00,
     27         /**
     28             The blur layer's dx/dy/radius aren't affected by the canvas
     29             transform.
     30         */
     31         kIgnoreTransform_BlurFlag   = 0x01,
     32         kOverrideColor_BlurFlag     = 0x02,
     33         kHighQuality_BlurFlag       = 0x04,
     34         /** mask for all blur flags */
     35         kAll_BlurFlag               = 0x07
     36     };
     37 
     38     static SkBlurDrawLooper* Create(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
     39                                     uint32_t flags = kNone_BlurFlag) {
     40         return SkNEW_ARGS(SkBlurDrawLooper, (color, sigma, dx, dy, flags));
     41     }
     42 
     43     virtual ~SkBlurDrawLooper();
     44 
     45     virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE;
     46 
     47     virtual size_t contextSize() const SK_OVERRIDE { return sizeof(BlurDrawLooperContext); }
     48 
     49     SK_TO_STRING_OVERRIDE()
     50     SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
     51 
     52 protected:
     53     SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
     54                      uint32_t flags);
     55 
     56 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
     57     SkBlurDrawLooper(SkReadBuffer&);
     58 #endif
     59     virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
     60 
     61     virtual bool asABlurShadow(BlurShadowRec*) const SK_OVERRIDE;
     62 
     63 private:
     64     SkMaskFilter*   fBlur;
     65     SkColorFilter*  fColorFilter;
     66     SkScalar        fDx, fDy, fSigma;
     67     SkColor         fBlurColor;
     68     uint32_t        fBlurFlags;
     69 
     70     enum State {
     71         kBeforeEdge,
     72         kAfterEdge,
     73         kDone
     74     };
     75 
     76     class BlurDrawLooperContext : public SkDrawLooper::Context {
     77     public:
     78         explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
     79 
     80         virtual bool next(SkCanvas* canvas, SkPaint* paint) SK_OVERRIDE;
     81 
     82     private:
     83         const SkBlurDrawLooper* fLooper;
     84         State fState;
     85     };
     86 
     87     void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
     88     void initEffects();
     89 
     90     typedef SkDrawLooper INHERITED;
     91 };
     92 
     93 #endif
     94