OLD | NEW |
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 17 matching lines...) Expand all Loading... |
28 rect->fBottom = SkScalarMul(rect->fBottom, SkFloatToScalar(yScale)); | 28 rect->fBottom = SkScalarMul(rect->fBottom, SkFloatToScalar(yScale)); |
29 } | 29 } |
30 | 30 |
31 static float adjust_sigma(float sigma, int *scaleFactor, int *radius) { | 31 static float adjust_sigma(float sigma, 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 } | 36 } |
37 *radius = static_cast<int>(ceilf(sigma * 3.0f)); | 37 *radius = static_cast<int>(ceilf(sigma * 3.0f)); |
38 GrAssert(*radius <= GrConvolutionEffect::kMaxKernelRadius); | 38 SkASSERT(*radius <= GrConvolutionEffect::kMaxKernelRadius); |
39 return sigma; | 39 return sigma; |
40 } | 40 } |
41 | 41 |
42 static void convolve_gaussian_pass(GrContext* context, | 42 static void convolve_gaussian_pass(GrContext* context, |
43 const SkRect& srcRect, | 43 const SkRect& srcRect, |
44 const SkRect& dstRect, | 44 const SkRect& dstRect, |
45 GrTexture* texture, | 45 GrTexture* texture, |
46 Gr1DKernelEffect::Direction direction, | 46 Gr1DKernelEffect::Direction direction, |
47 int radius, | 47 int radius, |
48 float sigma, | 48 float sigma, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 GrTexture* GaussianBlur(GrContext* context, | 115 GrTexture* GaussianBlur(GrContext* context, |
116 GrTexture* srcTexture, | 116 GrTexture* srcTexture, |
117 bool canClobberSrc, | 117 bool canClobberSrc, |
118 const SkRect& rect, | 118 const SkRect& rect, |
119 bool cropToRect, | 119 bool cropToRect, |
120 float sigmaX, | 120 float sigmaX, |
121 float sigmaY) { | 121 float sigmaY) { |
122 GrAssert(NULL != context); | 122 SkASSERT(NULL != context); |
123 | 123 |
124 GrContext::AutoRenderTarget art(context); | 124 GrContext::AutoRenderTarget art(context); |
125 | 125 |
126 GrContext::AutoMatrix am; | 126 GrContext::AutoMatrix am; |
127 am.setIdentity(context); | 127 am.setIdentity(context); |
128 | 128 |
129 SkIRect clearRect; | 129 SkIRect clearRect; |
130 int scaleFactorX, radiusX; | 130 int scaleFactorX, radiusX; |
131 int scaleFactorY, radiusY; | 131 int scaleFactorY, radiusY; |
132 sigmaX = adjust_sigma(sigmaX, &scaleFactorX, &radiusX); | 132 sigmaX = adjust_sigma(sigmaX, &scaleFactorX, &radiusX); |
133 sigmaY = adjust_sigma(sigmaY, &scaleFactorY, &radiusY); | 133 sigmaY = adjust_sigma(sigmaY, &scaleFactorY, &radiusY); |
134 | 134 |
135 SkRect srcRect(rect); | 135 SkRect srcRect(rect); |
136 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); | 136 scale_rect(&srcRect, 1.0f / scaleFactorX, 1.0f / scaleFactorY); |
137 srcRect.roundOut(); | 137 srcRect.roundOut(); |
138 scale_rect(&srcRect, static_cast<float>(scaleFactorX), | 138 scale_rect(&srcRect, static_cast<float>(scaleFactorX), |
139 static_cast<float>(scaleFactorY)); | 139 static_cast<float>(scaleFactorY)); |
140 | 140 |
141 GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.hei
ght())); | 141 GrContext::AutoClip acs(context, SkRect::MakeWH(srcRect.width(), srcRect.hei
ght())); |
142 | 142 |
143 GrAssert(kBGRA_8888_GrPixelConfig == srcTexture->config() || | 143 SkASSERT(kBGRA_8888_GrPixelConfig == srcTexture->config() || |
144 kRGBA_8888_GrPixelConfig == srcTexture->config() || | 144 kRGBA_8888_GrPixelConfig == srcTexture->config() || |
145 kAlpha_8_GrPixelConfig == srcTexture->config()); | 145 kAlpha_8_GrPixelConfig == srcTexture->config()); |
146 | 146 |
147 GrTextureDesc desc; | 147 GrTextureDesc desc; |
148 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; | 148 desc.fFlags = kRenderTarget_GrTextureFlagBit | kNoStencil_GrTextureFlagBit; |
149 desc.fWidth = SkScalarFloorToInt(srcRect.width()); | 149 desc.fWidth = SkScalarFloorToInt(srcRect.width()); |
150 desc.fHeight = SkScalarFloorToInt(srcRect.height()); | 150 desc.fHeight = SkScalarFloorToInt(srcRect.height()); |
151 desc.fConfig = srcTexture->config(); | 151 desc.fConfig = srcTexture->config(); |
152 | 152 |
153 GrAutoScratchTexture temp1, temp2; | 153 GrAutoScratchTexture temp1, temp2; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
256 } else if (srcTexture == temp2.texture()) { | 256 } else if (srcTexture == temp2.texture()) { |
257 return temp2.detach(); | 257 return temp2.detach(); |
258 } else { | 258 } else { |
259 srcTexture->ref(); | 259 srcTexture->ref(); |
260 return srcTexture; | 260 return srcTexture; |
261 } | 261 } |
262 } | 262 } |
263 #endif | 263 #endif |
264 | 264 |
265 } | 265 } |
OLD | NEW |