Telerik blogs

With the R3 2023 release, we added a SkiaSharp library-based implementation as an alternative to the GDI+ rendering engine. Let’s take a deeper dive.

Progress Telerik Reporting now offers a SkiaSharp-based graphics library for Linux, as of the R3 2023 release.

What is GDI+

GDI+ stands for Graphics Device Interface Plus. It is a 2D graphics programming interface and library provided by Microsoft as part of the Windows operating system. GDI+ is a successor to the original GDI (Graphics Device Interface) and offers more advanced features and capabilities for rendering 2D graphics in applications developed for the Windows platform. The services of GDI+ are exposed through a set of C++ classes.

GDI+ provides a set of APIs that allow developers to create and manipulate graphics, draw shapes, text and images, and perform various graphical operations. It is often used in Windows applications to handle tasks like drawing graphics, rendering images, and creating user interfaces. GDI+ supports features like anti-aliased rendering, alpha blending, gradient fills and various image formats.

While GDI+ has been widely used in Windows application development, it has been largely replaced by newer graphics technologies, such as Direct2D and Windows Presentation Foundation (WPF), which offer improved performance and better support for modern graphics hardware. Nevertheless, GDI+ remains a valuable tool for developers working with legacy applications and for certain types of graphics tasks in Windows programming.

What Motivated Us

From System.Drawing to System.Drawing.Common

While System.Drawing is a .NET Framework namespace that provides managed wrappers and classes for GDI+ functionality, the System.Drawing.Common was ported to be a platform independent wrapper which has been decided to bring over because of Mono’s cross-platform implementation—the native library libgdiplus.

Libgdiplus

“Since System.Drawing.Common was really designed to be a thin wrapper over Windows technologies, its cross-platform implementation is a bit like a square peg in a round hole; it’s subpar because it was only designed with Windows in mind.”
— Microsoft by Santiago Fernandez Madero

To cut a long story short, Microsoft announced they are not planning to continue with the development of the System.Drawing.Common to work on non-Windows platforms: Make System.Drawing.Common only supported on Windows.

So, our only shot was to find the best alternative.

Why (Exactly) SkiaSharp?

SkiaSharp’s cross-platform support makes it an attractive choice for developers who need to create applications that run on multiple operating systems.

As we can see from the SkiaSharp GitHub repository, SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google’s Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server, and desktop models to render images.

SkiaSharp provides cross-platform bindings for:

  • .NET Standard 1.3
  • .NET Core
  • .NET 6
  • Tizen
  • Android
  • iOS
  • tvOS
  • macOS
  • Mac Catalyst
  • WinUI 3 (Windows App SDK / Uno Platform)
  • Windows Classic Desktop (Windows.Forms / WPF)
  • Web Assembly (WASM)
  • Uno Platform (iOS / macOS / Android / WebAssembly)

Community and Support

SkiaSharp benefits from an active open-source community and has gained popularity for its cross-platform capabilities, resulting in a wealth of resources and support.

How We Did It

After the library was chosen, the entire process was separated into three main stages:

  1. Abstraction – In this stage, we designed a Telerik.Drawing.Contract class library where we created a layer of abstraction of all the System.Drawing classes/methods/properties that we use in our code base. Abstraction logic is handled by nearly 100 classes and approximately 1,200 methods. The idea was to have the option to easily change the rendering implementation when needed.

  2. GDI+ implementation – The next (maybe most important stage) was to get everything working again. We created a Telerik.Drawing.GDI class library which implements the contract abstraction by using the original System.Drawing APIs. This step should preserve the full functionality of Telerik Reporting as it was before the changes.

  3. SkiaSharp implementation – The most challenging part was to mimic all these functions to use SkiaSharp APIs and to achieve (for now—almost) the same result as it had initially.

This level of abstraction gives us the option to change and provide more rendering implementations easily if needed.

Challenges Encountered

  • SkiaSharp – Our first challenge was to get acquainted with the library’s APIs.
  • Multiline text wrapping – The SkiaSharp library does not provide out-of-the-box APIs for splitting multiline text and we decided to take advantage of a dependent library—RichTextKit.
  • Graphics – We faced several difficulties when mimicking the Graphics class related to PDF file format specifics and differences between the System.Drawing and SkiaSharp APIs.

