Faster alternative to saveLayer

89 views
Skip to first unread message

Sherlock Doyle

unread,
Nov 14, 2021, 5:40:48 AM11/14/21
to skia-discuss
I've several complex shapes which I need to draw with some opacity. I'm using saveLayer with a paint of required opacity. Points to note:
  1. Each of the shape has multiple paints, so can't change opacity of those paints.
  2. Each shape might have different opacity, so can't use a single saveLayer for all the shapes.
But each saveLayer almost doubles the time required for drawing.

I've also tried drawing to a Picture (with PictureRecorder) followed by a canvas.drawPicture(picture), which is fast. But as soon as I include a Paint (canvas.drawPicture(picture, nullptr, paint)), it slows down.

Any suggestions?

Jeru Sanders

unread,
Dec 11, 2021, 12:43:55 PM12/11/21
to skia-discuss
You shouldn't need to saveLayer to modify alpha. I queue up all my drawing commands and multiply the nested alphas on the way down. You can also paint.setColor(applyMyAlpha(paint.getColor())), you just have to remember what the alpha is as you recursively draw.

Sherlock Doyle

unread,
Dec 12, 2021, 4:01:26 AM12/12/21
to skia-discuss
I don't simply have a color in the paints always. Sometime, it'll be a shader. Can't change alpha there without recreating the shader.
Reply all
Reply to author
Forward
0 new messages