mirror of
https://github.com/storytold/effectcraft.git
synced 2026-12-04 13:03:22 -05:00
* Puppet tools: a precomp layer's overlay is evaluated off the UI thread (#2516) With a Puppet tool active, the viewer evaluated the selected layers' Puppet meshes and pins on the UI thread once per project revision. A precomp layer's input has no layer-cache key, so every edit anywhere (each Position or Scale change, every drag step) re-rendered its whole nested composition at full size on the UI thread, and the whole window slowed down. `Renderer::layer_input_cacheable` tells whether a layer's input is kept by the layer cache, and `PuppetSource` evaluates a Puppet from shared parts. Cacheable inputs are still evaluated in the frame; the rest are evaluated on a worker, one at a time, the layer's last overlay drawn until the new one lands. Only a layer's first overlay is waited for, at most 16 ms. In a 4K comp with a precomp of four large solids, a Position edit with the Puppet tool active went from 48 ms to 20 ms to its frame, the same as with the Selection tool. * Puppet tools: take an inline overlay before waiting; doc fixes On the web the overlay is evaluated inline and sent before the frame waits for it, and recv_timeout reads the clock, which std doesn't have there. try_recv takes the inline result first; only with nothing yet and no overlay to draw does the frame wait. layer_input gets its own doc comment back (layer_input_cacheable's had been appended to it), PuppetSource's fields are documented, and its doc says it borrows. * refactor(render): one key function behind layer_input and its cacheable check layer_input_cacheable re-derived the layer cache key beside whole_layer_input instead of asking it, and the two had already fallen out of step: the part-read footage filter (#3271) and the content key were added to the render path only. Neither changes the answer today. layer_input renders with whole_raster set, which turns the footage filter off, and the content key keeps every key input_key gives, so this is not a behaviour fix. It removes the second derivation so that the next filter added to the render path cannot silently leave the predicate behind -- which matters, because callers decide by it whether to render off the UI thread. Both now ask Renderer::whole_layer_input_key. * perf(ui): the Layer panel renders its preview off the UI thread Double-clicking a clip opens it in the Layer panel, and the preview then rendered in the frame: a source decode, the masks and the effects up to the View choice, on the UI thread, whenever the render key changed. The key holds the current time and the project revision, so that was every step of a scrub and every edit anywhere in the project. Scrubbing in the panel stalled the whole window. render_tex now drives a slot: a frame starts the render on a worker and draws the panel's last texture until it lands, repainting when it does. One render at a time, so a fast scrub drops the frames it passed over instead of queueing a render for each. A frame waits (16 ms) only when there is nothing to draw yet, and takes an inline result with try_recv before reading the clock, which the web has none of. An empty render is kept under its key, so a layer with no pixels is not retried every frame. The same cost #2516 reported under the Puppet tools, fixed the same way; the layer cache still makes a repeat cheap. Trade-off: on a paint-stroke release the baked image lands a frame or two later instead of synchronously, so the stroke can blink once as the drag overlay hands over. Waiting in the frame is what #2516 says not to do. * fix(ui): a pin's turn and scale gesture starts from the project, not the drawn overlay CodeRabbit on #4411. A rotate or scale drag seeded Gesture::PuppetRotate and PuppetScale from PinHit, whose rotation and scale come from the overlay on screen. Since that overlay may now be one a worker rendered for an earlier revision or time, and puppet.setPin writes an absolute value, the drag's first frame could write a stale base back over the pin's current turn or scale. Undo recovers the edit but not the lost value. Before the overlay moved off the UI thread it was always current in the frame, so this is a hazard the move introduced. The gesture now reads the pin from the project at the press. PuppetSource::params flattens the Puppet effect's parameters without rendering the layer's input -- puppet::parse builds the pins from those alone -- so pin_now costs nothing on a press. Only Advanced and Bend pins are affected; Position pins have no rotation. Pin movement never was, as it follows the cursor. The test covers pin_now's contract -- the project's turn, not the drawn one -- rather than the whole press-and-drag path, which would need a render in flight at a precise moment. * docs(gaps): gap 5 says the Layer panel preview is addressed CodeRabbit on #4411. The row still described the preview as rendered on the UI thread at every scrub step and edit, while the revision history in the same file said it had moved off. The row now reads as addressed for both panels, and notes that each draws its last result while the new one renders. * test(ui): the pin-turn test does not depend on worker scheduling CodeRabbit on #4411. The test called overlay() again after changing the turn and asserted the result was still the old one. That holds only while the worker has not finished between the spawn and the try_recv that follows it -- OVERLAY_GRACE being zero stops the frame waiting, not the worker completing -- so the assertion was a timing one, which rule 28 asks tests not to make. The call is gone. The overlay a gesture would be seeded from is the one already in hand from the previous step, and an overlay already rendered keeps reporting the turn it was rendered for however the next worker is scheduled. The test now asserts the relation that matters -- the turn the project holds differs from the one that overlay holds, and pin_now reports the project's -- against that value. No barrier or injected pending result: the race goes away by not making the racy call, rather than by adding a test hook to the overlay path. * fix(ui): the Layer panel never draws another layer's picture The panel has one render slot and drew its last texture whatever it was rendered for, so switching layer or comp showed the old picture until the new render landed. The slot now hands out a texture only for the same comp and layer. Also update two comments that still said "synchronously". * fix(ui): the Layer panel never draws a closed project's picture Comp and layer ids restart in every project, so the render slot could hand the last project's texture to the new one. The render key now includes the project epoch. * fix(ui): the Puppet overlay never draws a closed project's pins Comp, layer and effect ids restart in each project, so the overlay key now includes the project epoch and effect, and only an overlay of the same ones stands in while a new one renders. --------- Co-authored-by: Simon Hull <[email protected]> Co-authored-by: FredApps <[email protected]>