Jump to content
vfbb

ANN: Skia4Delphi v3.4.0

Recommended Posts

github-social-preview.thumb.png.c133051d6f734675598ba501a7d5f867.png

 

 

v3.4.0

 

 

  • Added StrokeColor property to TSkLabel;
  • Added LetterSpacing property to TSkLabel;
  • Added automatically Skia to uses when use controls in form;
  • Added EncodedImageFormat property and MakeFromStream to SkCodec;
  • Added MakeRawShader to SkImage;
  • Added MakeImage to SkRuntimeEffects;
  • Exposed DirectContext in TGrCanvasCustom class to run code on the GPU more easily;
  • Fixed BackgroundColor property of TSkLabel;
  • Fixed issue loading bitmaps from stream when using Skia in Vcl project;
  • Fixed build script with python3 as default;
  • Minor improvements and fixes.

 

 

 

New StrokeColor property of TSkLabel

 

TSkLabel.thumb.png.f7e97774b9c560bc51c80e24435e264c.png

 

 

Github: github.com/skia4delphi/skia4delphi

Website: skia4delphi.org

 

  • Like 7
  • Thanks 1

Share this post


Link to post

@vfbb

Great, getting better with every build :classic_cheerleader:

 

Could you please clarify some basic internals, since I haven't looked into this too much ?

FMX has the drawback that it repaints the whole screen, even when only a small fraction of the screen has changed.

How is the screen painting handled in Skia controls ?

Is the control handled by Skia external library, or does it still behave like the original FMX ?

 

Maybe Skia completely replaced the FMX rendering engine, and is optimized after that for the whole FMX controls, or

the Skia rendering engine is used for their controls only, which leads to optimized drawing performance only for these controls, or

Skia can not optimize the general FMX behaviour, but it can optimize within FMX's limits.

 

Edited by Rollo62

Share this post


Link to post

@Rollo62 The replacement of the FMX graphic engine by Ski4Delphi graphic engine (which is done just by adding the line "GlobalUseSkia := True;" in the dpr), affects all the drawings in your app, whether the screen controls or drawings in TBitmaps. So even delphi controls like TRectangle, TCircle, and all others (even third-party controls) are now rendered on screen by the Skia-based Canvas. Everything is done automatically internally. With this, your entire application will automatically gain:

 

- Performance (up to 50%)
- Quality in drawings (everything is rendered with antialiasing, and maximum quality, producing smooth curves, no jagged edges)
- Fidelity (there are dozens of bugs in the FMX render that do not occur with Canvas based on Skia, mainly involving Metal)
- And other advantages

 

  • Like 3
  • Thanks 4

Share this post


Link to post
3 hours ago, Rollo62 said:

@vfbb

Great, getting better with every build :classic_cheerleader:

 

Could you please clarify some basic internals, since I haven't looked into this too much ?

FMX has the drawback that it repaints the whole screen, even when only a small fraction of the screen has changed.

How is the screen painting handled in Skia controls ?

Is the control handled by Skia external library, or does it still behave like the original FMX ?

 

Maybe Skia completely replaced the FMX rendering engine, and is optimized after that for the whole FMX controls, or

the Skia rendering engine is used for their controls only, which leads to optimized drawing performance only for these controls, or

Skia can not optimize the general FMX behaviour, but it can optimize within FMX's limits.

 

Well, original FMX canvases are very different depending on the platform. While for Android FMX repaints the whole screen, on Windows FMX only repaints the parts that need to be redrawn. In addition to what Vinicius answered, Skia4Delphi is indeed faster on most platforms, especially Android and has a lot of other advantages. But to answer your question, no, Skia4Delphi renders all controls even if only a small fraction has changed. I myself had the same question, and was thinking that it would be more efficient to only render the parts that have changed, but appraently Vinicius and his brother have done some tests and this was not the case. Implementing "dirty region" repainting within the FMX painting framework is not a trivial task - I have looked into it myself, and have abandoded this project for myself (or postponed at least).

Edited by M.Joos
  • Like 1

Share this post


Link to post

Hi Team,

I build exclusively Win 32bit Apps.  Primarily database Apps with support utilities.  Nothing fancy, no whizz-bang graphics etc.  My Customers are still mired in Win 7 OS & Hardware.

They access their apps via their local LAN, RDP into a Win 2012 Server and the web into the same Server via Cybele's ThinFinity.

The only 'Graphics' involved, aside from the nor Icons, are the saving/showing of images of equipment, currently in .jpg format.

