DEF_TEST(FlattenableFactoryToName, r) { SkIRect rects[2]; rects[0] = SkIRect::MakeXYWH(0, 150, 500, 200); rects[1] = SkIRect::MakeXYWH(150, 0, 200, 500); SkRegion region; region.setRects(rects, 2); sk_sp<SkImageFilter> filter(SkAlphaThresholdFilter::Make(region, 0.2f, 0.7f, nullptr)); test_flattenable(r, filter.get(), "SkAlphaThresholdFilter()"); SkBitmap bm; bm.allocN32Pixels(8, 8); bm.eraseColor(SK_ColorCYAN); sk_sp<SkImage> image(SkImage::MakeFromBitmap(bm)); auto shader = image->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); test_flattenable(r, shader.get(), "SkImage::newShader()"); }
// TODO: expand the testing to include the different ops & AA types! static void emit_clip(SkCanvas* canvas, ClipType clip) { switch (clip) { case kNone_ClipType: break; case kRect_ClipType: { SkRect r = SkRect::MakeLTRB(10, 10, 90, 90); canvas->clipRect(r, SkRegion::kIntersect_Op, true); break; } case kRRect_ClipType: { SkRect r = SkRect::MakeLTRB(10, 10, 90, 90); SkRRect rr; rr.setRectXY(r, 10, 10); canvas->clipRRect(rr, SkRegion::kIntersect_Op, true); break; } case kPath_ClipType: { SkPath p; p.moveTo(5.0f, 5.0f); p.lineTo(50.0f, 50.0f); p.lineTo(100.0f, 5.0f); p.close(); canvas->clipPath(p, SkRegion::kIntersect_Op, true); break; } case kRegion_ClipType: { SkIRect rects[2] = { { 1, 1, 55, 55 }, { 45, 45, 99, 99 }, }; SkRegion r; r.setRects(rects, 2); canvas->clipRegion(r, SkRegion::kIntersect_Op); break; } default: SkASSERT(0); } }
void onDraw(SkCanvas* canvas) override { SkIRect rects[2]; rects[0] = SkIRect::MakeXYWH(0, 150, WIDTH, HEIGHT - 300); rects[1] = SkIRect::MakeXYWH(150, 0, WIDTH - 300, HEIGHT); SkRegion region; region.setRects(rects, 2); SkMatrix matrix; matrix.reset(); matrix.setTranslate(WIDTH * .1f, HEIGHT * .1f); matrix.postScale(.8f, .8f); canvas->concat(matrix); SkPaint paint; paint.setImageFilter( SkAlphaThresholdFilter::Create(region, 0.2f, 0.7f))->unref(); canvas->saveLayer(nullptr, &paint); paint.setAntiAlias(true); SkPaint rect_paint; rect_paint.setColor(0xFF0000FF); canvas->drawRect(SkRect::MakeXYWH(0, 0, WIDTH / 2, HEIGHT / 2), rect_paint); rect_paint.setColor(0xBFFF0000); canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, 0, WIDTH / 2, HEIGHT / 2), rect_paint); rect_paint.setColor(0x3F00FF00); canvas->drawRect(SkRect::MakeXYWH(0, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rect_paint); rect_paint.setColor(0x00000000); canvas->drawRect(SkRect::MakeXYWH(WIDTH / 2, HEIGHT / 2, WIDTH / 2, HEIGHT / 2), rect_paint); canvas->restore(); }