#include "include/core/SkBitmap.h"
#include "include/core/SkColorType.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPixmap.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkRegion.h"
#include "include/core/SkScalar.h"
#include "include/core/SkTileMode.h"
#include "include/private/base/SkAssert.h"
#include "include/private/base/SkDebug.h"
#include "include/private/base/SkFixed.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/base/SkArenaAlloc.h"
#include "src/base/SkTLazy.h"
#include "src/core/SkAutoBlitterChoose.h"
#include "src/core/SkBlitter.h"
#include "src/core/SkDraw.h"
#include "src/core/SkImageInfoPriv.h"
#include "src/core/SkImagePriv.h"
#include "src/core/SkMatrixUtils.h"
#include "src/core/SkRasterClip.h"
#include "src/core/SkRectPriv.h"
#include "src/core/SkScan.h"
#if defined(SK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE)
#include "src/core/SkMaskFilterBase.h"
#endif
usingnamespaceskia_private;
static SkPaint make_paint_with_image(const SkPaint& origPaint, const SkBitmap& bitmap,
const SkSamplingOptions& sampling,
SkMatrix* matrix = nullptr) { … }
SkDraw::SkDraw() { … }
struct PtProcRec { … };
static void bw_pt_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static void bw_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static void bw_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static void aa_line_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static void aa_poly_hair_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static SkRect make_square_rad(SkPoint center, SkScalar radius) { … }
static SkXRect make_xrect(const SkRect& r) { … }
static void bw_square_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
static void aa_square_proc(const PtProcRec& rec, const SkPoint devPts[],
int count, SkBlitter* blitter) { … }
bool PtProcRec::init(SkCanvas::PointMode mode, const SkPaint& paint,
const SkMatrix* matrix, const SkRasterClip* rc) { … }
PtProcRec::Proc PtProcRec::chooseProc(SkBlitter** blitterPtr) { … }
#define MAX_DEV_PTS …
void SkDraw::drawPoints(SkCanvas::PointMode mode, size_t count,
const SkPoint pts[], const SkPaint& paint,
SkDevice* device) const { … }
static bool clipped_out(const SkMatrix& m, const SkRasterClip& c,
const SkRect& srcR) { … }
static bool clipped_out(const SkMatrix& matrix, const SkRasterClip& clip,
int width, int height) { … }
static bool clipHandlesSprite(const SkRasterClip& clip, int x, int y, const SkPixmap& pmap) { … }
void SkDraw::drawBitmap(const SkBitmap& bitmap, const SkMatrix& prematrix,
const SkRect* dstBounds, const SkSamplingOptions& sampling,
const SkPaint& origPaint) const { … }
void SkDraw::drawSprite(const SkBitmap& bitmap, int x, int y, const SkPaint& origPaint) const { … }
#if defined(SK_SUPPORT_LEGACY_ALPHA_BITMAP_AS_COVERAGE)
void SkDraw::drawDevMask(const SkMask& srcM, const SkPaint& paint) const {
if (srcM.fBounds.isEmpty()) {
return;
}
const SkMask* mask = &srcM;
SkMaskBuilder dstM;
if (paint.getMaskFilter() &&
as_MFB(paint.getMaskFilter())->filterMask(&dstM, srcM, *fCTM, nullptr)) {
mask = &dstM;
}
SkAutoMaskFreeImage ami(dstM.image());
SkAutoBlitterChoose blitterChooser(*this, nullptr, paint);
SkBlitter* blitter = blitterChooser.get();
SkAAClipBlitterWrapper wrapper;
const SkRegion* clipRgn;
if (fRC->isBW()) {
clipRgn = &fRC->bwRgn();
} else {
wrapper.init(*fRC, blitter);
clipRgn = &wrapper.getRgn();
blitter = wrapper.getBlitter();
}
blitter->blitMaskRegion(*mask, *clipRgn);
}
void SkDraw::drawBitmapAsMask(const SkBitmap& bitmap, const SkSamplingOptions& sampling,
const SkPaint& paint) const {
SkASSERT(bitmap.colorType() == kAlpha_8_SkColorType);
if (fRC->isEmpty()) {
return;
}
if (SkTreatAsSprite(*fCTM, bitmap.dimensions(), sampling, paint.isAntiAlias()))
{
int ix = SkScalarRoundToInt(fCTM->getTranslateX());
int iy = SkScalarRoundToInt(fCTM->getTranslateY());
SkPixmap pmap;
if (!bitmap.peekPixels(&pmap)) {
return;
}
SkMask mask(pmap.addr8(0, 0),
SkIRect::MakeXYWH(ix, iy, pmap.width(), pmap.height()),
SkToU32(pmap.rowBytes()),
SkMask::kA8_Format);
this->drawDevMask(mask, paint);
} else {
SkRect r;
SkMaskBuilder mask;
r.setIWH(bitmap.width(), bitmap.height());
fCTM->mapRect(&r);
r.round(&mask.bounds());
{
SkASSERT(fDst.bounds().contains(fRC->getBounds()));
SkIRect devBounds = fDst.bounds();
devBounds.intersect(fRC->getBounds().makeOutset(1, 1));
if (!mask.bounds().intersect(devBounds)) {
return;
}
}
mask.format() = SkMask::kA8_Format;
mask.rowBytes() = SkAlign4(mask.fBounds.width());
size_t size = mask.computeImageSize();
if (0 == size) {
return;
}
AutoTMalloc<uint8_t> storage(size);
mask.image() = storage.get();
memset(mask.image(), 0, size);
{
SkBitmap device;
device.installPixels(SkImageInfo::MakeA8(mask.fBounds.width(), mask.fBounds.height()),
mask.image(), mask.fRowBytes);
SkCanvas c(device);
c.translate(-SkIntToScalar(mask.fBounds.fLeft),
-SkIntToScalar(mask.fBounds.fTop));
c.concat(*fCTM);
SkPaint tmpPaint;
tmpPaint.setAntiAlias(paint.isAntiAlias());
tmpPaint.setDither(paint.isDither());
SkPaint paintWithShader = make_paint_with_image(tmpPaint, bitmap, sampling);
SkRect rr;
rr.setIWH(bitmap.width(), bitmap.height());
c.drawRect(rr, paintWithShader);
}
this->drawDevMask(mask, paint);
}
}
#endif