Open chcunningham opened 3 years ago
close() only closes that frame's handle on the frame. It may still be used elsewhere. Given the threading involved, I don't think there's any way to safely steal the buffer except in rare circumstances (RefPtr::HasOneRef() etc).
Yes, this is precisely the case that I mentioned, it can't work otherwise.
I expect this is in fact rather common: you decode, you get a frame, you read it back to apply some custom processing with wasm/js (this means a copy, for now). If this optimization isn't available, then the memory traffic is essentially doubled in the reasonably common case of a software decoder.
I agree, it's a good idea if we can make it work in common scenarios. We may want a separate closeXXX() method or parameter which activates this though for clarity and to avoid always transferring to a GC'd type to avoid increased memory pressure.
That said, a HasOneRef() type solutions has some edges that need solving:
Probably more, but that's all I can think of at the moment.
@padenot raised idea in editors call to frame.close() -> transfer cpu data immediately to ArrayBuffer. Tracking here to ponder it more.