static void test_blur_drawing(skiatest::Reporter* reporter) { SkPaint paint; paint.setColor(SK_ColorGRAY); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(SkIntToScalar(strokeWidth)); SkScalar sigma = SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(5)); for (int style = 0; style <= kLastEnum_SkBlurStyle; ++style) { SkBlurStyle blurStyle = static_cast<SkBlurStyle>(style); const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag; for (uint32_t flags = 0; flags < flagPermutations; ++flags) { SkMaskFilter* filter; filter = SkBlurMaskFilter::Create(blurStyle, sigma, flags); paint.setMaskFilter(filter); filter->unref(); for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { SkPath path; tests[test].addPath(&path); SkPath strokedPath; paint.getFillPath(path, &strokedPath); SkRect refBound = strokedPath.getBounds(); SkIRect iref; refBound.roundOut(&iref); iref.inset(-outset, -outset); SkBitmap refBitmap; create(&refBitmap, iref); SkCanvas refCanvas(refBitmap); refCanvas.translate(SkIntToScalar(-iref.fLeft), SkIntToScalar(-iref.fTop)); drawBG(&refCanvas); refCanvas.drawPath(path, paint); for (int view = 0; view < tests[test].viewLen; ++view) { SkIRect itest = tests[test].views[view]; SkBitmap testBitmap; create(&testBitmap, itest); SkCanvas testCanvas(testBitmap); testCanvas.translate(SkIntToScalar(-itest.fLeft), SkIntToScalar(-itest.fTop)); drawBG(&testCanvas); testCanvas.drawPath(path, paint); REPORTER_ASSERT(reporter, compare(refBitmap, iref, testBitmap, itest)); } } } } }
static void test_blur(skiatest::Reporter* reporter) { SkPaint paint; paint.setColor(SK_ColorGRAY); paint.setStyle(SkPaint::kStroke_Style); paint.setStrokeWidth(SkIntToScalar(strokeWidth)); SkScalar radius = SkIntToScalar(5); for (int style = 0; style < SkBlurMaskFilter::kBlurStyleCount; ++style) { SkBlurMaskFilter::BlurStyle blurStyle = static_cast<SkBlurMaskFilter::BlurStyle>(style); const uint32_t flagPermutations = SkBlurMaskFilter::kAll_BlurFlag; for (uint32_t flags = 0; flags < flagPermutations; ++flags) { SkMaskFilter* filter; filter = SkBlurMaskFilter::Create(radius, blurStyle, flags); SkMaskFilter::BlurInfo info; sk_bzero(&info, sizeof(info)); SkMaskFilter::BlurType type = filter->asABlur(&info); REPORTER_ASSERT(reporter, type == static_cast<SkMaskFilter::BlurType>(style + 1)); REPORTER_ASSERT(reporter, info.fRadius == radius); REPORTER_ASSERT(reporter, info.fIgnoreTransform == SkToBool(flags & SkBlurMaskFilter::kIgnoreTransform_BlurFlag)); REPORTER_ASSERT(reporter, info.fHighQuality == SkToBool(flags & SkBlurMaskFilter::kHighQuality_BlurFlag)); paint.setMaskFilter(filter); filter->unref(); for (size_t test = 0; test < SK_ARRAY_COUNT(tests); ++test) { SkPath path; tests[test].addPath(&path); SkPath strokedPath; paint.getFillPath(path, &strokedPath); SkRect refBound = strokedPath.getBounds(); SkIRect iref; refBound.roundOut(&iref); iref.inset(-outset, -outset); SkBitmap refBitmap; create(&refBitmap, iref, SkBitmap::kARGB_8888_Config); SkCanvas refCanvas(refBitmap); refCanvas.translate(SkIntToScalar(-iref.fLeft), SkIntToScalar(-iref.fTop)); drawBG(&refCanvas); refCanvas.drawPath(path, paint); for (int view = 0; view < tests[test].viewLen; ++view) { SkIRect itest = tests[test].views[view]; SkBitmap testBitmap; create(&testBitmap, itest, SkBitmap::kARGB_8888_Config); SkCanvas testCanvas(testBitmap); testCanvas.translate(SkIntToScalar(-itest.fLeft), SkIntToScalar(-itest.fTop)); drawBG(&testCanvas); testCanvas.drawPath(path, paint); REPORTER_ASSERT(reporter, compare(refBitmap, iref, testBitmap, itest)); } } } } }