| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkBlurMask.h" | 8 #include "SkBlurMask.h" |
| 9 #include "SkBlurMaskFilter.h" | 9 #include "SkBlurMaskFilter.h" |
| 10 #include "SkBlurDrawLooper.h" | 10 #include "SkBlurDrawLooper.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 paint.setColor(SK_ColorGRAY); | 104 paint.setColor(SK_ColorGRAY); |
| 105 paint.setStyle(SkPaint::kStroke_Style); | 105 paint.setStyle(SkPaint::kStroke_Style); |
| 106 paint.setStrokeWidth(SkIntToScalar(strokeWidth)); | 106 paint.setStrokeWidth(SkIntToScalar(strokeWidth)); |
| 107 | 107 |
| 108 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)); | 108 SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)); |
| 109 for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) { | 109 for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) { |
| 110 SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style); | 110 SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style); |
| 111 | 111 |
| 112 const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag; | 112 const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag; |
| 113 for (uint32_t flags = 0; flags < flagPermutations; ++flags) { | 113 for (uint32_t flags = 0; flags < flagPermutations; ++flags) { |
| 114 SkMaskFilter* filter; | 114 paint.setMaskFilter(SkBlurMaskFilter::Make(blurStyle, sigma, flags))
; |
| 115 filter = SkBlurMaskFilter::Create(blurStyle, sigma, flags); | |
| 116 | |
| 117 paint.setMaskFilter(filter); | |
| 118 filter->unref(); | |
| 119 | 115 |
| 120 for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { | 116 for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { |
| 121 SkPath path; | 117 SkPath path; |
| 122 tests[test].addPath(&path); | 118 tests[test].addPath(&path); |
| 123 SkPath strokedPath; | 119 SkPath strokedPath; |
| 124 paint.getFillPath(path, &strokedPath); | 120 paint.getFillPath(path, &strokedPath); |
| 125 SkRect refBound = strokedPath.getBounds(); | 121 SkRect refBound = strokedPath.getBounds(); |
| 126 SkIRect iref; | 122 SkIRect iref; |
| 127 refBound.roundOut(&iref); | 123 refBound.roundOut(&iref); |
| 128 iref.inset(-outset, -outset); | 124 iref.inset(-outset, -outset); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 static void blur_path(SkCanvas* canvas, const SkPath& path, | 223 static void blur_path(SkCanvas* canvas, const SkPath& path, |
| 228 SkScalar gaussianSigma) { | 224 SkScalar gaussianSigma) { |
| 229 | 225 |
| 230 SkScalar midX = path.getBounds().centerX(); | 226 SkScalar midX = path.getBounds().centerX(); |
| 231 SkScalar midY = path.getBounds().centerY(); | 227 SkScalar midY = path.getBounds().centerY(); |
| 232 | 228 |
| 233 canvas->translate(-midX, -midY); | 229 canvas->translate(-midX, -midY); |
| 234 | 230 |
| 235 SkPaint blurPaint; | 231 SkPaint blurPaint; |
| 236 blurPaint.setColor(SK_ColorWHITE); | 232 blurPaint.setColor(SK_ColorWHITE); |
| 237 SkMaskFilter* filter = SkBlurMaskFilter::Create(kNormal_SkBlurStyle, | 233 blurPaint.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, gaussian
Sigma, |
| 238 gaussianSigma, | 234 SkBlurMaskFilter::kHighQualit
y_BlurFlag)); |
| 239 SkBlurMaskFilter::kHighQuali
ty_BlurFlag); | |
| 240 blurPaint.setMaskFilter(filter)->unref(); | |
| 241 | 235 |
| 242 canvas->drawColor(SK_ColorBLACK); | 236 canvas->drawColor(SK_ColorBLACK); |
| 243 canvas->drawPath(path, blurPaint); | 237 canvas->drawPath(path, blurPaint); |
| 244 } | 238 } |
| 245 | 239 |
| 246 // Readback the blurred draw results from the canvas | 240 // Readback the blurred draw results from the canvas |
| 247 static void readback(SkCanvas* canvas, int* result, int resultCount) { | 241 static void readback(SkCanvas* canvas, int* result, int resultCount) { |
| 248 SkBitmap readback; | 242 SkBitmap readback; |
| 249 readback.allocN32Pixels(resultCount, 30); | 243 readback.allocN32Pixels(resultCount, 30); |
| 250 | 244 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 } | 450 } |
| 457 | 451 |
| 458 static void make_noop_layer(SkLayerDrawLooper::Builder* builder) { | 452 static void make_noop_layer(SkLayerDrawLooper::Builder* builder) { |
| 459 SkLayerDrawLooper::LayerInfo info; | 453 SkLayerDrawLooper::LayerInfo info; |
| 460 | 454 |
| 461 info.fPaintBits = 0; | 455 info.fPaintBits = 0; |
| 462 info.fColorMode = SkXfermode::kDst_Mode; | 456 info.fColorMode = SkXfermode::kDst_Mode; |
| 463 builder->addLayer(info); | 457 builder->addLayer(info); |
| 464 } | 458 } |
| 465 | 459 |
| 466 static void make_blur_layer(SkLayerDrawLooper::Builder* builder, SkMaskFilter* m
f) { | 460 static void make_blur_layer(SkLayerDrawLooper::Builder* builder, sk_sp<SkMaskFil
ter> mf) { |
| 467 SkLayerDrawLooper::LayerInfo info; | 461 SkLayerDrawLooper::LayerInfo info; |
| 468 | 462 |
| 469 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit; | 463 info.fPaintBits = SkLayerDrawLooper::kMaskFilter_Bit; |
| 470 info.fColorMode = SkXfermode::kSrc_Mode; | 464 info.fColorMode = SkXfermode::kSrc_Mode; |
| 471 SkPaint* paint = builder->addLayer(info); | 465 SkPaint* paint = builder->addLayer(info); |
| 472 paint->setMaskFilter(mf); | 466 paint->setMaskFilter(std::move(mf)); |
| 473 } | 467 } |
| 474 | 468 |
| 475 static void test_layerDrawLooper(skiatest::Reporter* reporter, SkMaskFilter* mf,
SkScalar sigma, | 469 static void test_layerDrawLooper(skiatest::Reporter* reporter, sk_sp<SkMaskFilte
r> mf, |
| 476 SkBlurStyle style, SkBlurQuality quality, bool
expectSuccess) { | 470 SkScalar sigma, SkBlurStyle style, SkBlurQualit
y quality, |
| 471 bool expectSuccess) { |
| 477 | 472 |
| 478 SkLayerDrawLooper::LayerInfo info; | 473 SkLayerDrawLooper::LayerInfo info; |
| 479 SkLayerDrawLooper::Builder builder; | 474 SkLayerDrawLooper::Builder builder; |
| 480 | 475 |
| 481 // 1 layer is too few | 476 // 1 layer is too few |
| 482 make_noop_layer(&builder); | 477 make_noop_layer(&builder); |
| 483 test_looper(reporter, builder.detach(), sigma, style, quality, false); | 478 test_looper(reporter, builder.detach(), sigma, style, quality, false); |
| 484 | 479 |
| 485 // 2 layers is good, but need blur | 480 // 2 layers is good, but need blur |
| 486 make_noop_layer(&builder); | 481 make_noop_layer(&builder); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 510 | 505 |
| 511 // Test asABlur for SkBlurMaskFilter | 506 // Test asABlur for SkBlurMaskFilter |
| 512 // | 507 // |
| 513 for (size_t i = 0; i < SK_ARRAY_COUNT(styles); ++i) { | 508 for (size_t i = 0; i < SK_ARRAY_COUNT(styles); ++i) { |
| 514 const SkBlurStyle style = (SkBlurStyle)styles[i]; | 509 const SkBlurStyle style = (SkBlurStyle)styles[i]; |
| 515 for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { | 510 for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { |
| 516 const SkScalar sigma = sigmas[j]; | 511 const SkScalar sigma = sigmas[j]; |
| 517 for (int flags = 0; flags <= SkBlurMaskFilter::kAll_BlurFlag; ++flag
s) { | 512 for (int flags = 0; flags <= SkBlurMaskFilter::kAll_BlurFlag; ++flag
s) { |
| 518 const SkBlurQuality quality = blurMaskFilterFlags_as_quality(fla
gs); | 513 const SkBlurQuality quality = blurMaskFilterFlags_as_quality(fla
gs); |
| 519 | 514 |
| 520 SkAutoTUnref<SkMaskFilter> mf(SkBlurMaskFilter::Create(style, si
gma, flags)); | 515 sk_sp<SkMaskFilter> mf(SkBlurMaskFilter::Make(style, sigma, flag
s)); |
| 521 if (nullptr == mf.get()) { | 516 if (nullptr == mf.get()) { |
| 522 REPORTER_ASSERT(reporter, sigma <= 0); | 517 REPORTER_ASSERT(reporter, sigma <= 0); |
| 523 } else { | 518 } else { |
| 524 REPORTER_ASSERT(reporter, sigma > 0); | 519 REPORTER_ASSERT(reporter, sigma > 0); |
| 525 SkMaskFilter::BlurRec rec; | 520 SkMaskFilter::BlurRec rec; |
| 526 bool success = mf->asABlur(&rec); | 521 bool success = mf->asABlur(&rec); |
| 527 if (flags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) { | 522 if (flags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag) { |
| 528 REPORTER_ASSERT(reporter, !success); | 523 REPORTER_ASSERT(reporter, !success); |
| 529 } else { | 524 } else { |
| 530 REPORTER_ASSERT(reporter, success); | 525 REPORTER_ASSERT(reporter, success); |
| 531 REPORTER_ASSERT(reporter, rec.fSigma == sigma); | 526 REPORTER_ASSERT(reporter, rec.fSigma == sigma); |
| 532 REPORTER_ASSERT(reporter, rec.fStyle == style); | 527 REPORTER_ASSERT(reporter, rec.fStyle == style); |
| 533 REPORTER_ASSERT(reporter, rec.fQuality == quality); | 528 REPORTER_ASSERT(reporter, rec.fQuality == quality); |
| 534 } | 529 } |
| 535 test_layerDrawLooper(reporter, mf, sigma, style, quality, su
ccess); | 530 test_layerDrawLooper(reporter, std::move(mf), sigma, style,
quality, success); |
| 536 } | 531 } |
| 537 test_blurDrawLooper(reporter, sigma, style, flags); | 532 test_blurDrawLooper(reporter, sigma, style, flags); |
| 538 } | 533 } |
| 539 } | 534 } |
| 540 } | 535 } |
| 541 | 536 |
| 542 // Test asABlur for SkEmbossMaskFilter -- should never succeed | 537 // Test asABlur for SkEmbossMaskFilter -- should never succeed |
| 543 // | 538 // |
| 544 { | 539 { |
| 545 SkEmbossMaskFilter::Light light = { | 540 SkEmbossMaskFilter::Light light = { |
| 546 { 1, 1, 1 }, 0, 127, 127 | 541 { 1, 1, 1 }, 0, 127, 127 |
| 547 }; | 542 }; |
| 548 for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { | 543 for (size_t j = 0; j < SK_ARRAY_COUNT(sigmas); ++j) { |
| 549 const SkScalar sigma = sigmas[j]; | 544 const SkScalar sigma = sigmas[j]; |
| 550 SkAutoTUnref<SkMaskFilter> mf(SkEmbossMaskFilter::Create(sigma, ligh
t)); | 545 auto mf(SkEmbossMaskFilter::Make(sigma, light)); |
| 551 if (mf.get()) { | 546 if (mf) { |
| 552 SkMaskFilter::BlurRec rec; | 547 SkMaskFilter::BlurRec rec; |
| 553 bool success = mf->asABlur(&rec); | 548 bool success = mf->asABlur(&rec); |
| 554 REPORTER_ASSERT(reporter, !success); | 549 REPORTER_ASSERT(reporter, !success); |
| 555 } | 550 } |
| 556 } | 551 } |
| 557 } | 552 } |
| 558 } | 553 } |
| 559 | 554 |
| 560 #if SK_SUPPORT_GPU | 555 #if SK_SUPPORT_GPU |
| 561 | 556 |
| 562 // This exercises the problem discovered in crbug.com/570232. The return value f
rom | 557 // This exercises the problem discovered in crbug.com/570232. The return value f
rom |
| 563 // SkBlurMask::BoxBlur wasn't being checked in SkBlurMaskFilter.cpp::GrRRectBlur
Effect::Create | 558 // SkBlurMask::BoxBlur wasn't being checked in SkBlurMaskFilter.cpp::GrRRectBlur
Effect::Create |
| 564 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctx) { | 559 DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SmallBoxBlurBug, reporter, ctx) { |
| 565 | 560 |
| 566 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); | 561 SkImageInfo info = SkImageInfo::MakeN32Premul(128, 128); |
| 567 auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); | 562 auto surface(SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info)); |
| 568 SkCanvas* canvas = surface->getCanvas(); | 563 SkCanvas* canvas = surface->getCanvas(); |
| 569 | 564 |
| 570 SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); | 565 SkRect r = SkRect::MakeXYWH(10, 10, 100, 100); |
| 571 SkRRect rr = SkRRect::MakeRectXY(r, 10, 10); | 566 SkRRect rr = SkRRect::MakeRectXY(r, 10, 10); |
| 572 | 567 |
| 573 SkPaint p; | 568 SkPaint p; |
| 574 p.setMaskFilter(SkBlurMaskFilter::Create(kNormal_SkBlurStyle, 0.01f))->unref
(); | 569 p.setMaskFilter(SkBlurMaskFilter::Make(kNormal_SkBlurStyle, 0.01f)); |
| 575 | 570 |
| 576 canvas->drawRRect(rr, p); | 571 canvas->drawRRect(rr, p); |
| 577 } | 572 } |
| 578 | 573 |
| 579 #endif | 574 #endif |
| 580 | 575 |
| 581 ////////////////////////////////////////////////////////////////////////////////
/////////// | 576 ////////////////////////////////////////////////////////////////////////////////
/////////// |
| OLD | NEW |