Bug 43213 - ctx.clearRect improperly clears shadow
Summary: ctx.clearRect improperly clears shadow
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: 528+ (Nightly build)
Hardware: All OS X 10.5
: P3 Normal
Assignee: Matthew Delaney
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-07-29 14:29 PDT by Matthew Delaney
Modified: 2010-07-30 22:08 PDT (History)
1 user (show)

See Also:


Attachments
Patch (10.82 KB, patch)
2010-07-29 16:45 PDT, Matthew Delaney
no flags Details | Formatted Diff | Diff
Patch (11.53 KB, patch)
2010-07-30 13:09 PDT, Matthew Delaney
no flags Details | Formatted Diff | Diff
Patch (10.96 KB, patch)
2010-07-30 13:24 PDT, Matthew Delaney
no flags Details | Formatted Diff | Diff
Patch (10.97 KB, patch)
2010-07-30 15:58 PDT, Matthew Delaney
no flags Details | Formatted Diff | Diff
Patch (10.96 KB, patch)
2010-07-30 16:09 PDT, Matthew Delaney
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Matthew Delaney 2010-07-29 14:29:45 PDT
Per the canvas spec: "Shapes are painted without affecting the current path, and are subject to the clipping region, and, with the exception of clearRect(), also shadow effects, global alpha, and global composition operators."

Currently, we're clearing the rect properly but also clearing the shadow (and apparently not properly neglecting the rest of the attributes as well).
Comment 1 Matthew Delaney 2010-07-29 16:45:07 PDT
Created attachment 63009 [details]
Patch
Comment 2 Darin Adler 2010-07-29 20:43:45 PDT
Comment on attachment 63009 [details]
Patch

> +    GraphicsContext* c = drawingContext();

I suggest the name "context" here instead of just "c".

> +    c->setShadow(FloatSize(width, -height), state().m_shadowBlur, state().m_shadowColor, DeviceColorSpace);

I suggest just passing FloatSize(), 0, and Color::transparent instead of fetching the values we just set in state().

> +    save();
> +    setAllAttributesToDefault();
>      willDraw(rect);
>      c->clearRect(rect);
> +    restore();

Does this extra work hurt performance? How much?
Comment 3 Matthew Delaney 2010-07-30 13:09:05 PDT
Created attachment 63095 [details]
Patch
Comment 4 Darin Adler 2010-07-30 13:14:05 PDT
Comment on attachment 63095 [details]
Patch

> Index: LayoutTests/canvas/philip/tests/2d.composite.operation.clear.html
> ===================================================================
> --- LayoutTests/canvas/philip/tests/2d.composite.operation.clear.html	(revision 64316)
> +++ LayoutTests/canvas/philip/tests/2d.composite.operation.clear.html	(working copy)
> @@ -26,7 +26,7 @@
>  _addTest(function(canvas, ctx) {
>  
>  ctx.globalCompositeOperation = 'xor';
> -ctx.globalCompositeOperation = 'clear';
> +ctx.globalCompositeOperation = 'foobar!';

Changing this test doesn't make a lot of sense given its name, and is separate from what you're doing here, so this should not be included in the patch.
Comment 5 Matthew Delaney 2010-07-30 13:24:01 PDT
Sorry, stray file from a different patch.

And on the performance, I'm seeing a different of 2 usec on average for that block of code (save() to restore(), inclusive) increasing from 5 to 7 usec.
Comment 6 Matthew Delaney 2010-07-30 13:24:14 PDT
Created attachment 63097 [details]
Patch
Comment 7 Oliver Hunt 2010-07-30 14:31:29 PDT
Comment on attachment 63097 [details]
Patch

r=me
Comment 8 WebKit Commit Bot 2010-07-30 15:45:40 PDT
Comment on attachment 63097 [details]
Patch

Rejecting patch 63097 from commit-queue.

Failed to run "['WebKitTools/Scripts/build-webkit', '--debug']" exit_code: 1
Last 500 characters of output:
bin/yacc
    /bin/sh -c /Users/eseidel/Projects/CommitQueue/WebKitBuild/WebCore.build/Debug/WebCore.build/Script-5DF50887116F3077005202AB.sh
** BUILD FAILED **

The following build commands failed:
WebCore:
	Distributed-CompileC /Users/eseidel/Projects/CommitQueue/WebKitBuild/WebCore.build/Debug/WebCore.build/Objects-normal/i386/CanvasRenderingContext2D.o /Users/eseidel/Projects/CommitQueue/WebCore/html/canvas/CanvasRenderingContext2D.cpp normal i386 c++ com.apple.compilers.gcc.4_2
(1 failure)


Full output: http://queues.webkit.org/results/3592638
Comment 9 Matthew Delaney 2010-07-30 15:58:16 PDT
Created attachment 63114 [details]
Patch
Comment 10 Darin Adler 2010-07-30 16:00:45 PDT
Comment on attachment 63114 [details]
Patch

> +    state().m_globalAlpha = (float)1.0;

Our consensus on best practice is to just put "1" in cases like this. If you really want a float, then 1.0f is the way to do it. (float)1.0 is not preferred style.

> +    context->setAlpha((float)1.0);

Ditto.
Comment 11 Matthew Delaney 2010-07-30 16:09:40 PDT
Created attachment 63115 [details]
Patch
Comment 12 Matthew Delaney 2010-07-30 16:10:19 PDT
Gotcha. Here's the fix!
Comment 13 WebKit Commit Bot 2010-07-30 22:08:26 PDT
Comment on attachment 63115 [details]
Patch

Clearing flags on attachment: 63115

Committed r64407: <http://trac.webkit.org/changeset/64407>
Comment 14 WebKit Commit Bot 2010-07-30 22:08:30 PDT
All reviewed patches have been landed.  Closing bug.