added skia

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@9338 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
mgaertner 2024-04-24 14:12:06 +00:00
parent 93167ada8b
commit efda057bcc
18 changed files with 1769 additions and 0 deletions

View File

@ -0,0 +1 @@
see https://wiki.freepascal.org/Skia

View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<Title Value="ConsoleAppSkiaFPC"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="Skia"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="ConsoleAppSkiaFPC.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="ConsoleAppSkiaFPC"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<AllowLabel Value="False"/>
</SyntaxOptions>
</Parsing>
<Linking>
<Debugging>
<DebugInfoType Value="dsDwarf2"/>
</Debugging>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,41 @@
{
Demo for a console app using the libsk4d library to create a surface, draw
on the canvas, and save the result as png file.
Note: In skia4delphi 6.1 when the library is not found it silently aborts.
}
program ConsoleAppSkiaFPC;
{$IFDEF MSWindows}
{$APPTYPE CONSOLE}
{$ENDIF}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
dynlibs { dynlibs is needed when loading dynamic lib libsk4d },
SysUtils, System.UITypes,
System.Skia;
procedure TestSkSurface;
var
LSurface: ISkSurface;
begin
// Creating a solid red image using SkSurface
LSurface := TSkSurface.MakeRaster(200, 200);
LSurface.Canvas.Clear(TAlphaColors.Red); // $FFFF0000
// create png file
LSurface.MakeImageSnapshot.EncodeToFile('test.png');
end;
begin
try
TestSkSurface;
WriteLn('Created test.png, <Enter>');
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="12"/>
<General>
<SessionStorage Value="InProjectDir"/>
<Title Value="PaintControlSkLCL"/>
<Scaled Value="True"/>
<ResourceType Value="res"/>
<UseXPManifest Value="True"/>
<XPManifest>
<DpiAware Value="True"/>
</XPManifest>
</General>
<BuildModes>
<Item Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
</RunParams>
<RequiredPackages>
<Item>
<PackageName Value="Skia.LCL"/>
</Item>
</RequiredPackages>
<Units>
<Unit>
<Filename Value="PaintControlSkLCL.lpr"/>
<IsPartOfProject Value="True"/>
</Unit>
<Unit>
<Filename Value="unit1.pas"/>
<IsPartOfProject Value="True"/>
<ComponentName Value="SkiaLCLPaintBoxDemo"/>
<HasResources Value="True"/>
<ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/>
</Unit>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target>
<Filename Value="PaintControlSkLCL"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<OtherUnitFiles Value="../../src/skia/skia4delphi"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
<Linking>
<Options>
<Win32>
<GraphicApplication Value="True"/>
</Win32>
</Options>
</Linking>
</CompilerOptions>
<Debugging>
<Exceptions>
<Item>
<Name Value="EAbort"/>
</Item>
<Item>
<Name Value="ECodetoolError"/>
</Item>
<Item>
<Name Value="EFOpenError"/>
</Item>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,29 @@
{
Demo for the LCL TSkPaintBox
}
program PaintControlSkLCL;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
{$IFDEF HASAMIGA}
athreads,
{$ENDIF}
Interfaces { this includes the LCL widgetset }
Forms,
LCL.SkiaInit { helper unit, to show an error if the libsk4d library was not found },
unit1;
{$R *.res}
begin
RequireDerivedFormResource:=True;
Application.Scaled:=True;
Application.Initialize;
Application.CreateForm(TSkiaLCLPaintBoxDemo, SkiaLCLPaintBoxDemo);
Application.Run;
end.

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

View File

@ -0,0 +1,10 @@
object SkiaLCLPaintBoxDemo: TSkiaLCLPaintBoxDemo
Left = 247
Height = 301
Top = 250
Width = 374
Caption = 'Skia LCL TSkPaintBox Demo'
OnCreate = FormCreate
OnDestroy = FormDestroy
LCLVersion = '3.99.0.0'
end

View File

