Bug 92778 - Float imprecision causes incorrect wrapping in LineLayout with subpixel layout
Summary: Float imprecision causes incorrect wrapping in LineLayout with subpixel layout
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Emil A Eklund
URL:
Keywords:
Depends on:
Blocks: 94881
  Show dependency treegraph
 
Reported: 2012-07-31 11:42 PDT by Emil A Eklund
Modified: 2012-08-23 17:44 PDT (History)
4 users (show)

See Also:


Attachments
Patch (12.09 KB, patch)
2012-07-31 12:16 PDT, Emil A Eklund
no flags Details | Formatted Diff | Diff
Patch (12.09 KB, patch)
2012-07-31 14:59 PDT, Emil A Eklund
no flags Details | Formatted Diff | Diff
Patch for landing (12.13 KB, patch)
2012-07-31 18:06 PDT, Emil A Eklund
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Emil A Eklund 2012-07-31 11:42:11 PDT
Due to float imprecision an incorrect wrapping decision is made in certain cases where the values being compare are close but not exactly the same. This can happen as the size of blocks is represented in layout units while line layout uses floats.

Downstream chromium bug: http://code.google.com/p/chromium/issues/detail?id=139502
Comment 1 Levi Weintraub 2012-07-31 12:13:45 PDT
So excited to get this one fixed!
Comment 2 Emil A Eklund 2012-07-31 12:16:46 PDT
Created attachment 155604 [details]
Patch
Comment 3 Eric Seidel (no email) 2012-07-31 13:37:10 PDT
Comment on attachment 155604 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=155604&action=review

> Source/WebCore/rendering/RenderBlockLineLayout.cpp:79
> +    bool fitsOnLine() const { return currentWidth() - m_availableWidth < LayoutUnit::epsilon(); }
> +    bool fitsOnLine(float extra) const { return currentWidth() + extra - m_availableWidth < LayoutUnit::epsilon(); }

Don't we have a helper to compare to layout units within epsilon?  It seems that might be more clear... I mean, not that this simple math isn't clear-ish too...

Also, this is looking specifically to see if currentWidth is no more than + epsilon greater than m_available width.  Why not just change the previous statements to be \

currentWidth() <= (m_availableWidth + LayoutUnit::epsilon())?

I guess your way doesn't overflow if available width is large?
Comment 4 Emil A Eklund 2012-07-31 14:59:10 PDT
(In reply to comment #3)
> (From update of attachment 155604 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=155604&action=review
> 
> > Source/WebCore/rendering/RenderBlockLineLayout.cpp:79
> > +    bool fitsOnLine() const { return currentWidth() - m_availableWidth < LayoutUnit::epsilon(); }
> > +    bool fitsOnLine(float extra) const { return currentWidth() + extra - m_availableWidth < LayoutUnit::epsilon(); }
> 
> Don't we have a helper to compare to layout units within epsilon?  It seems that might be more clear... I mean, not that this simple math isn't clear-ish too...

Not here, we have one for comparing a LayoutUnit with a float but here we are comparing two floats. I could hardcode the tolerance to 0.01 which it what we use in css code but as LayoutUnit::epsilon is the max we support it seemed more correct.

> 
> Also, this is looking specifically to see if currentWidth is no more than + epsilon greater than m_available width.  Why not just change the previous statements to be \
> 
> currentWidth() <= (m_availableWidth + LayoutUnit::epsilon())?
> 
> I guess your way doesn't overflow if available width is large?

Old habit, doesn't matter here as it is all float. Changed it as suggested.
Comment 5 Emil A Eklund 2012-07-31 14:59:18 PDT
Created attachment 155640 [details]
Patch
Comment 6 Eric Seidel (no email) 2012-07-31 17:50:31 PDT
Comment on attachment 155640 [details]
Patch

LGTM.
Comment 7 Emil A Eklund 2012-07-31 18:05:50 PDT
Saw some failures on mac that might I'm not entirely sure where not caused by this (as this effectively means that the value can be off by almost 1 on ports without subpixel support). Adding an ifdef just to make sure.
Comment 8 Emil A Eklund 2012-07-31 18:06:12 PDT
Created attachment 155694 [details]
Patch for landing
Comment 9 WebKit Review Bot 2012-07-31 21:04:08 PDT
Comment on attachment 155694 [details]
Patch for landing

Clearing flags on attachment: 155694

Committed r124295: <http://trac.webkit.org/changeset/124295>
Comment 10 WebKit Review Bot 2012-07-31 21:04:11 PDT
All reviewed patches have been landed.  Closing bug.