rob42
05/14/2024, 8:59 AMrememberGraphicsLayer()
, which looks like a fantastic way to render a composable into a bitmap.
What's the best way to do this without displaying the composable? e.g. outside my normal composable UI code?Sergey Y.
05/14/2024, 10:07 AMrob42
05/14/2024, 10:17 AMSergey Y.
05/14/2024, 10:18 AMSergey Y.
05/14/2024, 10:29 AMSergey Y.
05/14/2024, 10:32 AMrob42
05/14/2024, 10:53 AMrob42
05/14/2024, 10:53 AMChris Fillmore
05/14/2024, 11:17 AMSergey Y.
05/14/2024, 12:03 PMChris Fillmore
05/14/2024, 1:40 PMComposeView
, which acts as the content view for a…
• Presentation
, which is displayed on a…
• VirtualDisplay
, which draws to a…
• Surface
, which is backed by a…
• SurfaceTexture
Then I call composeView.setContent(...)
, and the texture is updated.
The performance is good for my use case, video still comes through at 30+ fps on older devices, though perhaps there’s a better approach, I don’t know.Chris Fillmore
05/14/2024, 1:41 PMprivate val savedStateRegistryOwner = EmptySavedStateRegistryOwner()
private val presentation = Presentation(appContext, virtualDisplay.display).apply {
window?.decorView?.let {
it.setViewTreeLifecycleOwner(ProcessLifecycleOwner.get())
it.setViewTreeSavedStateRegistryOwner(savedStateRegistryOwner)
}
}
private val composeView = ComposeView(appContext).apply {
layoutParams = virtualLayoutParams
setViewTreeLifecycleOwner(ProcessLifecycleOwner.get())
setViewTreeSavedStateRegistryOwner(savedStateRegistryOwner)
presentation.addContentView(this, virtualLayoutParams)
}
Dummy SavedStateRegistryOwner
private class EmptySavedStateRegistryOwner : SavedStateRegistryOwner {
private val controller = SavedStateRegistryController.create(this).apply {
performRestore(null)
}
private val lifecycleOwner: LifecycleOwner? = ProcessLifecycleOwner.get()
override fun getLifecycle(): Lifecycle {
return object : Lifecycle() {
override fun addObserver(observer: LifecycleObserver) {
lifecycleOwner?.lifecycle?.addObserver(observer)
}
override fun removeObserver(observer: LifecycleObserver) {
lifecycleOwner?.lifecycle?.removeObserver(observer)
}
override val currentState = State.INITIALIZED
}
}
override val savedStateRegistry: SavedStateRegistry
get() = controller.savedStateRegistry
}
Chris Fillmore
05/14/2024, 1:42 PMChris Fillmore
05/14/2024, 1:43 PMSergey Y.
05/14/2024, 1:44 PMChris Fillmore
05/14/2024, 1:45 PMChris Fillmore
05/14/2024, 1:45 PMSergey Y.
05/14/2024, 1:45 PMSergey Y.
05/14/2024, 1:49 PMChris Fillmore
05/14/2024, 1:50 PMChris Fillmore
05/14/2024, 1:54 PMSergey Y.
05/14/2024, 1:57 PMChris Fillmore
05/14/2024, 1:59 PMSergey Y.
05/14/2024, 2:05 PMrob42
05/14/2024, 3:20 PMpresentation.addContentView(...)
Chris Fillmore
05/14/2024, 3:24 PMChris Fillmore
05/14/2024, 3:24 PMpresentation.show()
rob42
05/14/2024, 3:24 PMrob42
05/14/2024, 7:39 PMyschimke
08/18/2024, 8:36 AM