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

Side by Side Diff: src/effects/SkGpuBlurUtils.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 | « src/effects/SkBlurImageFilter.cpp ('k') | tests/ImageFilterTest.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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 "SkGpuBlurUtils.h" 8 #include "SkGpuBlurUtils.h"
9 9
10 #include "SkRect.h" 10 #include "SkRect.h"
(...skipping 10 matching lines...) Expand all
21 21
22 #define MAX_BLUR_SIGMA 4.0f 22 #define MAX_BLUR_SIGMA 4.0f
23 23
24 static void scale_rect(SkRect* rect, float xScale, float yScale) { 24 static void scale_rect(SkRect* rect, float xScale, float yScale) {
25 rect->fLeft = SkScalarMul(rect->fLeft, xScale); 25 rect->fLeft = SkScalarMul(rect->fLeft, xScale);
26 rect->fTop = SkScalarMul(rect->fTop, yScale); 26 rect->fTop = SkScalarMul(rect->fTop, yScale);
27 rect->fRight = SkScalarMul(rect->fRight, xScale); 27 rect->fRight = SkScalarMul(rect->fRight, xScale);
28 rect->fBottom = SkScalarMul(rect->fBottom, yScale); 28 rect->fBottom = SkScalarMul(rect->fBottom, yScale);
29 } 29 }
30 30
31 static float adjust_sigma(float sigma, int *scaleFactor, int *radius) { 31 static float adjust_sigma(float sigma, int maxTextureSize, int *scaleFactor, int *radius) {
32 *scaleFactor = 1; 32 *scaleFactor = 1;
33 while (sigma > MAX_BLUR_SIGMA) { 33 while (sigma > MAX_BLUR_SIGMA) {
34 *scaleFactor *= 2; 34 *scaleFactor *= 2;
35 sigma *= 0.5f; 35 sigma *= 0.5f;
36 if (*scaleFactor > maxTextureSize) {
37 *scaleFactor = maxTextureSize;
38 sigma = MAX_BLUR_SIGMA;
39 }
36 } 40 }
37 *radius = static_cast<int>(ceilf(sigma * 3.0f)); 41 *radius = static_cast<int>(ceilf(sigma * 3.0f));
38 SkASSERT(*radius <= GrConvolutionEffect::kMaxKernelRadius); 42 SkASSERT(*radius <= GrConvolutionEffect::kMaxKernelRadius);
39 return sigma; 43 return sigma;
40 } 44 }
41 45
42 static void convolve_gaussian_pass(GrContext* context, 46 static void convolve_gaussian_pass(GrContext* context,
43 const SkRect& srcRect, 47 const SkRect& srcRect,
44 const SkRect& dstRect, 48 const SkRect& dstRect,
45 GrTexture* texture, 49 GrTexture* texture,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 SkASSERT(NULL != context); 126 SkASSERT(NULL != context);
123 127
124 GrContext::AutoRenderTarget art(context); 128 GrContext::AutoRenderTarget art(context);
125 129
126 GrContext::AutoMatrix am; 130 GrContext::AutoMatrix am;
127 am.setIdentity(context); 131 am.setIdentity(context);
128 132
129 SkIRect clearRect; 133 SkIRect clearRect;
130 int scaleFactorX, radiusX; 134 int scaleFactorX, radiusX;
131 int scaleFactorY, radiusY; 135 int scaleFactorY, radiusY;
132 sigmaX = adjust_sigma(sigmaX, &scaleFactorX, &radiusX); 136 int maxTextureSize = context->getMaxTextureSize();
133 sigmaY = adjust_sigma(sigmaY, &scaleFactorY, &radiusY); 137 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
138 sigmaY = adjust_sigma(sigmaY, maxTextureSize, &scaleFactorY, &radiusY);
134 139
135 SkRect srcRect(rect); 140 SkRect srcRect(rect);
136 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); 141 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY);
137 srcRect.roundOut(); 142 srcRect.roundOut();
138 scale_rect(&srcRect, static_cast<float>(scaleFactorX), 143 scale_rect(&srcRect, static_cast<float>(scaleFactorX),
139 static_cast<float>(scaleFactorY)); 144 static_cast<float>(scaleFactorY));
140 145
141 GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.hei ght())); 146 GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.hei ght()));
142 147
143 SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() || 148 SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() ||
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 } else if (srcTexture == temp2.texture()) { 261 } else if (srcTexture == temp2.texture()) {
257 return temp2.detach(); 262 return temp2.detach();
258 } else { 263 } else {
259 srcTexture->ref(); 264 srcTexture->ref();
260 return srcTexture; 265 return srcTexture;
261 } 266 }
262 } 267 }
263 #endif 268 #endif
264 269
265 } 270 }
OLDNEW
« no previous file with comments | « src/effects/SkBlurImageFilter.cpp ('k') | tests/ImageFilterTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698