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

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

Issue 209353014: Fix for crash on large image blur sigma values. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Tweak 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 | « no previous file | src/effects/SkGpuBlurUtils.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 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"
11 #include "SkReadBuffer.h" 11 #include "SkReadBuffer.h"
12 #include "SkWriteBuffer.h" 12 #include "SkWriteBuffer.h"
13 #include "SkGpuBlurUtils.h" 13 #include "SkGpuBlurUtils.h"
14 #include "SkBlurImage_opts.h" 14 #include "SkBlurImage_opts.h"
15 #if SK_SUPPORT_GPU 15 #if SK_SUPPORT_GPU
16 #include "GrContext.h" 16 #include "GrContext.h"
17 #endif 17 #endif
18 18
19 // This rather arbitrary-looking value results in a maximum box blur kernel size
20 // of 1000 pixels on the raster path, which matches the WebKit and Firefox
21 // implementations. Since the GPU path does not compute a box blur, putting
22 // the limit on sigma ensures consistent behaviour between the GPU and
23 // raster paths.
24 #define MAX_SIGMA SkIntToScalar(532)
25
19 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer) 26 SkBlurImageFilter::SkBlurImageFilter(SkReadBuffer& buffer)
20 : INHERITED(1, buffer) { 27 : INHERITED(1, buffer) {
21 fSigma.fWidth = buffer.readScalar(); 28 fSigma.fWidth = buffer.readScalar();
22 fSigma.fHeight = buffer.readScalar(); 29 fSigma.fHeight = buffer.readScalar();
23 buffer.validate(SkScalarIsFinite(fSigma.fWidth) && 30 buffer.validate(SkScalarIsFinite(fSigma.fWidth) &&
24 SkScalarIsFinite(fSigma.fHeight) && 31 SkScalarIsFinite(fSigma.fHeight) &&
25 (fSigma.fWidth >= 0) && 32 (fSigma.fWidth >= 0) &&
26 (fSigma.fHeight >= 0)); 33 (fSigma.fHeight >= 0));
27 } 34 }
28 35
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 164 }
158 165
159 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height()); 166 dst->setConfig(src.config(), srcBounds.width(), srcBounds.height());
160 dst->getBounds(&dstBounds); 167 dst->getBounds(&dstBounds);
161 if (!dst->allocPixels()) { 168 if (!dst->allocPixels()) {
162 return false; 169 return false;
163 } 170 }
164 171
165 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height()) ; 172 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height()) ;
166 ctx.ctm().mapVectors(&sigma, &localSigma, 1); 173 ctx.ctm().mapVectors(&sigma, &localSigma, 1);
174 sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA);
175 sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA);
167 176
168 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX; 177 int kernelSizeX, kernelSizeX3, lowOffsetX, highOffsetX;
169 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY; 178 int kernelSizeY, kernelSizeY3, lowOffsetY, highOffsetY;
170 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs etX); 179 getBox3Params(sigma.x(), &kernelSizeX, &kernelSizeX3, &lowOffsetX, &highOffs etX);
171 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs etY); 180 getBox3Params(sigma.y(), &kernelSizeY, &kernelSizeY3, &lowOffsetY, &highOffs etY);
172 181
173 if (kernelSizeX < 0 || kernelSizeY < 0) { 182 if (kernelSizeX < 0 || kernelSizeY < 0) {
174 return false; 183 return false;
175 } 184 }
176 185
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) { 265 if (getInput(0) && !getInput(0)->getInputResultGPU(proxy, src, ctx, &input, &srcOffset)) {
257 return false; 266 return false;
258 } 267 }
259 SkIRect rect; 268 SkIRect rect;
260 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) { 269 if (!this->applyCropRect(ctx, proxy, input, &srcOffset, &rect, &input)) {
261 return false; 270 return false;
262 } 271 }
263 GrTexture* source = input.getTexture(); 272 GrTexture* source = input.getTexture();
264 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height()) ; 273 SkVector sigma, localSigma = SkVector::Make(fSigma.width(), fSigma.height()) ;
265 ctx.ctm().mapVectors(&sigma, &localSigma, 1); 274 ctx.ctm().mapVectors(&sigma, &localSigma, 1);
275 sigma.fX = SkMinScalar(sigma.fX, MAX_SIGMA);
276 sigma.fY = SkMinScalar(sigma.fY, MAX_SIGMA);
266 offset->fX = rect.fLeft; 277 offset->fX = rect.fLeft;
267 offset->fY = rect.fTop; 278 offset->fY = rect.fTop;
268 rect.offset(-srcOffset); 279 rect.offset(-srcOffset);
269 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext( ), 280 SkAutoTUnref<GrTexture> tex(SkGpuBlurUtils::GaussianBlur(source->getContext( ),
270 source, 281 source,
271 false, 282 false,
272 SkRect::Make(rect), 283 SkRect::Make(rect),
273 true, 284 true,
274 sigma.x(), 285 sigma.x(),
275 sigma.y())); 286 sigma.y()));
276 WrapTexture(tex, rect.width(), rect.height(), result); 287 WrapTexture(tex, rect.width(), rect.height(), result);
277 return true; 288 return true;
278 #else 289 #else
279 SkDEBUGFAIL("Should not call in GPU-less build"); 290 SkDEBUGFAIL("Should not call in GPU-less build");
280 return false; 291 return false;
281 #endif 292 #endif
282 } 293 }
OLDNEW
« no previous file with comments | « no previous file | src/effects/SkGpuBlurUtils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698