Home | History | Annotate | Download | only in effects
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #ifndef SkBlurDrawLooper_DEFINED
     18 #define SkBlurDrawLooper_DEFINED
     19 
     20 #include "SkDrawLooper.h"
     21 #include "SkColor.h"
     22 
     23 class SkMaskFilter;
     24 class SkColorFilter;
     25 
     26 /** \class SkBlurDrawLooper
     27     This class draws a shadow of the object (possibly offset), and then draws
     28     the original object in its original position.
     29     should there be an option to just draw the shadow/blur layer? webkit?
     30 */
     31 class SK_API SkBlurDrawLooper : public SkDrawLooper {
     32 public:
     33     enum BlurFlags {
     34         kNone_BlurFlag = 0x00,
     35         /**
     36             The blur layer's dx/dy/radius aren't affected by the canvas
     37             transform.
     38         */
     39         kIgnoreTransform_BlurFlag   = 0x01,
     40         kOverrideColor_BlurFlag     = 0x02,
     41         kHighQuality_BlurFlag       = 0x04,
     42         /** mask for all blur flags */
     43         kAll_BlurFlag = 0x07
     44     };
     45 
     46     SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color,
     47                      uint32_t flags = kNone_BlurFlag);
     48     virtual ~SkBlurDrawLooper();
     49 
     50     // overrides from SkDrawLooper
     51     virtual void init(SkCanvas*);
     52     virtual bool next(SkCanvas*, SkPaint* paint);
     53 
     54     static SkFlattenable* CreateProc(SkFlattenableReadBuffer& buffer) {
     55         return SkNEW_ARGS(SkBlurDrawLooper, (buffer));
     56     }
     57 
     58 
     59 protected:
     60     SkBlurDrawLooper(SkFlattenableReadBuffer&);
     61     // overrides from SkFlattenable
     62     virtual void flatten(SkFlattenableWriteBuffer& );
     63     virtual Factory getFactory() { return CreateProc; }
     64 
     65 private:
     66     SkMaskFilter*   fBlur;
     67     SkColorFilter*  fColorFilter;
     68     SkScalar        fDx, fDy;
     69     SkColor         fBlurColor;
     70     uint32_t        fBlurFlags;
     71 
     72     enum State {
     73         kBeforeEdge,
     74         kAfterEdge,
     75         kDone
     76     };
     77     State   fState;
     78 
     79     typedef SkDrawLooper INHERITED;
     80 };
     81 
     82 #endif
     83