Bug 93772 - SVG as image drawn differently after layout
Summary: SVG as image drawn differently after layout
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: SVG (show other bugs)
Version: 420+
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Philip Rogers
URL:
Keywords:
Depends on: 94377
Blocks:
  Show dependency treegraph
 
Reported: 2012-08-11 18:18 PDT by Philip Rogers
Modified: 2014-11-28 10:14 PST (History)
2 users (show)

See Also:


Attachments
Testcase (1 of 2) (1.26 KB, text/html)
2012-08-11 18:18 PDT, Philip Rogers
no flags Details
Testcase (2 of 2) (188 bytes, image/svg+xml)
2012-08-11 18:19 PDT, Philip Rogers
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Philip Rogers 2012-08-11 18:18:51 PDT
Created attachment 157882 [details]
Testcase (1 of 2)

If we have an SVG file referenced as an image, the image will draw differently depending on if a layout has occurred:

        image.onload = function() {
            var context1 = canvas1.getContext('2d');
            context1.drawImage(img, 0, 0); // draws correctly

            setTimeout(function(){
                var context2 = canvas2.getContext('2d');
                context2.drawImage(img, 0, 0); // draws incorrectly, scaled 2x?
            }, 1);
        }

My guess is we're changing the size of the SVG during layout. This could be the source of a bug I've seen sporadically where SVG embedded in an image renders incorrectly on first load.
Comment 1 Philip Rogers 2012-08-11 18:19:19 PDT
Created attachment 157883 [details]
Testcase (2 of 2)
Comment 2 Philip Rogers 2012-08-13 23:18:47 PDT
Just updating to report what I've found so far. I think there is more than one bug hiding in here :(

I think one bug is that we use the device scale factor in calculating the bitmap size in SVGImageCache.cpp. It looks like implementations have steered towards doing that one level deeper (see http://code.google.com/p/chromium/issues/detail?id=127852). This isn't surprising since this code was written long ago.

A second bug is that on the first drawImage() call we have not done a layout of the SVG image, so it does not have size and scales set, and so we end up using drawImage directly. On the second drawImage() we have done a layout so we have cached data, but the cached data has zoom applied. The second drawImage therefore has zoom applied twice.

This second bug may get more complex because as a part of fixing our SVG sizing issues, it looks like a layout may be needed just to determine the aspect ratio of SVG content.