Mixing Juce and native views

For a project I’m working I need to mix and match Juce and native android views at will. Since hardware acceleration is essential for smooth drawing on android, and we can’t have more than one GLSurfaceView, I was thinking instead of using TextureView instead. TextureView is a normal view that shows a GL texture (via a SurfaceTexture) and isn’t limited to only having one per screen. To create one you need to give it a GL texture handle.

Based on that, I’ve come up with this mechanism:

  • Create a wrapper android View that extends TextureView for the Juce component. In the Wrapper constructor, instantiate via JNI the target Juce component.
  • The Juce component instantiates an Image with the OpenGLImageType, gets the GL texture handle and returns it to the android Wrapper view (via JNI), which uses it to create the SurfaceTexture to show the juce component.
  • The juce component paints to the GLImage instead of using the normal paint mechanism.
  • When the android View is removed, the Juce component is removed.

What are your thoughts? Does that sound feasible?

1 Like

Sounds reasonable to me. You can look at the implementation of JUCE’s OpenGLContext on android. It should be quite similar.

1 Like

I’m very interested in this too, it would open up lots of possibilities for using multiple JUCE Components within a View on Android.