JetBrains / skija

Java bindings for Skia
Apache License 2.0
2.63k stars 127 forks source link

How to run skja without jogl or lwjgl? #53

Open dariodariodario opened 4 years ago

dariodariodario commented 4 years ago

Hello, i was wondering if it possible to have the examples run in desktop without the aid of lwjgl or jogl. Any other dependency free way to do that?

tonsky commented 4 years ago

Well, the trick is, you need to create a window and initialize OpenGL some way. LWJGL is a bit of overkill, in terms that it provides whole OpenGL for you, and you only need to create a context. Guys in https://github.com/jetbrains/skiko have AWT integration, but it’s not avaliable as a standalone library. Another pointer is Winit/Glutin (Rust libraries that do exactly that: Window and OpenGL context init). Hope this helps :)

dariodariodario commented 4 years ago

so is opengl a mandatory requirement to draw in a window?

tonsky commented 4 years ago

Well, Skia works best when rendering to OpenGL, Metal or Vulkan contexts. So you need one of these.

It can render to bitmap (software renderer), and in theory you can show those bitmaps any way you want, but I am not sure about the performance of this solution.

dariodariodario commented 4 years ago

Interesting so Chrome uses opengl as a backend and flutter too?

On Wed, 18 Nov 2020 at 11:33, Nikita Prokopov notifications@github.com wrote:

Well, Skia works best when rendering to OpenGL, Metal or Vulkan contexts. So you need one of these.

It can render to bitmap (software renderer), and in theory you can show those bitmaps any way you want, but I am not sure about the performance of this solution.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/JetBrains/skija/issues/53#issuecomment-729620601, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAKSZKP4VJ23UQ6UWWEDOKLSQOWHLANCNFSM4TZYYV4A .

MikOfClassX commented 4 years ago

So basically I could provide a current GL context (i.e. FBO) and let SKIJA do the rendering ?

tonsky commented 4 years ago

Interesting so Chrome uses opengl as a backend and flutter too?

Yes, as far as I know

So basically I could provide a current GL context (i.e. FBO) and let SKIJA do the rendering ?

Something like that (sorry, I am not a graphical programmer, I might mix some terms, but this is how I understand it).

See https://github.com/JetBrains/skija/blob/fa2eca0c520716a072d5107cc5ad8fcdd05aa3e5/examples/lwjgl/src/main/java/org/jetbrains/skija/examples/lwjgl/Main.java#L124

and

https://github.com/google/skia/blob/59bafeeaa7de9eb753e3778c414e01dcf013dcd8/include/core/SkSurface.h#L218-L250

Solido commented 3 years ago

Just to complete this even by using software render I need access to a graphical context. Program can be launch and rendered without window from intelliJ but will crash when launched from a console. Not sure if it possible to render from a server side which was my original goal !

tonsky commented 3 years ago

@Solido what about examples/bitmap? Does that crashes for you too?

Solido commented 3 years ago

Yes launching shadow jar from ITerm lead to

Unhandled exception Type=Segmentation error vmState=0x00040000 J9Generic_Signal_Number=00000018 Signal_Number=0000000b Error_Value=00000000 Signal_Code=00000001 Handler1=000000000A895340 Handler2=0000000006668C80 InaccessibleAddress=0000000000000000 RDI=000000000C980A00 RSI=0000000000000000 RAX=0000000000000404 RBX=0000000000000000 RCX=0000000000000410 RDX=0000000000000000 R8=0000000000000000 R9=0000000000099454 R10=00007FA11700E058 R11=00000000476D1344 R12=0000000000000000 R13=0000000000000000 R14=000000000C980A00 R15=0000000000000000 RIP=000000000A89DDE0 GS=0000 FS=0000 RSP=000070000957DE00 RFlags=0000000000010246 CS=002B RBP=000070000957DEA0 ERR=0000000000000004 TRAPNO=000000040000000E CPU=0000000000040000 FAULTVADDR=0000000000000000 XMM0 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM1 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM2 000e1781000e1781 (f: 923521.000000, d: 1.959708e-308) XMM3 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM4 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM5 0000000000170000 (f: 1507328.000000, d: 7.447190e-318) XMM6 3fc29552f81ff523 (f: 4162843904.000000, d: 1.451820e-01) XMM7 402e7f9c1e980fa9 (f: 513281952.000000, d: 1.524924e+01) XMM8 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM9 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM10 0000000000000006 (f: 6.000000, d: 2.964394e-323) XMM11 0000000000000008 (f: 8.000000, d: 3.952525e-323) XMM12 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM13 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM14 0000000000000000 (f: 0.000000, d: 0.000000e+00) XMM15 0000000000000000 (f: 0.000000, d: 0.000000e+00)