Custom ImageFilter and affected area bounds

105 views
Skip to first unread message

Giuseppe

unread,
Jul 7, 2022, 5:05:55 AM7/7/22
to skia-discuss
Hello,

I'm creating my own custom ImageFilters, using SkImageFilters::RuntimeShader. 
Everything seems to be working as expected, except that in certain cases, the filter and its content is culled from the canvas. This makes me believe that I would need to specify the bounds of the area affected by the filter manually? But looking at the skia's source code, I can't find a way to define these bounds manually. How could I tell skia what are the bounds of the area affected by the filter? 

I was looking at the Blur image filter as an example, and I see that the SkBlurImageFilter overrides the computeFastBounds function and then expands the bounds using the blur sigma. I'd like to do something like this for my own filters, but now sure how with the SkImageFilters::RuntimeShader.

Thanks!

Ian Waters

unread,
Jul 8, 2022, 2:54:15 PM7/8/22
to skia-discuss
We do offscreen rendering for this kind of effect.

Something like:

1. Render the ‘current state’ to an SkShader via makeImageSnapshot().
2. Create a new surface with ‘expanded bounds’ (to fit the blur delta or whatever)
3. Draw a rectangle containing the shader, with the blur (or other custom shader) set on the paint.
4. Make a snapshot of the result (!) and paint that back onto your main canvas.

If there’s a better way, I’d like to hear it too!
Best,
Ian

PS. Happy to send sample code if needed.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/0d04c018-c6a1-4c27-b5fb-f6b278add665n%40googlegroups.com.

Brian Osman

unread,
Jul 8, 2022, 6:03:07 PM7/8/22
to skia-d...@googlegroups.com
Currently, this is the only thing that works (I think). We've talked about adding additional hooks so that custom filters can define how they transform the bounds, but there isn't any support for that yet, so they just operate using the original layer bounds. Doing the filtering "manually" via an offscreen surface is effectively what the image filter code does, so it should give you similar results (but obviously forces you to jump through some extra hoops).

Joe

unread,
Jul 13, 2022, 3:55:15 PM7/13/22
to skia-discuss
Thank you, I'll just create an offscreen manually then. SkImageFilters are so nice though, I hope we get a way to manually set the bounds in the future :)
Reply all
Reply to author
Forward
0 new messages