https://kotlinlang.org logo
#compose
Title
# compose
k

Koneko Toujou

09/10/2021, 10:41 PM
Does Compose draw each Composable directly to screen or does it first composite each composable to a texture which ultimately ends up on screen Eg Row Text Would Compose first draw Row directly to screen, and then draw Text directly to screen Or would Compose first draw Text to a texture, and then draw Text's texture to Row's texture, and then draw Row's texture to screen
z

Zach Klippenstein (he/him) [MOD]

09/10/2021, 11:44 PM
Romain is probably the best person to answer this, but I can try – don’t quote me on any of this 😅. Compose works with `RenderNode`s. In general, composable structure doesn’t imply layer/rendernode structure, but layers can be introduced by certain APIs like the
graphicsLayer
modifier or
withSaveLayer
calls inside draw scopes. Composables draw to
Canvas
objects which are backed (in most cases, at least on newer android versions) by those `RenderNode`s. I believe there’s some relationship between a
RenderNode
and a display list, but i’m not sure exactly what it is. So in your example case,
Row
doesn’t do anything with layers so
Text
would end up drawing to the same
Canvas
as whatever calls
Row
would have access to.
a

Adam Powell

09/10/2021, 11:52 PM
Right, Compose UI tries to only draw to an intermediate rendering target if it has to, for example, if you're applying an alpha modifier to a complex composable
k

Koneko Toujou

09/11/2021, 12:02 AM
Hmm ok
r

romainguy

09/11/2021, 3:41 AM
And technically all drawing is done in a texture of some sort (a Surface)
Android never draws directly on screen
k

Koneko Toujou

09/11/2021, 3:42 AM
Yea
r

romainguy

09/11/2021, 3:42 AM
But the UI toolkit tries to avoid intermediate textures as much as possible as it's expensive in terms of bandwidth.
k

Koneko Toujou

09/11/2021, 3:43 AM
Oh ok
r

romainguy

09/11/2021, 3:44 AM
@Zach Klippenstein (he/him) [MOD] RenderNode is basically what used to be called DisplayList. It has the same role
👍🏻 1
k

Koneko Toujou

09/11/2021, 3:46 AM
Bandwidth as in RAM/GPU memory? Eg a 2k texture would take up around 8MB to 15 MB (depending on screen exact resolution) of memory assuming 4 bytes per pixel, eg ARBG or RGBA or however the pixel format And thus having a lot of intermediate textures would inflate memory in proportion to how many are required and the exact size of each texture in bytes total
r

romainguy

09/11/2021, 3:50 AM
It's not so much about how much memory would be required at any given time but how much data would have to be read/written per frame
k

Koneko Toujou

09/11/2021, 3:51 AM
Such as copying pixels from GPU to CPU and back to GPU?
Or such as drawing each texture to another texture as a quad? Eg layering each texture on top of one another
2 Views