Bug 46918 - ContextShadow should not use the blur radius as kernel size of the box blurs
Summary: ContextShadow should not use the blur radius as kernel size of the box blurs
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: 528+ (Nightly build)
Hardware: PC Linux
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks: 46475
  Show dependency treegraph
 
Reported: 2010-09-30 10:29 PDT by Alejandro G. Castro
Modified: 2010-10-06 12:38 PDT (History)
5 users (show)

See Also:


Attachments
Proposed patch (3.18 KB, patch)
2010-09-30 10:33 PDT, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
Proposed patch (3.92 KB, patch)
2010-10-01 04:43 PDT, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
Proposed patch (4.77 KB, patch)
2010-10-04 04:34 PDT, Alejandro G. Castro
no flags Details | Formatted Diff | Diff
Proposed patch (4.77 KB, patch)
2010-10-04 04:49 PDT, Alejandro G. Castro
krit: review-
Details | Formatted Diff | Diff
Proposed patch (9.65 KB, patch)
2010-10-06 08:11 PDT, Alejandro G. Castro
krit: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Alejandro G. Castro 2010-09-30 10:29:07 PDT
Currently we are using the blur radius in ContextShadow directly as the kernel size when blurring, this is causing a bigger blurring effect than expected. We should calculate the kernel size required to get a blur effect which size is like the blur radius. We were using before 2/3 of the blur radius, because we are adding kernel_size/2 pixels with each box blur, therefore with 3 box blurs we get 3*kernel_size/2 more pixels, which should be the blur radius. Firefox is applying a similar solution.
Comment 1 Alejandro G. Castro 2010-09-30 10:33:45 PDT
Created attachment 69347 [details]
Proposed patch

This is an option without supporting fractional kernel sizes which would be probably the one with the best results, mostly for the small radii. It is basically what we are currently doing in FEGaussianBlur.
Comment 2 Martin Robinson 2010-09-30 10:45:18 PDT
Comment on attachment 69347 [details]
Proposed patch

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

> WebCore/platform/graphics/ContextShadow.cpp:158
> +    // We expand the area by the blur radius to give extra space for the blur transition.
> +    m_layerRect.inflate((m_type == BlurShadow) ? ceil(m_blurRadius) : 0);

