Sign in Join
Wiki copytemporary

Skia

Overview

Skiais an open source cross platform 2D graphics library used for example by Chrome and Firefox.

The skia4delphiproject provides shared and static libraries and Pascal units to access Skia with FPC and Delphi.

In lazarus-ccr there are Lazarus packages and LCL components.

Setup

Requirements

Download sk4d dynamic library

The sk4d dynamic library is provided by the skia4delphi project. Their installer is for Windows Delphi users. For Lazarus download the sources or clone the git:

  1. Go to https://github.com/skia4delphi/skia4delphi/releases
  2. Download the Source code (zip)
  3. Unpack the skia4delphi-6.1.0.zip
  4. You will find the sk4d library in Binary/Shared/YourPlatform

Your project must be able to find the library:

text
bash: export LD_LIBRARY_PATH=/home/user/skia4delphi-6.1.0/Binary/Shared/Linux64/

Download the Lazarus packages

Download lazarus-ccr via svn:

text
svn checkout https://svn.code.sf.net/p/lazarus-ccr/svn/ lazarus-ccr-svn

The skia files are in the directory lazarus-ccr-svn/components/skia .

There are three Lazarus packages:

Install Skia.LCL.Design

This is optional.

Requirements:

Install the package Skia.LCL.Design.lpk in the IDE:

You will find a new page Skia in the component palette.

TSkPaintBox

This is a TGraphicControl - a lcl control without its own handle. Useful if you just want to draw something with skia. Set the OnDraw event

pascal
procedure TForm1.FormCreate(Sender: TObject);
begin
  MySkPaintBox:=TSkPaintBox.Create(Self);
  with MySkPaintBox do begin
    Name:='MySkPaintBox';
    OnDraw:=@MySkPaintBoxDraw;
    SetBounds(10,10,50,50);
    Parent:=Self;
  end;
end;

procedure TForm1.MySkPaintBoxDraw(Sender: TObject; const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single);
begin
  aCanvas.Clear(TAlphaColors.Red);
end;

Note: the Opacity is not yet supported.

TSkCustomWinControl

This is TCustomControl - a lcl base class for custom controls with own handle and scrollbars. Override the DrawContent and Invalidate methods:

pascal
type
  TMySkiaControl = class(TSkCustomWinControl)
  public
    procedure DrawContent(const ACanvas: ISkCanvas; const {%H-}ADest: TRectF;
      const AOpacity: Single); override;
    procedure Invalidate; override;
  end;
...

procedure TMySkiaControl.DrawContent(const ACanvas: ISkCanvas; const ADest: TRectF; const AOpacity: Single);
begin
  // your drawing code
  aCanvas.Clear(TAlphaColors.White);
end;

procedure TMySkiaControl.Invalidate;
begin
  inherited Invalidate;
  Render.Redraw; // force a redraw
end;

Note: the Opacity is not yet supported.


From the Free Pascal wiki, page "Skia", as it stood on 2024-04-26 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.