Whilst I am intrigued by Skia4Delphi, I am curious if incorporating it in my Apps would provide any benefit to/for the end Users?

 

Regards & TIA,

Ian

Edited by Ian Branch

Share this post


Link to post
10 hours ago, Ian Branch said:

I am curious if incorporating it in my Apps would provide any benefit to/for the end Users?

No. Any custom graphics just confuse users of business apps. Moreover, it will burden remote channels with no real benefit

  • Like 1

Share this post


Link to post
19 hours ago, Rollo62 said:

FMX has the drawback that it repaints the whole screen, even when only a small fraction of the screen has changed.

How is the screen painting handled in Skia controls ?

Is the control handled by Skia external library, or does it still behave like the original FMX ?

Yes, we repaint the entire screen with every render.

 

Unfortunately FMX is right. To repaint only modified controls, we would have to have a layering system, basically a bitmap for each control containing the control draw cached. It would be a very high speed drawing system, because drawing bitmaps on the screen (without strech), is an almost instantaneous operation. However, there is an insurmountable problem with this solution: memory consumption. Bitmaps consume a lot of memory, if each control has its own, you will quickly have a memory overflow. In addition you will have other problems, such as controls that are larger than the MaxSize of the bitmap accepted on the device (such as scrollbox). On a device with infinite memory this would be the best option, but it is not the case.

 

There is another option, which FMX even implemented, which is to "filter" all controls that were changed through the region that was changed, repainting only them and with ClipRect on the changed region (it does this for Canvas that have the flag TCanvasStyle.SupportClipRects). Intuitively, this seemed like a great solution, but in practice it surprisingly turned out to be slightly worse. This is probably why FMX also disabled this option on non-Windows platforms.

Edited by vfbb

Share this post


Link to post

Thanks for the insights, this is what I expected too.

There was a TScene "demo"  from Eugene which pointed maybe in the same direction, this library I checked out some years ago, but never implemented into my current apps yet because the advantage was not so big for me.

Maybe that could be more relevant with Skia now, or is this already obsolete technology ?

 

If Skia is able to perform so well and stable, I will give it a try soon, probably beyond just testing.

My biggest concern is if such system is resilient and production stable now, or rather might break in the next OS or IDE updates.

I see you'r updating very eager, and it seems well supported, so thats a very good sign.

FMX is not really stable for me, and tend to behave different in every version.

If Skia is an approach to make FMX more stable, I'm jumping on that train very likely, but if Skia is adding another dimension of new failure modes, I will probably will make more tests.

 

  • Like 1

Share this post


Link to post
7 minutes ago, Rollo62 said:

m jumping on that train very likely, but if Skia is adding another dimension of new failure modes, I will probably will make more tests.

 

Unlike fmx Skia is developed by Google. They have more resources and ..... (I cannot write here that unlike Embarcadero most probably they will keep it stable).

  • Like 1

Share this post


Link to post

@Rollo62 Eugene's idea (creator of FMX) is great. He creates regions with cached drawings, through his control, then it is the programmer who has to define where he will cache the drawings, and have moderation about it. Unfortunately I had some issues mainly with updating the drawings of some controls inside it, so I never used it in production.

 

I'm very conservative when I think about third-party libraries. Some libs also partially solve the FMX performance problem, but they leave you hostage, since you have to change all your codes, use their controls, etc. This is the main difference, you implement Skia in your app changing only 1 line in dpr. The day you want to remove the library, just remove the line...

 

About updates and development stage, we still don't have the best code design and there's still a lot to optimize, a lot, such as: using Vulkan on Android and Windows 10+, and using hardware acceleration in drawings inside bitmaps, etc. But one thing I can say, it's very stable, it's no wonder that today we have 0 issues.

  • Like 1
  • Thanks 2

Share this post


Link to post
1 hour ago, Lajos Juhász said:

 

Unlike fmx Skia is developed by Google. They have more resources and ..... (I cannot write here that unlike Embarcadero most probably they will keep it stable).

Well... Google has a tendency to scrap even well used projects out of the blue. And just because something is being developed by Google doesn't make it a great thing...I feel quite contrarily, but maybe I just hate ads a bit more than others.

Share this post


Link to post
1 hour ago, Lajos Juhász said:

Unlike fmx Skia is developed by Google. They have more resources and ..... (I cannot write here that unlike Embarcadero most probably they will keep it stable).

Yes, thats true, but also my biggest concern.

Google is lightyears ahead, and Embarcadero needs to follow Google, Apple, Microsoft, and whatsnot.

