FireMonkey Paint Canvases


While giving a session on FireMonkey architecture yesterday at EKON, we got to the subject of alternative configuration for the direct paint operations, using the GPU in different ways. To demonstrate that on different platforms the Canvas object you use for painting is different, I added to an empty FireMonkey form the following OnPaint event handler:

procedure TFormFMtoGPU.FormPaint(Sender: TObject; Canvas: TCanvas;
const ARect: TRectF);
Canvas.Fill.Color := TAlphaColorRec.Blue;
Canvas.Font.Size := Height div 3;
Canvas.FillText (
ARect, Canvas.ClassName, True,
1, [], TTextAlign.taCenter);

If you run this FireMonkey applications on different platforms, you’ll see different Canvas objects are going to be used:

on Windows, by default, you get TCanvas2D2 (for Direct2D support)
on the Mac, you get TCanvasQuartz (Quartz is the OS X GPU library)
on mobile platforms, both iOS and Android, you get a TCanvasGpu

This “GPU Canvas” is a way to send graphic commands to the GPU directly, bypassing an operating system stack which is not always very efficient. Now what it less know is that you can use the same GPU Canvas also on Windows, by forcing it with the global setting 
to True in the project source code before the application object is initialized. On Windows there is also the option of disabling DirectX and using the GDI+ fallback, generally a slower solution with much worse anti-aliasing effects. This is achieved by setting to False the global setting 
. In other words, on Windows you have 3 separate options.
For more information, you can read the following:

The session at EKON was mostly focused on styles in FireMonkey, however a developer in the audience was able to tweak the canvas and get an application working on a rather old PC, so I though it was worth sharing the tip.

Comments are closed.