Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkRRect.h" | 8 #include "SkRRect.h" |
| 9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
| 10 | 10 |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 | 165 |
| 166 // Proportionally scale down all radii to fit. Find the minimum ratio | 166 // Proportionally scale down all radii to fit. Find the minimum ratio |
| 167 // of a side and the radii on that side (for all four sides) and use | 167 // of a side and the radii on that side (for all four sides) and use |
| 168 // that to scale down _all_ the radii. This algorithm is from the | 168 // that to scale down _all_ the radii. This algorithm is from the |
| 169 // W3 spec (http://www.w3.org/TR/css3-background/) section 5.5 - Overlapping | 169 // W3 spec (http://www.w3.org/TR/css3-background/) section 5.5 - Overlapping |
| 170 // Curves: | 170 // Curves: |
| 171 // "Let f = min(Li/Si), where i is one of { top, right, bottom, left }, | 171 // "Let f = min(Li/Si), where i is one of { top, right, bottom, left }, |
| 172 // Si is the sum of the two corresponding radii of the corners on side i, | 172 // Si is the sum of the two corresponding radii of the corners on side i, |
| 173 // and Ltop = Lbottom = the width of the box, | 173 // and Ltop = Lbottom = the width of the box, |
| 174 // and Lleft = Lright = the height of the box. | 174 // and Lleft = Lright = the height of the box. |
| 175 // If f < 1, then all corner radii are reduced by multiplying them by f." | 175 // If f < 1, then all corner radii are reduced by multiplying them by f." |
|
robertphillips
2015/03/11 18:13:28
So, if we don't do this math in doubles the code n
| |
| 176 SkScalar scale = SK_Scalar1; | 176 double scale = 1.0; |
| 177 | 177 |
| 178 if (fRadii[0].fX + fRadii[1].fX > rect.width()) { | 178 if (fRadii[0].fX + ((double)fRadii[1].fX) > rect.width()) { |
|
reed1
2015/03/13 14:16:21
can we use a helper function for these, one that t
robertphillips
2015/03/13 16:32:35
Done.
| |
| 179 scale = SkMinScalar(scale, | 179 scale = SkTMin(scale, rect.width() / (fRadii[0].fX + ((double)fRadii[1]. fX))); |
| 180 SkScalarDiv(rect.width(), fRadii[0].fX + fRadii[1].f X)); | |
| 181 } | 180 } |
| 182 if (fRadii[1].fY + fRadii[2].fY > rect.height()) { | 181 if (fRadii[1].fY + ((double)fRadii[2].fY) > rect.height()) { |
| 183 scale = SkMinScalar(scale, | 182 scale = SkTMin(scale, rect.height() / (fRadii[1].fY + ((double)fRadii[2] .fY))); |
| 184 SkScalarDiv(rect.height(), fRadii[1].fY + fRadii[2]. fY)); | |
| 185 } | 183 } |
| 186 if (fRadii[2].fX + fRadii[3].fX > rect.width()) { | 184 if (fRadii[2].fX + ((double)fRadii[3].fX) > rect.width()) { |
| 187 scale = SkMinScalar(scale, | 185 scale = SkTMin(scale, rect.width() / (fRadii[2].fX + ((double)fRadii[3]. fX))); |
| 188 SkScalarDiv(rect.width(), fRadii[2].fX + fRadii[3].f X)); | |
| 189 } | 186 } |
| 190 if (fRadii[3].fY + fRadii[0].fY > rect.height()) { | 187 if (fRadii[3].fY + ((double)fRadii[0].fY) > rect.height()) { |
| 191 scale = SkMinScalar(scale, | 188 scale = SkTMin(scale, rect.height() / (fRadii[3].fY + ((double)fRadii[0] .fY))); |
| 192 SkScalarDiv(rect.height(), fRadii[3].fY + fRadii[0]. fY)); | |
| 193 } | 189 } |
| 194 | 190 |
| 195 if (scale < SK_Scalar1) { | 191 if (scale < 1.0) { |
| 196 for (int i = 0; i < 4; ++i) { | 192 for (int i = 0; i < 4; ++i) { |
| 197 fRadii[i].fX *= scale; | 193 fRadii[i].fX *= scale; |
| 198 fRadii[i].fY *= scale; | 194 fRadii[i].fY *= scale; |
| 199 } | 195 } |
| 200 } | 196 } |
| 201 | 197 |
| 202 // skbug.com/3239 -- its possible that we can hit the following inconsistenc y: | 198 // skbug.com/3239 -- its possible that we can hit the following inconsistenc y: |
| 203 // rad == bounds.bottom - bounds.top | 199 // rad == bounds.bottom - bounds.top |
| 204 // bounds.bottom - radius < bounds.top | 200 // bounds.bottom - radius < bounds.top |
| 205 // YIKES | 201 // YIKES |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 582 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); | 578 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); |
| 583 SkASSERT(patchesOfNine); | 579 SkASSERT(patchesOfNine); |
| 584 break; | 580 break; |
| 585 case kComplex_Type: | 581 case kComplex_Type: |
| 586 SkASSERT(!fRect.isEmpty()); | 582 SkASSERT(!fRect.isEmpty()); |
| 587 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); | 583 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); |
| 588 SkASSERT(!patchesOfNine); | 584 SkASSERT(!patchesOfNine); |
| 589 break; | 585 break; |
| 590 } | 586 } |
| 591 | 587 |
| 592 for (int i = 0; i < 4; ++i) { | 588 for (int i = 0; i < 4; ++i) { |
|
robertphillips
2015/03/11 18:13:28
This only enforces predicates on individual radii.
| |
| 593 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight ); | 589 validate_radius_check_predicates(fRadii[i].fX, fRect.fLeft, fRect.fRight ); |
| 594 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom ); | 590 validate_radius_check_predicates(fRadii[i].fY, fRect.fTop, fRect.fBottom ); |
| 595 } | 591 } |
| 596 } | 592 } |
| 597 #endif // SK_DEBUG | 593 #endif // SK_DEBUG |
| 598 | 594 |
| 599 /////////////////////////////////////////////////////////////////////////////// | 595 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |