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

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

Issue 155513012: [WIP] Add Context to SkDrawLooper. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: comments Created 6 years, 9 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
« no previous file with comments | « src/core/SkSmallAllocator.h ('k') | src/effects/SkLayerDrawLooper.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma
10 #include "SkBlurMaskFilter.h" 10 #include "SkBlurMaskFilter.h"
(...skipping 15 matching lines...) Expand all
26 SkScalar dx, SkScalar dy, uint32_t flags) { 26 SkScalar dx, SkScalar dy, uint32_t flags) {
27 this->init(sigma, dx, dy, color, flags); 27 this->init(sigma, dx, dy, color, flags);
28 } 28 }
29 29
30 void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy, 30 void SkBlurDrawLooper::init(SkScalar sigma, SkScalar dx, SkScalar dy,
31 SkColor color, uint32_t flags) { 31 SkColor color, uint32_t flags) {
32 fDx = dx; 32 fDx = dx;
33 fDy = dy; 33 fDy = dy;
34 fBlurColor = color; 34 fBlurColor = color;
35 fBlurFlags = flags; 35 fBlurFlags = flags;
36 fState = kDone;
37 36
38 SkASSERT(flags <= kAll_BlurFlag); 37 SkASSERT(flags <= kAll_BlurFlag);
39 if (sigma > 0) { 38 if (sigma > 0) {
40 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ? 39 uint32_t blurFlags = flags & kIgnoreTransform_BlurFlag ?
41 SkBlurMaskFilter::kIgnoreTransform_BlurFlag : 40 SkBlurMaskFilter::kIgnoreTransform_BlurFlag :
42 SkBlurMaskFilter::kNone_BlurFlag; 41 SkBlurMaskFilter::kNone_BlurFlag;
43 42
44 blurFlags |= flags & kHighQuality_BlurFlag ? 43 blurFlags |= flags & kHighQuality_BlurFlag ?
45 SkBlurMaskFilter::kHighQuality_BlurFlag : 44 SkBlurMaskFilter::kHighQuality_BlurFlag :
46 SkBlurMaskFilter::kNone_BlurFlag; 45 SkBlurMaskFilter::kNone_BlurFlag;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const { 82 void SkBlurDrawLooper::flatten(SkWriteBuffer& buffer) const {
84 this->INHERITED::flatten(buffer); 83 this->INHERITED::flatten(buffer);
85 buffer.writeScalar(fDx); 84 buffer.writeScalar(fDx);
86 buffer.writeScalar(fDy); 85 buffer.writeScalar(fDy);
87 buffer.writeColor(fBlurColor); 86 buffer.writeColor(fBlurColor);
88 buffer.writeFlattenable(fBlur); 87 buffer.writeFlattenable(fBlur);
89 buffer.writeFlattenable(fColorFilter); 88 buffer.writeFlattenable(fColorFilter);
90 buffer.writeUInt(fBlurFlags); 89 buffer.writeUInt(fBlurFlags);
91 } 90 }
92 91
93 void SkBlurDrawLooper::init(SkCanvas*) { 92 SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const {
94 fState = kBeforeEdge; 93 return SkNEW_PLACEMENT_ARGS(storage, BlurDrawLooperContext, (this));
95 } 94 }
96 95
97 bool SkBlurDrawLooper::next(SkCanvas* canvas, SkPaint* paint) { 96 SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext(
97 const SkBlurDrawLooper* looper)
98 : fLooper(looper), fState(SkBlurDrawLooper::kBeforeEdge) {}
99
100 bool SkBlurDrawLooper::BlurDrawLooperContext::next(SkCanvas* canvas,
101 SkPaint* paint) {
98 switch (fState) { 102 switch (fState) {
99 case kBeforeEdge: 103 case kBeforeEdge:
100 // we do nothing if a maskfilter is already installed 104 // we do nothing if a maskfilter is already installed
101 if (paint->getMaskFilter()) { 105 if (paint->getMaskFilter()) {
102 fState = kDone; 106 fState = kDone;
103 return false; 107 return false;
104 } 108 }
105 #ifdef SK_BUILD_FOR_ANDROID 109 #ifdef SK_BUILD_FOR_ANDROID
106 SkColor blurColor; 110 SkColor blurColor;
107 blurColor = fBlurColor; 111 blurColor = fLooper->fBlurColor;
108 if (SkColorGetA(blurColor) == 255) { 112 if (SkColorGetA(blurColor) == 255) {
109 blurColor = SkColorSetA(blurColor, paint->getAlpha()); 113 blurColor = SkColorSetA(blurColor, paint->getAlpha());
110 } 114 }
111 paint->setColor(blurColor); 115 paint->setColor(blurColor);
112 #else 116 #else
113 paint->setColor(fBlurColor); 117 paint->setColor(fLooper->fBlurColor);
114 #endif 118 #endif
115 paint->setMaskFilter(fBlur); 119 paint->setMaskFilter(fLooper->fBlur);
116 paint->setColorFilter(fColorFilter); 120 paint->setColorFilter(fLooper->fColorFilter);
117 canvas->save(SkCanvas::kMatrix_SaveFlag); 121 canvas->save(SkCanvas::kMatrix_SaveFlag);
118 if (fBlurFlags & kIgnoreTransform_BlurFlag) { 122 if (fLooper->fBlurFlags & kIgnoreTransform_BlurFlag) {
119 SkMatrix transform(canvas->getTotalMatrix()); 123 SkMatrix transform(canvas->getTotalMatrix());
120 transform.postTranslate(fDx, fDy); 124 transform.postTranslate(fLooper->fDx, fLooper->fDy);
121 canvas->setMatrix(transform); 125 canvas->setMatrix(transform);
122 } else { 126 } else {
123 canvas->translate(fDx, fDy); 127 canvas->translate(fLooper->fDx, fLooper->fDy);
124 } 128 }
125 fState = kAfterEdge; 129 fState = kAfterEdge;
126 return true; 130 return true;
127 case kAfterEdge: 131 case kAfterEdge:
128 canvas->restore(); 132 canvas->restore();
129 fState = kDone; 133 fState = kDone;
130 return true; 134 return true;
131 default: 135 default:
132 SkASSERT(kDone == fState); 136 SkASSERT(kDone == fState);
133 return false; 137 return false;
(...skipping 24 matching lines...) Expand all
158 &needsSeparator); 162 &needsSeparator);
159 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality", 163 SkAddFlagToString(str, SkToBool(kHighQuality_BlurFlag & fBlurFlags), "Hi ghQuality",
160 &needsSeparator); 164 &needsSeparator);
161 } 165 }
162 str->append(")"); 166 str->append(")");
163 167
164 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added 168 // TODO: add optional "fBlurFilter->toString(str);" when SkMaskFilter::toStr ing is added
165 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here 169 // alternatively we could cache the radius in SkBlurDrawLooper and just add it here
166 } 170 }
167 #endif 171 #endif
OLDNEW
« no previous file with comments | « src/core/SkSmallAllocator.h ('k') | src/effects/SkLayerDrawLooper.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698