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

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

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

Powered by Google App Engine
This is Rietveld 408576698