Is it possible to get a hardware-accelerated Canva...
# compose
c
Is it possible to get a hardware-accelerated Canvas in Compose? I’m doing some canvas drawing currently with
SurfaceView.lockHardwareCanvas()
. I didn’t see anything here about it: https://developer.android.com/jetpack/compose/graphics
n
The compose canvas is the same as the View canvas which has been hardware accelerated for a number of android releases. Is there something specific you are trying to accomplish with a SurfaceView?
c
Thanks for responding. My full use case is that I am using WebRTC for live streaming, and allowing the user to overlay/draw things on top of the local device preview. Using a SurfaceView was just how I implemented the overlay, and I’m drawing into its canvas. I’m not really satisfied with this implementation since Canvas drawing provides no structured hierarchy. So I’m considering how I could create a generic
@Composable
to support rendering local device camera preview, and allow drawing/overlay on top. There are potentially a lot of ways I could go with this and perhaps the question of hardware accelerated Canvas is not important.
n
It seems like you would want to leverage traditional compose View interop here with a SurfaceView. I'm not sure if anything in compose changes your live stream use case other than leveraging one way data flow through the composition hierarchy
c
Out-of-the-box WebRTC provides video frames as OpenGL textures, and we are meant to pass these to a
SurfaceViewRenderer
(basically a webrtc SurfaceView that can render OpenGL textures). But I am also considering bypassing the WebRTC libs’ capture/render code completely, and write my own capturer, which would remove the need for SurfaceViewRenderer.
in which case I could just use a
SurfaceView
(or perhaps look at CameraX) to show the local preview, and use regular Composables to draw the overlay
(I haven’t spent much time with CameraX so I’m not sure if it would be helpful here)
I forgot to mention, I am using interop with a SurfaceView to draw the overlay currently, i.e.:
Copy code
AndroidView(factory = { mySurfaceView })
n
CameraX should help with a lot of the logic necessary to interact with the camera hardware itself. If you are just streaming WebRTC from elsewhere and displaying it then it's not that useful for this case. However if the client app is live streaming frames from the phone's camera then CameraX would be useful
c
Yes the app captures from local device camera and sends video over webrtc. Thanks for the tips!
👍 1
130 Views