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

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

Issue 189913021: Implement support for a Context parameter in image filters (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Revert all but the Context changes. 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 | Annotate | Revision Log
« no previous file with comments | « src/effects/SkMergeImageFilter.cpp ('k') | src/effects/SkOffsetImageFilter.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 * Copyright 2012 The Android Open Source Project 2 * Copyright 2012 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkMorphologyImageFilter.h" 8 #include "SkMorphologyImageFilter.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 { 133 {
134 procY(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0), 134 procY(src.getAddr32(bounds.left(), bounds.top()), dst->getAddr32(0, 0),
135 radiusY, bounds.height(), bounds.width(), 135 radiusY, bounds.height(), bounds.width(),
136 src.rowBytesAsPixels(), dst->rowBytesAsPixels()); 136 src.rowBytesAsPixels(), dst->rowBytesAsPixels());
137 } 137 }
138 138
139 bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p rocX, 139 bool SkMorphologyImageFilter::filterImageGeneric(SkMorphologyImageFilter::Proc p rocX,
140 SkMorphologyImageFilter::Proc p rocY, 140 SkMorphologyImageFilter::Proc p rocY,
141 Proxy* proxy, 141 Proxy* proxy,
142 const SkBitmap& source, 142 const SkBitmap& source,
143 const SkMatrix& ctm, 143 const Context& ctx,
144 SkBitmap* dst, 144 SkBitmap* dst,
145 SkIPoint* offset) const { 145 SkIPoint* offset) const {
146 SkBitmap src = source; 146 SkBitmap src = source;
147 SkIPoint srcOffset = SkIPoint::Make(0, 0); 147 SkIPoint srcOffset = SkIPoint::Make(0, 0);
148 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctm, &src, &srcO ffset)) { 148 if (getInput(0) && !getInput(0)->filterImage(proxy, source, ctx, &src, &srcO ffset)) {
149 return false; 149 return false;
150 } 150 }
151 151
152 if (src.colorType() != kPMColor_SkColorType) { 152 if (src.colorType() != kPMColor_SkColorType) {
153 return false; 153 return false;
154 } 154 }
155 155
156 SkIRect bounds; 156 SkIRect bounds;
157 src.getBounds(&bounds); 157 src.getBounds(&bounds);
158 bounds.offset(srcOffset); 158 bounds.offset(srcOffset);
159 if (!this->applyCropRect(&bounds, ctm)) { 159 if (!this->applyCropRect(&bounds, ctx.ctm())) {
160 return false; 160 return false;
161 } 161 }
162 162
163 SkAutoLockPixels alp(src); 163 SkAutoLockPixels alp(src);
164 if (!src.getPixels()) { 164 if (!src.getPixels()) {
165 return false; 165 return false;
166 } 166 }
167 167
168 dst->setConfig(src.config(), bounds.width(), bounds.height()); 168 dst->setConfig(src.config(), bounds.width(), bounds.height());
169 dst->allocPixels(); 169 dst->allocPixels();
170 if (!dst->getPixels()) { 170 if (!dst->getPixels()) {
171 return false; 171 return false;
172 } 172 }
173 173
174 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), 174 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
175 SkIntToScalar(this->radius().height())); 175 SkIntToScalar(this->radius().height()));
176 ctm.mapVectors(&radius, 1); 176 ctx.ctm().mapVectors(&radius, 1);
177 int width = SkScalarFloorToInt(radius.fX); 177 int width = SkScalarFloorToInt(radius.fX);
178 int height = SkScalarFloorToInt(radius.fY); 178 int height = SkScalarFloorToInt(radius.fY);
179 179
180 if (width < 0 || height < 0) { 180 if (width < 0 || height < 0) {
181 return false; 181 return false;
182 } 182 }
183 183
184 SkIRect srcBounds = bounds; 184 SkIRect srcBounds = bounds;
185 srcBounds.offset(-srcOffset); 185 srcBounds.offset(-srcOffset);
186 186
(...skipping 18 matching lines...) Expand all
205 callProcX(procX, src, dst, width, srcBounds); 205 callProcX(procX, src, dst, width, srcBounds);
206 } else if (height > 0) { 206 } else if (height > 0) {
207 callProcY(procY, src, dst, height, srcBounds); 207 callProcY(procY, src, dst, height, srcBounds);
208 } 208 }
209 offset->fX = bounds.left(); 209 offset->fX = bounds.left();
210 offset->fY = bounds.top(); 210 offset->fY = bounds.top();
211 return true; 211 return true;
212 } 212 }
213 213
214 bool SkErodeImageFilter::onFilterImage(Proxy* proxy, 214 bool SkErodeImageFilter::onFilterImage(Proxy* proxy,
215 const SkBitmap& source, const SkMatrix& c tm, 215 const SkBitmap& source, const Context& ct x,
216 SkBitmap* dst, SkIPoint* offset) const { 216 SkBitmap* dst, SkIPoint* offset) const {
217 Proc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorphologyProcType); 217 Proc erodeXProc = SkMorphologyGetPlatformProc(kErodeX_SkMorphologyProcType);
218 if (!erodeXProc) { 218 if (!erodeXProc) {
219 erodeXProc = erode<kX>; 219 erodeXProc = erode<kX>;
220 } 220 }
221 Proc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorphologyProcType); 221 Proc erodeYProc = SkMorphologyGetPlatformProc(kErodeY_SkMorphologyProcType);
222 if (!erodeYProc) { 222 if (!erodeYProc) {
223 erodeYProc = erode<kY>; 223 erodeYProc = erode<kY>;
224 } 224 }
225 return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctm, dst, offset); 225 return this->filterImageGeneric(erodeXProc, erodeYProc, proxy, source, ctx, dst, offset);
226 } 226 }
227 227
228 bool SkDilateImageFilter::onFilterImage(Proxy* proxy, 228 bool SkDilateImageFilter::onFilterImage(Proxy* proxy,
229 const SkBitmap& source, const SkMatrix& ctm, 229 const SkBitmap& source, const Context& c tx,
230 SkBitmap* dst, SkIPoint* offset) const { 230 SkBitmap* dst, SkIPoint* offset) const {
231 Proc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorphologyProcType ); 231 Proc dilateXProc = SkMorphologyGetPlatformProc(kDilateX_SkMorphologyProcType );
232 if (!dilateXProc) { 232 if (!dilateXProc) {
233 dilateXProc = dilate<kX>; 233 dilateXProc = dilate<kX>;
234 } 234 }
235 Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType ); 235 Proc dilateYProc = SkMorphologyGetPlatformProc(kDilateY_SkMorphologyProcType );
236 if (!dilateYProc) { 236 if (!dilateYProc) {
237 dilateYProc = dilate<kY>; 237 dilateYProc = dilate<kY>;
238 } 238 }
239 return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctm , dst, offset); 239 return this->filterImageGeneric(dilateXProc, dilateYProc, proxy, source, ctx , dst, offset);
240 } 240 }
241 241
242 void SkMorphologyImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const { 242 void SkMorphologyImageFilter::computeFastBounds(const SkRect& src, SkRect* dst) const {
243 if (getInput(0)) { 243 if (getInput(0)) {
244 getInput(0)->computeFastBounds(src, dst); 244 getInput(0)->computeFastBounds(src, dst);
245 } else { 245 } else {
246 *dst = src; 246 *dst = src;
247 } 247 }
248 dst->outset(SkIntToScalar(fRadius.width()), SkIntToScalar(fRadius.height())) ; 248 dst->outset(SkIntToScalar(fRadius.width()), SkIntToScalar(fRadius.height())) ;
249 } 249 }
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 } 531 }
532 SkImageFilter::WrapTexture(src, rect.width(), rect.height(), dst); 532 SkImageFilter::WrapTexture(src, rect.width(), rect.height(), dst);
533 return true; 533 return true;
534 } 534 }
535 535
536 }; 536 };
537 537
538 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate, 538 bool SkMorphologyImageFilter::filterImageGPUGeneric(bool dilate,
539 Proxy* proxy, 539 Proxy* proxy,
540 const SkBitmap& src, 540 const SkBitmap& src,
541 const SkMatrix& ctm, 541 const Context& ctx,
542 SkBitmap* result, 542 SkBitmap* result,
543 SkIPoint* offset) const { 543 SkIPoint* offset) const {
544 SkBitmap input = src; 544 SkBitmap input = src;
545 SkIPoint srcOffset = SkIPoint::Make(0, 0); 545 SkIPoint srcOffset = SkIPoint::Make(0, 0);
546 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctm, &input, &srcOffset)) { 546 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
547 return false; 547 return false;
548 } 548 }
549 SkIRect bounds; 549 SkIRect bounds;
550 input.getBounds(&bounds); 550 input.getBounds(&bounds);
551 bounds.offset(srcOffset); 551 bounds.offset(srcOffset);
552 if (!this->applyCropRect(&bounds, ctm)) { 552 if (!this->applyCropRect(&bounds, ctx.ctm())) {
553 return false; 553 return false;
554 } 554 }
555 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()), 555 SkVector radius = SkVector::Make(SkIntToScalar(this->radius().width()),
556 SkIntToScalar(this->radius().height())); 556 SkIntToScalar(this->radius().height()));
557 ctm.mapVectors(&radius, 1); 557 ctx.ctm().mapVectors(&radius, 1);
558 int width = SkScalarFloorToInt(radius.fX); 558 int width = SkScalarFloorToInt(radius.fX);
559 int height = SkScalarFloorToInt(radius.fY); 559 int height = SkScalarFloorToInt(radius.fY);
560 560
561 if (width < 0 || height < 0) { 561 if (width < 0 || height < 0) {
562 return false; 562 return false;
563 } 563 }
564 564
565 SkIRect srcBounds = bounds; 565 SkIRect srcBounds = bounds;
566 srcBounds.offset(-srcOffset); 566 srcBounds.offset(-srcOffset);
567 if (width == 0 && height == 0) { 567 if (width == 0 && height == 0) {
568 input.extractSubset(result, srcBounds); 568 input.extractSubset(result, srcBounds);
569 offset->fX = bounds.left(); 569 offset->fX = bounds.left();
570 offset->fY = bounds.top(); 570 offset->fY = bounds.top();
571 return true; 571 return true;
572 } 572 }
573 573
574 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType : GrMorphologyEffect::kErode_MorphologyType; 574 GrMorphologyEffect::MorphologyType type = dilate ? GrMorphologyEffect::kDila te_MorphologyType : GrMorphologyEffect::kErode_MorphologyType;
575 if (!apply_morphology(input, srcBounds, type, 575 if (!apply_morphology(input, srcBounds, type,
576 SkISize::Make(width, height), result)) { 576 SkISize::Make(width, height), result)) {
577 return false; 577 return false;
578 } 578 }
579 offset->fX = bounds.left(); 579 offset->fX = bounds.left();
580 offset->fY = bounds.top(); 580 offset->fY = bounds.top();
581 return true; 581 return true;
582 } 582 }
583 583
584 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t SkMatrix& ctm, 584 bool SkDilateImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, cons t Context& ctx,
585 SkBitmap* result, SkIPoint* offset) con st { 585 SkBitmap* result, SkIPoint* offset) con st {
586 return this->filterImageGPUGeneric(true, proxy, src, ctm, result, offset); 586 return this->filterImageGPUGeneric(true, proxy, src, ctx, result, offset);
587 } 587 }
588 588
589 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const SkMatrix& ctm, 589 bool SkErodeImageFilter::filterImageGPU(Proxy* proxy, const SkBitmap& src, const Context& ctx,
590 SkBitmap* result, SkIPoint* offset) cons t { 590 SkBitmap* result, SkIPoint* offset) cons t {
591 return this->filterImageGPUGeneric(false, proxy, src, ctm, result, offset); 591 return this->filterImageGPUGeneric(false, proxy, src, ctx, result, offset);
592 } 592 }
593 593
594 #endif 594 #endif
OLDNEW
« no previous file with comments | « src/effects/SkMergeImageFilter.cpp ('k') | src/effects/SkOffsetImageFilter.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698