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

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

Issue 1245183002: Misc cleanup (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Address gcc complaint Created 5 years, 5 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
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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 } else { 191 } else {
192 temp2.reset(context->textureProvider()->refScratchTexture( 192 temp2.reset(context->textureProvider()->refScratchTexture(
193 desc, GrTextureProvider::kApprox_ScratchTexMatch)); 193 desc, GrTextureProvider::kApprox_ScratchTexMatch));
194 tempTexture = temp2.get(); 194 tempTexture = temp2.get();
195 } 195 }
196 196
197 if (NULL == dstTexture || NULL == tempTexture) { 197 if (NULL == dstTexture || NULL == tempTexture) {
198 return NULL; 198 return NULL;
199 } 199 }
200 200
201 GrDrawContext* drawContext = context->drawContext(); 201 GrDrawContext* srcDrawContext = NULL;
202 if (!drawContext) {
203 return NULL;
204 }
205 202
206 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { 203 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
207 GrPaint paint; 204 GrPaint paint;
208 SkMatrix matrix; 205 SkMatrix matrix;
209 matrix.setIDiv(srcTexture->width(), srcTexture->height()); 206 matrix.setIDiv(srcTexture->width(), srcTexture->height());
210 SkRect dstRect(srcRect); 207 SkRect dstRect(srcRect);
211 if (cropToRect && i == 1) { 208 if (cropToRect && i == 1) {
212 dstRect.offset(-dstRect.fLeft, -dstRect.fTop); 209 dstRect.offset(-dstRect.fLeft, -dstRect.fTop);
213 SkRect domain; 210 SkRect domain;
214 matrix.mapRect(&domain, rect); 211 matrix.mapRect(&domain, rect);
215 domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f, 212 domain.inset(i < scaleFactorX ? SK_ScalarHalf / srcTexture->width() : 0.0f,
216 i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f); 213 i < scaleFactorY ? SK_ScalarHalf / srcTexture->height() : 0.0f);
217 SkAutoTUnref<GrFragmentProcessor> fp( GrTextureDomainEffect::Creat e( 214 SkAutoTUnref<GrFragmentProcessor> fp( GrTextureDomainEffect::Creat e(
218 paint.getProcessorDataManager(), 215 paint.getProcessorDataManager(),
219 srcTexture, 216 srcTexture,
220 matrix, 217 matrix,
221 domain, 218 domain,
222 GrTextureDomain::kDecal_Mode, 219 GrTextureDomain::kDecal_Mode,
223 GrTextureParams::kBilerp_FilterMode)); 220 GrTextureParams::kBilerp_FilterMode));
224 paint.addColorProcessor(fp); 221 paint.addColorProcessor(fp);
225 } else { 222 } else {
226 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k Bilerp_FilterMode); 223 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k Bilerp_FilterMode);
227 paint.addColorTextureProcessor(srcTexture, matrix, params); 224 paint.addColorTextureProcessor(srcTexture, matrix, params);
228 } 225 }
229 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, 226 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
230 i < scaleFactorY ? 0.5f : 1.0f); 227 i < scaleFactorY ? 0.5f : 1.0f);
231 drawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, pai nt, SkMatrix::I(), 228
232 dstRect, srcRect); 229 GrDrawContext* dstDrawContext = context->drawContext();
230 if (!dstDrawContext) {
231 return NULL;
232 }
233 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint,
234 SkMatrix::I(), dstRect, srcRect);
235
236 srcDrawContext = dstDrawContext;
233 srcRect = dstRect; 237 srcRect = dstRect;
234 srcTexture = dstTexture; 238 srcTexture = dstTexture;
235 SkTSwap(dstTexture, tempTexture); 239 SkTSwap(dstTexture, tempTexture);
236 } 240 }
237 241
238 const SkIRect srcIRect = srcRect.roundOut(); 242 const SkIRect srcIRect = srcRect.roundOut();
239 243
240 // For really small blurs(Certainly no wider than 5x5 on desktop gpus) it is faster to just 244 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i s faster to just
241 // launch a single non separable kernel vs two launches 245 // launch a single non separable kernel vs two launches
242 if (sigmaX > 0.0f && sigmaY > 0 && 246 if (sigmaX > 0.0f && sigmaY > 0.0f &&
243 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { 247 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) {
244 // We shouldn't be scaling because this is a small size blur 248 // We shouldn't be scaling because this is a small size blur
245 SkASSERT((scaleFactorX == scaleFactorY) == 1); 249 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
246 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 250 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
247 convolve_gaussian_2d(drawContext, dstTexture->asRenderTarget(), clip, sr cRect, dstRect, 251
252 GrDrawContext* dstDrawContext = context->drawContext();
253 if (!dstDrawContext) {
254 return NULL;
255 }
256 convolve_gaussian_2d(dstDrawContext, dstTexture->asRenderTarget(), clip, srcRect, dstRect,
248 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT oRect, srcIRect); 257 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT oRect, srcIRect);
258
259 srcDrawContext = dstDrawContext;
260 srcRect = dstRect;
249 srcTexture = dstTexture; 261 srcTexture = dstTexture;
250 srcRect = dstRect;
251 SkTSwap(dstTexture, tempTexture); 262 SkTSwap(dstTexture, tempTexture);
252 263
253 } else { 264 } else {
254 if (sigmaX > 0.0f) { 265 if (sigmaX > 0.0f) {
255 if (scaleFactorX > 1) { 266 if (scaleFactorX > 1) {
267 // TODO: if we pass in the source draw context we don't need thi s here
268 if (!srcDrawContext) {
269 srcDrawContext = context->drawContext();
270 if (!srcDrawContext) {
271 return NULL;
272 }
273 }
274
256 // Clear out a radius to the right of the srcRect to prevent the 275 // Clear out a radius to the right of the srcRect to prevent the
257 // X convolution from reading garbage. 276 // X convolution from reading garbage.
258 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, 277 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
259 radiusX, srcIRect.height()); 278 radiusX, srcIRect.height());
260 drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0 , false); 279 srcDrawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false);
261 } 280 }
262 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 281 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
263 convolve_gaussian(drawContext, dstTexture->asRenderTarget(), clip, s rcRect, dstRect, 282
283 GrDrawContext* dstDrawContext = context->drawContext();
284 if (!dstDrawContext) {
285 return NULL;
286 }
287 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip , srcRect, dstRect,
264 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX, 288 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX,
265 cropToRect); 289 cropToRect);
290
291 srcDrawContext = dstDrawContext;
266 srcTexture = dstTexture; 292 srcTexture = dstTexture;
267 srcRect = dstRect; 293 srcRect = dstRect;
268 SkTSwap(dstTexture, tempTexture); 294 SkTSwap(dstTexture, tempTexture);
269 } 295 }
270 296
271 if (sigmaY > 0.0f) { 297 if (sigmaY > 0.0f) {
272 if (scaleFactorY > 1 || sigmaX > 0.0f) { 298 if (scaleFactorY > 1 || sigmaX > 0.0f) {
299 // TODO: if we pass in the source draw context we don't need thi s here
300 if (!srcDrawContext) {
301 srcDrawContext = context->drawContext();
302 if (!srcDrawContext) {
303 return NULL;
304 }
305 }
306
273 // Clear out a radius below the srcRect to prevent the Y 307 // Clear out a radius below the srcRect to prevent the Y
274 // convolution from reading garbage. 308 // convolution from reading garbage.
275 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, 309 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
276 srcIRect.width(), radiusY); 310 srcIRect.width(), radiusY);
277 drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0 , false); 311 srcDrawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false);
278 } 312 }
279 313
280 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 314 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
281 convolve_gaussian(drawContext, dstTexture->asRenderTarget(), clip, s rcRect, 315
316 GrDrawContext* dstDrawContext = context->drawContext();
317 if (!dstDrawContext) {
318 return NULL;
319 }
320 convolve_gaussian(dstDrawContext, dstTexture->asRenderTarget(), clip , srcRect,
282 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio n, radiusY, sigmaY, 321 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio n, radiusY, sigmaY,
283 cropToRect); 322 cropToRect);
323
324 srcDrawContext = dstDrawContext;
284 srcTexture = dstTexture; 325 srcTexture = dstTexture;
285 srcRect = dstRect; 326 srcRect = dstRect;
286 SkTSwap(dstTexture, tempTexture); 327 SkTSwap(dstTexture, tempTexture);
287 } 328 }
288 } 329 }
289 330
290 if (scaleFactorX > 1 || scaleFactorY > 1) { 331 if (scaleFactorX > 1 || scaleFactorY > 1) {
332 SkASSERT(srcDrawContext);
333
291 // Clear one pixel to the right and below, to accommodate bilinear 334 // Clear one pixel to the right and below, to accommodate bilinear
292 // upsampling. 335 // upsampling.
293 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, 336 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
294 srcIRect.width() + 1, 1); 337 srcIRect.width() + 1, 1);
295 drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false) ; 338 srcDrawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, fal se);
296 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, 339 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
297 1, srcIRect.height()); 340 1, srcIRect.height());
298 drawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, false) ; 341 srcDrawContext->clear(srcTexture->asRenderTarget(), &clearRect, 0x0, fal se);
299 SkMatrix matrix; 342 SkMatrix matrix;
300 matrix.setIDiv(srcTexture->width(), srcTexture->height()); 343 matrix.setIDiv(srcTexture->width(), srcTexture->height());
301 344
302 GrPaint paint; 345 GrPaint paint;
303 // FIXME: this should be mitchell, not bilinear. 346 // FIXME: this should be mitchell, not bilinear.
304 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode); 347 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode);
305 paint.addColorTextureProcessor(srcTexture, matrix, params); 348 paint.addColorTextureProcessor(srcTexture, matrix, params);
306 349
307 SkRect dstRect(srcRect); 350 SkRect dstRect(srcRect);
308 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); 351 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
309 drawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, pai nt, 352
310 SkMatrix::I(), dstRect, srcRect); 353 GrDrawContext* dstDrawContext = context->drawContext();
354 if (!dstDrawContext) {
355 return NULL;
356 }
357 dstDrawContext->drawNonAARectToRect(dstTexture->asRenderTarget(), clip, paint,
358 SkMatrix::I(), dstRect, srcRect);
359
360 srcDrawContext = dstDrawContext;
311 srcRect = dstRect; 361 srcRect = dstRect;
312 srcTexture = dstTexture; 362 srcTexture = dstTexture;
313 SkTSwap(dstTexture, tempTexture); 363 SkTSwap(dstTexture, tempTexture);
314 } 364 }
365
315 return SkRef(srcTexture); 366 return SkRef(srcTexture);
316 } 367 }
317 #endif 368 #endif
318 369
319 } 370 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698