This is clearly an unfair game 🙂

 

58 minutes ago, vfbb said:

I'm very conservative when I think about third-party libraries. Some libs also partially solve the FMX performance problem, but they leave you hostage, since you have to change all your codes, use their controls, etc. This is the main difference, you implement Skia in your app changing only 1 line in dpr. The day you want to remove the library, just remove the line...

Thanks, I was not aware of that fact.

That make is much more easy to just move to Skia, without too much rewrite of existing code.

This makes is more easy to join and to use and improve it, you should make this fact more clear since this could ease the decisions.

 

58 minutes ago, vfbb said:

About updates and development stage, we still don't have the best code design and there's still a lot to optimize, a lot, such as: using Vulkan on Android and Windows 10+, and using hardware acceleration in drawings inside bitmaps, etc. But one thing I can say, it's very stable, it's no wonder that today we have 0 issues.

If it only would concern sourcecode, I would be relaxed, but since Skia also involved external libraries as a binary base, there is a lot more risk of using it.

Easily it might break iOS, Macos, Android and even Windows, when running out of sync in new IDE, XCode, SDK versions or OS versions.

Again, very good to know about the simple Skia on/off switch behaviour, so that I still can check FMX and Skia behaviour in parallel.

You could not advertise this fact big enough :classic_biggrin:

 

 

Share this post


Link to post
21 minutes ago, Sherlock said:

Well... Google has a tendency to scrap even well used projects out of the blue. And just because something is being developed by Google doesn't make it a great thing...I feel quite contrarily, but maybe I just hate ads a bit more than others.

Good point, but IMHO Skia is just in the early phase of rocketing launch into many projects.

I would assume this may stay quite some time very active, the more people get aware of this nice library.

 

Edit:

References  References References

Quote

The library is used as of 2021 in Google Chrome, Chrome OS, Chromium OS, Mozilla Firefox, Mozilla Thunderbird, Android, Firefox OS, LibreOffice (from version 7.0), Flutter and Avalonia (from Alpha 4).

The Skia library is also present on the BlackBerry PlayBook, though the extent of its usage is unclear.

 

...

 

The Skia Graphics Engine or Skia is an open-source 2D graphics library written in C++. Skia abstracts away platform-specific graphics API (which differ from one to another).[1] Skia Inc. originally developed the library; Google acquired it in 2005,[2] and then released the software as open source licensed under the New BSD free software license in 2008.

 

Edited by Rollo62
  • Like 1

Share this post


Link to post

Hi,
It worked as expected on Android, but I can't test on Ubuntu :classic_blush:
I first have a problem of a lacking package I think it was zlib1g-dev, I install this one. 

But, if now I can deploy my project or the demo the program don't run. What did I miss ? Is there any doc/help for a "good" deployment ? 

Share this post


Link to post

Has anybody tried to do printing of an control ?

 

The TextLayout is bound to TSkCanvasCustom for display but the printing goes to GDI+ canvas,

which custom TextLayout knows nothing about. As a result all text is missing in the printout.

Share this post


Link to post

A second question about printing:

 

Skia has an example of rendering to a PDF canvas, but this canvas is of a  TskCanvas  class

and thus not compatible with FMX adapter class TSkCanvasCustom  (which uses TskCanvas internally).

Is there an easy way to create TSkCanvasCustom from a given TskCanvas instance?

Share this post


Link to post
11 minutes ago, everybyte2 said:

A second question about printing:

 

Skia has an example of rendering to a PDF canvas, but this canvas is of a  TskCanvas  class

and thus not compatible with FMX adapter class TSkCanvasCustom  (which uses TskCanvas internally).

Is there an easy way to create TSkCanvasCustom from a given TskCanvas instance?

You cannot convert SkCustomCanvas <> SkCanvas. However, you can transform bitmaps into ISkImage (via TBitmap.ToSkImage) and paint it in ISkCanvas of the PDF. That way you can do anything, for example, paint controls on a TBitmap, convert that TBitmap to ISkImage, and then paint that ISkImage onto the PDF's ISkCanvas.

 

20 minutes ago, everybyte2 said:

Has anybody tried to do printing of an control ?

 

The TextLayout is bound to TSkCanvasCustom for display but the printing goes to GDI+ canvas,

which custom TextLayout knows nothing about. As a result all text is missing in the printout.

Printing is an untested area in our project, so it's possibly an issue. It would really help if you opened an issue on the GitHub page with a project that simulates the problem.

https://github.com/skia4delphi/skia4delphi/issues

Share this post


Link to post