We probably want to change the name m_blurRadius to m_blurWidth to clear up any confusion about what this value means.
Comment 3 Alejandro G. Castro 2010-09-30 11:32:30 PDT
(In reply to comment #2)
>
> [...]
> 
> We probably want to change the name m_blurRadius to m_blurWidth to clear up any confusion about what this value means.

I agree, I've checked the CSS spec and it is call blur distance we can use that:

http://www.w3.org/TR/css3-background/#box-shadow
Comment 4 Jarred Nicholls 2010-09-30 19:57:27 PDT
Alejandro, I would update this patch to conform to the landed patch in r68824 (https://bugs.webkit.org/show_bug.cgi?id=46931), which removes the unnecessary calls to ceil (which happen to break MSVC builds since 9/23 when the Qt blur was forked for Cairo).  Just FYI.
Comment 5 Alejandro G. Castro 2010-09-30 23:56:58 PDT
(In reply to comment #4)
> Alejandro, I would update this patch to conform to the landed patch in r68824 (https://bugs.webkit.org/show_bug.cgi?id=46931), which removes the unnecessary calls to ceil (which happen to break MSVC builds since 9/23 when the Qt blur was forked for Cairo).  Just FYI.

Thanks for information, I'll do it.
Comment 6 Alejandro G. Castro 2010-10-01 04:43:51 PDT
Created attachment 69450 [details]
Proposed patch

Addressed the recomendations, I've used blurDistance (from the css spec) and d (from the svg spec). Rebased over Jarred patch.
Comment 7 Early Warning System Bot 2010-10-01 05:02:25 PDT
Attachment 69450 [details] did not build on qt:
Build output: http://queues.webkit.org/results/4212035
Comment 8 Jarred Nicholls 2010-10-01 05:31:32 PDT
See r68145, Mark changed several files in Cairo and Qt to use m_blurRadius that will also need refactoring for the name change to m_blurDistance, e.g. qt/FontQt.cpp.
Comment 9 Jarred Nicholls 2010-10-01 08:56:36 PDT
(In reply to comment #8)
> See r68145, Mark changed several files in Cairo and Qt to use m_blurRadius that will also need refactoring for the name change to m_blurDistance, e.g. qt/FontQt.cpp.

First off, I meant to type Martin and for some reason typed Mark.  My apologies Martin!

Second, it's actually just the qt/FontQt.cpp after doing a search.  Hope that saves you some time.
Comment 10 Alejandro G. Castro 2010-10-01 09:11:09 PDT
(In reply to comment #9)
> (In reply to comment #8)
> > See r68145, Mark changed several files in Cairo and Qt to use m_blurRadius that will also need refactoring for the name change to m_blurDistance, e.g. qt/FontQt.cpp.
> 
> First off, I meant to type Martin and for some reason typed Mark.  My apologies Martin!
> 
> Second, it's actually just the qt/FontQt.cpp after doing a search.  Hope that saves you some time.

Yeah, thanks very much Jarred, preparing the patch.
Comment 11 Alejandro G. Castro 2010-10-04 04:34:01 PDT
Created attachment 69615 [details]
Proposed patch

I've modified the m_blurRadius in FontQt, is there any reason not to declare those members as private and add a funtion to get them? In that case we could open other bug to do that.
Comment 12 Early Warning System Bot 2010-10-04 04:40:43 PDT
Attachment 69615 [details] did not build on qt:
Build output: http://queues.webkit.org/results/4166069
Comment 13 Alejandro G. Castro 2010-10-04 04:49:50 PDT
Created attachment 69617 [details]
Proposed patch
Comment 14 Dirk Schulze 2010-10-06 05:03:48 PDT
Comment on attachment 69617 [details]
Proposed patch

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

Please fix the issues and I'm fine with it. r- because of the issues.

> WebCore/platform/graphics/ContextShadow.cpp:88
> +    unsigned d = max(2.f, (2 / 3.f) * m_blurDistance);

d is unsigned, you can't use unsigned d = max(2.f
use
unsigned d = max<unsigned>(2, floorf(2 / 3.f * m_blurDistance)); instead.

> WebCore/platform/graphics/ContextShadow.cpp:158
> +    m_layerRect.inflate((m_type == BlurShadow) ? m_blurDistance : 0);

remove the braces arround m_type == BlurShadow

> WebCore/platform/graphics/ContextShadow.cpp:171
> +            m_layerRect.inflate((m_type == BlurShadow) ? m_blurDistance : 0);

Ditto.
Comment 15 Dirk Schulze 2010-10-06 05:04:43 PDT
(In reply to comment #14)
> (From update of attachment 69617 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=69617&action=review
> d is unsigned, you can't use unsigned d = max(2.f
> use
> unsigned d = max<unsigned>(2, floorf(2 / 3.f * m_blurDistance)); instead.
> 
you still need a static_cast<unsigned> for floorf, sorry.
Comment 16 Alejandro G. Castro 2010-10-06 08:09:05 PDT
(In reply to comment #15)
> (In reply to comment #14)
> > (From update of attachment 69617 [details] [details])
> > View in context: https://bugs.webkit.org/attachment.cgi?id=69617&action=review
> > d is unsigned, you can't use unsigned d = max(2.f
> > use
> > unsigned d = max<unsigned>(2, floorf(2 / 3.f * m_blurDistance)); instead.
> > 
> you still need a static_cast<unsigned> for floorf, sorry.

Thanks for the review, I'm going to use int the distance is limited to 128 so it is not a problem, something like:

+    int d = max(2, static_cast<int>(floorf((2 / 3.f) * m_blurDistance)));
Comment 17 Alejandro G. Castro 2010-10-06 08:11:30 PDT
Created attachment 69942 [details]
Proposed patch

Fixed the issues pointed out in the comments.
Comment 18 Dirk Schulze 2010-10-06 10:15:03 PDT
Comment on attachment 69942 [details]
Proposed patch

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

LGTM. Please use a better phrasing in the ChangeLog.

> WebCore/ChangeLog:10
> +        Calculate the size of the kernel in the blur algorihtm using the
> +        radius instead of using directly. Change the name of the variables

using directly 
something is missing here. What don't you want to use directly?
Comment 19 Alejandro G. Castro 2010-10-06 10:35:07 PDT
(In reply to comment #18)
> (From update of attachment 69942 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=69942&action=review
> 
> LGTM. Please use a better phrasing in the ChangeLog.
> 
> > WebCore/ChangeLog:10
> > +        Calculate the size of the kernel in the blur algorihtm using the
> > +        radius instead of using directly. Change the name of the variables
> 
> using directly 
> something is missing here. What don't you want to use directly?

Yep, ... instead of using directly the blur distance as the kernel size. Thanks, I'm going to commit it.
Comment 20 Martin Robinson 2010-10-06 12:38:09 PDT
Committed r69223: <http://trac.webkit.org/changeset/69223>