cBug 1792313 - Avoid using nscoord for intermediate computation with SVG rectangles. r=tnikkel

Under strong scales, going through the integer coordinate representation loses too much information. This patch tries to keep the same operations while sticking to floating point coordinates.

Differential Revision: https://phabricator.services.mozilla.com/D158750
This commit is contained in:
Nicolas Silva 2022-10-10 13:32:36 +00:00
parent b553b8225d
commit 2213a95042
4 changed files with 18 additions and 8 deletions

View File

@ -0,0 +1,4 @@
<svg width="500" height="500" viewBox="0 0 500 500" version="2.0" xmlns="http://www.w3.org/2000/svg">
<rect fill="red" x="-5" y="-5" width="510" height="510"/>
<rect fill="blue" x="50" y="50" width="400" height="400"/>
</svg>

After

Width:  |  Height:  |  Size: 234 B

View File

@ -0,0 +1,4 @@
<svg width="500" height="500" viewBox="0 0 0.1 0.1" version="2.0" xmlns="http://www.w3.org/2000/svg">
<rect fill="red" x="-1" y="-1" width="3" height="3"/>
<rect fill="blue" x="0.01" y="0.01" width="0.08" height="0.08"/>
</svg>

After

Width:  |  Height:  |  Size: 236 B

View File

@ -628,3 +628,5 @@ fails-if(Android) != mask-resource.html about:blank # The image the test uses is
fuzzy(0-1,0-150) == mask-opacity-invalidation-1.html mask-opacity-invalidation-1-ref.html # clip-path mask/opacity optimization
skip-if(Android) skip-if(cocoaWidget) skip-if(/^Windows\x20NT\x2010\.0/.test(http.oscpu)) == transform-animation-on-path.html transform-animation-on-path-ref.html #Bug 1638909
== 1792313.svg 1792313-ref.svg

View File

@ -809,17 +809,17 @@ bool SVGGeometryFrame::CreateWebRenderCommands(
}
if (!aDryRun) {
nscoord appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
int32_t appUnitsPerCSSPixel = AppUnitsPerCSSPixel();
auto appUnitsPerDevPx = PresContext()->AppUnitsPerDevPixel();
float scale = (float)AppUnitsPerCSSPixel() / (float)appUnitsPerDevPx;
auto rect = simplePath.AsRect();
auto appRect =
nsLayoutUtils::RoundGfxRectToAppRect(rect, appUnitsPerCSSPixel);
auto offset = aItem->ToReferenceFrame() - GetPosition();
appRect += offset;
auto destRect = LayoutDeviceRect::FromAppUnits(appRect, appUnitsPerDevPx);
rect.Scale(scale);
auto wrRect = wr::ToLayoutRect(destRect);
auto offset = LayoutDevicePoint::FromAppUnits(
aItem->ToReferenceFrame() - GetPosition(), appUnitsPerDevPx);
rect.MoveBy(offset.x, offset.y);
auto wrRect = wr::ToLayoutRect(rect);
SVGContextPaint* contextPaint =
SVGContextPaint::GetContextPaint(GetContent());