static void test_asMode(skiatest::Reporter* reporter) { for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) { SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode); SkXfermode::Mode reportedMode = ILLEGAL_MODE; REPORTER_ASSERT(reporter, reportedMode != mode); // test IsMode REPORTER_ASSERT(reporter, SkXfermode::AsMode(xfer, &reportedMode)); REPORTER_ASSERT(reporter, reportedMode == mode); // repeat that test, but with asMode instead if (xfer) { reportedMode = (SkXfermode::Mode) -1; REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); REPORTER_ASSERT(reporter, reportedMode == mode); xfer->unref(); } else { REPORTER_ASSERT(reporter, SkXfermode::kSrcOver_Mode == mode); } } SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc); SkXfermode::Mode reportedMode = ILLEGAL_MODE; REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode)); REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); REPORTER_ASSERT(reporter, !SkXfermode::AsMode(bogusXfer, &reportedMode)); REPORTER_ASSERT(reporter, reportedMode == ILLEGAL_MODE); bogusXfer->unref(); }
ShaderView() { SkImageDecoder::DecodeFile("/cover.png", &fBitmap); SkPoint pts[2]; SkColor colors[2]; pts[0].set(0, 0); pts[1].set(SkIntToScalar(100), 0); colors[0] = SK_ColorRED; colors[1] = SK_ColorBLUE; SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode); pts[0].set(0, 0); pts[1].set(0, SkIntToScalar(100)); colors[0] = SK_ColorBLACK; colors[1] = SkColorSetARGB(0x80, 0, 0, 0); SkShader* shaderB = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode); SkXfermode* mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kDstIn_Mode); fShader = new SkComposeShader(shaderA, shaderB, mode); shaderA->unref(); shaderB->unref(); mode->unref(); }
static void test_asMode(skiatest::Reporter* reporter) { for (int mode = 0; mode <= SkXfermode::kLastMode; mode++) { SkXfermode* xfer = SkXfermode::Create((SkXfermode::Mode) mode); SkXfermode::Mode reportedMode = (SkXfermode::Mode) -1; REPORTER_ASSERT(reporter, xfer != NULL || mode == SkXfermode::kSrcOver_Mode); if (xfer) { REPORTER_ASSERT(reporter, xfer->asMode(&reportedMode)); REPORTER_ASSERT(reporter, reportedMode == mode); xfer->unref(); } } SkXfermode* bogusXfer = new SkProcXfermode(bogusXfermodeProc); SkXfermode::Mode reportedMode = (SkXfermode::Mode) -1; REPORTER_ASSERT(reporter, !bogusXfer->asMode(&reportedMode)); REPORTER_ASSERT(reporter, reportedMode == -1); bogusXfer->unref(); }
void mbe_copy_source(mbe_t *src, mbe_t *dst) { SkPaint *paint = dst->paint; const SkBitmap *bmap; SkXfermode *mode; /* _prepare_paint(dst, SkPaint::kFill_Style); */ mode = SkXfermode::Create(SkXfermode::kSrc_Mode); paint->setXfermode(mode); bmap = &src->canvas->getDevice()->accessBitmap(false); dst->canvas->drawBitmap(*bmap, 0, 0, paint); paint->reset(); mode->unref(); /* _finish_paint(dst); */ }
void onDraw(SkCanvas* canvas) override { // start with the center of a 3x3 grid static const uint16_t fan[] = { 4, 0, 1, 2, 5, 8, 7, 6, 3, 0 }; const struct { const SkColor* fColors; const SkPoint* fTexs; } rec[] = { { fColors, NULL }, { NULL, fTexs }, { fColors, fTexs }, }; const SkXfermode::Mode modes[] = { SkXfermode::kSrc_Mode, SkXfermode::kDst_Mode, SkXfermode::kModulate_Mode, }; SkPaint paint; paint.setShader(fShader); paint.setAlpha(fAlpha); canvas->translate(20, 20); for (size_t j = 0; j < SK_ARRAY_COUNT(modes); ++j) { SkXfermode* xfer = SkXfermode::Create(modes[j]); canvas->save(); for (size_t i = 0; i < SK_ARRAY_COUNT(rec); ++i) { canvas->drawVertices(SkCanvas::kTriangleFan_VertexMode, SK_ARRAY_COUNT(fPts), fPts, rec[i].fTexs, rec[i].fColors, xfer, fan, SK_ARRAY_COUNT(fan), paint); canvas->translate(200, 0); } canvas->restore(); canvas->translate(0, 200); xfer->unref(); } }
static SkShader* make_bitmapfade(const SkBitmap& bm) { SkPoint pts[2]; SkColor colors[2]; pts[0].set(0, 0); pts[1].set(0, SkIntToScalar(bm.height())); colors[0] = SK_ColorBLACK; colors[1] = SkColorSetARGB(0, 0, 0, 0); SkShader* shaderA = SkGradientShader::CreateLinear(pts, colors, NULL, 2, SkShader::kClamp_TileMode); SkShader* shaderB = SkShader::CreateBitmapShader(bm, SkShader::kClamp_TileMode, SkShader::kClamp_TileMode); SkXfermode* mode = SkPorterDuff::CreateXfermode(SkPorterDuff::kDstIn_Mode); SkShader* shader = new SkComposeShader(shaderB, shaderA, mode); shaderA->unref(); shaderB->unref(); mode->unref(); return shader; }