Choice of Factories - EtheaDev/SVGIconImageList GitHub Wiki
SVGIconImageList provides three alternative ways of parsing and displaying SVG files:
-
Delphi Image32 (default): the new implementation, using Image32 library by Angus Johnson (FMX for Windows, Android and iOS)
-
or choose the use of SKIA4Delphi library, a cross-platform 2D graphics API based on Google's Skia Graphics Library (incomplete support)
-
Then, it's possibile to "prefer" a native Windows SVG support which is based on Direct2D, written by Kiriakos Vlahos. This is only available in Windows 10 with the Creators Update: if not present the library uses one of the first three choice (TSVG or Image32 or Cairo).
If you want to compare the three factories you can use the SVG Viewer Demo and look at the resulting rendered images by the engines:
Delphi Image32 is the most complete library that supports more features not supported into TSVG, like blur, gradient, merge, drop-shadow, markers, simbol, pattern, subpixels, so it's the default choice.
You can see the supported SVG elements and attributes supported by Direct2D here. The most notable ommission are:
-
the text element. You can work around this by converting the text elements in your SVGs to paths using software such Inkscape.
-
style sheets and the class attribute: see https://docs.microsoft.com/en-us/windows/win32/direct2d/svg-support.
This table shows the performance of the three rendering engines tested with SVGExplorer, using a significant amount of icons from different sets, rendered at 32x32 pixels.
Count | Icon set | Image32 | D2D | Skia4Delphi |
---|---|---|---|---|
997 | Font-Awesome | 1265ms | 1453ms | 1172ms |
654 | Papirus | 2750ms(1) | 937ms | 1266ms(1) |
5366 | Material-Design | 11015ms | 12001ms | 10688ms |
As you can see, the three engines perform differently depending on the icons and their complexity.
(1)Notice that Image32 and Skia4Delphi are the only engines capable of rendering blur effect (that is always slow to calculate): this is the reason of "slow" performance to render Papirus icons that contains blur effect.
Currently and if you take no action the Image32 factory is the preferred implementation, used also to build packages.
You can override the default by calling SetGlobalSVGFactory at the initialization section of any unit. For example to always use the TSVG based factory you use the statement bellow:
SetGlobalSVGFactory(GetSkiaSVGFactory);
In SVGIconImageList.inc under the Source directory you will find following conditional defines:
//Prefer Engine Direct2D by Kiriakos Vlahos
//if supported by Windows Platform (from Windows Creators update)
{.$DEFINE PreferNativeSvgSupport}
{.$DEFINE GPUSupport}
{$IFDEF PreferNativeSvgSupport}
// Throw an exception if the SVG contains text elements or class attributes
// which are not supported by Windows SVG. Since it costs some performance,
// you should only turn it on during debugging or if it's absolutely necessary.
{.$DEFINE CheckForUnsupportedSvg}
{$ENDIF}
//if PreferNativeSvgSupport not active or not available:
//use Delphi Engine from Image32 library by Angus Johnson (included into Image32 folder)
{$DEFINE Image32_SVGEngine}
//or use Engine Skia with skia4delphi wrapper by Vinícius Felipe Botelho Barbosa (included into skia4delphi folder)
{.$DEFINE Skia_SVGEngine}
If you undefine PreferNativeSvgSupport and you do not call SetGlobalSVGFactory the Image32 or Skia4Delphi factory will always be used.
GPUSupport only applies to the Direct2D factory. Is it is defined Direct2D will be using the GPU if possible. The reason is undefined by default is that with some slow GPUs it may reduce performance.