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"
|
|
|
|
|
2017-02-08 20:12:19 +00:00
|
|
|
class SkArenaAlloc;
|
2008-12-17 15:59:43 +00:00
|
|
|
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:
|
2017-03-23 20:23:38 +00:00
|
|
|
static sk_sp<SkDrawLooper> Make(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy) {
|
|
|
|
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy));
|
2016-03-21 20:25:16 +00:00
|
|
|
}
|
2013-08-27 16:14:03 +00:00
|
|
|
|
2017-02-08 20:12:19 +00:00
|
|
|
SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
|
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:
|
2017-03-23 20:23:38 +00:00
|
|
|
SkBlurDrawLooper(SkColor color, SkScalar sigma, SkScalar dx, SkScalar dy);
|
2014-04-15 15:48:36 +00:00
|
|
|
|
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;
|
2014-04-29 15:20:16 +00:00
|
|
|
SkScalar fDx, fDy, fSigma;
|
2008-12-17 15:59:43 +00:00
|
|
|
SkColor fBlurColor;
|
|
|
|
|
|
|
|
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
|
|
|
|
2017-03-23 20:23:38 +00:00
|
|
|
void init(SkScalar sigma, SkScalar dx, SkScalar dy, SkColor color);
|
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
|