Optimize single lines in Device::drawPoints

Draw the lines as rectangles instead of going through path rendering.
Only do this when calling through drawPoints(). (We don't do this
optimization for drawPath() because it can undermine batching.)

NOTE: Lines will still trigger DMSAA after this CL. We need to update
FillRRect to use a local matrix first, in order to have a non-MSAA
renderer capable of drawing these strokes.

Change-Id: I20aa10cd82fa171ade430a3da44ece5688c12417
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/497296
Reviewed-by: Greg Daniel <egdaniel@google.com>
Commit-Queue: Christopher Dalton <csmartdalton@google.com>
This commit is contained in:
Chris Dalton 2022-02-01 11:36:15 -07:00 committed by SkCQ
parent 71a34c302d
commit ea161cde89
2 changed files with 42 additions and 15 deletions

View File

@ -344,20 +344,47 @@ void Device::drawPoints(SkCanvas::PointMode mode,
GrAA aa = fSurfaceDrawContext->chooseAA(paint);
if (paint.getPathEffect() && 2 == count && SkCanvas::kLines_PointMode == mode) {
GrStyle style(paint, SkPaint::kStroke_Style);
GrPaint grPaint;
if (!SkPaintToGrPaint(this->recordingContext(), fSurfaceDrawContext->colorInfo(), paint,
this->asMatrixProvider(), &grPaint)) {
if (count == 2 && mode == SkCanvas::kLines_PointMode) {
if (paint.getPathEffect()) {
// Probably a dashed line. Draw as a path.
GrPaint grPaint;
if (SkPaintToGrPaint(this->recordingContext(),
fSurfaceDrawContext->colorInfo(),
paint,
this->asMatrixProvider(),
&grPaint)) {
SkPath path;
path.setIsVolatile(true);
path.moveTo(pts[0]);
path.lineTo(pts[1]);
fSurfaceDrawContext->drawPath(this->clip(),
std::move(grPaint),
aa,
this->localToDevice(),
path,
GrStyle(paint, SkPaint::kStroke_Style));
}
return;
}
if (!paint.getMaskFilter() &&
paint.getStrokeWidth() > 0 && // drawStrokedLine doesn't support hairlines.
paint.getStrokeCap() != SkPaint::kRound_Cap) { // drawStrokedLine doesn't do round caps.
// Simple stroked line. Bypass path rendering.
GrPaint grPaint;
if (SkPaintToGrPaint(this->recordingContext(),
fSurfaceDrawContext->colorInfo(),
paint,
this->asMatrixProvider(),
&grPaint)) {
fSurfaceDrawContext->drawStrokedLine(this->clip(),
std::move(grPaint),
aa,
this->localToDevice(),
pts,
SkStrokeRec(paint, SkPaint::kStroke_Style));
}
return;
}
SkPath path;
path.setIsVolatile(true);
path.moveTo(pts[0]);
path.lineTo(pts[1]);
fSurfaceDrawContext->drawPath(this->clip(), std::move(grPaint), aa, this->localToDevice(),
path, style);
return;
}
SkScalar scales[2];

View File

@ -645,6 +645,9 @@ public:
void testingOnly_SetPreserveOpsOnFullClear() { fPreserveOpsOnFullClear_TestingOnly = true; }
#endif
void drawStrokedLine(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, const SkPoint[2],
const SkStrokeRec&);
private:
enum class QuadOptimization;
@ -692,9 +695,6 @@ private:
DrawQuad* quad,
const SkRect* subset = nullptr);
void drawStrokedLine(const GrClip*, GrPaint&&, GrAA, const SkMatrix&, const SkPoint[2],
const SkStrokeRec&);
// Tries to detect if the given shape is a simple, and draws it without path rendering if
// we know how.
bool drawSimpleShape(const GrClip*, GrPaint*, GrAA, const SkMatrix&, const GrStyledShape&);