Bug 43718

Summary: Canvas: Fast-path for setting the already set color with setStrokeColor() and setFillColor()
Product: WebKit Reporter: Andreas Kling <kling>
Component: WebCore Misc.Assignee: Nobody <webkit-unassigned>
Status: RESOLVED FIXED    
Severity: Normal CC: darin, oliver
Priority: P2 Keywords: Performance
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Proposed patch none

Description Andreas Kling 2010-08-09 05:01:19 PDT
Some JS demos, for example "Monster" at Chrome Experiments, use the WebKit-specific color setters of CanvasRenderingContext2D.

For this particular demo, roughly 5% of the calls to setFillColor() have the same color as is already set on the context. We should detect this and make an early return before creating any CanvasStyle objects (or calling into GraphicsContext.)
Comment 1 Andreas Kling 2010-08-09 05:06:32 PDT
Created attachment 63887 [details]
Proposed patch
Comment 2 Andreas Kling 2010-08-09 05:07:01 PDT
The "Monster" demo mentioned in bug description:
http://www.chromeexperiments.com/detail/monster/
Comment 3 Antonio Gomes 2010-08-09 06:23:13 PDT
Comment on attachment 63887 [details]
Proposed patch

Looks good.
Comment 4 Andreas Kling 2010-08-09 06:56:55 PDT
Comment on attachment 63887 [details]
Proposed patch

Clearing flags on attachment: 63887

Committed r64980: <http://trac.webkit.org/changeset/64980>
Comment 5 Andreas Kling 2010-08-09 06:57:05 PDT
All reviewed patches have been landed.  Closing bug.
Comment 6 Darin Adler 2010-08-09 09:03:55 PDT
A side comment:

I think it's dangerous to overload and treat floating point values as RGBA or CMYKA just based on the number of arguments. Thus, these functions should have RGBA and CMYKA in their names. Similarly, the create functions for CanvasStyle should have RGBA and CMYKA and such in their names too.

The reason the functions in CanvasStyle used overloading historically is that they were constructors. Tis is one advantage of the create functions over direct calls to the constructors. We can leave the overloading trick to the constructors only.

CanvasRenderingContext2D has to do this overloading because that's in the specification, but internally we should not repeat that mistake.