Commit 08e2d2a0 authored by fmalita's avatar fmalita Committed by Commit bot

Clamp radial gradient end radii

Ensure that the end radius stays within finite float range, to
avoid degenerate cases down the line.

BUG=616993
R=fs@opera.com

Review-Url: https://codereview.chromium.org/2041653002
Cr-Commit-Position: refs/heads/master@{#398029}
parent 8795b7e5
<DOCTYPE html>
<style>
div {
display: inline-block;
margin: 10px;
width: 400px;
height: 100px;
}
.r1 {
background-image: repeating-radial-gradient(closest-corner ellipse at -184467440737095516150000000000000000000% 37%, red, green);
}
.r2 {
background-image: repeating-radial-gradient(farthest-corner ellipse at -184467440737095516150000000000000000000% 37%, red, green);
}
.r3 {
background-image: repeating-radial-gradient(closest-side ellipse at -184467440737095516150000000000000000000% 37%, red, green);
}
.r4 {
background-image: repeating-radial-gradient(farthest-side ellipse at -184467440737095516150000000000000000000% 37%, red, green);
}
.r5 {
background-image: repeating-radial-gradient(closest-corner ellipse at 184467440737095516150000000000000000000% 37%, red, green);
}
.r6 {
background-image: repeating-radial-gradient(farthest-corner ellipse at 184467440737095516150000000000000000000% 37%, red, green);
}
.r7 {
background-image: repeating-radial-gradient(closest-side ellipse at 184467440737095516150000000000000000000% 37%, red, green);
}
.r8 {
background-image: repeating-radial-gradient(farthest-side ellipse at 184467440737095516150000000000000000000% 37%, red, green);
}
</style>
<div class="r1"></div>
<div class="r2"></div>
<div class="r3"></div>
<div class="r4"></div>
<div class="r5"></div>
<div class="r6"></div>
<div class="r7"></div>
<div class="r8"></div>
PASS: did not crash.
<script>
if (window.testRunner)
testRunner.dumpAsText();
</script>
...@@ -1033,10 +1033,10 @@ enum EndShapeType { ...@@ -1033,10 +1033,10 @@ enum EndShapeType {
FloatSize radiusToSide(const FloatPoint& point, const FloatSize& size, EndShapeType shape, FloatSize radiusToSide(const FloatPoint& point, const FloatSize& size, EndShapeType shape,
bool (*compare)(float, float)) bool (*compare)(float, float))
{ {
float dx1 = fabs(point.x()); float dx1 = clampTo<float>(fabs(point.x()));
float dy1 = fabs(point.y()); float dy1 = clampTo<float>(fabs(point.y()));
float dx2 = fabs(point.x() - size.width()); float dx2 = clampTo<float>(fabs(point.x() - size.width()));
float dy2 = fabs(point.y() - size.height()); float dy2 = clampTo<float>(fabs(point.y() - size.height()));
float dx = compare(dx1, dx2) ? dx1 : dx2; float dx = compare(dx1, dx2) ? dx1 : dx2;
float dy = compare(dy1, dy2) ? dy1 : dy2; float dy = compare(dy1, dy2) ? dy1 : dy2;
...@@ -1056,7 +1056,7 @@ inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio) ...@@ -1056,7 +1056,7 @@ inline FloatSize ellipseRadius(const FloatPoint& p, float aspectRatio)
// a/b = aspectRatio, b = a/aspectRatio // a/b = aspectRatio, b = a/aspectRatio
// a = sqrt(x^2 + y^2/(1/r^2)) // a = sqrt(x^2 + y^2/(1/r^2))
float a = sqrtf(p.x() * p.x() + p.y() * p.y() * aspectRatio * aspectRatio); float a = sqrtf(p.x() * p.x() + p.y() * p.y() * aspectRatio * aspectRatio);
return FloatSize(a, a / aspectRatio); return FloatSize(clampTo<float>(a), clampTo<float>(a / aspectRatio));
} }
// Compute the radius to the closest/farthest corner (depending on the compare functor). // Compute the radius to the closest/farthest corner (depending on the compare functor).
...@@ -1153,6 +1153,10 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthCon ...@@ -1153,6 +1153,10 @@ PassRefPtr<Gradient> CSSRadialGradientValue::createGradient(const CSSToLengthCon
} }
} }
DCHECK(std::isfinite(firstRadius));
DCHECK(std::isfinite(secondRadius.width()));
DCHECK(std::isfinite(secondRadius.height()));
bool isDegenerate = !secondRadius.width() || !secondRadius.height(); bool isDegenerate = !secondRadius.width() || !secondRadius.height();
RefPtr<Gradient> gradient = Gradient::create(firstPoint, firstRadius, secondPoint, RefPtr<Gradient> gradient = Gradient::create(firstPoint, firstRadius, secondPoint,
isDegenerate ? 0 : secondRadius.width(), isDegenerate ? 1 : secondRadius.aspectRatio()); isDegenerate ? 0 : secondRadius.width(), isDegenerate ? 1 : secondRadius.aspectRatio());
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment