void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkPaint& paint) { SkPath path; path.setIsVolatile(true); for (int i = 0; i < count; ++i) { SkPoint quad[4]; xform[i].toQuad(tex[i].width(), tex[i].height(), quad); SkMatrix localM; localM.setRSXform(xform[i]); localM.preTranslate(-tex[i].left(), -tex[i].top()); SkPaint pnt(paint); sk_sp<SkShader> shader = atlas->makeShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM); if (!shader) { break; } pnt.setShader(std::move(shader)); if (colors) { pnt.setColorFilter(SkColorFilter::MakeModeFilter(colors[i], mode)); } path.rewind(); path.addPoly(quad, 4, true); path.setConvexity(SkPath::kConvex_Convexity); this->drawPath(draw, path, pnt, nullptr, true); } }
void SkOverdrawCanvas::onDrawTextRSXform(const void* text, size_t byteLength, const SkRSXform xform[], const SkRect*, const SkPaint& paint) { CountTextProc proc = nullptr; switch (paint.getTextEncoding()) { case SkPaint::kUTF8_TextEncoding: proc = SkUTF8_CountUTF8Bytes; break; case SkPaint::kUTF16_TextEncoding: proc = count_utf16; break; case SkPaint::kUTF32_TextEncoding: proc = return_4; break; case SkPaint::kGlyphID_TextEncoding: proc = return_2; break; } SkASSERT(proc); SkMatrix matrix; const void* stopText = (const char*)text + byteLength; while ((const char*)text < (const char*)stopText) { matrix.setRSXform(*xform++); matrix.setConcat(this->getTotalMatrix(), matrix); int subLen = proc((const char*)text); this->save(); this->concat(matrix); this->drawText(text, subLen, 0, 0, paint); this->restore(); text = (const char*)text + subLen; } }
void SkBaseDevice::drawAtlas(const SkDraw& draw, const SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, SkXfermode::Mode mode, const SkPaint& paint) { SkPath path; path.setIsVolatile(true); for (int i = 0; i < count; ++i) { SkPoint quad[4]; xform[i].toQuad(tex[i].width(), tex[i].height(), quad); SkMatrix localM; localM.setRSXform(xform[i]); localM.preTranslate(-tex[i].left(), -tex[i].top()); SkPaint pnt(paint); pnt.setShader(atlas->newShader(SkShader::kClamp_TileMode, SkShader::kClamp_TileMode, &localM))->unref(); if (colors && colors[i] != SK_ColorWHITE) { SkAutoTUnref<SkColorFilter> cf(SkColorFilter::CreateModeFilter(colors[i], mode)); pnt.setColorFilter(cf); } path.rewind(); path.addPoly(quad, 4, true); path.setConvexity(SkPath::kConvex_Convexity); this->drawPath(draw, path, pnt, NULL, true); } }
void draw(SkCanvas* canvas) { SkPaint paint; paint.setColor(SK_ColorGRAY); paint.setAntiAlias(true); SkRect rect = {20, 20, 100, 100}; canvas->drawRect(rect, paint); paint.setColor(SK_ColorRED); SkMatrix matrix; matrix.setRSXform(SkRSXform::Make(.85f, .25f, rect.centerX(), rect.centerY())); canvas->concat(matrix); canvas->translate(-rect.centerX(), -rect.centerY()); canvas->drawRect(rect, paint); }
static void draw_atlas_sim(SkCanvas* canvas, SkImage* atlas, const SkRSXform xform[], const SkRect tex[], const SkColor colors[], int count, const SkRect* cull, const SkPaint* paint) { for (int i = 0; i < count; ++i) { SkMatrix matrix; matrix.setRSXform(xform[i]); canvas->save(); canvas->concat(matrix); canvas->drawImageRect(atlas, tex[i], tex[i].makeOffset(-tex[i].x(), -tex[i].y()), paint, SkCanvas::kFast_SrcRectConstraint); canvas->restore(); } }