2008-12-17 15:59:43 +00:00
|
|
|
/*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Copyright 2008 The Android Open Source Project
|
2008-12-17 15:59:43 +00:00
|
|
|
*
|
2011-07-28 14:26:00 +00:00
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
2008-12-17 15:59:43 +00:00
|
|
|
*/
|
|
|
|
|
2011-07-28 14:26:00 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
#ifndef SkBlurDrawLooper_DEFINED
|
|
|
|
#define SkBlurDrawLooper_DEFINED
|
|
|
|
|
|
|
|
#include "SkDrawLooper.h"
|
|
|
|
#include "SkColor.h"
|
|
|
|
|
|
|
|
class SkMaskFilter;
|
2011-02-18 19:03:01 +00:00
|
|
|
class SkColorFilter;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
/** \class SkBlurDrawLooper
|
|
|
|
This class draws a shadow of the object (possibly offset), and then draws
|
|
|
|
the original object in its original position.
|
|
|
|
should there be an option to just draw the shadow/blur layer? webkit?
|
|
|
|
*/
|
2011-03-15 21:27:08 +00:00
|
|
|
class SK_API SkBlurDrawLooper : public SkDrawLooper {
|
2008-12-17 15:59:43 +00:00
|
|
|
public:
|
2010-12-06 23:45:58 +00:00
|
|
|
enum BlurFlags {
|
|
|
|
kNone_BlurFlag = 0x00,
|
2012-08-23 18:09:54 +00:00
|
|
|
/**
|
|
|
|
The blur layer's dx/dy/radius aren't affected by the canvas
|
2010-12-06 23:45:58 +00:00
|
|
|
transform.
|
|
|
|
*/
|
2011-02-18 19:03:01 +00:00
|
|
|
kIgnoreTransform_BlurFlag = 0x01,
|
|
|
|
kOverrideColor_BlurFlag = 0x02,
|
|
|
|
kHighQuality_BlurFlag = 0x04,
|
2010-12-06 23:45:58 +00:00
|
|
|
/** mask for all blur flags */
|
2012-11-29 17:09:27 +00:00
|
|
|
kAll_BlurFlag = 0x07
|
2010-12-06 23:45:58 +00:00
|
|
|
};
|
|
|
|
|
2016-03-21 20:25:16 +00:00
|
|
|
static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
|
|
|
|
uint32_t flags = kNone_BlurFlag) {
|
|
|
|
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
|
|
|
|
}
|
2013-08-27 16:14:03 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
|
2014-03-12 09:42:01 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
size_t contextSize() const override { return sizeof(BlurDrawLooperContext); }
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2014-03-13 18:02:17 +00:00
|
|
|
SK_TO_STRING_OVERRIDE()
|
2012-03-26 17:57:35 +00:00
|
|
|
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
protected:
|
2014-04-15 15:48:36 +00:00
|
|
|
SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy,
|
|
|
|
uint32_t flags);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
void flatten(SkWriteBuffer&) const override;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool asABlurShadow(BlurShadowRec*) const override;
|
2014-04-29 15:20:16 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
private:
|
2016-04-04 17:02:58 +00:00
|
|
|
sk_sp<SkMaskFilter> fBlur;
|
2016-03-22 17:17:23 +00:00
|
|
|
sk_sp<SkColorFilter> fColorFilter;
|
2014-04-29 15:20:16 +00:00
|
|
|
SkScalar fDx, fDy, fSigma;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkColor fBlurColor;
|
2012-08-23 18:09:54 +00:00
|
|
|
uint32_t fBlurFlags;
|
2008-12-17 15:59:43 +00:00
|
|
|
|
|
|
|
enum State {
|
|
|
|
kBeforeEdge,
|
|
|
|
kAfterEdge,
|
|
|
|
kDone
|
|
|
|
};
|
2014-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
class BlurDrawLooperContext : public SkDrawLooper::Context {
|
|
|
|
public:
|
|
|
|
explicit BlurDrawLooperContext(const SkBlurDrawLooper* looper);
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool next(SkCanvas* canvas, SkPaint* paint) override;
|
2014-03-12 09:42:01 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const SkBlurDrawLooper* fLooper;
|
|
|
|
State fState;
|
|
|
|
};
|
2012-08-23 18:09:54 +00:00
|
|
|
|
2013-08-27 16:14:03 +00:00
|
|
|
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color, uint32_t flags);
|
2014-04-29 15:20:16 +00:00
|
|
|
void initEffects();
|
2013-08-27 16:14:03 +00:00
|
|
|
|
2008-12-17 15:59:43 +00:00
|
|
|
typedef SkDrawLooper INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|