Bug 266869 - Fix rounding of very large and very small LayoutUnits
Summary: Fix rounding of very large and very small LayoutUnits
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-12-24 13:29 PST by Ahmad Saleem
Modified: 2023-12-29 21:44 PST (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ahmad Saleem 2023-12-24 13:29:09 PST
Hi Team,

While looking into LayoutUnit.h code changes in Blink, I noticed that they fixed following bug:

Blink Commit - https://source.chromium.org/chromium/chromium/src/+/a7b04f8fe15406cbf98995da00fc63f73e9fff61

WebKit Source - https://github.com/WebKit/WebKit/blob/008483f2054324eb36aabbd31f58a59ffeff8da8/Source/WebCore/platform/LayoutUnit.h#L159

___

This compiles:

return toInt() + ((fraction().rawValue() + (kFixedPointDenominator / 2)) >> kLayoutUnitFractionalBits);

and

https://github.com/WebKit/WebKit/blob/008483f2054324eb36aabbd31f58a59ffeff8da8/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnitTests.cpp#L84
Test (LayoutUnitRounding):

// The fractional part of LayoutUnit::Max() is 0x3f, so it should round up.
    ASSERT_EQ(((std::numeric_limits<int>::max() / kFixedPointDenominator) + 1), LayoutUnit::max().round());
    // The fractional part of LayoutUnit::Min() is 0, so the next bigger possible
    // value should round down.
    LayoutUnit epsilon;
    epsilon.setRawValue(1);
    ASSERT_EQ(((std::numeric_limits<int>::min() / kFixedPointDenominator)), (LayoutUnit::min() + epsilon).round());
}

___

Without change, running above test fails -> run-api-tests WebCoreLayoutUnit.LayoutUnitRounding

Ran 1 tests of 1 with 0 successful
------------------------------
Test suite failed

Failed

    TestWebKitAPI.WebCoreLayoutUnit.LayoutUnitRounding
        /Users/ahmadsaleem/Documents/GitHub-Webkit-Ahmad-Fork/Untitled/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnitTests.cpp:108Expected equality of these values:  ((std::numeric_limits<int>::max() / kFixedPointDenominator) + 1)    Which is: 33554432  LayoutUnit::max().round()    Which is: 33554431

___

Hence, I am raising so we can fix it.

Thanks!
Comment 1 Ahmad Saleem 2023-12-24 20:54:26 PST
PR - https://github.com/WebKit/WebKit/pull/22236 (Still draft to see if there are any other test failures)
Comment 2 EWS 2023-12-29 21:43:10 PST
Committed 272534@main (2afefe7449cd): <https://commits.webkit.org/272534@main>

Reviewed commits have been landed. Closing PR #22236 and removing active labels.
Comment 3 Radar WebKit Bug Importer 2023-12-29 21:44:13 PST
<rdar://problem/120285542>