Bug 44014 - [Qt] Path: Fast approximation of stroke bounding rects
Summary: [Qt] Path: Fast approximation of stroke bounding rects
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: QtWebKit Unassigned
URL:
Keywords: Performance, Qt, QtTriaged
Depends on: 44018
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-14 13:39 PDT by Andreas Kling
Modified: 2010-08-17 11:44 PDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (1.86 KB, patch)
2010-08-14 13:43 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff
Proposed patch v2 (1.61 KB, patch)
2010-08-17 11:06 PDT, Andreas Kling
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Kling 2010-08-14 13:39:09 PDT
Path::strokeBoundingRect() is used by CanvasRenderingContext2D to determine the dirty region following a stroke() call.

We currently implement this using QPainterPathStroker which is very expensive for complex paths.

Instead of this we can use QPainterPath::controlPointRect() to approximate the bounding rect. The result will be slightly larger than what the current implementation would return but will run in a fraction of the time.
Comment 1 Andreas Kling 2010-08-14 13:42:36 PDT
Example page that spends a lot of time in Qt's strokeBoundingRect():
http://sebleedelisle.com/demos/html5landscape.html
Comment 2 Andreas Kling 2010-08-14 13:43:21 PDT
Created attachment 64425 [details]
Proposed patch
Comment 3 Andreas Kling 2010-08-14 14:48:33 PDT
(In reply to comment #1)
> Example page that spends a lot of time in Qt's strokeBoundingRect():
> http://sebleedelisle.com/demos/html5landscape.html

Speed improvement for this page with the proposed patch: 18.6%

About the patch, if we want to narrow down the returned rect further, I suppose the lineWidth could be divided by 2.
Comment 4 Ariya Hidayat 2010-08-14 15:15:18 PDT
Comment on attachment 64425 [details]
Proposed patch

Very nice!
Comment 5 Andreas Kling 2010-08-14 15:44:26 PDT
Comment on attachment 64425 [details]
Proposed patch

Clearing flags on attachment: 64425

Committed r65374: <http://trac.webkit.org/changeset/65374>
Comment 6 Andreas Kling 2010-08-14 15:44:35 PDT
All reviewed patches have been landed.  Closing bug.
Comment 7 WebKit Review Bot 2010-08-14 16:16:18 PDT
http://trac.webkit.org/changeset/65374 might have broken Qt Linux Release
Comment 8 Andreas Kling 2010-08-14 16:21:06 PDT
(In reply to comment #7)
> http://trac.webkit.org/changeset/65374 might have broken Qt Linux Release

Gaaahhh, that's what I get for compiling without SVG support..
Comment 9 Andreas Kling 2010-08-15 17:43:40 PDT
http://trac.webkit.org/changeset/65374 broke a bunch of SVG tests. Reopening.
Comment 10 Andreas Kling 2010-08-17 11:06:18 PDT
Created attachment 64609 [details]
Proposed patch v2

Move the (Qt-specific) logic in CRC2D::stroke() this time so as not to affect SVG.
Comment 11 Ariya Hidayat 2010-08-17 11:20:15 PDT
Comment on attachment 64609 [details]
Proposed patch v2

WebCore/html/canvas/CanvasRenderingContext2D.cpp:833
 +          boundingRect.inflate(state().m_miterLimit + state().m_lineWidth);
This means we still ignore the CanvasStrokeStyleApplier, not sure how severe it would be.
A workaround is to expand the boundingRect by the stroke width, sadly this does not take into account miter join.

Clearing the review flag while this is being thought off.
Comment 12 Ariya Hidayat 2010-08-17 11:31:55 PDT
Comment on attachment 64609 [details]
Proposed patch v2

LGTM. re=me
Comment 13 Andreas Kling 2010-08-17 11:44:04 PDT
Comment on attachment 64609 [details]
Proposed patch v2

Clearing flags on attachment: 64609

Committed r65525: <http://trac.webkit.org/changeset/65525>
Comment 14 Andreas Kling 2010-08-17 11:44:15 PDT
All reviewed patches have been landed.  Closing bug.