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

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

Issue 471473002: Optimize CSS box-shadow performance (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: backed blur mask with a bitmap Created 6 years, 3 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
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"
11 #include "SkGpuBlurUtils.h" 11 #include "SkGpuBlurUtils.h"
12 #include "SkReadBuffer.h" 12 #include "SkReadBuffer.h"
13 #include "SkWriteBuffer.h" 13 #include "SkWriteBuffer.h"
14 #include "SkMaskCache.h"
14 #include "SkMaskFilter.h" 15 #include "SkMaskFilter.h"
15 #include "SkRRect.h" 16 #include "SkRRect.h"
16 #include "SkRTConf.h" 17 #include "SkRTConf.h"
17 #include "SkStringUtils.h" 18 #include "SkStringUtils.h"
18 #include "SkStrokeRec.h" 19 #include "SkStrokeRec.h"
19 20
20 #if SK_SUPPORT_GPU 21 #if SK_SUPPORT_GPU
21 #include "GrContext.h" 22 #include "GrContext.h"
22 #include "GrTexture.h" 23 #include "GrTexture.h"
23 #include "GrEffect.h" 24 #include "GrEffect.h"
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight); 362 SkRect smallR = SkRect::MakeWH(totalSmallWidth, totalSmallHeight);
362 363
363 SkRRect smallRR; 364 SkRRect smallRR;
364 SkVector radii[4]; 365 SkVector radii[4];
365 radii[SkRRect::kUpperLeft_Corner] = UL; 366 radii[SkRRect::kUpperLeft_Corner] = UL;
366 radii[SkRRect::kUpperRight_Corner] = UR; 367 radii[SkRRect::kUpperRight_Corner] = UR;
367 radii[SkRRect::kLowerRight_Corner] = LR; 368 radii[SkRRect::kLowerRight_Corner] = LR;
368 radii[SkRRect::kLowerLeft_Corner] = LL; 369 radii[SkRRect::kLowerLeft_Corner] = LL;
369 smallRR.setRectRadii(smallR, radii); 370 smallRR.setRectRadii(smallR, radii);
370 371
372 SkScalar sigma = this->computeXformedSigma(matrix);
373 if (SkMaskCache::Find(sigma, rrect, &patch->fMask)) {
374 patch->fOuterRect = dstM.fBounds;
375 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1;
376 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1;
377 return kTrue_FilterReturn;
378 }
379
371 bool analyticBlurWorked = false; 380 bool analyticBlurWorked = false;
372 if (c_analyticBlurRRect) { 381 if (c_analyticBlurRRect) {
373 analyticBlurWorked = 382 analyticBlurWorked =
374 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin, 383 this->filterRRectMask(&patch->fMask, smallRR, matrix, &margin,
375 SkMask::kComputeBoundsAndRenderImage_CreateMod e); 384 SkMask::kComputeBoundsAndRenderImage_CreateMod e);
376 } 385 }
377 386
378 if (!analyticBlurWorked) { 387 if (!analyticBlurWorked) {
379 if (!draw_rrect_into_mask(smallRR, &srcM)) { 388 if (!draw_rrect_into_mask(smallRR, &srcM)) {
380 return kFalse_FilterReturn; 389 return kFalse_FilterReturn;
381 } 390 }
382 391
383 SkAutoMaskFreeImage amf(srcM.fImage); 392 SkAutoMaskFreeImage amf(srcM.fImage);
384 393
385 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) { 394 if (!this->filterMask(&patch->fMask, srcM, matrix, &margin)) {
386 return kFalse_FilterReturn; 395 return kFalse_FilterReturn;
387 } 396 }
388 } 397 }
389 398
390 patch->fMask.fBounds.offsetTo(0, 0); 399 patch->fMask.fBounds.offsetTo(0, 0);
391 patch->fOuterRect = dstM.fBounds; 400 patch->fOuterRect = dstM.fBounds;
392 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1; 401 patch->fCenter.fX = SkScalarCeilToInt(leftUnstretched) + 1;
393 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1; 402 patch->fCenter.fY = SkScalarCeilToInt(topUnstretched) + 1;
403 SkMaskCache::Add(sigma, rrect, patch->fMask);
404
394 return kTrue_FilterReturn; 405 return kTrue_FilterReturn;
395 } 406 }
396 407
397 SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" ); 408 SK_CONF_DECLARE( bool, c_analyticBlurNinepatch, "mask.filter.analyticNinePatch", true, "Use the faster analytic blur approach for ninepatch rects" );
398 409
399 SkMaskFilter::FilterReturn 410 SkMaskFilter::FilterReturn
400 SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count, 411 SkBlurMaskFilterImpl::filterRectsToNine(const SkRect rects[], int count,
401 const SkMatrix& matrix, 412 const SkMatrix& matrix,
402 const SkIRect& clipBounds, 413 const SkIRect& clipBounds,
403 NinePatch* patch) const { 414 NinePatch* patch) const {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
463 if (1 == count) { 474 if (1 == count) {
464 innerIR = srcM.fBounds; 475 innerIR = srcM.fBounds;
465 center.set(smallW, smallH); 476 center.set(smallW, smallH);
466 } else { 477 } else {
467 SkASSERT(2 == count); 478 SkASSERT(2 == count);
468 rects[1].roundIn(&innerIR); 479 rects[1].roundIn(&innerIR);
469 center.set(smallW + (innerIR.left() - srcM.fBounds.left()), 480 center.set(smallW + (innerIR.left() - srcM.fBounds.left()),
470 smallH + (innerIR.top() - srcM.fBounds.top())); 481 smallH + (innerIR.top() - srcM.fBounds.top()));
471 } 482 }
472 483
484 SkScalar sigma = this->computeXformedSigma(matrix);
485 if (SkMaskCache::Find(sigma, count, rects, &patch->fMask)) {
486 patch->fOuterRect = dstM.fBounds;
487 patch->fCenter = center;
488 return kTrue_FilterReturn;
489 }
490
473 // +1 so we get a clean, stretchable, center row/col 491 // +1 so we get a clean, stretchable, center row/col
474 smallW += 1; 492 smallW += 1;
475 smallH += 1; 493 smallH += 1;
476 494
477 // we want the inset amounts to be integral, so we don't change any 495 // we want the inset amounts to be integral, so we don't change any
478 // fractional phase on the fRight or fBottom of our smallR. 496 // fractional phase on the fRight or fBottom of our smallR.
479 const SkScalar dx = SkIntToScalar(innerIR.width() - smallW); 497 const SkScalar dx = SkIntToScalar(innerIR.width() - smallW);
480 const SkScalar dy = SkIntToScalar(innerIR.height() - smallH); 498 const SkScalar dy = SkIntToScalar(innerIR.height() - smallH);
481 if (dx < 0 || dy < 0) { 499 if (dx < 0 || dy < 0) {
482 // we're too small, relative to our blur, to break into nine-patch, 500 // we're too small, relative to our blur, to break into nine-patch,
(...skipping 23 matching lines...) Expand all
506 } 524 }
507 } else { 525 } else {
508 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin, 526 if (!this->filterRectMask(&patch->fMask, smallR[0], matrix, &margin,
509 SkMask::kComputeBoundsAndRenderImage_CreateMod e)) { 527 SkMask::kComputeBoundsAndRenderImage_CreateMod e)) {
510 return kFalse_FilterReturn; 528 return kFalse_FilterReturn;
511 } 529 }
512 } 530 }
513 patch->fMask.fBounds.offsetTo(0, 0); 531 patch->fMask.fBounds.offsetTo(0, 0);
514 patch->fOuterRect = dstM.fBounds; 532 patch->fOuterRect = dstM.fBounds;
515 patch->fCenter = center; 533 patch->fCenter = center;
534 SkMaskCache::Add(sigma, count, rects, patch->fMask);
535
516 return kTrue_FilterReturn; 536 return kTrue_FilterReturn;
517 } 537 }
518 538
519 void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src, 539 void SkBlurMaskFilterImpl::computeFastBounds(const SkRect& src,
520 SkRect* dst) const { 540 SkRect* dst) const {
521 SkScalar pad = 3.0f * fSigma; 541 SkScalar pad = 3.0f * fSigma;
522 542
523 dst->set(src.fLeft - pad, src.fTop - pad, 543 dst->set(src.fLeft - pad, src.fTop - pad,
524 src.fRight + pad, src.fBottom + pad); 544 src.fRight + pad, src.fBottom + pad);
525 } 545 }
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 930
911 SkPath path; 931 SkPath path;
912 path.addRRect( smallRRect ); 932 path.addRRect( smallRRect );
913 933
914 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust RenderImage_CreateMode, SkPaint::kFill_Style); 934 SkDraw::DrawToMask(path, &mask.fBounds, NULL, NULL, &mask, SkMask::kJust RenderImage_CreateMode, SkPaint::kFill_Style);
915 935
916 SkMask blurred_mask; 936 SkMask blurred_mask;
917 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi gh_SkBlurQuality, NULL, true ); 937 SkBlurMask::BoxBlur(&blurred_mask, mask, sigma, kNormal_SkBlurStyle, kHi gh_SkBlurQuality, NULL, true );
918 938
919 blurNinePatchTexture = context->createTexture(&params, texDesc, blurRRec tNinePatchID, blurred_mask.fImage, 0); 939 blurNinePatchTexture = context->createTexture(&params, texDesc, blurRRec tNinePatchID, blurred_mask.fImage, 0);
920 SkMask::FreeImage(blurred_mask.fImage);
921 } 940 }
922 941
923 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture); 942 SkAutoTUnref<GrTexture> blurunref(blurNinePatchTexture);
924 if (NULL == blurNinePatchTexture) { 943 if (NULL == blurNinePatchTexture) {
925 return NULL; 944 return NULL;
926 } 945 }
927 946
928 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture)); 947 return SkNEW_ARGS(GrRRectBlurEffect, (sigma, rrect, blurNinePatchTexture));
929 } 948 }
930 949
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1219 } else { 1238 } else {
1220 str->append("None"); 1239 str->append("None");
1221 } 1240 }
1222 str->append("))"); 1241 str->append("))");
1223 } 1242 }
1224 #endif 1243 #endif
1225 1244
1226 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter) 1245 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_START(SkBlurMaskFilter)
1227 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl) 1246 SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBlurMaskFilterImpl)
1228 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END 1247 SK_DEFINE_FLATTENABLE_REGISTRAR_GROUP_END
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698