slint icon indicating copy to clipboard operation
slint copied to clipboard

Optimization: Do not render items covered by opaque items

Open ogoffart opened this issue 2 years ago • 0 comments

We often have screens where pages goes on top of eachother, and we want to not render these items at all. We could have a opaque detection at several level:

  1. In the backend while doing the rendeing. femtovg can use a z buffer. in the software renderer, we can process the spans front to back first too to detect which regions are covered.
  2. we can also do a first pass before the processing.

The algorithm for 2 would be the following:

Mark opaque regions

  • Visit items front to back. When we see an opaque item, use a space partition data structure to mark opaque region belonging to that item. (this can be done without registering dependencies)
  • When doing the rendering
    • if a region is marked as opaque belonging to another item: don't do the rendering
    • if a region is marked as opaque belonging to the item to render: render the item and mark the space as not opaque
    • otherwise simply render the item

Filter sibiling items

This would rely on the compiler to detect items for which the children are in bounds (most items) and also items whose sibling might overlap.

When rendering an item whose children may overlap:

  • instead of simply recursing into it, loop over the direct children in reverse order (front to back). If one of them is opaque and cover the whole item, then break the loop and start rendering from there only.

This should detect the common case of "StackView" kind of thing, but would miss a lot of other cases. But does not need to keep a mapping between the region and the most opaque item.

ogoffart avatar Mar 15 '22 18:03 ogoffart