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

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

Issue 1413673002: Remove DrawingMgr shims from GrContext (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Remove abandon, reset & flush from public DrawingMgr API Created 5 years, 2 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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 GrTextureParams::kBilerp_FilterMode)); 213 GrTextureParams::kBilerp_FilterMode));
214 paint.addColorFragmentProcessor(fp); 214 paint.addColorFragmentProcessor(fp);
215 } else { 215 } else {
216 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k Bilerp_FilterMode); 216 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::k Bilerp_FilterMode);
217 paint.addColorTextureProcessor(srcTexture, matrix, params); 217 paint.addColorTextureProcessor(srcTexture, matrix, params);
218 } 218 }
219 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f, 219 scale_rect(&dstRect, i < scaleFactorX ? 0.5f : 1.0f,
220 i < scaleFactorY ? 0.5f : 1.0f); 220 i < scaleFactorY ? 0.5f : 1.0f);
221 221
222 SkAutoTUnref<GrDrawContext> dstDrawContext( 222 SkAutoTUnref<GrDrawContext> dstDrawContext(
223 context->drawContext(dstTexture->as RenderTarget())); 223 context->drawingMgr().drawContext(dstTexture->a sRenderTarget()));
224 if (!dstDrawContext) { 224 if (!dstDrawContext) {
225 return nullptr; 225 return nullptr;
226 } 226 }
227 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); 227 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
228 228
229 srcDrawContext.swap(dstDrawContext); 229 srcDrawContext.swap(dstDrawContext);
230 srcRect = dstRect; 230 srcRect = dstRect;
231 srcTexture = dstTexture; 231 srcTexture = dstTexture;
232 SkTSwap(dstTexture, tempTexture); 232 SkTSwap(dstTexture, tempTexture);
233 } 233 }
234 234
235 const SkIRect srcIRect = srcRect.roundOut(); 235 const SkIRect srcIRect = srcRect.roundOut();
236 236
237 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i s faster to just 237 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i s faster to just
238 // launch a single non separable kernel vs two launches 238 // launch a single non separable kernel vs two launches
239 if (sigmaX > 0.0f && sigmaY > 0.0f && 239 if (sigmaX > 0.0f && sigmaY > 0.0f &&
240 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { 240 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) {
241 // We shouldn't be scaling because this is a small size blur 241 // We shouldn't be scaling because this is a small size blur
242 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); 242 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
243 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 243 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
244 244
245 SkAutoTUnref<GrDrawContext> dstDrawContext( 245 SkAutoTUnref<GrDrawContext> dstDrawContext(
246 context->drawContext(dstTexture->as RenderTarget())); 246 context->drawingMgr().drawContext(dstTexture->a sRenderTarget()));
247 if (!dstDrawContext) { 247 if (!dstDrawContext) {
248 return nullptr; 248 return nullptr;
249 } 249 }
250 convolve_gaussian_2d(dstDrawContext, clip, srcRect, dstRect, 250 convolve_gaussian_2d(dstDrawContext, clip, srcRect, dstRect,
251 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT oRect, srcIRect); 251 srcTexture, radiusX, radiusY, sigmaX, sigmaY, cropT oRect, srcIRect);
252 252
253 srcDrawContext.swap(dstDrawContext); 253 srcDrawContext.swap(dstDrawContext);
254 srcRect = dstRect; 254 srcRect = dstRect;
255 srcTexture = dstTexture; 255 srcTexture = dstTexture;
256 SkTSwap(dstTexture, tempTexture); 256 SkTSwap(dstTexture, tempTexture);
257 257
258 } else { 258 } else {
259 if (sigmaX > 0.0f) { 259 if (sigmaX > 0.0f) {
260 if (scaleFactorX > 1) { 260 if (scaleFactorX > 1) {
261 // TODO: if we pass in the source draw context we don't need thi s here 261 // TODO: if we pass in the source draw context we don't need thi s here
262 if (!srcDrawContext) { 262 if (!srcDrawContext) {
263 srcDrawContext.reset(context->drawContext(srcTexture->asRend erTarget())); 263 srcDrawContext.reset(
264 context->drawingMgr().drawContext(srcTexture->as RenderTarget()));
264 if (!srcDrawContext) { 265 if (!srcDrawContext) {
265 return nullptr; 266 return nullptr;
266 } 267 }
267 } 268 }
268 269
269 // Clear out a radius to the right of the srcRect to prevent the 270 // Clear out a radius to the right of the srcRect to prevent the
270 // X convolution from reading garbage. 271 // X convolution from reading garbage.
271 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, 272 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
272 radiusX, srcIRect.height()); 273 radiusX, srcIRect.height());
273 srcDrawContext->clear(&clearRect, 0x0, false); 274 srcDrawContext->clear(&clearRect, 0x0, false);
274 } 275 }
275 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 276 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
276 277
277 SkAutoTUnref<GrDrawContext> dstDrawContext( 278 SkAutoTUnref<GrDrawContext> dstDrawContext(
278 context->drawContext(dstTexture->asR enderTarget())); 279 context->drawingMgr().drawContext(dstTexture->as RenderTarget()));
279 if (!dstDrawContext) { 280 if (!dstDrawContext) {
280 return nullptr; 281 return nullptr;
281 } 282 }
282 convolve_gaussian(dstDrawContext, clip, srcRect, dstRect, 283 convolve_gaussian(dstDrawContext, clip, srcRect, dstRect,
283 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX, 284 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX,
284 cropToRect); 285 cropToRect);
285 286
286 srcDrawContext.swap(dstDrawContext); 287 srcDrawContext.swap(dstDrawContext);
287 srcTexture = dstTexture; 288 srcTexture = dstTexture;
288 srcRect = dstRect; 289 srcRect = dstRect;
289 SkTSwap(dstTexture, tempTexture); 290 SkTSwap(dstTexture, tempTexture);
290 } 291 }
291 292
292 if (sigmaY > 0.0f) { 293 if (sigmaY > 0.0f) {
293 if (scaleFactorY > 1 || sigmaX > 0.0f) { 294 if (scaleFactorY > 1 || sigmaX > 0.0f) {
294 // TODO: if we pass in the source draw context we don't need thi s here 295 // TODO: if we pass in the source draw context we don't need thi s here
295 if (!srcDrawContext) { 296 if (!srcDrawContext) {
296 srcDrawContext.reset(context->drawContext(srcTexture->asRend erTarget())); 297 srcDrawContext.reset(
298 context->drawingMgr().drawContext(srcTexture->as RenderTarget()));
297 if (!srcDrawContext) { 299 if (!srcDrawContext) {
298 return nullptr; 300 return nullptr;
299 } 301 }
300 } 302 }
301 303
302 // Clear out a radius below the srcRect to prevent the Y 304 // Clear out a radius below the srcRect to prevent the Y
303 // convolution from reading garbage. 305 // convolution from reading garbage.
304 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, 306 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
305 srcIRect.width(), radiusY); 307 srcIRect.width(), radiusY);
306 srcDrawContext->clear(&clearRect, 0x0, false); 308 srcDrawContext->clear(&clearRect, 0x0, false);
307 } 309 }
308 310
309 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height()); 311 SkRect dstRect = SkRect::MakeWH(srcRect.width(), srcRect.height());
310 312
311 SkAutoTUnref<GrDrawContext> dstDrawContext( 313 SkAutoTUnref<GrDrawContext> dstDrawContext(
312 context->drawContext(dstTexture->as RenderTarget())); 314 context->drawingMgr().drawContext(dstTexture->as RenderTarget()));
313 if (!dstDrawContext) { 315 if (!dstDrawContext) {
314 return nullptr; 316 return nullptr;
315 } 317 }
316 convolve_gaussian(dstDrawContext, clip, srcRect, 318 convolve_gaussian(dstDrawContext, clip, srcRect,
317 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio n, radiusY, sigmaY, 319 dstRect, srcTexture, Gr1DKernelEffect::kY_Directio n, radiusY, sigmaY,
318 cropToRect); 320 cropToRect);
319 321
320 srcDrawContext.swap(dstDrawContext); 322 srcDrawContext.swap(dstDrawContext);
321 srcTexture = dstTexture; 323 srcTexture = dstTexture;
322 srcRect = dstRect; 324 srcRect = dstRect;
(...skipping 17 matching lines...) Expand all
340 342
341 GrPaint paint; 343 GrPaint paint;
342 // FIXME: this should be mitchell, not bilinear. 344 // FIXME: this should be mitchell, not bilinear.
343 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode); 345 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode);
344 paint.addColorTextureProcessor(srcTexture, matrix, params); 346 paint.addColorTextureProcessor(srcTexture, matrix, params);
345 347
346 SkRect dstRect(srcRect); 348 SkRect dstRect(srcRect);
347 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); 349 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
348 350
349 SkAutoTUnref<GrDrawContext> dstDrawContext( 351 SkAutoTUnref<GrDrawContext> dstDrawContext(
350 context->drawContext(dstTexture->asR enderTarget())); 352 context->drawingMgr().drawContext(dstTexture->as RenderTarget()));
351 if (!dstDrawContext) { 353 if (!dstDrawContext) {
352 return nullptr; 354 return nullptr;
353 } 355 }
354 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect); 356 dstDrawContext->drawNonAARectToRect(clip, paint, SkMatrix::I(), dstRect, srcRect);
355 357
356 srcDrawContext.swap(dstDrawContext); 358 srcDrawContext.swap(dstDrawContext);
357 srcRect = dstRect; 359 srcRect = dstRect;
358 srcTexture = dstTexture; 360 srcTexture = dstTexture;
359 SkTSwap(dstTexture, tempTexture); 361 SkTSwap(dstTexture, tempTexture);
360 } 362 }
361 363
362 return SkRef(srcTexture); 364 return SkRef(srcTexture);
363 } 365 }
364 #endif 366 #endif
365 367
366 } 368 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698