What is Already Done

  • PDF rendering
  • HTML rendering
  • OOXML rendering (Word, Excel, PowerPoint)
  • Image rendering

With the R3 2023 release, we provided support for PDF, HTML, Image and OOXML rendering with our new SKIA engine.

What’s Ahead

We have a plan to continuously improve the already provided rendering options with (and not only) better performance and to upgrade with XAML rendering as well.

Easy Setup

With R3 2023, Telerik Reporting provided an easy-to-set-up option for changing the default graphics engine between GDI and SKIA.

The provided options are as follows:

  • PlatformDependent – The default value. On the Windows platform, the report engine will use the GDI graphics engine. On non-Windows platforms, the report engine will use the Skia graphics engine.

  • GDI – The application will use GDI graphics engine. On non-Windows platforms in applications that target .NET 7 or higher, this will cause runtime exceptions of type PlatformNotSupported to be thrown. For .NET 6 and lower frameworks, this setting will require installing libgdiplus library that handles GDI calls.

  • Skia – The application will use the Skia graphics engine through the SkiaSharp implementation. Can be used on Windows and non-Windows platforms in applications that target .NET 6 or higher framework.

The complete description can be found in the Configuring the Report Engine/GraphicsEngine help article.

SkiaSharp vs. GDI+

Performance:

  • SkiaSharp is known for its performance and is optimized for modern hardware, making it suitable for graphics-intensive applications. It uses hardware acceleration when available, which can result in improved performance.

  • GDI+ is older technology and may not offer the same level of performance as SkiaSharp, especially on newer hardware. It lacks some of the optimizations and hardware acceleration available in more modern graphics libraries.

There are still some differences and missing features that we want to bring to address:

  • Image rendering in EMF (metafile) is still not supported.
  • Font resolution – both rendering engines handle cases when the font set is not available but the solutions they provide defer and there are scenarios with different font fallbacks when comparing the result of the renderings.
  • GDI+ implementation natively supports multiline text wrapping but for now SKIA does not, and we are currently relying on an external RichTextKit library.

Here is an example of our Dashboard report exported to PDF file using both rendering options:

Conclusions

In summary, the choice between SkiaSharp and GDI+ depends on your specific requirements. SkiaSharp is a more versatile and performance-oriented choice, especially if you need cross-platform compatibility. GDI+ may still be suitable for Windows applications or when specific requirements necessitate its use (e.g., WinForms, WPF, WinUI), but it is less favored for modern graphics development on the Windows platform.

Future Initiatives

Providing our clients the ability to render their reports on various OS is a major step to another challenge—having a fully featured, cross-platform Telerik Report Server.

In 2024, our development efforts will be pointed toward migrating the Telerik Report Server to .NET 6. This includes refactoring on both client- and server-side of the web application, retargeting to a modern web framework like ASP.NET Core MVC, and allowing hosting it on web servers other than IIS (Internet Information Services). Naturally, the journey will end with reusing the Skia rendering engine in Report Server application, allowing for embedding it in cloud applications that run on different Linux distributions.

Try Telerik Reporting Yourself

Get yourself a free trial of Telerik Reporting today and start developing your apps better, faster and more easily.

Try Telerik Reporting

Share Your Feedback

Let’s continue to build the future of Telerik Reporting together! So, do not forget to share your thoughts as a comment below or let us know if you have any suggestions and/or need any features/components by visiting our Feedback Portal and Telerik Reporting Forum.


profile_pic_cropped
About the Author

Martin Velikov

Martin is a Software Engineer, part of the Document Processing team in Sofia, Bulgaria since July 2019. He is passionate about new technologies and is always on the crest of a wave with the novelties. In his spare time, Martin likes travelling to new destinations and exploring new cultures, hanging out with friends, reading books, practicing sports, and more.

Related Posts

Comments

Comments are disabled in preview mode.