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

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

Issue 1845283003: Gamma-correctness pushed into Skia, top-down. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Rebase Created 4 years, 8 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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 const GrClip& clip, 49 const GrClip& clip,
50 const SkRect& dstRect, 50 const SkRect& dstRect,
51 const SkPoint& srcOffset, 51 const SkPoint& srcOffset,
52 GrTexture* texture, 52 GrTexture* texture,
53 Gr1DKernelEffect::Direction direction, 53 Gr1DKernelEffect::Direction direction,
54 int radius, 54 int radius,
55 float sigma, 55 float sigma,
56 bool useBounds, 56 bool useBounds,
57 float bounds[2]) { 57 float bounds[2]) {
58 GrPaint paint; 58 GrPaint paint;
59 paint.setAllowSRGBInputs(drawContext->allowSRGBInputs());
59 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian( 60 SkAutoTUnref<GrFragmentProcessor> conv(GrConvolutionEffect::CreateGaussian(
60 texture, direction, radius, sigma, useBounds, bounds)); 61 texture, direction, radius, sigma, useBounds, bounds));
61 paint.addColorFragmentProcessor(conv); 62 paint.addColorFragmentProcessor(conv);
62 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 63 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
63 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); 64 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y());
64 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo calMatrix); 65 drawContext->fillRectWithLocalMatrix(clip, paint, SkMatrix::I(), dstRect, lo calMatrix);
65 } 66 }
66 67
67 static void convolve_gaussian_2d(GrDrawContext* drawContext, 68 static void convolve_gaussian_2d(GrDrawContext* drawContext,
68 const GrClip& clip, 69 const GrClip& clip,
69 const SkRect& dstRect, 70 const SkRect& dstRect,
70 const SkPoint& srcOffset, 71 const SkPoint& srcOffset,
71 GrTexture* texture, 72 GrTexture* texture,
72 int radiusX, 73 int radiusX,
73 int radiusY, 74 int radiusY,
74 SkScalar sigmaX, 75 SkScalar sigmaX,
75 SkScalar sigmaY, 76 SkScalar sigmaY,
76 const SkRect* srcBounds) { 77 const SkRect* srcBounds) {
77 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y()); 78 SkMatrix localMatrix = SkMatrix::MakeTrans(-srcOffset.x(), -srcOffset.y());
78 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1); 79 SkISize size = SkISize::Make(2 * radiusX + 1, 2 * radiusY + 1);
79 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY); 80 SkIPoint kernelOffset = SkIPoint::Make(radiusX, radiusY);
80 GrPaint paint; 81 GrPaint paint;
82 paint.setAllowSRGBInputs(drawContext->allowSRGBInputs());
81 SkIRect bounds; 83 SkIRect bounds;
82 if (srcBounds) { 84 if (srcBounds) {
83 srcBounds->roundOut(&bounds); 85 srcBounds->roundOut(&bounds);
84 } else { 86 } else {
85 bounds.setEmpty(); 87 bounds.setEmpty();
86 } 88 }
87 89
88 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus sian( 90 SkAutoTUnref<GrFragmentProcessor> conv(GrMatrixConvolutionEffect::CreateGaus sian(
89 texture, bounds, size, 1.0, 0.0, kernelOffset, 91 texture, bounds, size, 1.0, 0.0, kernelOffset,
90 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_ Mode, 92 srcBounds ? GrTextureDomain::kDecal_Mode : GrTextureDomain::kIgnore_ Mode,
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 convolve_gaussian_1d(drawContext, clip, rightRect, srcOffset, texture, 159 convolve_gaussian_1d(drawContext, clip, rightRect, srcOffset, texture,
158 direction, radius, sigma, true, bounds); 160 direction, radius, sigma, true, bounds);
159 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture, 161 convolve_gaussian_1d(drawContext, clip, midRect, srcOffset, texture,
160 direction, radius, sigma, false, bounds); 162 direction, radius, sigma, false, bounds);
161 } 163 }
162 } 164 }
163 165
164 GrTexture* GaussianBlur(GrContext* context, 166 GrTexture* GaussianBlur(GrContext* context,
165 GrTexture* srcTexture, 167 GrTexture* srcTexture,
166 bool canClobberSrc, 168 bool canClobberSrc,
169 bool allowSRGBInputs,
167 const SkRect& dstBounds, 170 const SkRect& dstBounds,
168 const SkRect* srcBounds, 171 const SkRect* srcBounds,
169 float sigmaX, 172 float sigmaX,
170 float sigmaY) { 173 float sigmaY) {
171 SkASSERT(context); 174 SkASSERT(context);
172 SkIRect clearRect; 175 SkIRect clearRect;
173 int scaleFactorX, radiusX; 176 int scaleFactorX, radiusX;
174 int scaleFactorY, radiusY; 177 int scaleFactorY, radiusY;
175 int maxTextureSize = context->caps()->maxTextureSize(); 178 int maxTextureSize = context->caps()->maxTextureSize();
176 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX); 179 sigmaX = adjust_sigma(sigmaX, maxTextureSize, &scaleFactorX, &radiusX);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 225 }
223 226
224 if (nullptr == dstTexture || nullptr == tempTexture) { 227 if (nullptr == dstTexture || nullptr == tempTexture) {
225 return nullptr; 228 return nullptr;
226 } 229 }
227 230
228 SkAutoTUnref<GrDrawContext> srcDrawContext; 231 SkAutoTUnref<GrDrawContext> srcDrawContext;
229 232
230 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) { 233 for (int i = 1; i < scaleFactorX || i < scaleFactorY; i *= 2) {
231 GrPaint paint; 234 GrPaint paint;
235 paint.setAllowSRGBInputs(allowSRGBInputs);
232 SkMatrix matrix; 236 SkMatrix matrix;
233 matrix.setIDiv(srcTexture->width(), srcTexture->height()); 237 matrix.setIDiv(srcTexture->width(), srcTexture->height());
234 SkRect dstRect(srcRect); 238 SkRect dstRect(srcRect);
235 if (srcBounds && i == 1) { 239 if (srcBounds && i == 1) {
236 SkRect domain; 240 SkRect domain;
237 matrix.mapRect(&domain, *srcBounds); 241 matrix.mapRect(&domain, *srcBounds);
238 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width( ) : 0.0f, 242 domain.inset((i < scaleFactorX) ? SK_ScalarHalf / srcTexture->width( ) : 0.0f,
239 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height () : 0.0f); 243 (i < scaleFactorY) ? SK_ScalarHalf / srcTexture->height () : 0.0f);
240 SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Cr eate( 244 SkAutoTUnref<const GrFragmentProcessor> fp(GrTextureDomainEffect::Cr eate(
241 srcTexture, 245 srcTexture,
(...skipping 19 matching lines...) Expand all
261 } 265 }
262 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR ect); 266 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR ect);
263 267
264 srcDrawContext.swap(dstDrawContext); 268 srcDrawContext.swap(dstDrawContext);
265 srcRect = dstRect; 269 srcRect = dstRect;
266 srcTexture = dstTexture; 270 srcTexture = dstTexture;
267 SkTSwap(dstTexture, tempTexture); 271 SkTSwap(dstTexture, tempTexture);
268 localSrcBounds = srcRect; 272 localSrcBounds = srcRect;
269 } 273 }
270 274
275 SkSurfaceProps props(allowSRGBInputs ? SkSurfaceProps::kAllowSRGBInputs_Flag : 0,
276 SkSurfaceProps::kLegacyFontHost_InitType);
277
271 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i s faster to just 278 // For really small blurs (certainly no wider than 5x5 on desktop gpus) it i s faster to just
272 // launch a single non separable kernel vs two launches 279 // launch a single non separable kernel vs two launches
273 srcRect = localDstBounds; 280 srcRect = localDstBounds;
274 if (sigmaX > 0.0f && sigmaY > 0.0f && 281 if (sigmaX > 0.0f && sigmaY > 0.0f &&
275 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) { 282 (2 * radiusX + 1) * (2 * radiusY + 1) <= MAX_KERNEL_SIZE) {
276 // We shouldn't be scaling because this is a small size blur 283 // We shouldn't be scaling because this is a small size blur
277 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY)); 284 SkASSERT((1 == scaleFactorX) && (1 == scaleFactorY));
278 285
279 SkAutoTUnref<GrDrawContext> dstDrawContext( 286 SkAutoTUnref<GrDrawContext> dstDrawContext(
280 context->drawContext(dstTexture->as RenderTarget())); 287 context->drawContext(dstTexture->asRenderTarget(), &props));
281 if (!dstDrawContext) { 288 if (!dstDrawContext) {
282 return nullptr; 289 return nullptr;
283 } 290 }
284 convolve_gaussian_2d(dstDrawContext, clip, srcRect, srcOffset, 291 convolve_gaussian_2d(dstDrawContext, clip, srcRect, srcOffset,
285 srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBo unds); 292 srcTexture, radiusX, radiusY, sigmaX, sigmaY, srcBo unds);
286 293
287 srcDrawContext.swap(dstDrawContext); 294 srcDrawContext.swap(dstDrawContext);
288 srcRect.offsetTo(0, 0); 295 srcRect.offsetTo(0, 0);
289 srcTexture = dstTexture; 296 srcTexture = dstTexture;
290 SkTSwap(dstTexture, tempTexture); 297 SkTSwap(dstTexture, tempTexture);
(...skipping 13 matching lines...) Expand all
304 } 311 }
305 312
306 // Clear out a radius to the right of the srcRect to prevent the 313 // Clear out a radius to the right of the srcRect to prevent the
307 // X convolution from reading garbage. 314 // X convolution from reading garbage.
308 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, 315 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
309 radiusX, srcIRect.height()); 316 radiusX, srcIRect.height());
310 srcDrawContext->clear(&clearRect, 0x0, false); 317 srcDrawContext->clear(&clearRect, 0x0, false);
311 } 318 }
312 319
313 SkAutoTUnref<GrDrawContext> dstDrawContext( 320 SkAutoTUnref<GrDrawContext> dstDrawContext(
314 context->drawContext(dstTexture->as RenderTarget())); 321 context->drawContext(dstTexture->asRenderTarget(), &props));
315 if (!dstDrawContext) { 322 if (!dstDrawContext) {
316 return nullptr; 323 return nullptr;
317 } 324 }
318 convolve_gaussian(dstDrawContext, clip, srcRect, 325 convolve_gaussian(dstDrawContext, clip, srcRect,
319 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX, 326 srcTexture, Gr1DKernelEffect::kX_Direction, radius X, sigmaX,
320 srcBounds, srcOffset); 327 srcBounds, srcOffset);
321 srcDrawContext.swap(dstDrawContext); 328 srcDrawContext.swap(dstDrawContext);
322 srcTexture = dstTexture; 329 srcTexture = dstTexture;
323 srcRect.offsetTo(0, 0); 330 srcRect.offsetTo(0, 0);
324 SkTSwap(dstTexture, tempTexture); 331 SkTSwap(dstTexture, tempTexture);
(...skipping 12 matching lines...) Expand all
337 } 344 }
338 345
339 // Clear out a radius below the srcRect to prevent the Y 346 // Clear out a radius below the srcRect to prevent the Y
340 // convolution from reading garbage. 347 // convolution from reading garbage.
341 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, 348 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
342 srcIRect.width(), radiusY); 349 srcIRect.width(), radiusY);
343 srcDrawContext->clear(&clearRect, 0x0, false); 350 srcDrawContext->clear(&clearRect, 0x0, false);
344 } 351 }
345 352
346 SkAutoTUnref<GrDrawContext> dstDrawContext( 353 SkAutoTUnref<GrDrawContext> dstDrawContext(
347 context->drawContext(dstTexture-> asRenderTarget())); 354 context->drawContext(dstTexture->asRenderTarget(), &props));
348 if (!dstDrawContext) { 355 if (!dstDrawContext) {
349 return nullptr; 356 return nullptr;
350 } 357 }
351 convolve_gaussian(dstDrawContext, clip, srcRect, 358 convolve_gaussian(dstDrawContext, clip, srcRect,
352 srcTexture, Gr1DKernelEffect::kY_Direction, radius Y, sigmaY, 359 srcTexture, Gr1DKernelEffect::kY_Direction, radius Y, sigmaY,
353 srcBounds, srcOffset); 360 srcBounds, srcOffset);
354 361
355 srcDrawContext.swap(dstDrawContext); 362 srcDrawContext.swap(dstDrawContext);
356 srcTexture = dstTexture; 363 srcTexture = dstTexture;
357 srcRect.offsetTo(0, 0); 364 srcRect.offsetTo(0, 0);
(...skipping 10 matching lines...) Expand all
368 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom, 375 clearRect = SkIRect::MakeXYWH(srcIRect.fLeft, srcIRect.fBottom,
369 srcIRect.width() + 1, 1); 376 srcIRect.width() + 1, 1);
370 srcDrawContext->clear(&clearRect, 0x0, false); 377 srcDrawContext->clear(&clearRect, 0x0, false);
371 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop, 378 clearRect = SkIRect::MakeXYWH(srcIRect.fRight, srcIRect.fTop,
372 1, srcIRect.height()); 379 1, srcIRect.height());
373 srcDrawContext->clear(&clearRect, 0x0, false); 380 srcDrawContext->clear(&clearRect, 0x0, false);
374 SkMatrix matrix; 381 SkMatrix matrix;
375 matrix.setIDiv(srcTexture->width(), srcTexture->height()); 382 matrix.setIDiv(srcTexture->width(), srcTexture->height());
376 383
377 GrPaint paint; 384 GrPaint paint;
385 paint.setAllowSRGBInputs(allowSRGBInputs);
378 // FIXME: this should be mitchell, not bilinear. 386 // FIXME: this should be mitchell, not bilinear.
379 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode); 387 GrTextureParams params(SkShader::kClamp_TileMode, GrTextureParams::kBile rp_FilterMode);
380 paint.addColorTextureProcessor(srcTexture, matrix, params); 388 paint.addColorTextureProcessor(srcTexture, matrix, params);
381 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode); 389 paint.setPorterDuffXPFactory(SkXfermode::kSrc_Mode);
382 390
383 SkRect dstRect(srcRect); 391 SkRect dstRect(srcRect);
384 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY); 392 scale_rect(&dstRect, (float) scaleFactorX, (float) scaleFactorY);
385 393
386 SkAutoTUnref<GrDrawContext> dstDrawContext( 394 SkAutoTUnref<GrDrawContext> dstDrawContext(
387 context->drawContext(dstTexture->asRenderTarget( ))); 395 context->drawContext(dstTexture->asRenderTarget( )));
388 if (!dstDrawContext) { 396 if (!dstDrawContext) {
389 return nullptr; 397 return nullptr;
390 } 398 }
391 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR ect); 399 dstDrawContext->fillRectToRect(clip, paint, SkMatrix::I(), dstRect, srcR ect);
392 400
393 srcDrawContext.swap(dstDrawContext); 401 srcDrawContext.swap(dstDrawContext);
394 srcRect = dstRect; 402 srcRect = dstRect;
395 srcTexture = dstTexture; 403 srcTexture = dstTexture;
396 SkTSwap(dstTexture, tempTexture); 404 SkTSwap(dstTexture, tempTexture);
397 } 405 }
398 406
399 return SkRef(srcTexture); 407 return SkRef(srcTexture);
400 } 408 }
401 #endif 409 #endif
402 410
403 } 411 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698