Currently, I have created a compose-blur library t...
# compose
c
Currently, I have created a compose-blur library to solve the same needs as https://issuetracker.google.com/issues/166927547. Now that I have finished the rendering of the static content, I am going to implement real-time blur, but I currently have some problem: 1. I want to know how to take screenshots of some widgets in compose, or their nodes, similar to the
findRenderObject().toImage()
in flutter, I really hope this exists, because the performance cost of cropping the widget area after using
PixelCopy
to screenshot the entire window view may be expensive. 2. I'm not sure if there is an api on compose that can monitor the changes of all components, similar to the native
View.doOnPreDraw
, if it does not exist, then I will try to refresh the blur by monitoring the changes of window view, but if it is invalid for compose, Then I may need to refresh every 100ms, which would be terrible!
r
Blur is coming in Android 12 btw
You should be able to use onPreDraw since Compose is hosted by a View anyway
Why crop the result of PixelCopy? All you need is to clip it at draw time which is basically free
s
@romainguy only in Android12 won't we get a blur api with compose to work on Android version lower than that?
c
@romainguy Sorry, I didn't understand how to crop when drawing. Blur must get the content on the back of the part, so how do I need to capture the back view image?
r
Ah right I see what you mean by “crop”. You would first need to render the UI without the blurred view in a separate bitmap.
c
@romainguy Yes, there may be some misunderstandings about what I said earlier. The srcRect parameter of PixelCopy can automatically clip out the desired position for me. But View.draw cannot. In order to do decomposition and compatibility, I must first use
windowView.draw
to draw the entire window view, then at this time, I must perform a clip operation, that's it... In short, all screen capture methods should be required once clip operation, the difference is that PixelCopy will be done automatically, while View.draw needs to be clip manually
r
PixelCopy should be fairly cheap but the issue you'll have with it is that I'll give you the content of the previous frame
c
@romainguy Can it be solved by refreshing the PixelCopy request after listening the window change?