Enable Skia GPU backend without creation Skia own EGLContext

295 views
Skip to first unread message

Igor Kuzmenko

unread,
Apr 8, 2015, 4:31:19 AM4/8/15
to skia-d...@googlegroups.com
Hi All,
I've tried to create android application where used Skia gpu backend. In my app I already have created EGLContext
And I'd like to use my own OpenGL Texture as render target for SkCanvas. Investigating source code I found that Skia 
creates it's own EGLContext. But in my case I want that Skia has used my EGLContext.

Does the current version of Skia support this case? Investegate source code I found out 6 different GLContextType.

enum GLContextType {
      kNative_GLContextType,
      kANGLE_GLContextType,
      kMESA_GLContextType,
      /** Similar to kNative but does not filter NVPR. It will fail if the GL driver does not
          support NVPR */
      kNVPR_GLContextType,
      kNull_GLContextType,
      kDebug_GLContextType,
      kLastGLContextType = kDebug_GLContextType
    };
But no one is suitable for my case.
When I've used kNative_GLContextType Skia creates its own EGLContext but that's not what I want. 
And kNull_GLContextType doesn't work too.

I've used old skia version (may be release of 3 years ago)  where SkNativeGLContext doesn't create own EGLContext, EGLDisplay, EGLSurface, etc. And my code worked fine.

Could someone explain is it possible created GrContext on my own EGLContext?

Thanks a lot!

Brian Salomon

unread,
Apr 8, 2015, 10:27:03 AM4/8/15
to skia-d...@googlegroups.com
Hi,

You shouldn't be using GrContextFactory. That class is really meant for our own test tools.

Since you built for Android you should have compiled GrGLCreateNativeInterface_egl.cpp (as opposed to the other variants based on agl, wgl, glx, ...).  Here are the steps:

  1. Call GrContext::Create(kOpenGL_GrBackend, NULL) while your GL context is current on the thread you'll get a GrContext that uses your context.
  2. You then use GrContext::wrapBackendTexture() with the kRenderTarget_GrSurfaceFlag set to wrap the texture you want to use.
  3. You can use the wrapped texture to create a SkSurface via SkSuface::NewRenderTargetDirect.

I put up a CL that would combine steps two and three:

 Hope that helps.

Brian

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at http://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Igor Kuzmenko

unread,
Apr 9, 2015, 3:37:19 AM4/9/15
to skia-d...@googlegroups.com
Brian, thanks a lot. It really helped!
Reply all
Reply to author
Forward
0 new messages