Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(454)

Issue 105363002: Make SVG images for custom CSS cursors appear sharp on retina displays (Closed)

Created:
7 years ago by Evan Wallace
Modified:
5 years, 4 months ago
Reviewers:
pdr., Rick Byers
CC:
blink-reviews
Base URL:
http://src.chromium.org/blink/trunk/
Visibility:
Public.

Description

Ensure using an SVG image as a custom CSS cursor gives a sharp image on a retina display. Rasterize the SVG image using the current device pixel ratio before the Cursor is converted to a WebCursor. BUG=325565 TEST=Check http://jsbin.com/aboVovOw on a retina display, cursor should not be blurry

Patch Set 1 #

Total comments: 2

Patch Set 2 : #

Unified diffs Side-by-side diffs Delta from patch set Stats (+42 lines, -18 lines) Patch
M Source/core/css/CSSCursorImageValue.cpp View 1 1 chunk +7 lines, -2 lines 0 comments Download
M Source/core/fetch/ImageResource.h View 1 2 chunks +2 lines, -0 lines 0 comments Download
M Source/core/fetch/ImageResource.cpp View 1 2 chunks +2 lines, -1 line 0 comments Download
M Source/core/platform/chromium/support/WebCursorInfo.cpp View 1 1 chunk +5 lines, -0 lines 0 comments Download
M Source/core/platform/graphics/BitmapImage.h View 1 1 chunk +1 line, -1 line 0 comments Download
M Source/core/platform/graphics/BitmapImage.cpp View 1 1 chunk +1 line, -1 line 0 comments Download
M Source/core/platform/graphics/Image.h View 1 1 chunk +6 lines, -1 line 0 comments Download
M Source/core/svg/graphics/SVGImage.h View 1 4 chunks +5 lines, -4 lines 0 comments Download
M Source/core/svg/graphics/SVGImage.cpp View 1 2 chunks +9 lines, -4 lines 0 comments Download
M Source/core/svg/graphics/SVGImageForContainer.h View 1 1 chunk +1 line, -1 line 0 comments Download
M Source/core/svg/graphics/SVGImageForContainer.cpp View 1 1 chunk +2 lines, -2 lines 0 comments Download
M Source/web/WebImageSkia.cpp View 1 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 8 (0 generated)
Evan Wallace
7 years ago (2013-12-04 20:10:14 UTC) #1
pdr.
At a high level, I think we're fixing this at the wrong level. For example, ...
7 years ago (2013-12-04 20:55:40 UTC) #2
Evan Wallace
For context, I'm also working on getting this working in Firefox: https://bugzilla.mozilla.org/show_bug.cgi?id=888689. It makes sense ...
7 years ago (2013-12-04 21:31:09 UTC) #3
pdr.
On 2013/12/04 21:31:09, Evan Wallace wrote: > For context, I'm also working on getting this ...
7 years ago (2013-12-04 21:43:43 UTC) #4
Evan Wallace
On 2013/12/04 21:43:43, pdr wrote: > Wow :) This is excellent. I don't have my ...
7 years ago (2013-12-05 10:30:04 UTC) #5
pdr.
On 2013/12/05 10:30:04, Evan Wallace wrote: > On 2013/12/04 21:43:43, pdr wrote: > > Wow ...
7 years ago (2013-12-06 06:06:42 UTC) #6
pdr.
+rbyers This is a tough one. I still don't like the first approach (I think ...
7 years ago (2013-12-14 23:52:53 UTC) #7
Rick Byers
7 years ago (2013-12-18 06:31:52 UTC) #8
On 2013/12/14 23:52:53, pdr wrote:
> +rbyers
> 
> This is a tough one. I still don't like the first approach (I think this
should
> be handled at a different layer) but the second patch doesn't seem right
either.
> 
> I feel like we need to bring in some experts. Rick, you're the author of a
large
> Cursor patch and are probably the most knowledgeable about this area; can you
> share your thoughts on how to solve this problem? At a high level, I don't
think
> SVG should be special cased here, but I don't see a nice way to make that
work.

Yeah, I wrote the support for high-dpi cursors a year ago (with
-webkit-image-set), see http://crbug.com/136034.  But I totally neglected SVG
cursors at the time (except for adding some minimal test cases for them). 
Thanks for pushing on this Evan - I agree that it should be possible to specify
cursors with SVG and have them use the native resolution.

I'm no expert on Image stuff, but I've spent a couple hours trying to page this
back in and form an opinion.  As you've probably seen, the way it works for
-webkit-image-set cursors is that CSSCursorImageValue::cachedImage creates a
StyleImage for the current device scale factor.  With SVG images the StyleImage
doesn't need to change (necessarily) depending on the device scale factor.

What makes it so that an SVG image inline in the HTML is rasterized according to
the current device scale factor, but when used for a Cursor it's rasterized with
a fixed scale factor of 1?  Is it just that converting an Image to a WebImage
uses Image::nativeImageForCurrentFrame which doesn't take device scale factor
into account, but inline images use Image::draw* which does?  Are there other
uses of SVGImage::nativeImageForCurrentFrame which similarly don't correctly
support high-dpi scenarios?  Perhaps there should be a special version of
nativeImageForCurrentFrame on SVGImage which takes a desired scale factor as an
argument (since SVGImage is the only type of Image that doesn't have a fixed
scale)?  Then we could pass the current deviceScaleFactor into the WebCursorInfo
ctor and have it rasterize the SVG according to that scale.  That's _almost_
what the original patch is doing, except it seems hacky to pre-rasterize and
generate a new Cursor with a bitmap image.  I don't think it's crazy to
special-case SVG in WebCursorInfo since WebCursorInfo details (somewhat
implicitly) with rasterizing an Image to a bitmap and isn't going to want to
apply the device-scale to bitmap images.

I guess that's the other option though - WebCursorInfo could always include a
bitmap in device pixels and then not need a scale factor at all.  Then we'd
rasterize ALL Images using the current device scale factor and not need to
special-case SVG (but it would only be SVG that would scale gracefully).  This
would send some unnecessary bits across the IPC channel for the common case of
bitmap images, but otherwise I think it's basically identical to what we do
today (where it's up to the browser size to scale the image appropriately). 
I.e. maybe the fundamental problem here is that I chose to scale cursor images
to match the device scale in the browser process, after we've already had to
rasterize vector images for communication across IPC (I think this was motivated
by WebKit port compatibility at the time, no longer an issue in blink).  If we
did this scale-to-device-pixels just before the rasterization step in blink then
things would just fall out nicely. 

Thoughts?

Also this of course needs a test case.  See
fast/events/mouse-cursor-image-set.html for reference.

Powered by Google App Engine
This is Rietveld 408576698