Thanks for a quick reply!

 

The problem of rendering to a different canvas (rather than default) is an FMX problem, not Skia problem.

The TTextLayout derivative is bound to the default canvas when created and knows nothing about some other canvas type.

 

I created a workaround which works on Windows, other platforms are untested:

 

type
  TTextLayoutX = class(TTextLayout);

procedure TSkTextLayout.DoDrawLayout(const ACanvas: TCanvas);
var
  layoutClass: TTextLayoutClass;
  layout: TTextlayout;
begin
  if (ACanvas is TSkCanvasCustom) and Assigned(TSkCanvasCustom(ACanvas).Surface) then
    DoDrawLayout(TSkCanvasCustom(ACanvas).Surface.Canvas)
  else begin                                                                    //
{$REGION 'A-Dato workaround for printing (on GDI+)'}
    layoutClass := TTextLayoutManager.TextLayoutByCanvas(ACanvas.ClassType);
    if (layoutClass <> nil) then begin
      layout := layoutClass.Create;
      layout.TopLeft := TopLeft;
      layout.MaxSize := MaxSize;
      layout.Text := Text;
      layout.Padding := Padding;
      layout.WordWrap := WordWrap;
      layout.HorizontalAlign := HorizontalAlign;
      layout.VerticalAlign := VerticalAlign;
      //layout.VerticalAlign := TTextAlign.Trailing;    //too low
      layout.Color := Color;
      layout.Font := Font;
      layout.Opacity := Opacity;
      layout.RightToLeft := RightToLeft;
      TTextLayoutX(layout).DoDrawLayout(ACanvas);
    end;
{$ENDREGION}
  end;
end;

 

Share this post


Link to post
On 5/2/2022 at 5:33 AM, Serge_G said:

Hi,
It worked as expected on Android, but I can't test on Ubuntu :classic_blush:
I first have a problem of a lacking package I think it was zlib1g-dev, I install this one. 

But, if now I can deploy my project or the demo the program don't run. What did I miss ? Is there any doc/help for a "good" deployment ? 

What is your Ubuntu version? The packages needed to run on Ubuntu are the same for FMXLinux, if you can run a blank fmx app on your Ubuntu, you will be able to run our demo.

 

@Edit

Note: The Linux version of skia4delphi works only in RAD Studio 11.

Edited by vfbb

Share this post


Link to post

Hi,

Freanch Delphi Entreprise 11.1 (patch 1 now)  and Ubuntu 18.04 is my target.

19 hours ago, vfbb said:

if you can run a blank fmx app on your Ubuntu,

Well, it's not a blank one (only a SkiaLabel added), I'll investigate further  for this  zlib1g-dev  and test a blank project in debug mode.

 

Thanks

 

  • Like 1

Share this post


Link to post
11 hours ago, Serge_G said:

Hi,

Freanch Delphi Entreprise 11.1 (patch 1 now)  and Ubuntu 18.04 is my target.

Well, it's not a blank one (only a SkiaLabel added), I'll investigate further  for this  zlib1g-dev  and test a blank project in debug mode.

 

Thanks

 

Hi, 

On my side that it works nice under ubuntu 20.04TLS. (on a VM !) - I remove completely older version of skia (I had trouble on linux side (different than yours @Serge_G - lib load issue - But origin is on my side, I make mess 😉)),

-> I  just done the update via getit in 3.40, and Skia4Delphi demo app work nice ! 

@vfbb : very very nice work ! 
 

Edited by Vincent Gsell
link fail
  • Like 1
  • Thanks 1

Share this post


Link to post

Hi Vincent, 

Well I test with WSL and a full Ubuntu PC but always with 18.04,

12 hours ago, Vincent Gsell said:

I had trouble on linux side - lib load issue

Have this one now !

 

12 hours ago, Vincent Gsell said:

I remove completely older version of skia

I  just done the update via getit in 3.40

I use the GitHub SKIA version installer (not the getit one).

 

OK so, next step for me : installing Ubuntu 20.04 (it's time 😉)  first on my WSL.

  • Like 1

Share this post


Link to post

Installed fine (Windows 10) and worked fine in first project test. When I try a second project, I keep getting "skia library could not be loaded". These are tiny one-unit test projects.

 

Anyone have any idea what I'm overlooking? Thx.

Share this post


Link to post
29 minutes ago, domus said:

Anyone have any idea what I'm overlooking? Thx.

A basic debugging or search in source code would be enough to find an answer. The application was unable to load the skia library - sk4d.dll.

  • Like 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×