Rendering an SVG file to an ImageSkia

1,228 views
Skip to first unread message

Nicholas Bishop

unread,
Mar 1, 2018, 12:15:37 PM3/1/18
to Chromium-dev
Hi,

Is there any existing way to load an SVG file and render it into a
gfx::ImageSkia?

Thanks,
-Nicholas

Stephen Chenney

unread,
Mar 2, 2018, 12:15:55 PM3/2/18
to nbi...@neverware.com, Chromium-dev
Context please. In general, the SVG content will not end up in a rastered image until rasterization on the GPU. You would need to intercept the painting command stream and paint into the gfx object. Maybe the canvas APIs do something similar already but I doubt the destination type is the same.

Stephen.


--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
    http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/CAB0M8MkwGvWJOrjj0W3qxH38km_0xeDtm0VOhHuxp%3DFNVvtH%2Bw%40mail.gmail.com.


Nicholas Bishop

unread,
Mar 2, 2018, 5:07:55 PM3/2/18
to Stephen Chenney, Chromium-dev
Context: I'm trying to render an SVG icon file into an image for use
as an icon in the Chromium OS UI. The input files aren't known until
runtime, so I can't just pre-render them.

Peter Kasting

unread,
Mar 2, 2018, 5:22:19 PM3/2/18
to nbi...@neverware.com, Stephen Chenney, Chromium-dev
On Fri, Mar 2, 2018 at 2:06 PM, Nicholas Bishop <nbi...@neverware.com> wrote:
Context: I'm trying to render an SVG icon file into an image for use
as an icon in the Chromium OS UI. The input files aren't known until
runtime, so I can't just pre-render them.

We do something like this in chrome/browser/bitmap_fetcher/ : get image data from the network, decode it, and send it to consumers as Skia objects.

This in turn is built atop chrome/browser/image_decoder.h, which is a way of safely decoding image data inside a sandbox.

All that said, if you give even more context about what's going on here, I might have better suggestions.  Why SVG, for example, and where are the images coming from/what part of the UI are they for?

PK

PhistucK

unread,
Mar 4, 2018, 7:39:31 AM3/4/18
to nbi...@neverware.com, Chromium-dev


PhistucK

--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
    http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.

Dominick Ng

unread,
Mar 11, 2018, 8:19:52 PM3/11/18
to Chromium-dev, nbi...@neverware.com
We'd like to do something similar for this in order to allow websites to supply SVG icons for progressive web apps (which isn't currently supported in Chrome). This is a fairly commonly requested feature.

When a user adds a site to home screen, we download the icon specified by the site and use it as the home screen icon / shelf icon. We use WebContents::DownloadImage for this, which doesn't support SVG because SVG isn't really an image. We'd need a way of rendering SVG into a Skia object to allow us to support SVG as well for this process.

Florin Malita

unread,
Mar 11, 2018, 9:05:13 PM3/11/18
to domi...@chromium.org, Chromium-dev, nbi...@neverware.com, Mike Reed
Skia does have experimental/limited support for SVG rasterization: https://github.com/google/skia/blob/master/experimental/svg/model/SkSVGDOM.h

The API is explicit, but it wouldn't be a huge stretch to package as a supported image decoder and possibly hide behind the SkImage API.

This is not currently built by Chrome, and off the top of my head is missing filters effects, SMIL and text support.

Assuming there is a good use case and interest, we could allocate resources to fill some of the gaps.




Dominick Ng

unread,
Mar 11, 2018, 10:04:05 PM3/11/18
to Chromium-dev, domi...@chromium.org, nbi...@neverware.com, re...@chromium.org
Packaging this into Chrome as a supported image decoder would be a really useful thing for us, especially if it can be feature-compliant with the existing SVG implementation (so developers aren't surprised when their icons don't render right when retrieved via this pipeline). Otherwise, we have no way of supporting SVG icons.

Florin Malita

unread,
Mar 11, 2018, 10:53:41 PM3/11/18
to domi...@chromium.org, Chromium-dev, nbi...@neverware.com, Mike Reed
SVG is a beast, and I don't expect Skia's SVG renderer to reach full spec compliance or be on par with Blink's implementation.  If you require all Chrome-supported SVG bells and whistles to also be available for icons, then I believe your only option is to find a way to use Blink's SVG renderer.

If OTOH you can tolerate a well-defined SVG subset (most SVG art uses a small fraction of the spec), then the Skia SVG lib might be an option to consider.

Alex Danilo

unread,
Mar 11, 2018, 11:03:40 PM3/11/18
to fma...@chromium.org, domi...@chromium.org, Chromium-dev, nbi...@neverware.com, Mike Reed

Dominick Ng

unread,
Mar 12, 2018, 12:06:14 AM3/12/18
to Chromium-dev, fma...@chromium.org, domi...@chromium.org, nbi...@neverware.com, re...@chromium.org, ada...@chromium.org
Thanks Florin. For predictability reasons, we would want to try and match Blink's SVG rendering, which probably means we'll need to wait till https://crbug.com/294179 is resolved (thanks Alex).

Daniel Bratell

unread,
Mar 12, 2018, 6:35:41 AM3/12/18
to Chromium-dev, Dominick Ng, fma...@chromium.org, nbi...@neverware.com, re...@chromium.org, ada...@chromium.org
I think warning bells should chime when the best idea is to duplicate existing functionality. When is it ever right to have duplicate functionality in a product? Yet it keeps happening in Chromium.

/Daniel


PhistucK

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/512f3722-8ec1-4e82-9aa6-368f9ee04522%40chromium.org.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-dev/98de4580-32eb-474d-982b-043f26726ff3%40chromium.org.



--
/* Opera Software, Linköping, Sweden: CET (UTC+1) */

Jan Tošovský

unread,
Oct 23, 2018, 5:07:23 PM10/23/18
to Chromium-dev, domi...@chromium.org, nbi...@neverware.com, re...@chromium.org
> SVG is a beast, and I don't expect Skia's SVG renderer to reach full spec compliance
> or be on par with Blink's implementation.  If you require all Chrome-supported SVG
> bells and whistles to also be available for icons, then I believe your only option is to find
> a way to use Blink's SVG renderer.

I wish Blink's SVG implementation is moved into Skia (kind of optional module) so it could be used upstream without reinventing the wheel. But I understand there are surely lots of technical obstacles.

Currently I consider Flutter for my future mobile app. It will generate complex SVG (filters, masks, text on path). I prefer declarative SVG approach over low level rendering instructions (e.g. text on path would be quite tricky). Flutter use Skia. Flutter doesn't plan to support SVG https://github.com/flutter/flutter/issues/1831 - If Skia would support SVG natively, the Flutter could change mind...

There is SVG plugin for Flutter available https://github.com/dnfield/flutter_svg, but its support is rather basic.

So currently only option in Flutter is to wait for adding the support for kind of WebView https://github.com/flutter/plugins/tree/master/packages/webview_flutter - which is now still experimental. But I expect instantiating the full html renderer is very expensive in terms of CPU/memory.

There is Skia issue related to SVG, but it seems to have low priority https://bugs.chromium.org/p/skia/issues/detail?id=5596

I am big fan of SVG, I am glad it has finally broad browser support, I am glad it is now taken seriously by web designers and even developers, so I expect the demands for SVG libraries will increase significantly in near future.

Just putting my thoughts.

Reply all
Reply to author
Forward
0 new messages