Repository navigation
Description
Parent epic: #22
Implementation order: 12 of 20.
Depends on: #33.
Outcome
Make drawImage and export observe real, correctly timed GPU/Canvas2D pixels so Kestrel PNG export works unchanged.
Implementation
- Extend the canvas image-source abstraction to capture a source frame/generation at drawImage time. Later source rendering/resize/removal must not change already-copied destination pixels.
- Support relevant Canvas2D↔GPU source/snapshot paths and prepare the same contract for WebGL. Handle crop/scale overloads, alpha/premultiplication, orientation, color conversion and self-copy/overlap semantics.
- Preserve source leases until snapshot consumers finish. A queued draw_canvas referencing only the source node's latest content is insufficient.
- Implement actual canvas pixel serialization: toBlob returns valid encoded bytes with async callback semantics, and toDataURL returns a real data URL for supported formats. PNG is mandatory; unsupported requested types follow specified fallback behavior.
- Provide explicit GPU readback/encoding work outside the UI rendering critical path. Synchronous APIs must avoid engine↔UI/render-thread deadlocks; document and test their scheduling.
- Preserve origin-clean/taint rules, empty dimensions, type/quality handling and export failure behavior.
- Make Kestrel's renderer.screenshot() compose its GPU scene and Canvas2D annotation overlay before encoding; keep the app unchanged.
Tests
- Render frame A, drawImage to another canvas, render frame B, then export destination: it must retain A.
- Crop/scale, transparent edges, cross-canvas alpha, self-copy, resize/removal after snapshot and delayed consumers.
- Decode generated PNG bytes with an independent decoder; verify signature, dimensions, channels and expected pixels.
- Export from inside a RAF callback, while hidden, during device loss and from normal host evaluation without deadlock.
- Kestrel PNG contains geometry and annotations in both themes; forced Canvas2D mode also exports correctly.
Verification evidence
Provide decoded-image comparisons, export callback/timing tests, origin-clean negatives, readback counters and race/lifetime evidence.
Acceptance
- Pixel snapshot semantics are stable across subsequent source changes.
- Browser APIs return real image bytes/data URLs, not opaque host tokens.
- Kestrel PNG export is visually correct without application changes.
- Explicit export readback does not become a normal presentation path.
- Export/teardown never deadlocks or leaks source/image leases.
Completion requirements
Link the implementation PR, exact test commands, native/runtime/framework revisions and verification artifacts before closing. Follow the epic's architecture and copy/lifetime invariants. Any unavailable mandatory hardware or missing required functionality remains incomplete, not a pass.
Frameforge workload specification (epic #53)
This issue remains the owner of canvas snapshots and PNG export. The Frameforge recording implementation is #58; it consumes this snapshot contract, not a duplicate pixel-copy implementation.
Reference: Frameforge repository, pinned export.js and renderer.js. framePNG() awaits GPU queue completion, draws the WebGPU canvas into a new Canvas2D canvas, calls toBlob('image/png'), then downloads the real Blob. Recording repeatedly uses the same WebGPU-to-Canvas2D drawImage path before captureStream.
Additional implementation and tests
- Preserve the exact source frame at drawImage time through subsequent rendering, resizing, source destruction and delayed encoding/capture. A GPU queue completion promise alone does not establish immutable canvas-image ownership.
- Keep the recording copy path GPU resident where supported; explicit PNG export may read back asynchronously. Do not turn the general drawImage path into per-frame GPU-to-CPU-to-GPU transfer just to support capture.
- Implement/qualify drawImage(HTMLVideoElement) for Frameforge thumbnail extraction using actual decoded frames from [Frameforge 1] Implement HTML media elements, native decoding and seek/playback lifecycle #54, including scaling/cropping and origin-clean propagation. Add real JPEG toDataURL thumbnail coverage when that format is supported; apply standard unsupported-type fallback.
- Verify images/stills and Canvas2D title text can be consumed by [GPU 18/20] Complete external image/video sources and GPU texture interoperability #40 without referencing subsequently mutated canvas content.
Frameforge acceptance
- Export original project frame with actual video + editable title + transformations, independently decode PNG and compare dimensions/pixels with Chrome reference.
- Snapshot A, present B, resize/dispose source, then encode/capture: destination remains A with correct alpha/color/orientation.
- Real imported-video thumbnail contains decoded content and valid encoded image bytes.
- Repeated export and capture do not deadlock the runtime/UI, expose tainted pixels or leak leases; export callbacks report failures correctly.
- Attach readback/copy counters showing that PNG readback is explicit and ordinary preview/capture stays on the intended GPU path.
Real host download verification belongs to #57. Do not mark the full workflow complete until its on-disk bytes have been verified.
Native save destination
Canvas encoding produces real image bytes; delivery to the user is a native Save operation via #57 and the hosting Avalonia/Uno backend file picker service. Do not add browser download chrome or an implicit Downloads destination. Frameforge PNG acceptance includes native Save dialog cancellation/overwrite handling and independently verified bytes at the selected destination.
Activity