How to use GPU-accelerated backend in skia

3,055 views
Skip to first unread message

Manish Rawat

unread,
Nov 23, 2016, 1:41:14 AM11/23/16
to skia-discuss
Hi,

I am working on building a sample app using skia 2D graphics native library on android. I've compiled and generated the libskia_android.so binary and successfully run the helloskia sample app using a rasterSurface.
For gpu backed surface (Ganesh), the example given here using GrContextFactory fails to compile.

I believe GrContextFactory has been removed from skia codebase and the example has not been updated.

I tried to create a GrContext using an eglContext (I am not sure if that's even allowed) and that fails with following error.

libEGL : call to OpenGL ES API with no current context (logged once per thread)

What is the correct way to use the skia gpu backend? I could not find relevant examples/samples on the web. Any pointers on the usage of skia gpu backend would be of great help.


Thanks,

Manish

Hal Canary

unread,
Nov 23, 2016, 11:01:34 AM11/23/16
to skia-discuss
This sounds like out-of-date documentation. I wrote that doc, but I don't really understand how GrContexts work.  I'll take a look at fixing it.

We still need a good mechanism to test that all sample code in the documentation compiles and works.

Hal Canary

unread,
Nov 23, 2016, 11:55:45 AM11/23/16
to skia-discuss
Since creating a GrContext is both complex and out of Skia's control, the GrContextFactory class has been moved to our tools/gpu directory.  You can refer to the platform-specific files in that directory for examples.

Our tools still use that class for testing.  It's probably overkill for what you want to do, since we designed it to allow runtime switching between of GL, EGL, Vulcan, and Angle (and a bunch of other complex things I don't understand).

Jim Van Verth

unread,
Nov 28, 2016, 11:37:29 AM11/28/16
to skia-discuss
You may want to look in tools/viewer/sk_app, in particular at GLWindowContext.{cpp,h} and android/GLWindowContext_android.cpp.

The viewer app in general is a better example of how we handle windowing these days. Unfortunately the build instructions for Android seem to have disappeared off skia.org. I'll get those updated, but I believe it's

ninja -C {gn-dir} Viewer_APK

where {gn-dir} is wherever you directed GN to store its build files.

--
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.

Brian Salomon

unread,
Nov 28, 2016, 4:43:05 PM11/28/16
to skia-discuss
That documentation was faulty. GrContextFactory was never intended to be used by clients. I will update that section of the documents. The gist is you create your own OpenGL context (or Vulkan device if you're feeling brave) and make sure it is current on the thread. You create a GrContext that will use that context and can be used to create a SkSurface. This is done using SkSurface::MakeRenderTarget if you want Skia to create the texture in which to render, SkSurface::MakeFromBackendTexture if you want to point Skia at a texture you created, or SkSurface::MakeFromBackendRenderTarget if you want to point Skia at a FBO you created (or FBO 0).

Brian

Manish Rawat

unread,
Dec 26, 2016, 10:32:45 AM12/26/16
to skia-discuss
Thanks Brian. That worked like a charm.

Brian Salomon

unread,
Dec 26, 2016, 10:00:28 PM12/26/16
to skia-discuss
Great, glad it worked for you!
Reply all
Reply to author
Forward
0 new messages