Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(17)

Side by Side Diff: src/effects/SkBlurDrawLooper.cpp

Issue 21835004: Blur refactoring (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: hide constant Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
10 #include "SkCanvas.h" 11 #include "SkCanvas.h"
11 #include "SkColorFilter.h" 12 #include "SkColorFilter.h"
12 #include "SkFlattenableBuffers.h" 13 #include "SkFlattenableBuffers.h"
13 #include "SkMaskFilter.h" 14 #include "SkMaskFilter.h"
14 #include "SkPaint.h" 15 #include "SkPaint.h"
15 #include "SkString.h" 16 #include "SkString.h"
16 #include "SkStringUtils.h" 17 #include "SkStringUtils.h"
17 18
18 SkBlurDrawLooper::SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy, 19 SkBlurDrawLooper::SkBlurDrawLooper(SkScalar radius, SkScalar dx, SkScalar dy,
19 SkColor color, uint32_t flags) 20 SkColor color, uint32_t flags) {
20 : fDx(dx), fDy(dy), fBlurColor(color), fBlurFlags(flags), fState(kDone) { 21 this->init(SkBlurMask::ConvertRadiusToSigma(radius), dx, dy, color, flags);
22 }
23
24 SkBlurDrawLooper::SkBlurDrawLooper(SkScalar sigma, SkScalar dx, SkScalar dy,
25 SkColor color, uint32_t flags,
26 bool unused) {
27 this->init(sigma, dx, dy, color, flags);
28 }
29
30 void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
31 SkColor color, uint32_t flags) {
32 fDx = dx;
33 fDy = dy;
34 fBlurColor = color;
35 fBlurFlags = flags;
36 fState = kDone;
21 37
22 SkASSERT(flags <= kAll_BlurFlag); 38 SkASSERT(flags <= kAll_BlurFlag);
23 if (radius > 0) { 39 if (sigma > 0) {
24 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ? 40 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ?
25 SkBlurMaskFilter::kIgnoreTransform_BlurFlag : 41 SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
26 SkBlurMaskFilter::kNone_BlurFlag; 42 SkBlurMaskFilter::kNone_BlurFlag;
27 43
28 blurFlags |= flags & kHighQuality_BlurFlag ? 44 blurFlags |= flags & kHighQuality_BlurFlag ?
29 SkBlurMaskFilter::kHighQuality_BlurFlag : 45 SkBlurMaskFilter::kHighQuality_BlurFlag :
30 SkBlurMaskFilter::kNone_BlurFlag; 46 SkBlurMaskFilter::kNone_BlurFlag;
31 47
32 fBlur = SkBlurMaskFilter::Create(radius, 48 fBlur = SkBlurMaskFilter::Create(sigma,
33 SkBlurMaskFilter::kNormal_BlurStyle, 49 SkBlurMaskFilter::kNormal_BlurStyle,
34 blurFlags); 50 blurFlags, true);
35 } else { 51 } else {
36 fBlur = NULL; 52 fBlur = NULL;
37 } 53 }
38 54
39 if (flags & kOverrideColor_BlurFlag) { 55 if (flags & kOverrideColor_BlurFlag) {
40 // Set alpha to 1 for the override since transparency will already 56 // Set alpha to 1 for the override since transparency will already
41 // be baked into the blurred mask. 57 // be baked into the blurred mask.
42 SkColor opaqueColor = SkColorSetA(color, 255); 58 SkColor opaqueColor = SkColorSetA(color, 255);
43 //The SrcIn xfer mode will multiply 'color' by the incoming alpha 59 //The SrcIn xfer mode will multiply 'color' by the incoming alpha
44 fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor, 60 fColorFilter = SkColorFilter::CreateModeFilter(opaqueColor,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 &needsSeparator); 158 &needsSeparator);
143 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality", 159 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality",
144 &needsSeparator); 160 &needsSeparator);
145 } 161 }
146 str->append(")"); 162 str->append(")");
147 163
148 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added 164 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added
149 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here 165 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here
150 } 166 }
151 #endif 167 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698