Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: src/core/SkRRect.cpp

Issue 1567723004: Fix handling of radii scaling to force the result to always be less (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Small cleanup. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/core/SkScaleToSides.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRRect.cpp
diff --git a/src/core/SkRRect.cpp b/src/core/SkRRect.cpp
index c8b3a6ba4c39ac536c909bfb2334c41a83982057..ca4fd561523f345b0f9b889c09ea5f44b13c628a 100644
--- a/src/core/SkRRect.cpp
+++ b/src/core/SkRRect.cpp
@@ -8,6 +8,7 @@
#include <cmath>
#include "SkRRect.h"
#include "SkMatrix.h"
+#include "SkScaleToSides.h"
///////////////////////////////////////////////////////////////////////////////
@@ -120,48 +121,6 @@ static double compute_min_scale(double rad1, double rad2, double limit, double c
return curMin;
}
-// This code assumes that a and b fit in in a float, and therefore the resulting smaller value of
-// a and b will fit in a float. The side of the rectangle may be larger than a float.
-// Scale must be less than or equal to the ratio limit / (*a + *b).
-static void adjust_radii(double limit, double scale, float* a, float* b) {
- SkASSERT(scale < 1.0 && scale > 0.0);
- // This check is conservative. (double)*a + (double)*b >= (double)(*a + *b)
- if ((double)*a + (double)*b > limit) {
- float* minRadius = a;
- float* maxRadius = b;
- // Force minRadius to be the smaller of the two.
- if (*minRadius > *maxRadius) {
- SkTSwap(minRadius, maxRadius);
- }
- // newMinRadius must be float in order to give the actual value of the radius.
- // The newMinRadius will always be smaller than limit. The largest that minRadius can be
- // is 1/2 the ratio of minRadius : (minRadius + maxRadius), therefore in the resulting
- // division, minRadius can be no larger than 1/2 limit + ULP.
- float newMinRadius = *minRadius * scale;
- *minRadius = newMinRadius;
- // Because newMaxRadius is the result of a double to float conversion, it can be larger
- // than limit, but only by one ULP.
- float newMaxRadius = (float)(limit - newMinRadius);
- // If newMaxRadius is larger than the same value as a double, then it needs to be
- // reduced by one ULP to be less than limit - newMinRadius.
- // Note: nexttowardf is a c99 call and should be std::nexttoward, but this is not
- // implemented in the ARM compiler.
- if (newMaxRadius > limit - newMinRadius) {
- newMaxRadius = nexttowardf(newMaxRadius, limit - newMinRadius);
- }
- // This handles the case where both sets of radii are larger than a side by differing
- // scale factors. The one that needs the larger scale factor (the radii with less
- // overlap) will produce radii that are short enough just using the smaller scale factor
- // from the side where the radii overlap is larger.
- *maxRadius = SkMinScalar(scale * *maxRadius, newMaxRadius);
- } else {
- *a *= scale;
- *b *= scale;
- }
- SkASSERT(*a >= 0.0f && *b >= 0.0f);
- SkASSERT((*a + *b) <= limit);
-}
-
void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
fRect = rect;
fRect.sort();
@@ -220,10 +179,10 @@ void SkRRect::setRectRadii(const SkRect& rect, const SkVector radii[4]) {
scale = compute_min_scale(fRadii[3].fY, fRadii[0].fY, height, scale);
if (scale < 1.0) {
- adjust_radii(width, scale, &fRadii[0].fX, &fRadii[1].fX);
- adjust_radii(height, scale, &fRadii[1].fY, &fRadii[2].fY);
- adjust_radii(width, scale, &fRadii[2].fX, &fRadii[3].fX);
- adjust_radii(height, scale, &fRadii[3].fY, &fRadii[0].fY);
+ ScaleToSides::AdjustRadii(width, scale, &fRadii[0].fX, &fRadii[1].fX);
+ ScaleToSides::AdjustRadii(height, scale, &fRadii[1].fY, &fRadii[2].fY);
+ ScaleToSides::AdjustRadii(width, scale, &fRadii[2].fX, &fRadii[3].fX);
+ ScaleToSides::AdjustRadii(height, scale, &fRadii[3].fY, &fRadii[0].fY);
}
// At this point we're either oval, simple, or complex (not empty or rect).
« no previous file with comments | « no previous file | src/core/SkScaleToSides.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698