Bug 140812

Summary: Apply feTurbulence spec change to fix zero length vector generation
Product: WebKit Reporter: Nikos Andronikos <nikos.andronikos>
Component: SVGAssignee: Nikos Andronikos <nikos.andronikos>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, dino, kondapallykalyan, krit, zimmermann
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
Patch
none
Patch none

Description Nikos Andronikos 2015-01-22 19:31:21 PST
A bug in the Filter Effects feTurbulence algorithm has recently been fixed in the spec.
Discussion:
https://lists.w3.org/Archives/Public/www-svg/2015Jan/0003.html
http://www.w3.org/2015/01/15-svg-minutes.html#item06

Updated spec:
http://dev.w3.org/fxtf/filters/#elementdef-feturbulence
Change is the addition of do while loop on these lines:
do
{ for (j = 0; j < 2; j++) fGradient[k][i][j] = (double)(((lSeed = random(lSeed)) % (BSize + BSize)) - BSize) / BSize; }

while(fGradient[k][i][0] == 0 && fGradient[k][i][1] == 0);

Test: http://jsfiddle.net/dodgeyhack/mo7x85zw/

This change is already landed in Chrome Canary and FireFox nightly.
Comment 1 Nikos Andronikos 2015-01-22 21:02:26 PST
Created attachment 245202 [details]
Patch
Comment 2 Dirk Schulze 2015-01-26 03:22:48 PST
Comment on attachment 245202 [details]
Patch

Looks good to me. I am not happy to submit it without a test. IIRC there were some test cases on public-fx or www-svg. Could you add one of these please? r- because of missing test.
Comment 3 Nikos Andronikos 2015-01-26 17:17:33 PST
Created attachment 245393 [details]
Patch
Comment 4 Nikos Andronikos 2015-01-26 17:54:40 PST
(In reply to comment #2)
> Comment on attachment 245202 [details]
> Patch
> 
> Looks good to me. I am not happy to submit it without a test. IIRC there
> were some test cases on public-fx or www-svg. Could you add one of these
> please? r- because of missing test.

Ok, done. I was a bit worried about adding a pixel test but managed to come up with a way to use a reftest for this.
Comment 5 Darin Adler 2015-01-26 21:46:43 PST
Comment on attachment 245393 [details]
Patch

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

> Source/WebCore/platform/graphics/filters/FETurbulence.cpp:186
> +            do {
> +                gradient[0] = static_cast<float>((paintingData.random() % (2 * s_blockSize)) - s_blockSize) / s_blockSize;
> +                gradient[1] = static_cast<float>((paintingData.random() % (2 * s_blockSize)) - s_blockSize) / s_blockSize;
> +            } while (!gradient[0] && !gradient[1]);

Is a loop really the best way to avoid zeroes here?
Comment 6 Darin Adler 2015-01-26 21:47:27 PST
Comment on attachment 245393 [details]
Patch

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

>> Source/WebCore/platform/graphics/filters/FETurbulence.cpp:186
>> +            } while (!gradient[0] && !gradient[1]);
> 
> Is a loop really the best way to avoid zeroes here?

I guess that’s what the specification calls for.
Comment 7 Nikos Andronikos 2015-01-26 21:58:28 PST
(In reply to comment #6)
> Comment on attachment 245393 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=245393&action=review
> 
> >> Source/WebCore/platform/graphics/filters/FETurbulence.cpp:186
> >> +            } while (!gradient[0] && !gradient[1]);
> > 
> > Is a loop really the best way to avoid zeroes here?
> 
> I guess that’s what the specification calls for.

It does =)
The idea is that the random distribution is maintained. Falling back to some known value would skew the result (but only very slightly in this case).

Discussion was here: https://lists.w3.org/Archives/Public/www-svg/2015Jan/0005.html

Thanks for the review.
Comment 8 WebKit Commit Bot 2015-01-26 22:32:05 PST
Comment on attachment 245393 [details]
Patch

Clearing flags on attachment: 245393

Committed r179171: <http://trac.webkit.org/changeset/179171>
Comment 9 WebKit Commit Bot 2015-01-26 22:32:09 PST
All reviewed patches have been landed.  Closing bug.