which is then racy
We can guard with InterlockedCompareExchange and free the extra context in the unlikely case it raced. I intentionally didn't consider creating that context at initialization (overall GL or drawable) as in the majority of cases it is not needed.
dependent on EGL_NO_CONFIG_KHR support.
Might avoid using it and select config for drawable format. That would imply having this backup context per drawable but probably not a big deal?
It then assumes that surface isn't already current in a different thread (which is not allowed)
Do you have any link / info about this part by any chance, what are the EGL rules here? We can probably track / check if the surface has active context attached in some thread and skip this path then.
a different context than the one which was used to draw doesn't look right.
Why? An app is free to switch the context any time and use different contexts to draw on a surface, and then select a different one any time, even if for SwapBuffers only. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10033#note_128871