Recent

Author Topic: About Skia graphics engine !  (Read 2585 times)

loaded

  • Hero Member
  • *****
  • Posts: 878
About Skia graphics engine !
« on: July 10, 2025, 01:40:08 pm »
Hi All,
I learned something today;
Skia is an open-source 2D graphics engine developed by Google, used as the foundation for platforms like Android, Chrome, and Flutter. I've heard some rumors about its compatibility with Lazarus. Is this true? 🤔
Also, if anyone has any experience with this engine and would like to share it, I'd be very grateful. 😀 Regards.
The more memory computers have, the less memory people seem to use. 😅

paweld

  • Hero Member
  • *****
  • Posts: 1613
Re: About Skia graphics engine !
« Reply #1 on: July 10, 2025, 02:23:42 pm »
Skia4Delphi works with FPC 3.3.1 - more info: https://wiki.lazarus.freepascal.org/Skia
Best regards / Pozdrawiam
paweld

DomingoGP

  • Full Member
  • ***
  • Posts: 115
Re: About Skia graphics engine !
« Reply #2 on: July 10, 2025, 10:07:17 pm »
Some time ago I was playing with skia4delphi. Making some changes I got it to compile with FPC 3.2 and render on a BGRABITMAP.

I attach the changed files and a project that works with lazarus in case someone wants to try it.
NOTE: I do not include sk4d.dll which must be in the same directory as the application.

The changes basically consist of changing the order of some type definitions and changing the references to functions by pointers to functions.


loaded

  • Hero Member
  • *****
  • Posts: 878
Re: About Skia graphics engine !
« Reply #3 on: July 11, 2025, 08:25:34 am »
paweld and DomingoGP, thank you very much for your answers.  👏
DomingoGP, I think you have experience on this subject. Thank you also for the example. By the way, what are your personal thoughts on the speed and ease of use?
« Last Edit: July 11, 2025, 08:28:03 am by loaded »
The more memory computers have, the less memory people seem to use. 😅

DomingoGP

  • Full Member
  • ***
  • Posts: 115
Re: About Skia graphics engine !
« Reply #4 on: July 11, 2025, 09:12:08 am »
I'm sorry but I have basically only used skia for this example, so I have very little experience.

I guess it is faster than BGRABitmap but I think it is more difficult to use, but these are just my assumptions.
The documentation for using it that I have found is rather sparse and I haven't gone any deeper.

loaded

  • Hero Member
  • *****
  • Posts: 878
Re: About Skia graphics engine !
« Reply #5 on: July 11, 2025, 09:50:48 am »
Brother DomingoGP, even this little bit of experience you've taken the trouble to share with me, taking your precious time, is invaluable to me. Thank you very much. 🙏
I'll handle the rest myself. Regards.🙋‍♂️
The more memory computers have, the less memory people seem to use. 😅

DomingoGP

  • Full Member
  • ***
  • Posts: 115
Re: About Skia graphics engine !
« Reply #6 on: July 11, 2025, 09:58:37 am »
You are welcome!

gues1

  • Guest
Re: About Skia graphics engine !
« Reply #7 on: July 11, 2025, 10:27:10 am »
I don't know if this can help, but you can start from here (may be there is something usefull, sure some links): https://docwiki.embarcadero.com/RADStudio/Athens/en/Skia4Delphi

Take care that all you read about it from Embarcadero was based on FMX (the multi platform framework of Delphi).

Bye

loaded

  • Hero Member
  • *****
  • Posts: 878
Re: About Skia graphics engine !
« Reply #8 on: July 11, 2025, 02:09:30 pm »
Thank you for your valuable answer, brother gues1. I think I will review this page soon. 👏
The more memory computers have, the less memory people seem to use. 😅

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: About Skia graphics engine !
« Reply #9 on: July 12, 2025, 07:58:51 pm »
I've been researching this topic myself for a while. Skia internally uses OpenGL, but working with text rendering in it can be a real headache.

My personal solution was to create an OpenGLControl on the Lazarus side and call Skia from a C++ library I built.
Surprisingly, this worked flawlessly and is fully compatible.

I don't have a minimal demo project ready for this setup, but I can provide one if anyone's interested.

I should mention that it's a bit of a hassle to maintain. However, if you compile the C++ library with `-static-libstdc++`, integration with Pascal becomes much easier.

