neslib / DelphiBlend2D

Blend2D for Delphi: language bindings and framework for Blend2D
zlib License
31 stars 10 forks source link

Neslib.Skia ? #2

Closed ghost closed 3 years ago

ghost commented 3 years ago

where Neslib.Skia.pas?

neslib commented 3 years ago

Neslib.Skia is a private repository (for now) and not needed to work with Blend2D. It is only used when the USE_SKIA define is set to compare performance between Skia and Blend2D.

edwinyzh commented 3 years ago

Neslib.Skia is a private repository (for now) and not needed to work with Blend2D. It is only used when the USE_SKIA define is set to compare performance between Skia and Blend2D.

May I ask with your test which is faster? Since now thanks to people who also have done amazing works like you, we have also skia4delphi, I want to know which is better (in various perspectvies).

neslib commented 3 years ago

I have attached a spreadsheet that compares the Blend2D examples to their FireMonkey (Direct2D on Windows) and Skia equivalents. It also tests multi-threaded rendering for Blend2D (up to 16 threads). Note that this spreadsheet is about 18 months old, and only tested Win64 on my own desktop PC.

Performance.xlsx

Blend2D almost always outperforms Skia in my tests. I should note though that the Skia version I used was compiled with Visual Studio, while Google suggests using Clang for better performance. Don't know what the numbers for a Clang version would be... Also, Skia also has a hardware-accelerated (OpenGL) backend, which I did not use.

Note that the FireMonkey versions are almost always fastest on my machine. That is because it used Direct2D acceleration and I have a decent graphics card. The graphical capabilities of FireMonkey are pretty limited though, and performance depends heavily on the graphics card, and is pretty bad on non-Windows platforms.

I personally use Skia professionally, but only because Blend2D is still in beta and not supported on all platforms yet. I am not a fan of Skia. It is a nightmare to build, bloated, has too many dependencies and I don't like the API very much. But it has more features than Blend2D (although I really don't need those additional features myself). I prefer for Blend2D to stay lean and only focus on 2D vector drawing features.

edwinyzh commented 3 years ago

Thanks neslib for the very detailed insightful comments on the performance comparison of the various 2D graphical libs!

paulocesarbot commented 2 years ago

Hey my friend… I found the discussion very interesting. Blend2D looks very promising!

I'm one of the authors of Skia4Delphi, the compilation used is with clang, you can test with it if you need.

We are making examples of it using OpenGL, Metal on iOS / macOS as hardware accelerator.

Anyway, your codes are amazing, I'm a big fan.

Best regards,

neslib commented 2 years ago

@paulocesarbot I saw your Skia library a while back, but haven't look at it yet. It looks very interesting. Maybe I'll use that one instead of my wrapper so we can have an "official" comparison between Skia and Blend2D!

Is your library based on the official Skia C wrapper, or the more complete C wrapper that ships with SkiaSharp? (Mine is based on the SkiaSharp one).

paulocesarbot commented 2 years ago

@neslib we rewrite the entire FlatAPI.

https://github.com/google/skia/compare/chrome/m88...viniciusfbb:main

To maintain compatibility with older versions of the library, SkiaSharp doesn't have several functions, and none of the exposed modules, so we rewrote from 0.

Example: The amazing SkParagraph, or Skia's own SVG module, or SkShaper (they directly use harfbuzz in a separate library).

To compile icudata statically on Windows (as it is on other platforms), we had to make some changes there and then.

I agree that it's a bit boring to compile, but thinking about it, and in the developer, we did this:

https://github.com/viniciusfbb/skia4delphi/blob/main/Documents/BUILD.md

Now we're working on a subclass of TCanvas, implementing the GPU and Skia to use it, which optionally can be registered (some boolean like GlobalUseMetal), to use it as a backend.

The initial bankmark is amazing. Being able to load SVGs, Lotties, write RTL text, using the GPU, and have so many drawing and effects options doing a cast and using Skia's Canvas, can be a game changer for FMX.

Currently, to achieve maximum quality we have to add many images in different resolutions, and increase a lot the size of app.

Now, we can do this with SVG, Lottie…

Optionally we can draw on background thread using raster (without canvas global locks)… FMX has a several global locks for several reasons, context is not thread-safe, GPU helper is not either.

We can do a lot of things.

