Changeset 140192 in webkit


Ignore:
Timestamp:
Jan 18, 2013 12:21:57 PM (11 years ago)
Author:
leviw@chromium.org
Message:

LayoutUnit should round half consistently, not away from zero
https://bugs.webkit.org/show_bug.cgi?id=107208

Reviewed by Eric Seidel.

Source/WebCore:

The current implementation of LayoutUnit::round() always rounds half away from zero. This can result in
a shift of 1 pixel moving an element aligned at a half-pixel by 2. This problem is particularly common with
RenderLayers, which pass the sub-pixel accumulation into their renderers after translating the graphics
context passed in by their rounded location. This changes round() to always round 0.5 up.

Test: fast/sub-pixel/sub-pixel-root-layer.html

  • platform/LayoutUnit.h:

(WebCore::LayoutUnit::round): Always round 0.5 up.

  • rendering/RenderLayer.cpp:

(WebCore::RenderLayer::paintLayerContents): We no longer need to prevent rootLayers from passing in a
sub-pixel offset. This eliminates the shifting of elements when applying translateZ(0) or similar.

Tools:

  • TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp: Updating to reflect and

cover this change in rounding behavior.

LayoutTests:

  • fast/sub-pixel/sub-pixel-root-layer-expected.html: Added.
  • fast/sub-pixel/sub-pixel-root-layer.html: Added.
  • platform/chromium-linux/fast/regions/overflow-moving-below-floats-in-variable-width-regions-expected.png:
  • platform/chromium-linux/fast/regions/overflow-size-change-in-variable-width-regions-expected.png:
  • platform/chromium-linux/fast/regions/overflow-size-change-with-stacking-context-expected.png:
  • platform/chromium-win/fast/regions/overflow-moving-below-floats-in-variable-width-regions-expected.txt:
  • platform/chromium-win/fast/regions/overflow-size-change-in-variable-width-regions-expected.txt:
  • platform/chromium-win/fast/regions/overflow-size-change-with-stacking-context-expected.txt:
  • platform/chromium/TestExpectations:
  • platform/mac/TestExpectations:
