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

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

Issue 669993003: use SkMaskCache inside SkBlurMaskFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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/SkMaskCache.cpp ('k') | tests/MaskCacheTest.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 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
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 8
9 #include "SkBlurMaskFilter.h" 9 #include "SkBlurMaskFilter.h"
10 #include "SkBlurMask.h" 10 #include "SkBlurMask.h"
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 canvas.drawPath(path, paint); 250 canvas.drawPath(path, paint);
251 } 251 }
252 return true; 252 return true;
253 } 253 }
254 254
255 static bool rect_exceeds(const SkRect& r, SkScalar v) { 255 static bool rect_exceeds(const SkRect& r, SkScalar v) {
256 return r.fLeft < -v || r.fTop < -v || r.fRight > v || r.fBottom > v || 256 return r.fLeft < -v || r.fTop < -v || r.fRight > v || r.fBottom > v ||
257 r.width() > v || r.height() > v; 257 r.width() > v || r.height() > v;
258 } 258 }
259 259
260 #include "SkMaskCache.h"
261
262 static bool copy_cacheddata_to_mask(SkCachedData* data, SkMask* mask) {
263 const size_t size = data->size();
264 SkASSERT(mask->computeTotalImageSize() <= size);
265
266 mask->fImage = SkMask::AllocImage(size);
267 if (mask->fImage) {
268 memcpy(mask->fImage, data->data(), size);
269 return true;
270 }
271 return false;
272 }
273
274 static SkCachedData* copy_mask_to_cacheddata(const SkMask& mask) {
275 const size_t size = mask.computeTotalImageSize();
276 SkCachedData* data = SkResourceCache::NewCachedData(size);
277 if (data) {
278 memcpy(data->writable_data(), mask.fImage, size);
279 return data;
280 }
281 return NULL;
282 }
283
284 static bool find_cached_rrect(SkMask* mask, SkScalar sigma, SkBlurStyle style,
285 SkBlurQuality quality, const SkRRect& rrect) {
286 SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, qualit y, rrect, mask));
287 return data.get() && copy_cacheddata_to_mask(data, mask);
288 }
289
290 static void add_cached_rrect(const SkMask& mask, SkScalar sigma, SkBlurStyle sty le,
291 SkBlurQuality quality, const SkRRect& rrect) {
292 SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask));
293 if (data.get()) {
294 SkMaskCache::Add(sigma, style, quality, rrect, mask, data);
295 }
296 }
297
298 static bool find_cached_rects(SkMask* mask, SkScalar sigma, SkBlurStyle style,
299 SkBlurQuality quality, const SkRect rects[], int c ount) {
300 SkAutoTUnref<SkCachedData> data(SkMaskCache::FindAndRef(sigma, style, qualit y, rects, count, mask));
301 return data.get() && copy_cacheddata_to_mask(data, mask);
302 }
303
304 static void add_cached_rects(const SkMask& mask, SkScalar sigma, SkBlurStyle sty le,
305 SkBlurQuality quality, const SkRect rects[], int co unt) {
306 SkAutoTUnref<SkCachedData> data(copy_mask_to_cacheddata(mask));
307 if (data.get()) {
308 SkMaskCache::Add(sigma, style, quality, rects, count, mask, data);
309 }
310 }
311
260 #ifdef SK_IGNORE_FAST_RRECT_BLUR 312 #ifdef SK_IGNORE_FAST_RRECT_BLUR
261 SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect" , false, "Use the faster analytic blur approach for ninepatch rects" ); 313 SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect" , false, "Use the faster analytic blur approach for ninepatch rects" );
262 #else 314 #else
263 SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect" , true, "Use the faster analytic blur approach for ninepatch round rects" ); 315 SK_CONF_DECLARE( bool, c_analyticBlurRRect, "mask.filter.blur.analyticblurrrect" , true, "Use the faster analytic blur approach for ninepatch round rects" );
264 #endif 316 #endif
265 317
266 SkMaskFilter::FilterReturn 318 SkMaskFilter::FilterReturn
267 SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma trix, 319 SkBlurMaskFilterImpl::filterRRectToNine(const SkRRect& rrect, const SkMatrix& ma trix,
268 const SkIRect& clipBounds, 320 const SkIRect& clipBounds,
269 NinePatch* patch) const { 321 NinePatch* patch) const {
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight); 413 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight);
362 414
363 SkRRect smallRR; 415 SkRRect smallRR;
364 SkVector radii[4]; 416 SkVector radii[4];
365 radii[SkRRect::kUpperLeft_Corner] = UL; 417 radii[SkRRect::kUpperLeft_Corner] = UL;
366 radii[SkRRect::kUpperRight_Corner] = UR; 418 radii[SkRRect::kUpperRight_Corner] = UR;
367 radii[SkRRect::kLowerRight_Corner] = LR; 419 radii[SkRRect::kLowerRight_Corner] = LR;
368 radii[SkRRect::kLowerLeft_Corner] = LL; 420 radii[SkRRect::kLowerLeft_Corner] = LL;
369 smallRR.setRectRadii(smallR, radii); 421 smallRR.setRectRadii(smallR, radii);
370 422
371 bool analyticBlurWorked = false; 423 const SkScalar sigma = this->computeXformedSigma(matrix);
372 if (c_analyticBlurRRect) { 424 if (!find_cached_rrect(&patch->fMask, sigma, fBlurStyle, this->getQuality(), smallRR)) {
373 analyticBlurWorked = 425 bool analyticBlurWorked = false;
374 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin, 426 if (c_analyticBlurRRect) {
375 SkMask::kComputeBoundsAndRenderImage_CreateMod e); 427 analyticBlurWorked =
376 } 428 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin,
377 429 SkMask::kComputeBoundsAndRenderImage_Creat eMode);
378 if (!analyticBlurWorked) {
379 if (!draw_rrect_into_mask(smallRR, &srcM)) {
380 return kFalse_FilterReturn;
381 } 430 }
382 431
383 SkAutoMaskFreeImage amf(srcM.fImage); 432 if (!analyticBlurWorked) {
433 if (!draw_rrect_into_mask(smallRR, &srcM)) {
434 return kFalse_FilterReturn;
435 }
384 436
385 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) { 437 SkAutoMaskFreeImage amf(srcM.fImage);
386 return kFalse_FilterReturn; 438
439 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
440 return kFalse_FilterReturn;
441 }
387 } 442 }
443 add_cached_rrect(patch->fMask, sigma, fBlurStyle, this->getQuality(), sm allRR);
388 } 444 }
389 445
390 patch->fMask.fBounds.offsetTo(0, 0); 446 patch->fMask.fBounds.offsetTo(0, 0);
391 patch->fOuterRect = dstM.fBounds; 447 patch->fOuterRect = dstM.fBounds;
392 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1; 448 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1;
393 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1; 449 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1;
394 return kTrue_FilterReturn; 450 return kTrue_FilterReturn;
395 } 451 }
396 452
397 SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" ); 453 SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" );
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
487 smallR[0].set(rects[0].left(), rects[0].top(), rects[0].right() - dx, rects[ 0].bottom() - dy); 543 smallR[0].set(rects[0].left(), rects[0].top(), rects[0].right() - dx, rects[ 0].bottom() - dy);
488 if (smallR[0].width() < 2 || smallR[0].height() < 2) { 544 if (smallR[0].width() < 2 || smallR[0].height() < 2) {
489 return kUnimplemented_FilterReturn; 545 return kUnimplemented_FilterReturn;
490 } 546 }
491 if (2 == count) { 547 if (2 == count) {
492 smallR[1].set(rects[1].left(), rects[1].top(), 548 smallR[1].set(rects[1].left(), rects[1].top(),
493 rects[1].right() - dx, rects[1].bottom() - dy); 549 rects[1].right() - dx, rects[1].bottom() - dy);
494 SkASSERT(!smallR[1].isEmpty()); 550 SkASSERT(!smallR[1].isEmpty());
495 } 551 }
496 552
497 if (count > 1 || !c_analyticBlurNinepatch) { 553 const SkScalar sigma = this->computeXformedSigma(matrix);
498 if (!draw_rects_into_mask(smallR, count, &srcM)) { 554 if (!find_cached_rects(&patch->fMask, sigma, fBlurStyle, this->getQuality(), rects, count)) {
499 return kFalse_FilterReturn; 555 if (count > 1 || !c_analyticBlurNinepatch) {
556 if (!draw_rects_into_mask(smallR, count, &srcM)) {
557 return kFalse_FilterReturn;
558 }
559
560 SkAutoMaskFreeImage amf(srcM.fImage);
561
562 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
563 return kFalse_FilterReturn;
564 }
565 } else {
566 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin,
567 SkMask::kComputeBoundsAndRenderImage_Creat eMode)) {
568 return kFalse_FilterReturn;
569 }
500 } 570 }
501 571 add_cached_rects(patch->fMask, sigma, fBlurStyle, this->getQuality(), re cts, count);
502 SkAutoMaskFreeImage amf(srcM.fImage);
503
504 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
505 return kFalse_FilterReturn;
506 }
507 } else {
508 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin,
509 SkMask::kComputeBoundsAndRenderImage_CreateMod e)) {
510 return kFalse_FilterReturn;
511 }
512 } 572 }
513 patch->fMask.fBounds.offsetTo(0, 0); 573 patch->fMask.fBounds.offsetTo(0, 0);
514 patch->fOuterRect = dstM.fBounds; 574 patch->fOuterRect = dstM.fBounds;
515 patch->fCenter = center; 575 patch->fCenter = center;
516 return kTrue_FilterReturn; 576 return kTrue_FilterReturn;
517 } 577 }
518 578
519 void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src, 579 void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
520 SkRect* dst) const { 580 SkRect* dst) const {
521 SkScalar pad = 3.0f * fSigma; 581 SkScalar pad = 3.0f * fSigma;
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
1218 } else { 1278 } else {
1219 str->append("None"); 1279 str->append("None");
1220 } 1280 }
1221 str->append("))"); 1281 str->append("))");
1222 } 1282 }
1223 #endif 1283 #endif
1224 1284
1225 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1285 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1226 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1286 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1227 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1287 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW
« no previous file with comments | « src/core/SkMaskCache.cpp ('k') | tests/MaskCacheTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698