Bug 1684050 - choose appropriate stroke res scale for PathSkia::StrokeContainsPoint. r=bobowen

This uses SkDraw::ComputeResScaleForStroking to ensure we exactly match the resolution scale
that is chosen for drawing the stroked path inside the guts of Skia. This should ensure these
two don't get out of sync.

This also cleans out the old overscale code in ComputeResScaleForStroking that was necessary
during an ancient Skia porting effort but has now bitrotted into irrelevance.

Differential Revision: https://phabricator.services.mozilla.com/D101686
This commit is contained in:
Lee Salzman 2021-01-14 09:01:54 +00:00
parent 5c56e4c045
commit caa9cd4f4d
4 changed files with 9 additions and 22 deletions

View File

@ -10,6 +10,7 @@
#include "Logging.h"
#include "HelpersSkia.h"
#include "PathHelpers.h"
#include "skia/src/core/SkDraw.h"
namespace mozilla::gfx {
@ -138,8 +139,11 @@ bool PathSkia::StrokeContainsPoint(const StrokeOptions& aStrokeOptions,
return false;
}
SkMatrix skiaMatrix;
GfxMatrixToSkiaMatrix(aTransform, skiaMatrix);
SkPath strokePath;
paint.getFillPath(mPath, &strokePath);
paint.getFillPath(mPath, &strokePath, nullptr,
SkDraw::ComputeResScaleForStroking(skiaMatrix));
return SkPathContainsPoint(strokePath, aPoint, aTransform);
}

View File

@ -802,7 +802,7 @@ DRAW_PATH:
this->drawPath(path, paint, nullptr, true);
}
SkScalar SkDraw::ComputeResScaleForStroking(const SkMatrix& matrix, SkScalar* overscale) {
SkScalar SkDraw::ComputeResScaleForStroking(const SkMatrix& matrix) {
// Not sure how to handle perspective differently, so we just don't try (yet)
SkScalar sx = SkPoint::Length(matrix[SkMatrix::kMScaleX], matrix[SkMatrix::kMSkewY]);
SkScalar sy = SkPoint::Length(matrix[SkMatrix::kMSkewX], matrix[SkMatrix::kMScaleY]);
@ -810,11 +810,7 @@ SkScalar SkDraw::ComputeResScaleForStroking(const SkMatrix& matrix, SkScalar* ov
SkScalar scale = SkTMax(sx, sy);
if (scale > 0) {
static const SkScalar kMaxStrokeScale = 1e5f;
if (overscale && scale > kMaxStrokeScale) {
*overscale = scale / kMaxStrokeScale;
scale = kMaxStrokeScale;
}
return scale;
return SkTMin(scale, kMaxStrokeScale);
}
}
return 1;
@ -953,17 +949,9 @@ void SkDraw::drawPath(const SkPath& origSrcPath, const SkPaint& origPaint,
if (this->computeConservativeLocalClipBounds(&cullRect)) {
cullRectPtr = &cullRect;
}
SkScalar overscale = SK_Scalar1;
doFill = paint->getFillPath(*pathPtr, tmpPath, cullRectPtr,
ComputeResScaleForStroking(*fMatrix, &overscale));
ComputeResScaleForStroking(*fMatrix));
pathPtr = tmpPath;
if (overscale != SK_Scalar1) {
if (matrix != &tmpMatrix) {
tmpMatrix = *matrix;
matrix = &tmpMatrix;
}
tmpMatrix.postScale(overscale, overscale);
}
}
// avoid possibly allocating a new path in transform if we can

View File

@ -124,7 +124,7 @@ public:
static RectType ComputeRectType(const SkPaint&, const SkMatrix&,
SkPoint* strokeSize);
static SkScalar ComputeResScaleForStroking(const SkMatrix& matrix, SkScalar* overscale = nullptr);
static SkScalar ComputeResScaleForStroking(const SkMatrix& matrix);
private:
void drawBitmapAsMask(const SkBitmap&, const SkPaint&) const;

View File

@ -1,5 +0,0 @@
[2d.path.isPointInStroke.scaleddashes.html]
[isPointInStroke() should return correct results on dashed paths at high scale factors]
expected:
if not early_beta_or_earlier and (os == "win") and webrender and not debug: ["FAIL", "PASS"]
FAIL