The latest RAD Studio / C++ Builder 12 comes with Skia graphics library support for C++. Skia is an open-source graphic library that provides to support a variety of hardware and software platforms. Google sponsor the Skia project but the library available for use by anyone under the BSD Free Software License. Projects which include Skia find that it provides smooth 2D graphics that uses GPU efficiently. In this post we explain what Skia is, its features and how we can use it in C++.
Table of Contents
What is Skia in modern C++?
Skia is an open-source graphic library that provides support variety of hardware and software platforms. Google sponsor the Skia project but is available for use by anyone under the BSD Free Software License. It was originally designed for The Google Chrome web browser and ChromeOS, Android, and Flutter It was also initially adopted by Mozilla Firefox and the Firefox OS, but now it is used in a great many other products. The core components are provided by the Skia development team, but they consider and include contributions from any source.
Skia works with VCL and FMX. With FMX, you can switch to Skia as your rendering engine to significantly improve the performance of your FireMonkey applications and unlock smoother animations with a single line of code.
Embarcadero’s implementation of Skia support provides a comprehensive 2D API to render images across mobile, server, and desktop models. It is compatible with all RAD Studio frameworks (Console, FMX, and VCL) and platforms. It provides common 2D APIs by abstracting complexities in implementing low-level libraries used behind, such as OpenGL, Vulkan, DirectX, and Metal, among others, implementing optimizations and new features.
Although the basic Skia library is compatible with all frameworks, some features are unique:
What are the Skia features that can be used in a modern C++ app?
Here are some of the Skia features;
FEATURE | DETAILS |
2D draws | Shapes, paths, and texts |
SVG | Render and creation. |
Image decoders | BMP, GIF, ICO, JPG, PNG, WBMP, WEBP, and raw images. |
Image encoders | PNG, JPG, and WEBP. |
Animations player | Lottie, Telegram Stickers, animated GIFs, and animated WEBP |
Anti-aliasing | High draw quality, no jagged edges. |
Font | Font weight, families fallbacks, and custom font (without installation), ligature. |
Text | Multiple styles, max lines, line spacing, justified text, text outline, gradient, and decorations. |
Right-To-Left languages | Rendering of texts in Persian, Arabic, Hebrew, etc. |
Generation of vectorized PDF. | |
Unicode | Graphemes parser. |
Filters | Color, mask, and image filters |
Clippings | Support for many advanced clipping operations such as paths and shaders. |
Gradients | Linear, radial, sweep, and conical gradients. |
Shader | Creation of shaders to execute specific draws directly on the GPU through a single shader language (SkSL). |
Which Operating Systems are supported by Skia?
Maybe this is one of the reasons why Skia is important, it is friendly with most of popular operating systems, here are the platforms supported;
- Windows
- macOS
- iOS (including simulator)
- Android (including simulator)
- Linux (main distributions)
- FuschiaOS
- Tizen
- tvOS
- watchOS
How can we enable Skia in modern C++ Builder 12.1 RAD Studio IDE?
Skia is a new 2D render feature of RAD Studio / C++ Builder 12.1. It comes with Skia.Package.FMX, Skia.Package.RTL, Skia.Package.VCL. package libraries officially.
If you want to use Skia in your C++ Builder applications, first you need to download the latest RAD Studio / C++ Builder. Then open your project and you just need to enable Skia by right-clicking on your project in the Project window in C++ Builder. You don’t need to install any 3rd party components, after the RAD Studio 12.1 version, it is completely included in RAD Studio libraries.
This step automatically configures the links and deployments of the library binaries to the project. In addition, it adds code to the project source code.
The Skia library integration also offers some new specific native controls and components. These controls are available only if Skia is enabled and deployed to the target platform. TSkAnimatedImage
, TSkLabel
, TSkSVG
, TSkPaintBox
and TSkAnimatedPaintBox
.
How can we enable Skia in modern C++ Builder project code?
In addition to Enabling Skia as above , it is recommended to add the FMX.Skia.hpp
header to your Project.cpp
as shown below:
1 2 3 |
#include <FMX.Skia.hpp> |
and recommended to set true GlobalUseSkia
, GlobalUseVulkan
and set false GlobalUseSkiaRasterWhenAvailable
flags inyour Project.cpp
like so:
1 2 3 4 5 |
GlobalUseSkia = true; GlobalUseVulkan = true; GlobalUseSkiaRasterWhenAvailable = false; |
As an example, your Project.cpp could be something like this:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#include <fmx.h> #ifdef _WIN32 #include <tchar.h> #endif #pragma hdrstop #include <System.StartUpCopy.hpp> #include <FMX.Skia.hpp> //--------------------------------------------------------------------------- USEFORM("MyProject_Unit1.cpp", Form1); //--------------------------------------------------------------------------- extern "C" int FMXmain() { try { GlobalUseSkia = true; GlobalUseVulkan = true; GlobalUseSkiaRasterWhenAvailable = false; //GlobalUseMetal = true; //ReportMemoryLeaksOnShutdown = true; Application->Initialize(); Application->CreateForm(__classid(TForm1), &Form1); Application->Run(); } catch (Exception &exception) { Application->ShowException(&exception); } catch (...) { try { throw Exception(""); } catch (Exception &exception) { Application->ShowException(&exception); } } return 0; } |
Now you can add Skia components to your application. They can be found in Palette window in the latest C++ Builder 12.
Why Skia is an important feature in C++?
Skia looks like it has faster graphics in most of the graphical visuals, but also it is smooth and friendly with GPU. It has amazing Shaders support which means you can use every shader of your GPU to calculate each pixel, and it has Vulkan options too. It is very useful in 2D graphics but you can use it in 3D graphics too.
How can I support and follow the Skia project?
If you are good at graphics and want to improve Skia, you can follow this project from below,
If you want to know more about Skia features in RAD Studio and Delphi please read this post for details.
- Skia4Delphi – github.com/skia4delphi/skia4delphi
- Webinar – blogs.embarcadero.com/?p=140459
- Skia Documentation
- More on Shaders
- More Samples
Are there any document and more links about Skia?
If you want to see more examples, please install the latest RAD Studio / C++ Builder12.1 full or trial version and check this sample in Samples folder:C:\Users\Public\Documents\Embarcadero\Studio\23.0\Samples\CPP\Multi-Device Samples\Skia4Delphi
project. It has many examples that runs different Skia graphical examples.
C++ Builder is the easiest and fastest C and C++ compiler and IDE for building simple or professional applications on the Windows operating system. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.
Design. Code. Compile. Deploy.
Start Free Trial
Free C++Builder Community Edition