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

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

Issue 286273002: Optimize CSS box-shadow performance by caching the SkMask of the blur effect. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: add mutex for thread-safe and use SkDiscardableMemory Created 6 years, 7 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 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 9
10 #include "SkBlurMask.h" 10 #include "SkBlurMask.h"
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 534
535 if (src.fImage) { 535 if (src.fImage) {
536 size_t dstSize = dst->computeImageSize(); 536 size_t dstSize = dst->computeImageSize();
537 if (0 == dstSize) { 537 if (0 == dstSize) {
538 return false; // too big to allocate, abort 538 return false; // too big to allocate, abort
539 } 539 }
540 540
541 int sw = src.fBounds.width(); 541 int sw = src.fBounds.width();
542 int sh = src.fBounds.height(); 542 int sh = src.fBounds.height();
543 const uint8_t* sp = src.fImage; 543 const uint8_t* sp = src.fImage;
544 uint8_t* dp = SkMask::AllocImage(dstSize); 544 uint8_t* dp = NULL;
545 SkAutoTCallVProc<uint8_t, SkMask_FreeImage> autoCall(dp); 545 SkDiscardableMemory* dm = NULL;
546 if (dst->fUseDiscardableMemory && (dm = SkDiscardableMemory::Create(dstS ize))) {
547 dp = static_cast<uint8_t*>(dm->data());
548 dst->fDiscardableMemory = dm;
549 } else
550 dp = SkMask::AllocImage(dstSize);
546 551
547 // build the blurry destination 552 // build the blurry destination
548 SkAutoTMalloc<uint8_t> tmpBuffer(dstSize); 553 SkAutoTMalloc<uint8_t> tmpBuffer(dstSize);
549 uint8_t* tp = tmpBuffer.get(); 554 uint8_t* tp = tmpBuffer.get();
550 int w = sw, h = sh; 555 int w = sw, h = sh;
551 556
552 if (outerWeight == 255) { 557 if (outerWeight == 255) {
553 int loRadius, hiRadius; 558 int loRadius, hiRadius;
554 get_adjusted_radii(passRadius, &loRadius, &hiRadius); 559 get_adjusted_radii(passRadius, &loRadius, &hiRadius);
555 if (kHigh_SkBlurQuality == quality) { 560 if (kHigh_SkBlurQuality == quality) {
(...skipping 25 matching lines...) Expand all
581 } 586 }
582 } 587 }
583 588
584 dst->fImage = dp; 589 dst->fImage = dp;
585 // if need be, alloc the "real" dst (same size as src) and copy/merge 590 // if need be, alloc the "real" dst (same size as src) and copy/merge
586 // the blur into it (applying the src) 591 // the blur into it (applying the src)
587 if (style == kInner_SkBlurStyle) { 592 if (style == kInner_SkBlurStyle) {
588 // now we allocate the "real" dst, mirror the size of src 593 // now we allocate the "real" dst, mirror the size of src
589 size_t srcSize = src.computeImageSize(); 594 size_t srcSize = src.computeImageSize();
590 if (0 == srcSize) { 595 if (0 == srcSize) {
596 if (dm) {
597 dm->unlock();
598 SkDELETE(dm);
599 } else if (dp) {
600 SkMask::FreeImage(dp);
601 }
591 return false; // too big to allocate, abort 602 return false; // too big to allocate, abort
592 } 603 }
593 dst->fImage = SkMask::AllocImage(srcSize); 604 dst->fImage = SkMask::AllocImage(srcSize);
594 merge_src_with_blur(dst->fImage, src.fRowBytes, 605 merge_src_with_blur(dst->fImage, src.fRowBytes,
595 sp, src.fRowBytes, 606 sp, src.fRowBytes,
596 dp + passCount * (rx + ry * dst->fRowBytes), 607 dp + passCount * (rx + ry * dst->fRowBytes),
597 dst->fRowBytes, sw, sh); 608 dst->fRowBytes, sw, sh);
598 SkMask::FreeImage(dp); 609 if (dm) {
610 dm->unlock();
611 SkDELETE(dm);
612 } else if (dp) {
613 SkMask::FreeImage(dp);
614 }
599 } else if (style != kNormal_SkBlurStyle) { 615 } else if (style != kNormal_SkBlurStyle) {
600 clamp_with_orig(dp + passCount * (rx + ry * dst->fRowBytes), 616 clamp_with_orig(dp + passCount * (rx + ry * dst->fRowBytes),
601 dst->fRowBytes, sp, src.fRowBytes, sw, sh, style); 617 dst->fRowBytes, sp, src.fRowBytes, sw, sh, style);
602 } 618 }
603 (void)autoCall.detach();
604 } 619 }
605 620
606 if (style == kInner_SkBlurStyle) { 621 if (style == kInner_SkBlurStyle) {
607 dst->fBounds = src.fBounds; // restore trimmed bounds 622 dst->fBounds = src.fBounds; // restore trimmed bounds
608 dst->fRowBytes = src.fRowBytes; 623 dst->fRowBytes = src.fRowBytes;
609 } 624 }
610 625
611 return true; 626 return true;
612 } 627 }
613 628
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 (void)autoCall.detach(); 1002 (void)autoCall.detach();
988 } 1003 }
989 1004
990 if (style == kInner_SkBlurStyle) { 1005 if (style == kInner_SkBlurStyle) {
991 dst->fBounds = src.fBounds; // restore trimmed bounds 1006 dst->fBounds = src.fBounds; // restore trimmed bounds
992 dst->fRowBytes = src.fRowBytes; 1007 dst->fRowBytes = src.fRowBytes;
993 } 1008 }
994 1009
995 return true; 1010 return true;
996 } 1011 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698