RESOLVED FIXED Bug 106966
Image::currentFrameHasAlpha should not always return false for SVGImage
https://bugs.webkit.org/show_bug.cgi?id=106966
Summary Image::currentFrameHasAlpha should not always return false for SVGImage
Philip Rogers
Reported 2013-01-15 18:00:46 PST
Image::currentFrameHasAlpha is not overridden in SVGImage and always returns false. SVG Images can have alpha too so this needs to return the correct alpha value, or at least return true. http://trac.webkit.org/changeset/135629 was recently added which takes advantage of the alpha value and probably breaks transparent SVG images.
Attachments
Trivial patch (1.55 KB, patch)
2013-01-22 10:34 PST, Philip Rogers
no flags
First pass at addressing reviewer comments (37.52 KB, patch)
2013-01-28 10:13 PST, Philip Rogers
webkit.review.bot: commit-queue-
Update for bot happiness (38.12 KB, patch)
2013-01-28 12:01 PST, Philip Rogers
buildbot: commit-queue-
Update for bot happines (2) (40.14 KB, patch)
2013-01-29 14:44 PST, Philip Rogers
senorblanco: review+
Update per reviewer comments (40.16 KB, patch)
2013-01-30 14:07 PST, Philip Rogers
webkit.review.bot: commit-queue-
Rebased patch for landing (40.38 KB, patch)
2013-02-01 12:03 PST, Philip Rogers
no flags
Justin Novosad
Comment 1 2013-01-15 19:47:20 PST
I'm not sure why the default base class implementation returns false. I would think that true is always the conservative response here.
Philip Rogers
Comment 2 2013-01-22 10:34:47 PST
Created attachment 184009 [details] Trivial patch
Stephen Chenney
Comment 3 2013-01-22 10:37:21 PST
Comment on attachment 184009 [details] Trivial patch View in context: https://bugs.webkit.org/attachment.cgi?id=184009&action=review > Source/WebCore/platform/graphics/Image.h:102 > + virtual bool currentFrameHasAlpha() { return true; } Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community.
Darin Adler
Comment 4 2013-01-22 10:42:10 PST
Comment on attachment 184009 [details] Trivial patch View in context: https://bugs.webkit.org/attachment.cgi?id=184009&action=review >> Source/WebCore/platform/graphics/Image.h:102 >> + virtual bool currentFrameHasAlpha() { return true; } > > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. Besides that issue (and I personally would be open to pure virtual for this), I think the function name is wrong. It should be named currentFrameMayHaveAlpha or some other name like that that makes it clear that it does not give a definitive answer for all types of images.
Justin Novosad
Comment 5 2013-01-22 10:48:29 PST
(In reply to comment #3) > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. I also think we need to understand the impact of this change. Many of the sites that call this method need to know whether it is safe to assume that the image is opaque in order to apply shortcuts (occlusion culling, skip blending, etc.) In that context "true" is an appropriate default value since it is safe to have false positives. Before submitting this, we should make sure that this change is in fact safe for all the call sites. Also, does this fix any bugs? If we used to be falsely assuming that SVGimages are always opaque and they're not, then there is a good chance that this patch fixes a bug. It would be nice to have a LayoutTest that proves it. If this was not causing a bug, do we understand why?
Philip Rogers
Comment 6 2013-01-23 11:53:34 PST
Comment on attachment 184009 [details] Trivial patch Thanks for the reviews! I'm clearing the r? flag while I prepare the updated patch.
Philip Rogers
Comment 7 2013-01-28 10:13:50 PST
Created attachment 185001 [details] First pass at addressing reviewer comments
Philip Rogers
Comment 8 2013-01-28 10:28:04 PST
(In reply to comment #3) > (From update of attachment 184009 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=184009&action=review > > > Source/WebCore/platform/graphics/Image.h:102 > > + virtual bool currentFrameHasAlpha() { return true; } > > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. I agree, and fixing this exposed a small bug: GeneratedImage also needs to implement this. I've updated the latest patch to address this. (In reply to comment #4) > (From update of attachment 184009 [details]) > View in context: https://bugs.webkit.org/attachment.cgi?id=184009&action=review > > >> Source/WebCore/platform/graphics/Image.h:102 > >> + virtual bool currentFrameHasAlpha() { return true; } > > > > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. > > Besides that issue (and I personally would be open to pure virtual for this), I think the function name is wrong. It should be named currentFrameMayHaveAlpha or some other name like that that makes it clear that it does not give a definitive answer for all types of images. I tried a couple names such as currentFrameMayHaveAlpha and currentFrameMayhaveTransparency but I wasn't happy with how it looked from the caller's perspective. As an example, RenderImage::backgroundIsObscured() calls this function but is really looking to know whether the image is fully opaque or not. The latest patch uses "currentFrameIsKnownToBeOpaque". (In reply to comment #5) > (In reply to comment #3) > > > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. > > I also think we need to understand the impact of this change. Many of the sites that call this method need to know whether it is safe to assume that the image is opaque in order to apply shortcuts (occlusion culling, skip blending, etc.) In that context "true" is an appropriate default value since it is safe to have false positives. Before submitting this, we should make sure that this change is in fact safe for all the call sites. I hope the new function name "knownToBeOpaque" clarifies how we handle the unknown case. > > Also, does this fix any bugs? If we used to be falsely assuming that SVGimages are always opaque and they're not, then there is a good chance that this patch fixes a bug. It would be nice to have a LayoutTest that proves it. > > If this was not causing a bug, do we understand why? This was a tough one--this does not actually fix any bugs! When accessing SVG images we currently go through the SVGImageCache which returns a bitmap image for imageForRenderer. Therefore, in all of the callsites we actually weren't dealing with an SVG image but instead a rasterized bitmap image of the SVG image. In WK106159 I hope to change this. The latest patch modifies a test that will catch regressions in the future.
WebKit Review Bot
Comment 9 2013-01-28 10:55:47 PST
Comment on attachment 185001 [details] First pass at addressing reviewer comments Attachment 185001 [details] did not pass chromium-ews (chromium-xvfb): Output: http://queues.webkit.org/results/16160636
Stephen White
Comment 10 2013-01-28 11:00:47 PST
Thanks very much for taking this on! Justin and I were discussing how misleading the current situation is, and this is a great improvement. (In reply to comment #8) > I tried a couple names such as currentFrameMayHaveAlpha and currentFrameMayhaveTransparency but I wasn't happy with how it looked from the caller's perspective. As an example, RenderImage::backgroundIsObscured() calls this function but is really looking to know whether the image is fully opaque or not. The latest patch uses "currentFrameIsKnownToBeOpaque". I hate to bikeshed, but could it be simply currentFrameIsOpaque() (and isOpaque())? They're shorter, and I think it's clear that the conservative thing to do is return false if you're not certain. > (In reply to comment #5) > > (In reply to comment #3) > > > > > Do the derived classes that actually do not have alpha all explicitly set it? Personally I would tend to make this pure virtual and have everyone override it, but I have no idea how that would sit with the general community. > > > > I also think we need to understand the impact of this change. Many of the sites that call this method need to know whether it is safe to assume that the image is opaque in order to apply shortcuts (occlusion culling, skip blending, etc.) In that context "true" is an appropriate default value since it is safe to have false positives. Before submitting this, we should make sure that this change is in fact safe for all the call sites. > > I hope the new function name "knownToBeOpaque" clarifies how we handle the unknown case. > > > > > Also, does this fix any bugs? If we used to be falsely assuming that SVGimages are always opaque and they're not, then there is a good chance that this patch fixes a bug. It would be nice to have a LayoutTest that proves it. > > > > If this was not causing a bug, do we understand why? > > This was a tough one--this does not actually fix any bugs! When accessing SVG images we currently go through the SVGImageCache which returns a bitmap image for imageForRenderer. Therefore, in all of the callsites we actually weren't dealing with an SVG image but instead a rasterized bitmap image of the SVG image. In WK106159 I hope to change this. The latest patch modifies a test that will catch regressions in the future.
Peter Beverloo (cr-android ews)
Comment 11 2013-01-28 11:21:00 PST
Comment on attachment 185001 [details] First pass at addressing reviewer comments Attachment 185001 [details] did not pass cr-android-ews (chromium-android): Output: http://queues.webkit.org/results/16160637
Philip Rogers
Comment 12 2013-01-28 12:01:52 PST
Created attachment 185029 [details] Update for bot happiness
Philip Rogers
Comment 13 2013-01-28 12:31:18 PST
(In reply to comment #10) > I hate to bikeshed, but could it be simply currentFrameIsOpaque() (and isOpaque())? They're shorter, and I think it's clear that the conservative thing to do is return false if you're not certain. This is obvious at the moment but a year from now (when I've forgotten the details) I would be very surprised to get a non-opaque image that returns true for isOpaque. For that reason I'd like to lean towards keeping it in the function name.
Build Bot
Comment 14 2013-01-28 12:34:28 PST
Comment on attachment 185029 [details] Update for bot happiness Attachment 185029 [details] did not pass win-ews (win): Output: http://queues.webkit.org/results/16154713
Stephen White
Comment 15 2013-01-28 12:47:24 PST
(In reply to comment #13) > (In reply to comment #10) > > I hate to bikeshed, but could it be simply currentFrameIsOpaque() (and isOpaque())? They're shorter, and I think it's clear that the conservative thing to do is return false if you're not certain. > > This is obvious at the moment but a year from now (when I've forgotten the details) I would be very surprised to get a non-opaque image that returns true for isOpaque. For that reason I'd like to lean towards keeping it in the function name. Wait.. if that were true, then your current patch would have isKnownToBeOpaque() returning true for a non-opaque image in the above case. That doesn't seem right either. I'm guessing the surprising case is isOpaque() returning false for an opaque image. isKnownToBeOpaque() returning false for opaque seems less surprising, so I retract my objection to the verbosity. :)
Philip Rogers
Comment 16 2013-01-29 14:44:41 PST
Created attachment 185309 [details] Update for bot happines (2) One last build file update. Source/WebKit/win/WebKit.vcproj/WebKitExports.def.in needed an update for win bot's happiness.
Stephen White
Comment 17 2013-01-30 13:19:42 PST
Comment on attachment 185309 [details] Update for bot happines (2) View in context: https://bugs.webkit.org/attachment.cgi?id=185309&action=review Looks good, but Justin wants to take a look. > Source/WebCore/ChangeLog:13 > + This patch renames hasAlpha and currentFrameHasAlpha to isKnownOpaque and Nit: code says isKnownToBeOpaque, but ChangeLog says isKnownOpaque.
Justin Novosad
Comment 18 2013-01-30 13:23:32 PST
Comment on attachment 185309 [details] Update for bot happines (2) View in context: https://bugs.webkit.org/attachment.cgi?id=185309&action=review Me likes, but I'm no reviewer. > Source/WebCore/platform/graphics/skia/BitmapImageSingleFrameSkia.cpp:14 > + return m_nativeImage.bitmap().isOpaque(); Seeing this makes me think we should probably follow the example of this patch in skia and rename isOpaque to knownToBeOpaque, because it has a similar conservative best guess behavior. > Source/WebCore/svg/graphics/SVGImage.h:85 > + // FIXME: Implement this be less conservative. Unclear. Punctuation would help.
Stephen White
Comment 19 2013-01-30 13:27:39 PST
Comment on attachment 185309 [details] Update for bot happines (2) r=me. Nits are at your discretion.
Philip Rogers
Comment 20 2013-01-30 14:07:20 PST
Created attachment 185559 [details] Update per reviewer comments Two small updates: Fix the Hamletian ChangeLog typo and fix the grammar mistake in the FIXMEs. @Darin I think this patch is ready to commit but I'd like to double-check that your concerns were addressed. Do you mind taking one more look?
Philip Rogers
Comment 21 2013-02-01 11:27:58 PST
(In reply to comment #20) > Created an attachment (id=185559) [details] > Update per reviewer comments > > Two small updates: Fix the Hamletian ChangeLog typo and fix the grammar mistake in the FIXMEs. > > @Darin > I think this patch is ready to commit but I'd like to double-check that your concerns were addressed. Do you mind taking one more look? It has been a couple days so I'm going to send this to the queue before it rots. I am happy to re-open, roll-out, or revisit this at any time.
WebKit Review Bot
Comment 22 2013-02-01 11:32:07 PST
Comment on attachment 185559 [details] Update per reviewer comments Rejecting attachment 185559 [details] from commit-queue. Failed to run "['/mnt/git/webkit-commit-queue/Tools/Scripts/webkit-patch', '--status-host=queues.webkit.org', '--bot-id=gce-cq-04', 'apply-attachment', '--no-update', '--non-interactive', 185559, '--port=chromium-xvfb']" exit_code: 2 cwd: /mnt/git/webkit-commit-queue Last 500 characters of output: /PlatformContextSkiaTest.cpp patching file Source/WebKit/win/WebKit.vcproj/WebKitExports.def.in patching file LayoutTests/ChangeLog Hunk #1 succeeded at 1 with fuzz 3. patching file LayoutTests/fast/box-shadow/image-box-shadow-expected.html patching file LayoutTests/fast/box-shadow/image-box-shadow.html patching file LayoutTests/fast/box-shadow/resources/green.svg Failed to run "[u'/mnt/git/webkit-commit-queue/Tools/Scripts/svn-apply', '--force']" exit_code: 1 cwd: /mnt/git/webkit-commit-queue Full output: http://queues.webkit.org/results/16306938
Philip Rogers
Comment 23 2013-02-01 12:03:42 PST
Created attachment 186098 [details] Rebased patch for landing Looks like the previous patch went stale after all. Attaching an updated, rebased patch that's ready for the queue.
WebKit Review Bot
Comment 24 2013-02-01 13:32:35 PST
Comment on attachment 186098 [details] Rebased patch for landing Clearing flags on attachment: 186098 Committed r141637: <http://trac.webkit.org/changeset/141637>
WebKit Review Bot
Comment 25 2013-02-01 13:32:41 PST
All reviewed patches have been landed. Closing bug.
Note You need to log in before you can comment on or make changes to this bug.