@ -0,0 +1,118 @@
{
Demo for the LCL TSkPaintBox
}
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Types, Forms, Controls, Graphics, Dialogs, LCL.Skia,
System.Skia, system.UITypes;
type
{ TSkiaLCLPaintBoxDemo }
TSkiaLCLPaintBoxDemo = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
procedure OnSkPaintBoxDraw(Sender: TObject; const aCanvas: ISkCanvas;
const {%H-}aDest: TRectF; const {%H-}aOpacity: Single);
public
LogoPNG: ISkImage;
SkPaintBox: TSkPaintBox;
end;
var
SkiaLCLPaintBoxDemo: TSkiaLCLPaintBoxDemo;
implementation
{$R *.lfm}
{ TSkiaLCLPaintBoxDemo }
procedure TSkiaLCLPaintBoxDemo.FormCreate(Sender: TObject);
var
ms: TMemoryStream;
begin
SkPaintBox:=TSkPaintBox.Create(Self);
with SkPaintBox do
begin
Name:='SkPaintBox';
Align:=alClient;
OnDraw:=@OnSkPaintBoxDraw;
Parent:=Self;
end;
ms:=TMemoryStream.Create;
try
ms.LoadFromFile('powered_by.png');
ms.Position := 0;
LogoPNG := TSkImage.MakeFromEncodedStream(ms);
finally
ms.Free;
end;
end;
procedure TSkiaLCLPaintBoxDemo.FormDestroy(Sender: TObject);
begin
LogoPNG:=nil;
end;
procedure TSkiaLCLPaintBoxDemo.OnSkPaintBoxDraw(Sender: TObject;
const aCanvas: ISkCanvas; const aDest: TRectF; const aOpacity: Single);
var
SkPaint, SkPaint2: ISkPaint;
r: TRectF;
Oval: ISkRoundRect;
aPathBuilder: ISkPathBuilder;
aPath: ISkPath;
aTypeface: ISkTypeface;
aFont: ISkFont;
aTextBlob: ISkTextBlob;
begin
aCanvas.Clear(TAlphaColors.White);
SkPaint:=TSkPaint.Create(TSkPaintStyle.Stroke);
SkPaint.SetAntiAlias(true);
SkPaint.setStrokeWidth(4);
SkPaint.setColor(TAlphaColors.Red);
r:=RectF(50, 50, 90, 110);
aCanvas.DrawRect(r, SkPaint);
Oval:=TSkRoundRect.Create;
Oval.SetOval(r);
Oval.Offset(40,60);
SkPaint.setColor(TAlphaColors.Blue);
aCanvas.DrawRoundRect(Oval, SkPaint);
SkPaint.setColor(TAlphaColors.Cyan);
aCanvas.DrawCircle(180, 50, 25, SkPaint);
r.offset(80, 0);
SkPaint.setColor(TAlphaColors.Yellow);
aCanvas.DrawRoundRect(r, 10, 10, SkPaint);
aPathBuilder:=TSkPathBuilder.Create;
aPathBuilder.cubicTo(768, 0, -512, 256, 256, 256);
aPath:=aPathBuilder.Detach;
SkPaint.setColor(TAlphaColors.Lime);
aCanvas.DrawPath(aPath, SkPaint);
aCanvas.DrawImage(LogoPNG, 128, 128);
aTypeface := TSkTypeface.MakeFromName('Monospace', TSkFontStyle.Normal);
aFont := TSkFont.Create(aTypeface, 18, 1);
aFont.Edging := TSkFontEdging.AntiAlias;
SkPaint2:=TSkPaint.Create;
aTextBlob:=TSkTextBlob.MakeFromText('Hello, Skia!',aFont);
aCanvas.DrawTextBlob(aTextBlob, 50, 25, SkPaint2);
end;
end.

View File

