I have a use case that is difficult to implement in Skia. PDF files have these concepts called transparency groups. Or just "group." Where there are two flags. Isolate and knockout. One flag controls whether or not a blendmode should apply within the drawing instructions inside the group. While the other flag controls whether or not to apply the blendmode to the final result of all the calls. (sort of like a Skia layer, with a blendmode on it's paint)
Between these two flags, there are 4 combinations. The sticky one is when you say: don't apply blendmode within group, but apply to result. AND there is more than one blendmode inside the group.
For example, the attached PNG is the result of a group that said:
- draw a thick red line with multiply blendmode.
- draw a thick blue line with screen blendmode.
The option to not apply blendmodes within a group, means that the blue line overwrites the pixels generated by the red line, rather than mixing together in a screened purple. The final result of the group contains some pixels that should multiply and some that should screen. Which isn't something a Skia layer can do. So, in Skia, I am guessing they have to be two separate layers.
I have found a way to do it, in Skia, but it requires copying the geometry of the later layers into the earlier layers, with the kDestOut blendmode. So that it can erase those pixels from the earlier layers. Here is my solution:
https://fiddle.skia.org/c/bf58440043a39447160bf8815a50ba2e
But I was wondering if anyone had any other, better, ideas on how to handle such a scenario?
My solution increases the amount of data and rendering that has to happen.