Though this is actually true for the new_read/new_draw ones,
Thanks, in v3 I have dropped reference counting for `new_read`/`new_draw`, which has removed the need to do some of the more fancy stuff (`wl_array` etc) to release them. I am still keeping the references to `read`/`draw`, since I need these drawables to stay around as long as they are used by EGL. Wayland EGL doesn't deal well with destruction of the native `struct wl_egl_window` while there is current `EGLSurface` (in another thread) that is still using it.
The reference counting approach also enables us to keep a drawable temporarily valid during an operation without locking it for the whole operation (which is something we need to use in a few functions, e.g., SwapBuffers, wgl_context_make_current).
but perhaps you could move these "destroyed but still in use" drawables in a separate global list if they need to be kept alive for some reason.
Here is how I would imagine this approach to work:
1. When the drawable for a HWND is replaced (or deleted), and there is a context using that drawable, mark the drawable as destroyed (e.g., with a `drawable->destroyed` flag or move it to a list), otherwise destroy the drawable. 2. When a context doesn't need a drawable anymore and it's mark as destroyed, destroy the drawable.
Am I understanding your "destroyed but still in use" idea properly, or did you have something else in mind?
BTW, this assumes that only one context is able to have the drawable current at any time, which is true for EGL at least. This is in effect an ad-hoc reference count with up to two owners. Not sure if this is more straightforward than the normal reference count, though, and also won't enable us to keep drawables temporarily valid as described previously.