I love your work. I want really met you someday. !

Best regards,

paulocesarbot commented 2 years ago

We do not use your method using managed records because of backward compatibility.

Few properties, I remember at the moment, just SkCanvas, every time you use it, it creates a new interface. I thought about putting a holder, since the class doesn't change until the surface is destroyed, the same happens with SkPDFDocument.

Let’s see…

It is always possible to improve.

Another detail is that we started using the latest version of Skia, but it undergoes changes almost daily, and to maintain it is very difficult.

Following the SkiaSharp method we use the last stable inactive Milestone, which is now 89, we will update.

neslib commented 2 years ago

@paulocesarbot This is all very impressive. I was waiting for SkiaSharp to wrap SkParagraph since it can solve some inconsistent shaping/Right-To-Left support in FireMonkey. I am not a big fan of including the ICU databases though, since they are huge.

I started my own text rendering/shaping library a while back that is independent from the rendering backend. It also uses HarfBuzz for shaping, but some lighter-weight libraries for RTL and line breaking (instead of ICU). It is somewhat base on RichTextKit (which uses SkiaSharp as a rendering backend). That project is on hold for now however. Maybe your SkParagraph wrapper provides a good alternative.

In will definitely check it out and probably use it here to compare against Blend2D. I love that you are supporting all current platforms supported by Delphi. One question though: have you also considered making static libraries for Android and macOS. I generally prefer those over dynamic libraries...

paulocesarbot commented 2 years ago

Thank you very much! It’s really important to us, be recognized by someone so good, we are still apprentices.

Regarding linking, I actually thought about it. It's not difficult to do static linking on Android / macOS. The biggest issue is on Windows, although it's easier since XE2 as COFF objects can be used, it's still difficult because it's C++, it involves extracting objects with mangling names, a lot of work, and maybe not the top priority right now.

Our priority right now is the GPU, getting us to draw using the GPU. We could make an easier integration if the Emb allowed change a few things. Because Skia changes context states of OpenGL, the best it’s create one shared context, if inside the drawing I call a FMX function that calls .Valid the current context changes, so it’s dungerous….

We're going the bigger but cleaner way: create a TCanvas descendant class and the developer optionally registers it as the default.

SkParagraph allows you to create paragraphs with maximum number of lines, maximum width, multiple styles. I have a sentence with some words in bold, for example. Skia's own

SkShaper, as we used it, allows you to render RTL texts, using ICU/Harfbuzz. I don't like using the icu data, after all, it's 10mb, but it's the best option at the moment. It's a lot of work for two people.

It supports all Delphi platforms, and is configured with the minimal version as well. Only macOS ARM that started good macOS 11, and Delphi supports it from there.

Well, we are only two children, trying make a good work…

When you’ve time send your contact… Telegram or Skype, will be a pleasure trade experiences with you

best regards!

paulocesarbot commented 2 years ago

Not to mention that we still have SVG, Lotties, WebP, thousands of effects and drawing resources. I'm sure it will give an up for Firemonkey.

neslib commented 2 years ago

@paulocesarbot Sorry for the late response. I'm usually very busy during the week. The best way to reach me is through old-fashioned email (erik-at-bilsen-dot-com). We can then schedule Skype sessions.

I know it is a lot of work to keep the wrapper up-to-date. That's one of the reasons I haven't published my Skia wrapper. And now I don't have to anymore since it seems you guys are doing an excellent job! (From what I have seen so far. I haven't had a chance to test it out myself yet).

So keep it up. A full-featured Skia canvas for FireMonkey could be a game changer...

neslib commented 2 years ago

@paulocesarbot Quick question: I would like to conditionally use Skia4Delphi in the benchmark project. Probably with a conditional define and custom configuration. Is it possible to use S4D conditionally in a project?

I ask because I see you need to explicitly enable Skia support using an IDE menu option. What does this option do? Does it just add deployment files? If that is the case, then I could just add those deployment files to a custom configuration, so the benchmark can still be compiled without Skia support.

paulocesarbot commented 2 years ago

Hello @neslib! Sorry, I hadn't seen your message before.

The "Enable Skia" button in IDE menu options is just for configurate the deploy files. You can use the library without it and configuring the deployment manually. On windows, in addition to configuring the deployment (for remote builds), it automatically copies the dll to the project's .exe directory during builds.