Location:
trunk
Files:
2 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r140187 r140192  
     12013-01-18  Levi Weintraub  <leviw@chromium.org>
     2
     3        LayoutUnit should round half consistently, not away from zero
     4        https://bugs.webkit.org/show_bug.cgi?id=107208
     5
     6        Reviewed by Eric Seidel.
     7
     8        * fast/sub-pixel/sub-pixel-root-layer-expected.html: Added.
     9        * fast/sub-pixel/sub-pixel-root-layer.html: Added.
     10        * platform/chromium-linux/fast/regions/overflow-moving-below-floats-in-variable-width-regions-expected.png:
     11        * platform/chromium-linux/fast/regions/overflow-size-change-in-variable-width-regions-expected.png:
     12        * platform/chromium-linux/fast/regions/overflow-size-change-with-stacking-context-expected.png:
     13        * platform/chromium-win/fast/regions/overflow-moving-below-floats-in-variable-width-regions-expected.txt:
     14        * platform/chromium-win/fast/regions/overflow-size-change-in-variable-width-regions-expected.txt:
     15        * platform/chromium-win/fast/regions/overflow-size-change-with-stacking-context-expected.txt:
     16        * platform/chromium/TestExpectations:
     17        * platform/mac/TestExpectations:
     18
    1192013-01-18  Martin Robinson  <mrobinson@igalia.com>
    220
  • trunk/LayoutTests/platform/chromium-win/fast/regions/overflow-moving-below-floats-in-variable-width-regions-expected.txt

    r117821 r140192  
    2323      RenderBlock {DIV} at (48,51) size 294x245 [border: (1px solid #008000)]
    2424        RenderBlock {DIV} at (1,1) size 500x20
    25           RenderText {#text} at (-13,0) size 270x19
    26             text run at (-13,0) width 270: "Clipped line of text that should not be visible."
     25          RenderText {#text} at (-12,0) size 270x19
     26            text run at (-12,0) width 270: "Clipped line of text that should not be visible."
    2727        RenderBlock {P} at (1,44) size 291x80
    2828          RenderText {#text} at (0,0) size 291x79
     
    3838            text run at (0,60) width 252: "These lines will not spill out of the regions."
    3939        RenderBlock {DIV} at (1,224) size 500x20
    40           RenderText {#text} at (-23,0) size 270x19
    41             text run at (-23,0) width 270: "Clipped line of text that should not be visible."
     40          RenderText {#text} at (-22,0) size 270x19
     41            text run at (-22,0) width 270: "Clipped line of text that should not be visible."
    4242  Regions for flow 'flow1'
    4343    RenderRegion {DIV} #region1
  • trunk/LayoutTests/platform/chromium-win/fast/regions/overflow-size-change-in-variable-width-regions-expected.txt

    r112709 r140192  
    2121      RenderBlock {DIV} at (36,1) size 218x391 [border: (1px solid #008000)]
    2222        RenderBlock {DIV} at (1,1) size 500x20
    23           RenderText {#text} at (-13,0) size 270x19
    24             text run at (-13,0) width 270: "Clipped line of text that should not be visible."
     23          RenderText {#text} at (-12,0) size 270x19
     24            text run at (-12,0) width 270: "Clipped line of text that should not be visible."
    2525        RenderBlock {P} at (1,37) size 216x137
    26           RenderText {#text} at (-13,0) size 229x136
    27             text run at (-13,0) width 141: "These lines will not spill"
    28             text run at (-13,20) width 141: "out of the regions."
     26          RenderText {#text} at (-12,0) size 228x136
     27            text run at (-12,0) width 140: "These lines will not spill"
     28            text run at (-12,20) width 140: "out of the regions."
    2929            text run at (0,57) width 216: "These lines will not spill out of the"
    3030            text run at (0,77) width 51: "regions. "
     
    3333            text run at (0,117) width 135: "spill out of the regions."
    3434        RenderBlock {P} at (1,190) size 216x144
    35           RenderText {#text} at (0,0) size 239x143
     35          RenderText {#text} at (0,0) size 238x143
    3636            text run at (0,0) width 216: "These lines will not spill out of the"
    3737            text run at (0,20) width 216: "regions. These lines will not spill out"
     
    3939            text run at (96,40) width 120: "These lines will not"
    4040            text run at (0,60) width 216: "spill out of the regions. These lines"
    41             text run at (-23,84) width 81: "will not spill"
    42             text run at (-23,104) width 81: "out of the"
    43             text run at (-23,124) width 47: "regions."
     41            text run at (-22,84) width 80: "will not spill"
     42            text run at (-22,104) width 80: "out of the"
     43            text run at (-22,124) width 47: "regions."
    4444        RenderBlock {DIV} at (1,350) size 500x20
    45           RenderText {#text} at (-23,0) size 270x19
    46             text run at (-23,0) width 270: "Clipped line of text that should not be visible."
     45          RenderText {#text} at (-22,0) size 270x19
     46            text run at (-22,0) width 270: "Clipped line of text that should not be visible."
    4747  Regions for flow 'flow1'
    4848    RenderRegion {DIV} #region1
  • trunk/LayoutTests/platform/chromium-win/fast/regions/overflow-size-change-with-stacking-context-expected.txt

    r112709 r140192  
    2121      RenderBlock (relative positioned) {DIV} at (36,1) size 218x371 [border: (1px solid #008000)]
    2222        RenderBlock {P} at (1,37) size 216x137
    23           RenderText {#text} at (-13,0) size 229x136
    24             text run at (-13,0) width 141: "These lines will not spill"
    25             text run at (-13,20) width 141: "out of the regions."
     23          RenderText {#text} at (-12,0) size 228x136
     24            text run at (-12,0) width 140: "These lines will not spill"
     25            text run at (-12,20) width 140: "out of the regions."
    2626            text run at (0,57) width 216: "These lines will not spill out of the"
    2727            text run at (0,77) width 51: "regions. "
     
    3030            text run at (0,117) width 135: "spill out of the regions."
    3131        RenderBlock {P} at (1,190) size 216x144
    32           RenderText {#text} at (0,0) size 239x143
     32          RenderText {#text} at (0,0) size 238x143
    3333            text run at (0,0) width 216: "These lines will not spill out of the"
    3434            text run at (0,20) width 216: "regions. These lines will not spill out"
     
    3636            text run at (96,40) width 120: "These lines will not"
    3737            text run at (0,60) width 216: "spill out of the regions. These lines"
    38             text run at (-23,84) width 81: "will not spill"
    39             text run at (-23,104) width 81: "out of the"
    40             text run at (-23,124) width 47: "regions."
     38            text run at (-22,84) width 80: "will not spill"
     39            text run at (-22,104) width 80: "out of the"
     40            text run at (-22,124) width 47: "regions."
    4141    layer at (42,356) size 500x20 backgroundClip at (51,80) size 216x369 clip at (51,80) size 216x369 outlineClip at (51,80) size 216x369
    4242      RenderBlock (positioned) {DIV} at (1,350) size 500x20
    43         RenderText {#text} at (-23,0) size 270x19
    44           text run at (-23,0) width 270: "Clipped line of text that should not be visible."
     43        RenderText {#text} at (-22,0) size 270x19
     44          text run at (-22,0) width 270: "Clipped line of text that should not be visible."
    4545  Regions for flow 'flow1'
    4646    RenderRegion {DIV} #region1
  • trunk/LayoutTests/platform/chromium/TestExpectations

    r140181 r140192  
    39113911webkit.org/b/11645 [ Mac Android ] fast/table/025.html [ Failure ]
    39123912
     3913# Rebaseline required after https://webkit.org/b/107208
     3914Bug(leviw) [ Mac Android Win ] fast/regions/overflow-moving-below-floats-in-variable-width-regions.html [ Pass Failure ImageOnlyFailure ]
     3915Bug(leviw) [ Mac Android Win ] fast/regions/overflow-size-change-in-variable-width-regions.html [ Pass Failure ImageOnlyFailure ]
     3916Bug(leviw) [ Mac Android Win ] fast/regions/overflow-size-change-with-stacking-context.html [ Pass Failure ImageOnlyFailure ]
     3917
    39133918# Rebaseline required after https://bugs.webkit.org/show_bug.cgi?id=101177
    39143919webkit.org/b/101177 svg/dynamic-updates/SVGUseElement-dom-requiredFeatures.html [ ImageOnlyFailure Pass ]
  • trunk/LayoutTests/platform/mac/TestExpectations

    r140174 r140192  
    12801280webkit.org/b/103955 fast/repaint/selection-rl.html [ ImageOnlyFailure ]
    12811281webkit.org/b/103955 fast/repaint/caret-with-transformation.html [ Missing ]
     1282
     1283# Rebaseline required after https://webkit.org/b/107208
     1284webkit.org/b/107208 fast/regions/overflow-moving-below-floats-in-variable-width-regions.html [ Pass Failure ImageOnlyFailure ]
     1285webkit.org/b/107208 fast/regions/overflow-size-change-in-variable-width-regions.html [ Pass Failure ImageOnlyFailure ]
     1286webkit.org/b/107208 fast/regions/overflow-size-change-with-stacking-context.html [ Pass Failure ImageOnlyFailure ]
     1287
  • trunk/Source/WebCore/ChangeLog

    r140185 r140192  
     12013-01-18  Levi Weintraub  <leviw@chromium.org>
     2
     3        LayoutUnit should round half consistently, not away from zero
     4        https://bugs.webkit.org/show_bug.cgi?id=107208
     5
     6        Reviewed by Eric Seidel.
     7
     8        The current implementation of LayoutUnit::round() always rounds half away from zero. This can result in
     9        a shift of 1 pixel moving an element aligned at a half-pixel by 2. This problem is particularly common with
     10        RenderLayers, which pass the sub-pixel accumulation into their renderers after translating the graphics
     11        context passed in by their rounded location. This changes round() to always round 0.5 up.
     12
     13        Test: fast/sub-pixel/sub-pixel-root-layer.html
     14
     15        * platform/LayoutUnit.h:
     16        (WebCore::LayoutUnit::round): Always round 0.5 up.
     17        * rendering/RenderLayer.cpp:
     18        (WebCore::RenderLayer::paintLayerContents): We no longer need to prevent rootLayers from passing in a
     19        sub-pixel offset. This eliminates the shifting of elements when applying translateZ(0) or similar.
     20
    1212013-01-18  Kentaro Hara  <haraken@chromium.org>
    222
  • trunk/Source/WebCore/platform/LayoutUnit.h

    r138978 r140192  
    229229        if (m_value > 0)
    230230            return saturatedAddition(rawValue(), kEffectiveFixedPointDenominator / 2) / kEffectiveFixedPointDenominator;
    231         return saturatedSubtraction(rawValue(), kEffectiveFixedPointDenominator / 2) / kEffectiveFixedPointDenominator;
     231        return saturatedSubtraction(rawValue(), (kEffectiveFixedPointDenominator / 2) - 1) / kEffectiveFixedPointDenominator;
    232232#elif ENABLE(SUBPIXEL_LAYOUT)
    233233        if (m_value > 0)
    234234            return (m_value + (kEffectiveFixedPointDenominator / 2)) / kEffectiveFixedPointDenominator;
    235         return (m_value - (kEffectiveFixedPointDenominator / 2)) / kEffectiveFixedPointDenominator;
     235        return (m_value - ((kEffectiveFixedPointDenominator / 2) - 1)) / kEffectiveFixedPointDenominator;
    236236#else
    237237        return m_value;
  • trunk/Source/WebCore/rendering/RenderLayer.cpp

    r140177 r140192  
    36653665        calculateRects(clipRectsContext, localPaintingInfo.paintDirtyRect, layerBounds, damageRect, clipRectToApply, outlineRect, &offsetFromRoot);
    36663666        paintOffset = toPoint(layerBounds.location() - renderBoxLocation() + localPaintingInfo.subPixelAccumulation);
    3667         if (this == localPaintingInfo.rootLayer)
    3668             paintOffset = roundedIntPoint(paintOffset);
    36693667    }
    36703668
  • trunk/Tools/ChangeLog

    r140189 r140192  
     12013-01-18  Levi Weintraub  <leviw@chromium.org>
     2
     3        LayoutUnit should round half consistently, not away from zero
     4        https://bugs.webkit.org/show_bug.cgi?id=107208
     5
     6        Reviewed by Eric Seidel.
     7
     8        * TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp: Updating to reflect and
     9        cover this change in rounding behavior.
     10
    1112013-01-18  Tim Horton  <timothy_horton@apple.com>
    212
  • trunk/Tools/TestWebKitAPI/Tests/WebCore/LayoutUnit.cpp

    r138952 r140192  
    8282TEST(WebCoreLayoutUnit, LayoutUnitRounding)
    8383{
    84     ASSERT_EQ(LayoutUnit(-1.5f).round(), -2);
     84    ASSERT_EQ(LayoutUnit(-1.9f).round(), -2);
     85    ASSERT_EQ(LayoutUnit(-1.6f).round(), -2);
     86    ASSERT_EQ(LayoutUnit(-1.52f).round(), -2);
     87    ASSERT_EQ(LayoutUnit(-1.5f).round(), -1);
    8588    ASSERT_EQ(LayoutUnit(-1.49f).round(), -1);
    8689    ASSERT_EQ(LayoutUnit(-1.0f).round(), -1);
    8790    ASSERT_EQ(LayoutUnit(-0.99f).round(), -1);
    88     ASSERT_EQ(LayoutUnit(-0.50f).round(), -1);
     91    ASSERT_EQ(LayoutUnit(-0.51f).round(), 0);
     92    ASSERT_EQ(LayoutUnit(-0.50f).round(), 0);
    8993    ASSERT_EQ(LayoutUnit(-0.49f).round(), 0);
    9094    ASSERT_EQ(LayoutUnit(-0.1f).round(), 0);
Note: See TracChangeset for help on using the changeset viewer.