Home | History | Annotate | Download | only in effects
      1 
      2 /*
      3  * Copyright 2008 The Android Open Source Project
      4  *
      5  * Use of this source code is governed by a BSD-style license that can be
      6  * found in the LICENSE file.
      7  */
      8 
      9 
     10 #ifndef SkBlurDrawLooper_DEFINED
     11 #define SkBlurDrawLooper_DEFINED
     12 
     13 #include "SkDrawLooper.h"
     14 #include "SkColor.h"
     15 
     16 class SkMaskFilter;
     17 class SkColorFilter;
     18 
     19 /** \class SkBlurDrawLooper
     20     This class draws a shadow of the object (possibly offset), and then draws
     21     the original object in its original position.
     22     should there be an option to just draw the shadow/blur layer? webkit?
     23 */
     24 class SK_API SkBlurDrawLooper : public SkDrawLooper {
     25 public:
     26     enum BlurFlags {
     27         kNone_BlurFlag = 0x00,
     28         /**
     29             The blur layer's dx/dy/radius aren't affected by the canvas
     30             transform.
     31         */
     32         kIgnoreTransform_BlurFlag   = 0x01,
     33         kOverrideColor_BlurFlag     = 0x02,
     34         kHighQuality_BlurFlag       = 0x04,
     35         /** mask for all blur flags */
     36         kAll_BlurFlag = 0x07
     37     };
     38 
     39     SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
     40                      uint32_t flags = kNone_BlurFlag);
     41     virtual ~SkBlurDrawLooper();
     42 
     43     // overrides from SkDrawLooper
     44     virtual void init(SkCanvas*);
     45     virtual bool next(SkCanvas*, SkPaint* paint);
     46 
     47     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
     48         return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
     49     }
     50 
     51     SK_DECLARE_FLATTENABLE_REGISTRAR()
     52 
     53 protected:
     54     SkBlurDrawLooper(SkFlattenableReadBuffer&);
     55     // overrides from SkFlattenable
     56     virtual void flatten(SkFlattenableWriteBuffer& );
     57     virtual Factory getFactory() { return CreateProc; }
     58 
     59 private:
     60     SkMaskFilter*   fBlur;
     61     SkColorFilter*  fColorFilter;
     62     SkScalar        fDx, fDy;
     63     SkColor         fBlurColor;
     64     uint32_t        fBlurFlags;
     65 
     66     enum State {
     67         kBeforeEdge,
     68         kAfterEdge,
     69         kDone
     70     };
     71     State   fState;
     72 
     73     typedef SkDrawLooper INHERITED;
     74 };
     75 
     76 #endif
     77