From ea161cde8924200a66dca5f3f30d0ccf478aacfa Mon Sep 17 00:00:00 2001 From: Chris Dalton Date: Tue, 1 Feb 2022 11:36:15 -0700 Subject: [PATCH] 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 Commit-Queue: Christopher Dalton --- src/gpu/v1/Device.cpp | 51 +++++++++++++++++++++++------- src/gpu/v1/SurfaceDrawContext_v1.h | 6 ++-- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/src/gpu/v1/Device.cpp b/src/gpu/v1/Device.cpp index e467ca2d25..68f3a7444d 100644 --- a/src/gpu/v1/Device.cpp +++ b/src/gpu/v1/Device.cpp @@ -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]; diff --git a/src/gpu/v1/SurfaceDrawContext_v1.h b/src/gpu/v1/SurfaceDrawContext_v1.h index f0c5b88f39..783c3c07d6 100644 --- a/src/gpu/v1/SurfaceDrawContext_v1.h +++ b/src/gpu/v1/SurfaceDrawContext_v1.h @@ -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&);