Jonathan
07/29/2024, 3:46 PMdrawBehind { ... } to draw a custom shadow directly on a Canvas. I’m currently in the process of optimizing code and I wondered if I would get any performance benefits using a Modifier.graphicLayer { ... } or maybe even using the DrawModifierNode?
I’m curious to know if the Modifier.graphicLayer {} would potentially gain performance improvements because out-the-box Modifier.shadow(...) uses a graphicLayer to achieve a shadow. Any thoughts, recommendations or links to articles that would help me make a good decision.romainguy
07/29/2024, 3:47 PMgraphicsLayer because it has to. Material shadows are handled at the RenderNode level, which is what a graphicsLayer creates by defaultromainguy
07/29/2024, 3:47 PMgraphicsLayer in one of two situations:romainguy
07/29/2024, 3:48 PMromainguy
07/29/2024, 3:49 PMgraphicsLayer (which is effectively a GPU texture). This should rarely be needed, but it sometimes is for certain effects (blend modes) or correctness (stacked alpha)Jonathan
07/29/2024, 3:55 PMShape and a Color .
Inside of my drawIntoCanvas block I assign the provided Color on the Canvas’ paint object and set anti alias to true, then I grab the outline of the specified Shape and draw it on the Canvas. Does using a graphicLayer seem like a misuse? The shadow will need alpha blending because some content with a Modifier will be drawn on top of a custom background that we’d like to still be visible.romainguy
07/29/2024, 4:00 PMgraphicsLayer seems unnecessary for what you are doing. Alpha blending is fine; alpha becomes a problem when you want to apply alpha to multiple overlapping primitives. It’s not the same drawing a 50% transparent blue rectangle and then a 50% transparent red rectangle that overlaps the blue rectangle, vs drawing the two rectangles 100% opaque and making the result 50% transparentJonathan
07/29/2024, 4:02 PMDrawModifierNode or just replace my drawBehind {} with a drawWithCache {} ?