how can I render on Android view from NDK, which linked myself builded skia lib?

392 views
Skip to first unread message

陈国栋

unread,
Mar 22, 2017, 4:29:36 AM3/22/17
to skia-discuss
I find that skia is not stable on Android system.  It may have different api or interface on different version system.

So I build myself skia,  But How can use myself skia render the Android View ?

event on iOS I have the same question.

Derek Sollenberger

unread,
Mar 22, 2017, 1:41:54 PM3/22/17
to skia-discuss
You are right that the copy of libskia.so found on Android is not ABI stable as is intended for use only by the OS.  If you statically (or dynamically) link Skia into your individual app you can render to an Android View a couple of different ways.  The easiest way is to use a SurfaceView which you can turn into an ANativeWindow in the C++ code and use to either lockPixels (for CPU access) or create an FBO (for GPU access).  The viewer application checked into our repository is an example of how you can do either of those approaches.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.
Message has been deleted

陈国栋

unread,
Mar 23, 2017, 5:25:29 AM3/23/17
to skia-discuss
Yes I find the way on IOS, But I Donot How to draw on iOS,

在 2017年3月23日星期四 UTC+8上午1:41:54,Derek写道:

Derek Sollenberger

unread,
Mar 23, 2017, 8:21:30 AM3/23/17
to skia-d...@googlegroups.com
The viewer application uses a combination of C++ and Java and it does use the Android View system to interleave drawing with standard Android Views and a custom Skia View.  The custom Skia view is implemented using a SurfaceView which inherits from android.view.View.  See the following file that shows how we inflate the view from XML (i.e. findViewById) and add the appropriate callbacks to our java class to manage the lifecycle of the surface (i.e. getHolder().addCallback).

https://github.com/google/skia/blob/fcee51038aeaf3596a4ffcdba0bf18e3155e09b9/platform_tools/android/apps/viewer/src/main/java/org/skia/viewer/ViewerActivity.java#L76


On Thu, Mar 23, 2017 at 3:19 AM 陈国栋 <halbe...@gmail.com> wrote:
Tanks! Yes the viewer application is absolute using cpp, But I want to provide a Android view which is inherit the Android.View, So How can I draw on this view with myself skia lib.

在 2017年3月23日星期四 UTC+8上午1:41:54,Derek写道:
You are right that the copy of libskia.so found on Android is not ABI stable as is intended for use only by the OS.  If you statically (or dynamically) link Skia into your individual app you can render to an Android View a couple of different ways.  The easiest way is to use a SurfaceView which you can turn into an ANativeWindow in the C++ code and use to either lockPixels (for CPU access) or create an FBO (for GPU access).  The viewer application checked into our repository is an example of how you can do either of those approaches.

陈国栋

unread,
Mar 23, 2017, 8:31:38 AM3/23/17
to skia-d...@googlegroups.com
Yes  thanks. I have known. Now  I  must find this  way to render on  iOS.   Thanks very much 
'Derek Sollenberger' via skia-discuss <skia-d...@googlegroups.com>于2017年3月23日 周四下午8:21写道:
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/0Sxv8XqL5cE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.

Jelly Chen

unread,
Mar 24, 2017, 5:10:49 AM3/24/17
to skia-discuss

I hava success use Surface and render with skia use CPU raster.  But it is quite slow, So I want to how to raster with GPU, Can you let me some sample code.

the code of skia viewer with "GLWindowContext_android" is so complex.

在 2017年3月23日星期四 UTC+8下午8:21:30,Derek写道:

Derek Sollenberger

unread,
Mar 24, 2017, 11:38:07 AM3/24/17
to skia-discuss
Unfortunately, there are additional complexities to setting up a GPU surface that are beyond the scope of Skia.  
  • The GLWindowContext_android.cpp is how our tools interact with Android and EGL to setup the GLContext and make it current.  
  • The next step is not Android specific so it is not in that file, which stops after making the GL context current.  We then take the current context and create the Skia wrapper around that context in GLWindowContext::initializeContext().

陈国栋

unread,
Mar 24, 2017, 11:49:05 AM3/24/17
to skia-d...@googlegroups.com
If  it  can  use in android NDK. Render on  ANativeWindow from surface?
'Derek Sollenberger' via skia-discuss <skia-d...@googlegroups.com>于2017年3月24日 周五下午11:38写道:
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/0Sxv8XqL5cE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.

Derek Sollenberger

unread,
Mar 24, 2017, 11:54:53 AM3/24/17
to skia-d...@googlegroups.com
The conversion between surface and ANativeWindow is in the NDK and can be found here.

陈国栋

unread,
Mar 24, 2017, 12:02:15 PM3/24/17
to skia-d...@googlegroups.com
But I find ANativeWindow_lock take more than 12ms?  It is  performance so bad?
'Derek Sollenberger' via skia-discuss <skia-d...@googlegroups.com>于2017年3月24日 周五下午11:54写道:

陈国栋

unread,
Mar 24, 2017, 12:06:14 PM3/24/17
to skia-d...@googlegroups.com
Yes I know how to get  ANativeWindow from surfaceView.  But I use skia render on it without GPU accelerate is so slow. How can I confige opengl backened? 
'Derek Sollenberger' via skia-discuss <skia-d...@googlegroups.com>于2017年3月24日 周五下午11:54写道:

Jelly Chen

unread,
Mar 25, 2017, 11:57:07 AM3/25/17
to skia-discuss
How can I create an FBO from ANativeWindow?


在 2017年3月23日星期四 UTC+8上午1:41:54,Derek写道:
You are right that the copy of libskia.so found on Android is not ABI stable as is intended for use only by the OS.  If you statically (or dynamically) link Skia into your individual app you can render to an Android View a couple of different ways.  The easiest way is to use a SurfaceView which you can turn into an ANativeWindow in the C++ code and use to either lockPixels (for CPU access) or create an FBO (for GPU access).  The viewer application checked into our repository is an example of how you can do either of those approaches.
Reply all
Reply to author
Forward
0 new messages