diff options
author | Brian Osman <brianosman@google.com> | 2017-05-12 11:21:36 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-05-13 22:58:17 +0000 |
commit | 60751d7a069fb540aa468068f792fb6f4999832d (patch) | |
tree | 6c4b6fafba4006357bb8240db8f41eb28afeaf7b /include/core/SkRect.h | |
parent | ee93e7803ac23beaed838834948091b0062465aa (diff) |
Sort all user-supplied rects before computeFastBounds
https://codereview.chromium.org/908353002 fixed drawRect 2+ years ago, but
drawOval and drawArc were still susceptible. This version ensures that all
rects are sorted before we do the bounds check. Added a new makeSorted
helper to simplify the code, and an assert to catch any future oversight.
All other drawing functions compute their bounds rect in some way that
already ensures it is sorted.
Bug: skia:
Change-Id: I8926b2dbe9d496d0876f1ac5313bd058ae4568b7
Reviewed-on: https://skia-review.googlesource.com/16702
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'include/core/SkRect.h')
-rw-r--r-- | include/core/SkRect.h | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h index b8cf846404..a7b8b119d2 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -376,7 +376,22 @@ struct SK_API SkIRect { and may have crossed over each other. When this returns, left <= right && top <= bottom */ - void sort(); + void sort() { + if (fLeft > fRight) { + SkTSwap<int32_t>(fLeft, fRight); + } + if (fTop > fBottom) { + SkTSwap<int32_t>(fTop, fBottom); + } + } + + /** + * Return a new Rect that is the sorted version of this rect (left <= right, top <= bottom). + */ + SkIRect makeSorted() const { + return MakeLTRB(SkMin32(fLeft, fRight), SkMin32(fTop, fBottom), + SkMax32(fLeft, fRight), SkMax32(fTop, fBottom)); + } static const SkIRect& SK_WARN_UNUSED_RESULT EmptyIRect() { static const SkIRect gEmpty = { 0, 0, 0, 0 }; @@ -456,6 +471,11 @@ struct SK_API SkRect { */ bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } + /** + * Return true if the rectangle's width and height are >= 0 + */ + bool isSorted() const { return fLeft <= fRight && fTop <= fBottom; } + bool isLargest() const { return SK_ScalarMin == fLeft && SK_ScalarMin == fTop && SK_ScalarMax == fRight && @@ -888,6 +908,14 @@ public: } /** + * Return a new Rect that is the sorted version of this rect (left <= right, top <= bottom). + */ + SkRect makeSorted() const { + return MakeLTRB(SkMinScalar(fLeft, fRight), SkMinScalar(fTop, fBottom), + SkMaxScalar(fLeft, fRight), SkMaxScalar(fTop, fBottom)); + } + + /** * cast-safe way to treat the rect as an array of (4) SkScalars. */ const SkScalar* asScalars() const { return &fLeft; } |