Maybe I should split that in two, one for ensuring XFlush( gdi_display) for both wglFinish and wglFlush, and another for forcing glFinish when offscreen blit is used in glFlush?
That would probably help.
glFinish() should only be called from wglFlush() if we need to blit from offscreen drawable, and all the logic which detects / processes that is now inside present_gl_drawable().
Sorry, I don't understand? You're passing a flag to present_gl_drawable() to signal whether glFinish() should be called, so the logic is pretty clearly outside present_gl_drawable(). And as far as I can tell, the sequence isn't important; present_gl_drawable() doesn't do any GL work before glFinish() is called.