Skip to content

WIP: move filter node manipulation to element parsing/load time

John Ledbetter requested to merge johnl/librsvg:post-process into master

This is a refactor to support implementing basic filter functions. This attempts to move all usage of Node objects from Filter render-time to just after parsing and loading the elements.

Most Filters do not use the node at render time for anything except to get the bounds, which we can pass in separately.

However, Lighting, Merge, Turbulence, Flood, etc use their nodes for various other purposes, like to process their child nodes or compute other values. These manipulations need to move to post_process.

Status of this PR:

  • rename SetAttribute trait to LoadElement and add default post_process fn.
  • invoke post_process at XML load time (sort of)
  • implement post_process for lighting, merge, flood, etc. This should be done as commits rebased in just before the HEAD commit that removes node from the render arguments.
  • remove node argument from filters::render and instead pass an element.

Issues:

  • Need to figure out how to get a CascadedValues from the element instead of the node, which causes a runtime panic due to trying to borrow the (already borrowed) element from the node. (At least I think this is the issue -- it could be that the whole invocation of post_process is broken since we're borrowing the element mutably from the node and then also passing the node as an argument?
thread '<unnamed>' panicked at 'already mutably borrowed: BorrowError', /home/john/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/src/libcore/cell.rs:797:9
stack backtrace:
   0: ...snip...
  16: rctree::Node<T>::borrow
             at /home/john/.cargo/registry/src/github.com-1ecc6299db9ec823/rctree-0.3.3/src/lib.rs:213
  17: <rctree::Node<rsvg_internals::node::NodeData> as rsvg_internals::node::NodeBorrow>::borrow_element
             at rsvg_internals/src/node.rs:217
  18: rsvg_internals::node::CascadedValues::new_from_node
             at rsvg_internals/src/node.rs:138
  19: <rsvg_internals::filters::lighting::Common as rsvg_internals::element::LoadElement>::post_process
             at rsvg_internals/src/filters/lighting.rs:294
  20: rsvg_internals::element::Element::post_process

Merge request reports