OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2011 Google Inc. | 3 * Copyright 2011 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 #include "SkBlurDrawLooper.h" | 8 #include "SkBlurDrawLooper.h" |
9 #include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma | 9 #include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma |
10 #include "SkBlurMaskFilter.h" | 10 #include "SkBlurMaskFilter.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma, | 27 SkBlurDrawLooper::SkBlurDrawLooper(SkColor color, SkScalar sigma, |
28 SkScalar dx, SkScalar dy, uint32_t flags) { | 28 SkScalar dx, SkScalar dy, uint32_t flags) { |
29 this->init(sigma, dx, dy, color, flags); | 29 this->init(sigma, dx, dy, color, flags); |
30 } | 30 } |
31 | 31 |
32 void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, | 32 void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, |
33 SkColor color, uint32_t flags) { | 33 SkColor color, uint32_t flags) { |
34 fDx = dx; | 34 fDx = dx; |
35 fDy = dy; | 35 fDy = dy; |
36 fSigma = sigma; | |
36 fBlurColor = color; | 37 fBlurColor = color; |
37 fBlurFlags = flags; | 38 fBlurFlags = flags; |
38 | 39 |
39 SkASSERT(flags <= kAll_BlurFlag); | 40 SkASSERT(flags <= kAll_BlurFlag); |
40 if (sigma > 0) { | 41 if (sigma > 0) { |
41 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ? | 42 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ? |
42 SkBlurMaskFilter::kIgnoreTransform_BlurFlag : | 43 SkBlurMaskFilter::kIgnoreTransform_BlurFlag : |
43 SkBlurMaskFilter::kNone_BlurFlag; | 44 SkBlurMaskFilter::kNone_BlurFlag; |
44 | 45 |
45 blurFlags |= flags & kHighQuality_BlurFlag ? | 46 blurFlags |= flags & kHighQuality_BlurFlag ? |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 } | 78 } |
78 | 79 |
79 SkBlurDrawLooper::~SkBlurDrawLooper() { | 80 SkBlurDrawLooper::~SkBlurDrawLooper() { |
80 SkSafeUnref(fBlur); | 81 SkSafeUnref(fBlur); |
81 SkSafeUnref(fColorFilter); | 82 SkSafeUnref(fColorFilter); |
82 } | 83 } |
83 | 84 |
84 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { | 85 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { |
85 this->INHERITED::flatten(buffer); | 86 this->INHERITED::flatten(buffer); |
86 buffer.writeScalar(fDx); | 87 buffer.writeScalar(fDx); |
87 buffer.writeScalar(fDy); | 88 buffer.writeScalar(fDy); |
djsollen
2014/04/28 13:55:40
should we serialize fSigma too?
reed1
2014/04/28 20:59:27
Done.
| |
88 buffer.writeColor(fBlurColor); | 89 buffer.writeColor(fBlurColor); |
89 buffer.writeFlattenable(fBlur); | 90 buffer.writeFlattenable(fBlur); |
90 buffer.writeFlattenable(fColorFilter); | 91 buffer.writeFlattenable(fColorFilter); |
91 buffer.writeUInt(fBlurFlags); | 92 buffer.writeUInt(fBlurFlags); |
92 } | 93 } |
93 | 94 |
95 bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const { | |
96 if (fSigma <= 0.5f) { | |
97 return false; | |
98 } | |
99 | |
100 if (rec) { | |
101 rec->fRadius = SkBlurMask::ConvertSigmaToRadius(fSigma); | |
102 rec->fColor = fBlurColor; | |
103 rec->fOffset.set(fDx, fDy); | |
104 } | |
105 return true; | |
106 } | |
107 | |
108 //////////////////////////////////////////////////////////////////////////////// //////// | |
109 | |
94 SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const { | 110 SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const { |
95 return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this)); | 111 return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this)); |
96 } | 112 } |
97 | 113 |
98 SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext( | 114 SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext( |
99 const SkBlurDrawLooper* looper) | 115 const SkBlurDrawLooper* looper) |
100 : fLooper(looper), fState(SkBlurDrawLooper::kBeforeEdge) {} | 116 : fLooper(looper), fState(SkBlurDrawLooper::kBeforeEdge) {} |
101 | 117 |
102 bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas, | 118 bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas, |
103 SkPaint* paint) { | 119 SkPaint* paint) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
164 &needsSeparator); | 180 &needsSeparator); |
165 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality", | 181 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality", |
166 &needsSeparator); | 182 &needsSeparator); |
167 } | 183 } |
168 str->append(")"); | 184 str->append(")"); |
169 | 185 |
170 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added | 186 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added |
171 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here | 187 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here |
172 } | 188 } |
173 #endif | 189 #endif |
OLD | NEW |