@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<Name Value="Skia.LCL.Design"/>
<Type Value="RunAndDesignTime"/>
<Author Value="Mattias Gaertner"/>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
</SearchPaths>
</CompilerOptions>
<Description Value="IDE addon to install LCL components for Skia in Lazarus, requires FPC 3.3.1+"/>
<License Value="modified LGPL-2"/>
<Version Major="1"/>
<Files>
<Item>
<Filename Value="SkiaLCLRegister.pas"/>
<HasRegisterProc Value="True"/>
<UnitName Value="SkiaLCLRegister"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="Skia.LCL"/>
</Item>
<Item>
<PackageName Value="FCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,23 @@
unit SkiaLCLRegister;
{$mode objfpc}{$H+}
{$IF FPC_FULLVERSION<30301}
{$error requires at least fpc 3.3.1}
{$ENDIF}
interface
uses
LCL.Skia;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Skia', [TSkPaintBox]);
end;
end.

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<Name Value="Skia"/>
<Type Value="RunAndDesignTime"/>
<Author Value="Skia4Delphi Project"/>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<OtherUnitFiles Value="../../Source"/>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)/"/>
</SearchPaths>
</CompilerOptions>
<Description Value="Skia API, requires FPC 3.3.1+"/>
<License Value="BSD-style, see LICENSE file"/>
<Version Major="1"/>
<Files>
<Item>
<Filename Value="../../Source/System.Skia.API.pas"/>
<UnitName Value="System.Skia.API"/>
</Item>
<Item>
<Filename Value="../../Source/System.Skia.pas"/>
<UnitName Value="System.Skia"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="FCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit Skia;
{$warn 5023 off : no warning about unused units}
interface
uses
System.Skia.API, System.Skia, LazarusPackageIntf;
implementation
procedure Register;
begin
end;
initialization
RegisterPackage('Skia', @Register);
end.

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
{
The System.Skia.API unit loads the libsk4d library in its class constructors,
which eats any error message.
This unit logs an error via the LazLogger unit.
}
unit LCL.SkiaInit;
{$mode ObjFPC}{$H+}
interface
uses
SysUtils, LazLogger, System.Skia.API;
implementation
initialization
try
SkInitialize;
except
on E: Exception do begin
DebugLn('Failed loading skia libb: '+E.Message);
Halt(1);
end;
end;
end.

View File

@ -0,0 +1,57 @@
unit SkiaFPC;
{$mode ObjFPC}{$H+}
{$ModeSwitch advancedrecords}
interface
uses
Classes, SysUtils, Types;
type
TEpsilon = record
const
Matrix = 1E-5;
Vector = 1E-4;
Scale = 1E-4;
FontSize = 1E-2;
Position = 1E-3;
Angle = 1E-4;
end;
// System.Types
// move center of R to center of Bounds and return R
function RectCenter(var R: TRect; const Bounds: TRect): TRect;
function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
implementation
function RectCenter(var R: TRect; const Bounds: TRect): TRect;
var
d: integer;
begin
d:=(Bounds.Left+Bounds.Right - R.Left-R.Right) div 2;
inc(R.Left,d);
inc(R.Right,d);
d:=(Bounds.Top+Bounds.Bottom - R.Top-R.Bottom) div 2;
inc(R.Top,d);
inc(R.Bottom,d);
Result:=R;
end;
function RectCenter(var R: TRectF; const Bounds: TRectF): TRectF;
var
d: single;
begin
d:=(Bounds.Left+Bounds.Right - R.Left-R.Right)/2;
R.Left+=d;
R.Right+=d;
d:=(Bounds.Top+Bounds.Bottom - R.Top-R.Bottom)/2;
R.Top+=d;
R.Bottom+=d;
Result:=R;
end;
end.

View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="5">
<Name Value="Skia.LCL"/>
<Type Value="RunAndDesignTime"/>
<Author Value="Mattias Gaertner"/>
<CompilerOptions>
<Version Value="11"/>
<SearchPaths>
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
</SearchPaths>
</CompilerOptions>
<Description Value="LCL components with a skia canvas using skia4delphi, requires FPC 3.3.1+"/>
<Version Major="1"/>
<Files>
<Item>
<Filename Value="LCL.Skia.pas"/>
<UnitName Value="LCL.Skia"/>
</Item>
<Item>
<Filename Value="LCL.SkiaInit.pas"/>
<UnitName Value="LCL.SkiaInit"/>
</Item>
<Item>
<Filename Value="SkiaFPC.pas"/>
<UnitName Value="SkiaFPC"/>
</Item>
</Files>
<RequiredPkgs>
<Item>
<PackageName Value="Skia"/>
</Item>
<Item>
<PackageName Value="LCL"/>
</Item>
</RequiredPkgs>
<UsageOptions>
<UnitPath Value="$(PkgOutDir)"/>
</UsageOptions>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
</Package>
</CONFIG>

View File

@ -0,0 +1,21 @@
{ This file was automatically created by Lazarus. Do not edit!
This source is only used to compile and install the package.
}
unit Skia.LCL;
{$warn 5023 off : no warning about unused units}
interface
uses
LCL.Skia, LCL.SkiaInit, SkiaFPC, LazarusPackageIntf;
implementation
procedure Register;
begin
end;
initialization
RegisterPackage('Skia.LCL', @Register);
end.