If you're looking for a simpler yet faster alternative to LCLCanvas, Cairo might be the right choice for you. It doesn't use hardware acceleration, but I can say it's quite fast.

I can also prepare a minimal example for Cairo if you'd like.
Lazarus 4.99, FPC 3.3.1 on Fedora 42

ALLIGATOR

  • Sr. Member
  • ****
  • Posts: 414
  • I use FPC [main] 💪🐯💪
Re: About Skia graphics engine !
« Reply #10 on: July 13, 2025, 05:57:36 am »
Examples? The more, the better!
I may seem rude - please don't take it personally

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: About Skia graphics engine !
« Reply #11 on: July 13, 2025, 09:31:19 am »
Of course!

To be honest, I have a bit of a bias against Delphi components. I try to avoid them if possible. That's why I decided to go with a C++ integration approach.

First, we'll fetch the Skia source code from Git and compile it ourselves.
Create a folder and open a terminal in it.
Code: Bash  [Select][+][-]
  1. git clone https://github.com/google/skia.git --depth=1
Since I didn't want to clone the full history of the repository, I used `--depth=1`, but that's up to personal preference.

Next,
Code: Bash  [Select][+][-]
  1. cd skia
  2. python3 tools/git-sync-deps
  3.  
  4. bin/gn gen out/so --args='
  5.  is_official_build=true
  6.  is_component_build=true
  7.  skia_use_gl=true
  8.  skia_use_freetype=true
  9.  skia_use_fontconfig=true
  10.  target_os="linux"
  11.  cc="clang"
  12.  cxx="clang++"
  13.  extra_ldflags = ["-static-libstdc++", "-static-libgcc"]
  14. '
  15. ninja -C out/so
To catch any possible errors, run the commands one by one instead of using a script.

If everything went well, there should be a `libskia.so` file in the `out/so` directory.


You can extract the attached zip file and copy the `core` and `ui` folders next to the `skia` directory.
Now, the project structure will look like this:
Code: Text  [Select][+][-]
  1. LazSkiaTest
  2.   - core  // C++ side goes here
  3.   - skia  // Skia source and compiled files go here
  4.   - ui    // Pascal side that brings everything together

In `core/Pkgs/lib.skia_test/Dev/Main.cpp`, specify the path to a font file at line 91.
 
Then go into the core folder and run the following command.
This is a Make setup I personally use in my own projects — feel free to modify or use it however you like.
Code: Bash  [Select][+][-]
  1. make Build

Now, go into the `ui` folder and open the project.
It should be working at this point.

I’ve also included a screenshot in the attachment.

Good luck to everyone!
« Last Edit: July 13, 2025, 09:47:01 am by aydın »
Lazarus 4.99, FPC 3.3.1 on Fedora 42

cdbc

  • Hero Member
  • *****
  • Posts: 2782
    • http://www.cdbc.dk
Re: About Skia graphics engine !
« Reply #12 on: July 13, 2025, 10:33:57 am »
Hi
Where can I find the libskia.so if I forgot to create an 'out' directory?!?
On subsequent runs with out dir present, it just says 'Already up to date'...
Regards Benny

eta: BTW, both 'gn' and 'ninja' have prefixed 'fetch-' now...
« Last Edit: July 13, 2025, 10:35:58 am by cdbc »
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

aydın

  • Jr. Member
  • **
  • Posts: 86
Re: About Skia graphics engine !
« Reply #13 on: July 13, 2025, 12:01:45 pm »
cdbc, I didn't fully understand your issue.

The command I mentioned, `bin/gn gen`, already creates and prepares the out/so directory.
One possible error you might encounter is during 'python3 tools/git-sync-deps`. If that happens, just try running it again.

If you want to rebuild from scratch, simply delete the `out/so` directory, then run bin/gn followed by ninja.

Could you share more details about exactly which step is failing for you?
Lazarus 4.99, FPC 3.3.1 on Fedora 42

cdbc

  • Hero Member
  • *****
  • Posts: 2782
    • http://www.cdbc.dk
Re: About Skia graphics engine !
« Reply #14 on: July 13, 2025, 01:34:29 pm »
Hi
Hmmm.... Yes, deleted it all and started over -- ended up with a 1,08 Gb 'libskia.a' file and no libskia.so?!?
I daren't think of the finished size of the so...
Think I'll call it quits.
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

 

TinyPortal © 2005-2018