alibaba / GCanvas

A lightweight cross-platform graphics rendering engine. (超轻量的跨平台图形引擎) https://alibaba.github.io/GCanvas
Apache License 2.0
1.88k stars 208 forks source link

GCanvas doesn't work on Android #30

Closed jsommr closed 6 years ago

jsommr commented 6 years ago

I'm unable to get this library to work on Android.

One thing I've noticed is that the render function in the JNI seems to be off.

In GCanvas/GCanvas/core/src/GCanvasJNI.h

JNIEXPORT void JNICALL Java_com_taobao_gcanvas_GCanvasJNI_render(
        JNIEnv *je, jclass jc, jobject jCanvasRender, jstring contextId,
jstring renderCommands);

the render method requires 5 arguments, where the first two are automatically populated.

But in GCanvas/GCanvas/android/gcanvas_library/src/com/taobao/gcanvas/GCanvasJNI.java the method is given this signature:

public static native void render(String contextID, String renderCommands);

Calling this java-method will populate jclass jCanvasRender with String contextID and jstring contextId with String renderCommands.

Changing the java-signature to public static native void render(Object canvasRender, String contextID, String renderCommands); and passing null to canvasRender will start the parser without throwing errors, but nothing is shown on the GTextureView.

EDIT: More specifically, I'm passing this: com.taobao.gcanvas.GCanvasJNI.render(null, "123", "THello from GCanvas,50,50,0.0;"), where 123 is the GTextureView id. The command is run within an attached TextureView.SurfaceTextureListener in onSurfaceTextureAvailable. Perhaps the command is wrong...

hejian1639 commented 6 years ago

we will try to fix it in next version

DavidGOrtega commented 6 years ago
Supported operating systems are Android 4.0+ (API 14) and iOS 8.0+.

How can android 4.0+ be supported? I also found that react native bridge is incomplete to support android, only iOS.

jsommr commented 6 years ago

Having found more bugs while trying to make GCanvas work on Android, I don't think that platform have been given much care. It feels like the version bump from 0.0.1 to 1.0.0 was a bit premature since this library is still alpha.

fREEDtICE commented 6 years ago

@nerfpops Sorry for the inconvenience. The Weex version works fine and has released for more than 6 months on the production environment, it also used on Single's day. It's widely used in Taobao's App. So that's why we set the version to 1.0.0.

On the other hand, the ReactNative version is not as stable as Weex. You're right, we should not give 1.0.0 to RN version. All of these RN building issues will be fixed before next weekend, also we will update related docs.

jsommr commented 6 years ago

Thank you for your kind response. And no need to be sorry :D

I just don't understand how it could have ever worked for Android, when the JNI doesn't match with the Java signatures. I'm also getting a null reference exception somewhere I can't remember now, where Core is trying to get an OpenGL setting.

May I ask why you didn't use something like NanoVG? It supports both OpenGL ES2/3 and Metal for iOS and tries to resemble the canvas spec.

fREEDtICE commented 6 years ago

Hi @nerfpops, GCanvas ReactNative Android should be work, please check the new docs and try it. If there are any problems, please let me know.

The reason we don't use NanoVG or any other libraries is that, at the moment when this project started, we decided to make a rendering engine only also especially for the mobile platform.

Supporting Metal and Vulkan is on the schedule, we want to design a new APIs, not the Canvas APIs but more likely WebGPU APIs. Metal/Vulkan has a different hardware level design. If we make APIs compatible with Canvas APIs, it won't show its best performances.If you have any suggestions about next-generation graphics APIs, please let us know. Thanks.

fREEDtICE commented 6 years ago

Add document link: https://alibaba.github.io/GCanvas/docs/Integrate%20GCanvas%20on%20ReactNative.html

jsommr commented 6 years ago

I've only viewed the commits, since I didn't use GCanvas for React Native, but tried to build a bridge to NativeScript. The changes look great, really appreciate it! I've since switched to React Native where I use ART to render shared iOS, Android and web components in 2D.

flyskywhy commented 3 years ago

@nerfpops

Since Alibaba feat: delete weex bridge & reactive bridge, here comes the @flyskywhy/react-native-gcanvas npm package.

After months work, @flyskywhy/react-native-gcanvas runs well on Android and iOS, fix several bugs and add feat: support drawImage() from require('some.png') on Android, iOS and Web described in Changelog.md, refactor with the detailed Example As Usage in README.md.

With Performance Test Result, and Convenient With Browser-like canvas APIs with the easily <canvas/> ported example react-native-particles-bg runs on Android, iOS and Web, @flyskywhy/react-native-gcanvas is the best choice for now :yum: