Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render without Graphic Context #24

Closed
Solido opened this issue Aug 9, 2020 · 9 comments
Closed

Render without Graphic Context #24

Solido opened this issue Aug 9, 2020 · 9 comments

Comments

@Solido
Copy link
Contributor

Solido commented Aug 9, 2020

Hi Skija Team,

Thanks for the work on this lib, can't wait to see how it will integrate with yours IDE solutions.

Here are 2 questions that need some help please :

  • Is is possible to render image without any graphic context directly calling cpu | gpu ?

  • How compatible is it with Graal VM ?

Thank you !

Robert

@Solido Solido changed the title Render with Graphic Context Render without Graphic Context Aug 9, 2020
@tonsky
Copy link
Collaborator

tonsky commented Aug 9, 2020

Is is possible to render image without any graphic context directly calling cpu | gpu ?

I think you will need a CPU :) But yes, it is possible to render to an image directly.

var surface = Surface.makeRasterN32Premul(100, 100));
var canvas = surface.getCanvas();
...
byte[] pngBytes = surface.makeImageSnapshot().encodeToData().getBytes();

How compatible is it with Graal VM ?

Don’t know, but let me know if you figure it out—I’m curious too!

@Solido
Copy link
Contributor Author

Solido commented Aug 9, 2020

I'm still fighting just to get skija to work :/
But if I succeed i'll put the focus on Graal !
Thx

@tonsky
Copy link
Collaborator

tonsky commented Aug 9, 2020

Let me know if you have some specific questions. The build scripts are not the best yet, but I hope README has all the steps you need

@Solido
Copy link
Contributor Author

Solido commented Aug 11, 2020

Thank you @tonsky I gladly accept your help with the setup

Currently, under OSX, I can launch the LwjGL demo but doing it with Jogl fail with
Library libskija.dylib is not found in /

My goal is to setup a Gradle project and then directly render off-canvas using Skija and save to an image format.
So I started a new project and added

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    api "org.jetbrains.skija:skija:0.0.0-local"
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Compilation OK but a run get me to

Caught: java.lang.UnsatisfiedLinkError: 'long org.jetbrains.skija.impl.RefCnt._nGetFinalizer()'
java.lang.UnsatisfiedLinkError: 'long org.jetbrains.skija.impl.RefCnt._nGetFinalizer()'
	at org.jetbrains.skija.impl.RefCnt._nGetFinalizer(Native Method)
	at org.jetbrains.skija.impl.RefCnt.<clinit>(RefCnt.java:23)

Do I miss some setup on the launch dir so it can find a native lib ?

@tonsky
Copy link
Collaborator

tonsky commented Aug 11, 2020

You need to call Library.load() before calling any of the native methods. We might get rid of it in the future. I will look into JOGL example, probably some API changes broke it. LWJGL is always working and up-to-date

@Solido
Copy link
Contributor Author

Solido commented Aug 11, 2020

Thx !

Made some progress but calling Surface crash the program

Unhandled exception
Type=Segmentation error vmState=0x00040000
J9Generic_Signal_Number=00000018 Signal_Number=0000000b Error_Value=00000000 Signal_Code=00000001
Handler1=0000000006AA20A0 Handler2=0000000006CACC20 InaccessibleAddress=0000000000000030
RDI=0000000000000000 RSI=0000000000000001 RAX=000070000EFB8448 RBX=00007F935E867A00
RCX=0000000000000000 RDX=000070000EFB8448 R8=00007F935CE0E4F0 R9=0000000000001FF5
R10=000070000EFB8500 R11=0000000043F170A0 R12=00007F935CE0E4F0 R13=0000000000000002
R14=000070000EFB8580 R15=0000000000000001
RIP=0000000043F52D5D GS=0000 FS=0000 RSP=000070000EFB8440
RFlags=0000000000010202 CS=002B RBP=000070000EFB8510 ERR=0000003000000004
TRAPNO=000000040000000E CPU=0030000000040000 FAULTVADDR=0000000000000030
XMM0 40c0000040c00000 (f: 1086324736.000000, d: 8.192002e+03)
XMM1 c0c00000c0c00000 (f: 3233808384.000000, d: -8.192006e+03)
XMM2 4399000043990000 (f: 1134100480.000000, d: 4.503600e+17)
XMM3 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM4 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM5 0000000000000000 (f: 0.000000, d: 0.000000e+00)
XMM6 00007f935d8dc668 (f: 1569572480.000000, d: 6.930304e-310)
XMM7 000070000efb8680 (f: 251364992.000000, d: 6.084199e-310)
XMM8 0000000041040000 (f: 1090781184.000000, d: 5.389175e-315)
XMM9 d0f19ea71fda8845 (f: 534415424.000000, d: -8.356767e+81)
XMM10 5489c0e5fa14f738 (f: 4195677952.000000, d: 1.760293e+99)
XMM11 6a647391c17bfd96 (f: 3246128640.000000, d: 3.206055e+204)
XMM12 05ee5eb551679e50 (f: 1365745280.000000, d: 4.182714e-280)
XMM13 cb1c601da178138c (f: 2709001216.000000, d: -6.794571e+53)
XMM14 ec1fb990e9f1e725 (f: 3924944640.000000, d: -6.675085e+212)
XMM15 fd9a82cea5538121 (f: 2773713152.000000, d: -1.083631e+297)
Module=/Users/r/Documents/Skija/build/resources/main/libskija.dylib
Module_base_address=0000000043F13000 Symbol=_ZN8SkCanvas12onDrawPointsENS_9PointModeEmPK7SkPointRK7SkPaint
Symbol_address=0000000043F52C30
Target=2_90_20191016_371 (Mac OS X 10.15.4)
CPU=amd64 (8 logical CPUs) (0x200000000 RAM)

But I can create a Bitmap and draw.
It's just hellish to get bytes.

final bt = new Bitmap()
final width = 300
final height = 300
bt.allocN32Pixels width, height
...
 new Canvas(bt)

@tonsky
Copy link
Collaborator

tonsky commented Aug 11, 2020

Might be related: on a mac, you need to do it from the first thread. Maybe passing -XstartOnFirstThread to the JVM options might help

@Solido
Copy link
Contributor Author

Solido commented Aug 11, 2020

Thanks a lot @tonsky I got everything working now, this made my day.

The previous error came from the JDK 11 J9, I moved to JDK14 and it's faster on startup.

Here are some of my works that rely mainly on Flutter which use a limited set of Skia as Engine.
https://twitter.com/BlueAquilae

I'll try to see how I can explore more of Skia using your consequent work !

@Solido Solido closed this as completed Aug 11, 2020
@tonsky
Copy link
Collaborator

tonsky commented Aug 11, 2020

Looks dope! If you manage to build something like that in Skija, let me know — we might include it as an example (if you are interested)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants