Bug 54244 - Convert the line box tree to floating point and eliminate font rounding hacks
Summary: Convert the line box tree to floating point and eliminate font rounding hacks
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Dave Hyatt
URL:
Keywords: InRadar
Depends on:
Blocks: 68100
  Show dependency treegraph
 
Reported: 2011-02-10 14:01 PST by Dave Hyatt
Modified: 2011-09-14 12:05 PDT (History)
13 users (show)

See Also:


Attachments
Patch (don't really review, just catching build errors) (125.88 KB, patch)
2011-02-10 14:02 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (125.93 KB, patch)
2011-02-10 15:06 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (128.80 KB, patch)
2011-02-10 15:34 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (146.52 KB, patch)
2011-02-11 11:30 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (151.88 KB, patch)
2011-02-11 12:40 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (158.91 KB, patch)
2011-02-11 14:40 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (160.99 KB, patch)
2011-02-11 15:05 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (161.67 KB, patch)
2011-02-11 15:29 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (162.15 KB, patch)
2011-02-13 17:14 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (172.53 KB, patch)
2011-02-14 10:53 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Patch that applies (ignore for review, just testing builds) (177.08 KB, patch)
2011-02-14 11:52 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Ready for review! (195.50 KB, patch)
2011-02-14 13:19 PST, Dave Hyatt
mitz: review-
Details | Formatted Diff | Diff
Sample of layout tests changes (1.93 MB, patch)
2011-02-14 13:20 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Address Dan's comments. (198.16 KB, patch)
2011-02-15 11:01 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Update Windows since someone added new uses of string truncation. (201.02 KB, patch)
2011-02-15 12:20 PST, Dave Hyatt
no flags Details | Formatted Diff | Diff
Update for Windows again since code got added to WebKit2 (201.05 KB, patch)
2011-02-15 15:16 PST, Dave Hyatt
mitz: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Dave Hyatt 2011-02-10 14:01:59 PST
Convert the line box tree to floating point and eliminate font rounding hacks.  This fixes numerous issues in environments that don't return integral values for widths of glyphs.
Comment 1 Dave Hyatt 2011-02-10 14:02:53 PST
Created attachment 82044 [details]
Patch (don't really review, just catching build errors)
Comment 2 Dave Hyatt 2011-02-10 15:06:05 PST
Created attachment 82058 [details]
Patch that applies (ignore for review, just testing builds)
Comment 3 WebKit Review Bot 2011-02-10 15:09:31 PST
Attachment 82058 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/WebCore.exp.in', u'Source/W..." exit_code: 1

Source/WebCore/rendering/InlineTextBox.cpp:938:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:939:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:1109:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:1110:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/HitTestResult.h:114:  The parameter name "rect" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/platform/graphics/Font.h:97:  The parameter name "glyphOverflow" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/platform/graphics/Font.h:98:  The parameter name "run" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 7 in 44 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Dave Hyatt 2011-02-10 15:34:05 PST
Created attachment 82062 [details]
Patch that applies (ignore for review, just testing builds)
Comment 5 WebKit Review Bot 2011-02-10 15:36:58 PST
Attachment 82062 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/WebCore/WebCore.exp.in', u'Source/W..." exit_code: 1

Source/WebCore/rendering/InlineTextBox.cpp:938:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:939:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:1109:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/InlineTextBox.cpp:1110:  One space before end of line comments  [whitespace/comments] [5]
Source/WebCore/rendering/HitTestResult.h:114:  The parameter name "rect" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/platform/graphics/Font.h:97:  The parameter name "glyphOverflow" adds no information, so it should be removed.  [readability/parameter_name] [5]
Source/WebCore/platform/graphics/Font.h:98:  The parameter name "run" adds no information, so it should be removed.  [readability/parameter_name] [5]
Total errors found: 7 in 45 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 6 WebKit Review Bot 2011-02-10 15:37:15 PST
Attachment 82058 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7884413
Comment 7 WebKit Review Bot 2011-02-10 15:54:04 PST
Attachment 82062 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7869499
Comment 8 Build Bot 2011-02-10 16:10:28 PST
Attachment 82058 [details] did not build on win:
Build output: http://queues.webkit.org/results/7869503
Comment 9 Build Bot 2011-02-10 16:31:55 PST
Attachment 82062 [details] did not build on win:
Build output: http://queues.webkit.org/results/7869507
Comment 10 Early Warning System Bot 2011-02-10 19:07:39 PST
Attachment 82062 [details] did not build on qt:
Build output: http://queues.webkit.org/results/7884461
Comment 11 WebKit Review Bot 2011-02-10 21:57:11 PST
Attachment 82062 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7870574
Comment 12 mitz 2011-02-10 22:07:34 PST
<rdar://problem/8891123>
Comment 13 Collabora GTK+ EWS bot 2011-02-10 22:51:04 PST
Attachment 82062 [details] did not build on gtk:
Build output: http://queues.webkit.org/results/7869566
Comment 14 Dave Hyatt 2011-02-11 11:30:01 PST
Created attachment 82153 [details]
Patch that applies (ignore for review, just testing builds)
Comment 15 WebKit Review Bot 2011-02-11 11:44:14 PST
Attachment 82153 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7900003
Comment 16 Dave Hyatt 2011-02-11 12:40:19 PST
Created attachment 82161 [details]
Patch that applies (ignore for review, just testing builds)
Comment 17 Build Bot 2011-02-11 12:44:54 PST
Attachment 82153 [details] did not build on win:
Build output: http://queues.webkit.org/results/7893014
Comment 18 Early Warning System Bot 2011-02-11 12:47:10 PST
Attachment 82153 [details] did not build on qt:
Build output: http://queues.webkit.org/results/7870746
Comment 19 WebKit Review Bot 2011-02-11 12:52:51 PST
Attachment 82161 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7870748
Comment 20 Collabora GTK+ EWS bot 2011-02-11 13:08:21 PST
Attachment 82161 [details] did not build on gtk:
Build output: http://queues.webkit.org/results/7870754
Comment 21 Build Bot 2011-02-11 13:23:10 PST
Attachment 82161 [details] did not build on win:
Build output: http://queues.webkit.org/results/7869739
Comment 22 Early Warning System Bot 2011-02-11 13:37:14 PST
Attachment 82161 [details] did not build on qt:
Build output: http://queues.webkit.org/results/7867750
Comment 23 Dave Hyatt 2011-02-11 14:40:50 PST
Created attachment 82181 [details]
Patch that applies (ignore for review, just testing builds)
Comment 24 WebKit Review Bot 2011-02-11 14:55:35 PST
Attachment 82181 [details] did not build on chromium:
Build output: http://queues.webkit.org/results/7867766
Comment 25 Dave Hyatt 2011-02-11 15:05:13 PST
Created attachment 82187 [details]
Patch that applies (ignore for review, just testing builds)
Comment 26 Collabora GTK+ EWS bot 2011-02-11 15:23:49 PST
Attachment 82187 [details] did not build on gtk:
Build output: http://queues.webkit.org/results/7867771
Comment 27 Dave Hyatt 2011-02-11 15:29:27 PST
Created attachment 82194 [details]
Patch that applies (ignore for review, just testing builds)
Comment 28 Build Bot 2011-02-11 16:38:50 PST
Attachment 82194 [details] did not build on win:
Build output: http://queues.webkit.org/results/7884715
Comment 29 Dave Hyatt 2011-02-13 17:14:06 PST
Created attachment 82282 [details]
Patch that applies (ignore for review, just testing builds)
Comment 30 Dave Hyatt 2011-02-14 10:53:06 PST
Created attachment 82339 [details]
Patch that applies (ignore for review, just testing builds)

In pretty good shape now I think.  Fixed SVG dumping in this patch to not dump floats and also fixed a bug with vertical alignment created by some issues using the dumb PositionTop and PositionBottom constants.  I just yanked those since they aren't necessary.
Comment 31 Dave Hyatt 2011-02-14 11:52:49 PST
Created attachment 82347 [details]
Patch that applies (ignore for review, just testing builds)

Fix offsetForPosition, positionForOffset to be float-based to avoid rounding errors.  Patch localCaretRect to operate on floats to avoid truncation mistakes.
Comment 32 Dave Hyatt 2011-02-14 13:19:19 PST
Created attachment 82356 [details]
Ready for review!

Layout test changes too massive to include in the patch.  I'll post a followup attachment that provides a sample of how they're changing.
Comment 33 Dave Hyatt 2011-02-14 13:20:18 PST
Created attachment 82357 [details]
Sample of layout tests changes
Comment 34 Build Bot 2011-02-14 13:51:36 PST
Attachment 82347 [details] did not build on win:
Build output: http://queues.webkit.org/results/7909694
Comment 35 Build Bot 2011-02-14 14:54:54 PST
Attachment 82356 [details] did not build on win:
Build output: http://queues.webkit.org/results/7908713
Comment 36 mitz 2011-02-14 15:23:12 PST
Comment on attachment 82356 [details]
Ready for review!

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

r- because of EWS build failures. Some minor comments inside.

> Source/WebCore/ChangeLog:8
> +        hacks from the Font code and makes sure all Font APIS involving width measurement and width offsets use floats.

Typo: APIS

> Source/WebCore/platform/graphics/WidthIterator.cpp:173
> +                        float expansion = previousExpansion - m_expansion;

Don’t need this anymore, can just use m_expansionPerOpportunity. You don’t need previousExpansion at all I think.

> Source/WebCore/platform/graphics/mac/ComplexTextController.cpp:480
> +                            float expansion = previousExpansion - m_expansion;

Here too you can get rid of expansion and previousExpansion.

> Source/WebCore/platform/graphics/win/UniscribeController.cpp:-323
> -        // Match AppKit's rules for the integer vs. non-integer rendering modes.
> -        float roundedAdvance = roundf(advance);
> -        if (!m_font.isPrinterFont() && !fontData->isSystemFont()) {
> -            advance = roundedAdvance;
> -            offsetX = roundf(offsetX);
> -            offsetY = roundf(offsetY);
> -        }

Don’t we need this still?

> Source/WebCore/platform/graphics/win/UniscribeController.cpp:319
>                          float previousPadding = m_padding;
>                          m_padding -= m_padPerSpace;
> -                        advance += roundf(previousPadding) - roundf(m_padding);
> +                        advance += previousPadding - m_padding;

Again, no need for previousPadding anymore. Just add m_padPerSpace to advance and subtract m_padPerSpace from m_padding.

> Source/WebCore/rendering/InlineBox.cpp:109
> + 

Space!

> Source/WebCore/rendering/InlineBox.h:312
> +    

Spaces!

> Source/WebCore/rendering/RenderBlockLineLayout.cpp:397
> +                    trailingSpaceRun->m_box->setLogicalWidth(max(0.f, trailingSpaceRun->m_box->logicalWidth() - totalLogicalWidth + availableLogicalWidth));

Another way to write this is max<float>(0, …)

> Source/WebCore/rendering/RenderText.cpp:509
> +    // Go ahead and round left to snap it to the nearest pixel.

:)

> Source/WebCore/rendering/RenderText.cpp:705
> +        const_cast<RenderText*>(this)->computePreferredLogicalWidths(0.f);

Is this .f needed?

> Source/WebCore/rendering/RenderText.cpp:713
> +        const_cast<RenderText*>(this)->computePreferredLogicalWidths(0.f);

Ditto.

> Source/WebCore/rendering/RenderTreeAsText.cpp:474
> +    // to detect any changes caused by the conversion to floating point. :(

The best thing you can do is generate pixel results for all tests on your machine w/o the patch, then apply the patch and run-webkit-tests --pixel and see if there are any significant differences.
Comment 37 Dominic Cooney 2011-02-14 21:55:27 PST
This patch will also fix bug 14956, at least for LTR content.
Comment 38 Dave Hyatt 2011-02-15 11:00:23 PST
(In reply to comment #37)
> This patch will also fix bug 14956, at least for LTR content.

Not sure it will.  I'm rounding to pixels when painting borders and backgrounds, so you'll probably have to test it to see if it really fixes that issue.
Comment 39 Dave Hyatt 2011-02-15 11:01:32 PST
Created attachment 82488 [details]
Address Dan's comments.
Comment 40 Nikolas Zimmermann 2011-02-15 11:51:07 PST
Comment on attachment 82488 [details]
Address Dan's comments.

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

Great, looking forward to this patch! I have another patch in the works, eliminating SVG pixel test diffs between 10.6.6 32bit/64bit machines, that will probably change enclosingIntRect, we might want to discuss that, to avoid several rebaselines...

> Source/WebCore/rendering/InlineBox.h:244
> +    int pixelSnappedLogicalLeft() const { return logicalLeft(); }
> +    int pixelSnappedLogicalRight() const { return ceilf(logicalRight()); }

Hm, you want to cast to int, no? and isn't a ceilf missing in the pixelSnappedLogicalLeft() function?
Comment 41 Build Bot 2011-02-15 11:58:53 PST
Attachment 82488 [details] did not build on win:
Build output: http://queues.webkit.org/results/7912899
Comment 42 Nikolas Zimmermann 2011-02-15 12:03:04 PST
(In reply to comment #40)
> (From update of attachment 82488 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=82488&action=review
> 
> Great, looking forward to this patch! I have another patch in the works, eliminating SVG pixel test diffs between 10.6.6 32bit/64bit machines, that will probably change enclosingIntRect, we might want to discuss that, to avoid several rebaselines...
> 
> > Source/WebCore/rendering/InlineBox.h:244
> > +    int pixelSnappedLogicalLeft() const { return logicalLeft(); }
> > +    int pixelSnappedLogicalRight() const { return ceilf(logicalRight()); }

I wonder wheter we want to expose FloatRect's safeFloatToInt method here?
Comment 43 Dave Hyatt 2011-02-15 12:15:05 PST
(In reply to comment #40)
> (From update of attachment 82488 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=82488&action=review
> 
> Great, looking forward to this patch! I have another patch in the works, eliminating SVG pixel test diffs between 10.6.6 32bit/64bit machines, that will probably change enclosingIntRect, we might want to discuss that, to avoid several rebaselines...
> 
> > Source/WebCore/rendering/InlineBox.h:244
> > +    int pixelSnappedLogicalLeft() const { return logicalLeft(); }
> > +    int pixelSnappedLogicalRight() const { return ceilf(logicalRight()); }
> 
> Hm, you want to cast to int, no? and isn't a ceilf missing in the pixelSnappedLogicalLeft() function?

I should perhaps rename these methods.  They're about returning the enclosing left and right (same as what enclosingIntRect would do to a rectangle that included these as the left and right sides).

"enclosingLogicalLeft" sounded dumb though when I tried it. :)

Basically the left side is floored and the right side is ceilinged so that a bounding box or overflow will enclose the whole run.
Comment 44 Dave Hyatt 2011-02-15 12:20:39 PST
Created attachment 82502 [details]
Update Windows since someone added new uses of string truncation.
Comment 45 Eric Seidel (no email) 2011-02-15 13:02:54 PST
Curious.  do you expect this to be a noticeable effect on memory usage for memory-constrained ports?
Comment 46 Dave Hyatt 2011-02-15 13:08:31 PST
(In reply to comment #45)
> Curious.  do you expect this to be a noticeable effect on memory usage for memory-constrained ports?

Shouldn't be... it's just int -> float not int -> double.
Comment 47 Build Bot 2011-02-15 14:40:11 PST
Attachment 82502 [details] did not build on win:
Build output: http://queues.webkit.org/results/7919033
Comment 48 Eric Seidel (no email) 2011-02-15 14:56:51 PST
(In reply to comment #46)
> (In reply to comment #45)
> > Curious.  do you expect this to be a noticeable effect on memory usage for memory-constrained ports?
> 
> Shouldn't be... it's just int -> float not int -> double.

Ah yes, my mistake.
Comment 49 Dave Hyatt 2011-02-15 15:16:32 PST
Created attachment 82533 [details]
Update for Windows again since code got added to WebKit2
Comment 50 mitz 2011-02-15 15:16:32 PST
Comment on attachment 82502 [details]
Update Windows since someone added new uses of string truncation.

r+ if you resolve the Windows build issue (or if there is no issue)
Comment 51 Dave Hyatt 2011-02-17 11:22:41 PST
Landed in r78846.
Comment 52 WebKit Review Bot 2011-02-17 11:32:21 PST
http://trac.webkit.org/changeset/78846 might have broken EFL Linux Release (Build)
Comment 53 Marc-Antoine Ruel 2011-04-26 13:07:12 PDT
Comment on attachment 82533 [details]
Update for Windows again since code got added to WebKit2

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

> Source/WebCore/rendering/InlineBox.h:243
> +    int pixelSnappedLogicalLeft() const { return logicalLeft(); }

This code generates:
warning C4244: 'return' : conversion from 'float' to 'int', possible loss of data

It'd be better to do return static_cast<int>(logicalLeft()); to be clear about the intent.

There are warnings at line 245, 246, 249, 254, 256 and 266 (line numbers are slightly offset, I'm at r84935.