michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef SkBlurDrawLooper_DEFINED michael@0: #define SkBlurDrawLooper_DEFINED michael@0: michael@0: #include "SkDrawLooper.h" michael@0: #include "SkColor.h" michael@0: michael@0: class SkMaskFilter; michael@0: class SkColorFilter; michael@0: michael@0: /** \class SkBlurDrawLooper michael@0: This class draws a shadow of the object (possibly offset), and then draws michael@0: the original object in its original position. michael@0: should there be an option to just draw the shadow/blur layer? webkit? michael@0: */ michael@0: class SK_API SkBlurDrawLooper : public SkDrawLooper { michael@0: public: michael@0: enum BlurFlags { michael@0: kNone_BlurFlag = 0x00, michael@0: /** michael@0: The blur layer's dx/dy/radius aren't affected by the canvas michael@0: transform. michael@0: */ michael@0: kIgnoreTransform_BlurFlag = 0x01, michael@0: kOverrideColor_BlurFlag = 0x02, michael@0: kHighQuality_BlurFlag = 0x04, michael@0: /** mask for all blur flags */ michael@0: kAll_BlurFlag = 0x07 michael@0: }; michael@0: michael@0: SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy, michael@0: uint32_t flags = kNone_BlurFlag); michael@0: michael@0: // SK_ATTR_DEPRECATED("use sigma version") michael@0: SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, SkColor color, michael@0: uint32_t flags = kNone_BlurFlag); michael@0: virtual ~SkBlurDrawLooper(); michael@0: michael@0: virtual SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const SK_OVERRIDE; michael@0: michael@0: virtual size_t contextSize() const SK_OVERRIDE { return sizeof(BlurDrawLooperContext); } michael@0: michael@0: SK_TO_STRING_OVERRIDE() michael@0: SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper) michael@0: michael@0: protected: michael@0: SkBlurDrawLooper(SkReadBuffer&); michael@0: virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE; michael@0: michael@0: private: michael@0: SkMaskFilter* fBlur; michael@0: SkColorFilter* fColorFilter; michael@0: SkScalar fDx, fDy; michael@0: SkColor fBlurColor; michael@0: uint32_t fBlurFlags; michael@0: michael@0: enum State { michael@0: kBeforeEdge, michael@0: kAfterEdge, michael@0: kDone michael@0: }; michael@0: michael@0: class BlurDrawLooperContext : public SkDrawLooper::Context { michael@0: public: michael@0: explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper); michael@0: michael@0: virtual bool next(SkCanvas* canvas, SkPaint* paint) SK_OVERRIDE; michael@0: michael@0: private: michael@0: const SkBlurDrawLooper* fLooper; michael@0: State fState; michael@0: }; michael@0: michael@0: void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags); michael@0: michael@0: typedef SkDrawLooper INHERITED; michael@0: }; michael@0: michael@0: #endif