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

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

Issue 57513002: Change SkBlurImageFilter to use fixed-point division. Yields ~1.8X speedup on (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Updated ignored-tests.txt. Created 7 years, 1 month 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 | « expectations/gm/ignored-tests.txt ('k') | no next file » | 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 2011 The Android Open Source Project 2 * Copyright 2011 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 "SkBitmap.h" 8 #include "SkBitmap.h"
9 #include "SkBlurImageFilter.h" 9 #include "SkBlurImageFilter.h"
10 #include "SkColorPriv.h" 10 #include "SkColorPriv.h"
(...skipping 26 matching lines...) Expand all
37 this->INHERITED::flatten(buffer); 37 this->INHERITED::flatten(buffer);
38 buffer.writeScalar(fSigma.fWidth); 38 buffer.writeScalar(fSigma.fWidth);
39 buffer.writeScalar(fSigma.fHeight); 39 buffer.writeScalar(fSigma.fHeight);
40 } 40 }
41 41
42 static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize, 42 static void boxBlurX(const SkBitmap& src, SkBitmap* dst, int kernelSize,
43 int leftOffset, int rightOffset, const SkIRect& bounds) 43 int leftOffset, int rightOffset, const SkIRect& bounds)
44 { 44 {
45 int width = bounds.width(), height = bounds.height(); 45 int width = bounds.width(), height = bounds.height();
46 int rightBorder = SkMin32(rightOffset + 1, width); 46 int rightBorder = SkMin32(rightOffset + 1, width);
47 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
48 uint32_t scale = (1 << 24) / kernelSize;
49 uint32_t half = 1 << 23;
50 #endif
47 for (int y = 0; y < height; ++y) { 51 for (int y = 0; y < height; ++y) {
48 int sumA = 0, sumR = 0, sumG = 0, sumB = 0; 52 int sumA = 0, sumR = 0, sumG = 0, sumB = 0;
49 SkPMColor* p = src.getAddr32(bounds.fLeft, y + bounds.fTop); 53 SkPMColor* p = src.getAddr32(bounds.fLeft, y + bounds.fTop);
50 for (int i = 0; i < rightBorder; ++i) { 54 for (int i = 0; i < rightBorder; ++i) {
51 sumA += SkGetPackedA32(*p); 55 sumA += SkGetPackedA32(*p);
52 sumR += SkGetPackedR32(*p); 56 sumR += SkGetPackedR32(*p);
53 sumG += SkGetPackedG32(*p); 57 sumG += SkGetPackedG32(*p);
54 sumB += SkGetPackedB32(*p); 58 sumB += SkGetPackedB32(*p);
55 p++; 59 p++;
56 } 60 }
57 61
58 const SkColor* sptr = src.getAddr32(bounds.fLeft, bounds.fTop + y); 62 const SkColor* sptr = src.getAddr32(bounds.fLeft, bounds.fTop + y);
59 SkColor* dptr = dst->getAddr32(0, y); 63 SkColor* dptr = dst->getAddr32(0, y);
60 for (int x = 0; x < width; ++x) { 64 for (int x = 0; x < width; ++x) {
65 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
66 *dptr = SkPackARGB32((sumA * scale + half) >> 24,
67 (sumR * scale + half) >> 24,
68 (sumG * scale + half) >> 24,
69 (sumB * scale + half) >> 24);
70 #else
61 *dptr = SkPackARGB32(sumA / kernelSize, 71 *dptr = SkPackARGB32(sumA / kernelSize,
62 sumR / kernelSize, 72 sumR / kernelSize,
63 sumG / kernelSize, 73 sumG / kernelSize,
64 sumB / kernelSize); 74 sumB / kernelSize);
75 #endif
65 if (x >= leftOffset) { 76 if (x >= leftOffset) {
66 SkColor l = *(sptr - leftOffset); 77 SkColor l = *(sptr - leftOffset);
67 sumA -= SkGetPackedA32(l); 78 sumA -= SkGetPackedA32(l);
68 sumR -= SkGetPackedR32(l); 79 sumR -= SkGetPackedR32(l);
69 sumG -= SkGetPackedG32(l); 80 sumG -= SkGetPackedG32(l);
70 sumB -= SkGetPackedB32(l); 81 sumB -= SkGetPackedB32(l);
71 } 82 }
72 if (x + rightOffset + 1 < width) { 83 if (x + rightOffset + 1 < width) {
73 SkColor r = *(sptr + rightOffset + 1); 84 SkColor r = *(sptr + rightOffset + 1);
74 sumA += SkGetPackedA32(r); 85 sumA += SkGetPackedA32(r);
75 sumR += SkGetPackedR32(r); 86 sumR += SkGetPackedR32(r);
76 sumG += SkGetPackedG32(r); 87 sumG += SkGetPackedG32(r);
77 sumB += SkGetPackedB32(r); 88 sumB += SkGetPackedB32(r);
78 } 89 }
79 sptr++; 90 sptr++;
80 dptr++; 91 dptr++;
81 } 92 }
82 } 93 }
83 } 94 }
84 95
85 static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize, 96 static void boxBlurY(const SkBitmap& src, SkBitmap* dst, int kernelSize,
86 int topOffset, int bottomOffset, const SkIRect& bounds) 97 int topOffset, int bottomOffset, const SkIRect& bounds)
87 { 98 {
88 int width = bounds.width(), height = bounds.height(); 99 int width = bounds.width(), height = bounds.height();
89 int bottomBorder = SkMin32(bottomOffset + 1, height); 100 int bottomBorder = SkMin32(bottomOffset + 1, height);
90 int srcStride = src.rowBytesAsPixels(); 101 int srcStride = src.rowBytesAsPixels();
91 int dstStride = dst->rowBytesAsPixels(); 102 int dstStride = dst->rowBytesAsPixels();
103 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
104 uint32_t scale = (1 << 24) / kernelSize;
105 uint32_t half = 1 << 23;
106 #endif
92 for (int x = 0; x < width; ++x) { 107 for (int x = 0; x < width; ++x) {
93 int sumA = 0, sumR = 0, sumG = 0, sumB = 0; 108 int sumA = 0, sumR = 0, sumG = 0, sumB = 0;
94 SkColor* p = src.getAddr32(bounds.fLeft + x, bounds.fTop); 109 SkColor* p = src.getAddr32(bounds.fLeft + x, bounds.fTop);
95 for (int i = 0; i < bottomBorder; ++i) { 110 for (int i = 0; i < bottomBorder; ++i) {
96 sumA += SkGetPackedA32(*p); 111 sumA += SkGetPackedA32(*p);
97 sumR += SkGetPackedR32(*p); 112 sumR += SkGetPackedR32(*p);
98 sumG += SkGetPackedG32(*p); 113 sumG += SkGetPackedG32(*p);
99 sumB += SkGetPackedB32(*p); 114 sumB += SkGetPackedB32(*p);
100 p += srcStride; 115 p += srcStride;
101 } 116 }
102 117
103 const SkColor* sptr = src.getAddr32(bounds.fLeft + x, bounds.fTop); 118 const SkColor* sptr = src.getAddr32(bounds.fLeft + x, bounds.fTop);
104 SkColor* dptr = dst->getAddr32(x, 0); 119 SkColor* dptr = dst->getAddr32(x, 0);
105 for (int y = 0; y < height; ++y) { 120 for (int y = 0; y < height; ++y) {
121 #ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
122 *dptr = SkPackARGB32((sumA * scale + half) >> 24,
123 (sumR * scale + half) >> 24,
124 (sumG * scale + half) >> 24,
125 (sumB * scale + half) >> 24);
126 #else
106 *dptr = SkPackARGB32(sumA / kernelSize, 127 *dptr = SkPackARGB32(sumA / kernelSize,
107 sumR / kernelSize, 128 sumR / kernelSize,
108 sumG / kernelSize, 129 sumG / kernelSize,
109 sumB / kernelSize); 130 sumB / kernelSize);
131 #endif
110 if (y >= topOffset) { 132 if (y >= topOffset) {
111 SkColor l = *(sptr - topOffset * srcStride); 133 SkColor l = *(sptr - topOffset * srcStride);
112 sumA -= SkGetPackedA32(l); 134 sumA -= SkGetPackedA32(l);
113 sumR -= SkGetPackedR32(l); 135 sumR -= SkGetPackedR32(l);
114 sumG -= SkGetPackedG32(l); 136 sumG -= SkGetPackedG32(l);
115 sumB -= SkGetPackedB32(l); 137 sumB -= SkGetPackedB32(l);
116 } 138 }
117 if (y + bottomOffset + 1 < height) { 139 if (y + bottomOffset + 1 < height) {
118 SkColor r = *(sptr + (bottomOffset + 1) * srcStride); 140 SkColor r = *(sptr + (bottomOffset + 1) * srcStride);
119 sumA += SkGetPackedA32(r); 141 sumA += SkGetPackedA32(r);
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 fSigma.width(), 253 fSigma.width(),
232 fSigma.height())); 254 fSigma.height()));
233 offset->fX += rect.fLeft; 255 offset->fX += rect.fLeft;
234 offset->fY += rect.fTop; 256 offset->fY += rect.fTop;
235 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res ult); 257 return SkImageFilterUtils::WrapTexture(tex, rect.width(), rect.height(), res ult);
236 #else 258 #else
237 SkDEBUGFAIL("Should not call in GPU-less build"); 259 SkDEBUGFAIL("Should not call in GPU-less build");
238 return false; 260 return false;
239 #endif 261 #endif
240 } 262 }
OLDNEW
« no previous file with comments | « expectations/gm/ignored-tests.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698