bool SkDrawBase::computeConservativeLocalClipBounds(SkRect* localBounds) const { if (fRC->isEmpty()) { returnfalse;
}
SkMatrix inverse; if (!fCTM->invert(&inverse)) { returnfalse;
}
SkIRect devBounds = fRC->getBounds(); // outset to have slop for antialasing and hairlines
devBounds.outset(1, 1);
inverse.mapRect(localBounds, SkRect::Make(devBounds)); returntrue;
}
SkRect devRect; const SkRect& paintRect = paintMatrix ? *postPaintRect : prePaintRect; // skip the paintMatrix when transforming the rect by the CTM
fCTM->mapPoints(rect_points(devRect), rect_points(paintRect), 2);
devRect.sort();
// look for the quick exit, before we build a blitter
SkRect bbox = devRect; if (paint.getStyle() != SkPaint::kFill_Style) { // extra space for hairlines if (paint.getStrokeWidth() == 0) {
bbox.outset(1, 1);
} else { // For kStroke_RectType, strokeSize is already computed. const SkPoint& ssize = (kStroke_RectType == rtype)
? strokeSize
: compute_stroke_size(paint, *fCTM);
bbox.outset(SkScalarHalf(ssize.x()), SkScalarHalf(ssize.y()));
}
} if (SkPathPriv::TooBigForMath(bbox)) { return;
}
// we want to "fill" if we are kFill or kStrokeAndFill, since in the latter // case we are also hairline (if we've gotten to here), which devolves to // effectively just kFill switch (rtype) { case kFill_RectType: if (paint.isAntiAlias()) {
SkScan::AntiFillRect(devRect, clip, blitter);
} else {
SkScan::FillRect(devRect, clip, blitter);
} break; case kStroke_RectType: if (paint.isAntiAlias()) {
SkScan::AntiFrameRect(devRect, strokeSize, clip, blitter);
} else {
SkScan::FrameRect(devRect, strokeSize, clip, blitter);
} break; case kHair_RectType: if (paint.isAntiAlias()) {
SkScan::AntiHairRect(devRect, clip, blitter);
} else {
SkScan::HairRect(devRect, clip, blitter);
} break; default:
SkDEBUGFAIL("bad rtype");
}
}
static SkScalar fast_len(const SkVector& vec) {
SkScalar x = SkScalarAbs(vec.fX);
SkScalar y = SkScalarAbs(vec.fY); if (x < y) { using std::swap;
swap(x, y);
} return x + SkScalarHalf(y);
}
bool SkDrawTreatAAStrokeAsHairline(SkScalar strokeWidth, const SkMatrix& matrix,
SkScalar* coverage) {
SkASSERT(strokeWidth > 0); // We need to try to fake a thick-stroke with a modulated hairline.
{ // TODO: Investigate optimizing these options. They are in the same // order as SkDrawBase::drawPath, which handles each case. It may be // that there is no way to optimize for these using the SkRRect path.
SkScalar coverage; if (SkDrawTreatAsHairline(paint, *fCTM, &coverage)) { goto DRAW_PATH;
}
if (paint.getMaskFilter()) { // Transform the rrect into device space.
SkRRect devRRect; if (rrect.transform(*fCTM, &devRRect)) {
SkAutoBlitterChoose blitter(*this, nullptr, paint); if (as_MFB(paint.getMaskFilter())->filterRRect(devRRect, *fCTM, *fRC, blitter.get())) { return; // filterRRect() called the blitter, so we're done
}
}
}
DRAW_PATH: // Now fall back to the default case of using a path.
SkPath path;
path.addRRect(rrect);
this->drawPath(path, paint, nullptr, true);
}
{
SkScalar coverage; if (SkDrawTreatAsHairline(origPaint, *matrix, &coverage)) { constauto bm = origPaint.asBlendMode(); if (SK_Scalar1 == coverage) {
paint.writable()->setStrokeWidth(0);
} elseif (bm && SkBlendMode_SupportsCoverageAsAlpha(bm.value())) {
U8CPU newAlpha; #if 0
newAlpha = SkToU8(SkScalarRoundToInt(coverage * origPaint.getAlpha())); #else // this is the old technique, which we preserve for now so // we don't change previous results (testing) // the new way seems fine, its just (a tiny bit) different int scale = (int)(coverage * 256);
newAlpha = origPaint.getAlpha() * scale >> 8; #endif
SkPaint* writablePaint = paint.writable();
writablePaint->setStrokeWidth(0);
writablePaint->setAlpha(newAlpha);
}
}
}
// trim the bounds to reflect the clip (plus whatever slop the filter needs) // Ugh. Guard against gigantic margins from wacky filters. Without this // check we can request arbitrary amounts of slop beyond our visible // clip, and bring down the renderer (at least on finite RAM machines // like handsets, etc.). Need to balance this invented value between // quality of large filters like blurs, and the corresponding memory // requests. static constexpr int kMaxMargin = 128; if (!bounds->intersect(clipBounds.makeOutset(std::min(margin.fX, kMaxMargin),
std::min(margin.fY, kMaxMargin)))) { returnfalse;
}
if (SkMaskBuilder::kJustRenderImage_CreateMode != mode) { // By using infinite bounds for inverse fills, ComputeMaskBounds is able to clip it to // 'clipBounds' outset by whatever extra margin the mask filter requires. staticconst SkRect kInverseBounds = { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity,
SK_ScalarInfinity, SK_ScalarInfinity};
SkRect pathBounds = devPath.isInverseFillType() ? kInverseBounds
: devPath.getBounds(); if (!ComputeMaskBounds(pathBounds, clipBounds, filter,
filterMatrix, &dst->bounds())) returnfalse;
}
if (SkMaskBuilder::kComputeBoundsAndRenderImage_CreateMode == mode) {
dst->format() = SkMask::kA8_Format;
dst->rowBytes() = dst->fBounds.width();
size_t size = dst->computeImageSize(); if (0 == size) { // we're too big to allocate the mask, abort returnfalse;
}
dst->image() = SkMaskBuilder::AllocImage(size, SkMaskBuilder::kZeroInit_Alloc);
}
if (SkMaskBuilder::kJustComputeBounds_CreateMode != mode) {
draw_into_mask(*dst, devPath, style);
}
returntrue;
}
void SkDrawBase::drawDevicePoints(SkCanvas::PointMode mode, size_t count, const SkPoint pts[], const SkPaint& paint,
SkDevice* device) const { // if we're in lines mode, force count to be even if (SkCanvas::kLines_PointMode == mode) {
count &= ~(size_t)1;
}
// nothing to draw if (!count || fRC->isEmpty()) { return;
}
// needed? if (!SkIsFinite(&pts[0].fX, count * 2)) { return;
}
switch (mode) { case SkCanvas::kPoints_PointMode: { // temporarily mark the paint as filling.
SkPaint newPaint(paint);
newPaint.setStyle(SkPaint::kFill_Style);
if (newPaint.getStrokeCap() == SkPaint::kRound_Cap) { if (device) { for (size_t i = 0; i < count; ++i) {
SkRect r = SkRect::MakeLTRB(pts[i].fX - radius, pts[i].fY - radius,
pts[i].fX + radius, pts[i].fY + radius);
device->drawOval(r, newPaint);
}
} else {
SkPath path;
SkMatrix preMatrix;
path.addCircle(0, 0, radius); for (size_t i = 0; i < count; i++) {
preMatrix.setTranslate(pts[i].fX, pts[i].fY); // pass true for the last point, since we can modify // then path then
path.setIsVolatile((count-1) == i);
this->drawPath(path, newPaint, &preMatrix, (count-1) == i);
}
}
} else {
SkRect r;
for (size_t i = 0; i < count; i++) {
r.fLeft = pts[i].fX - radius;
r.fTop = pts[i].fY - radius;
r.fRight = r.fLeft + width;
r.fBottom = r.fTop + width; if (device) {
device->drawRect(r, newPaint);
} else {
this->drawRect(r, newPaint);
}
}
} break;
} case SkCanvas::kLines_PointMode: if (2 == count && paint.getPathEffect()) { // most likely a dashed line - see if it is one of the ones // we can accelerate
SkStrokeRec stroke(paint);
SkPathEffectBase::PointData pointData;
SkPath path = SkPath::Line(pts[0], pts[1]);
SkRect cullRect = SkRect::Make(fRC->getBounds());
if (as_PEB(paint.getPathEffect())->asPoints(&pointData, path, stroke, *fCTM,
&cullRect)) { // 'asPoints' managed to find some fast path
if (!pointData.fFirst.isEmpty()) { if (device) {
device->drawPath(pointData.fFirst, newP);
} else {
this->drawPath(pointData.fFirst, newP);
}
}
if (!pointData.fLast.isEmpty()) { if (device) {
device->drawPath(pointData.fLast, newP);
} else {
this->drawPath(pointData.fLast, newP);
}
}
if (pointData.fSize.fX == pointData.fSize.fY) { // The rest of the dashed line can just be drawn as points
SkASSERT(pointData.fSize.fX == SkScalarHalf(newP.getStrokeWidth()));
if (device) {
device->drawPoints(SkCanvas::kPoints_PointMode,
pointData.fNumPoints,
pointData.fPoints,
newP);
} else {
this->drawDevicePoints(SkCanvas::kPoints_PointMode,
pointData.fNumPoints,
pointData.fPoints,
newP,
device);
} break;
} else { // The rest of the dashed line must be drawn as rects
SkASSERT(!(SkPathEffectBase::PointData::kCircles_PointFlag &
pointData.fFlags));
SkRect r;
for (int i = 0; i < pointData.fNumPoints; ++i) {
r.setLTRB(pointData.fPoints[i].fX - pointData.fSize.fX,
pointData.fPoints[i].fY - pointData.fSize.fY,
pointData.fPoints[i].fX + pointData.fSize.fX,
pointData.fPoints[i].fY + pointData.fSize.fY); if (device) {
device->drawRect(r, newP);
} else {
this->drawRect(r, newP);
}
}
}
break;
}
}
[[fallthrough]]; // couldn't take fast path case SkCanvas::kPolygon_PointMode: {
count -= 1;
SkPath path;
SkPaint p(paint);
p.setStyle(SkPaint::kStroke_Style);
size_t inc = (SkCanvas::kLines_PointMode == mode) ? 2 : 1;
path.setIsVolatile(true); for (size_t i = 0; i < count; i += inc) {
path.moveTo(pts[i]);
path.lineTo(pts[i+1]); if (device) {
device->drawPath(path, p, true);
} else {
this->drawPath(path, p, nullptr, true);
}
path.rewind();
} break;
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.