Make sure local rects are sorted post-clipping
Bug: chromium:946338
Change-Id: I7d78e84ddde32436990f5da5bcd0c6230bb8eaf1
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/207871
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp
index 05241d6..73368ff 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -535,6 +535,9 @@
if (!rect->intersects(clipBounds)) {
return false;
}
+ // localRect is force-sorted after clipping, so this is a sanity check to make sure callers
+ // aren't intentionally using inverted local rectangles.
+ SkASSERT(localRect->isSorted());
const SkScalar dx = localRect->width() / rect->width();
const SkScalar dy = localRect->height() / rect->height();
if (clipBounds.fLeft > rect->fLeft) {
@@ -553,6 +556,9 @@
localRect->fBottom -= (rect->fBottom - clipBounds.fBottom) * dy;
rect->fBottom = clipBounds.fBottom;
}
+ // Ensure local coordinates remain sorted after clipping. If the original dstRect was very
+ // large, numeric precision can invert the localRect
+ localRect->sort();
return true;
}