glx: Don't crash on swap event for a Window (non-GLXWindow)
glx: Don't crash on swap event for a Window (non-GLXWindow)

Prior to GLX 1.3 there was the glxMakeCurrent() function that took a
single drawable handle. The Drawable could be either a bare XID for a
Window or an XID for a glxpixmap.

GLX 1.3 added glxMakeContextCurrent that takes 2 handles: one for
reading, one for writing. Nowadays the old glxMakeCurrent call is
implemented as a call to glxMakeContextCurrent with the single handle
duplicated.

Because of this it is allowed to use a plain-old Window ID as an
argument to glxMakeContextCurrent, although nobody really documents this
sort of thing. The manpage for the NEW call specifies the arguments as
GLXPixmaps, but the actual code accepts Window XIDs too, and handles
them correctly.

Similarly, the glxSelectEvents function can also take a bare Window XID.

The "piglit" tests all use GLXWindows and/or GLXPixmaps. You never
tested swap events with a bare Window XID. That is what my app was
doing.

The swap_events code worked with Window XIDs in mesa 7.x.y. The new code
added in versions 8, 9, and 10 assumes that all buffer swap events have
a GLXPixmap associated with them. Because of the historical quirks
above, this is not true. Swap events for bare Window XIDs do NOT have a
glxpixmap resulting in a segfault.

Any app that uses the old school glxMakeCurrent call with a Window XID
while trying to use swap_events will crash when the libs try to lookup
the nonexistent GLXPixmap associated with the incoming swap event.

I believe that the people who wrote the spec overlooked this, because
the "sbc" field comes from the OML_sync extension that is defined in
terms of glxpixmaps only.

v2 (idr): Formatting changes.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=54372
Reviewed-by: Ian Romanick <2b237cafb16dc45038e85df6c85e74e6d899eba9@intel.com>
Acked-by: Jesse Barnes <bc7add126c2dbb8382bf1c28ac262b9363a32706@virtuousgeek.org>
Cc: "10.1 10.2" <59f39c0db42d4479a46b02d4d2bc11120e37bb44@lists.freedesktop.org>

jbarczak/glsl-optimizer,dellis1972/glsl-optimizer,tokyovigilante/glsl-optimizer,tokyovigilante/glsl-optimizer,zz85/glsl-optimizer,mcanthony/glsl-optimizer,djreep81/glsl-optimizer,zeux/glsl-optimizer,tokyovigilante/glsl-optimizer,djreep81/glsl-optimizer,wolf96/glsl-optimizer,benaadams/glsl-optimizer,wolf96/glsl-optimizer,benaadams/glsl-optimizer,zz85/glsl-optimizer,jbarczak/glsl-optimizer,djreep81/glsl-optimizer,zz85/glsl-optimizer,zeux/glsl-optimizer,bkaradzic/glsl-optimizer,dellis1972/glsl-optimizer,wolf96/glsl-optimizer,zz85/glsl-optimizer,zz85/glsl-optimizer,bkaradzic/glsl-optimizer,djreep81/glsl-optimizer,tokyovigilante/glsl-optimizer,benaadams/glsl-optimizer,bkaradzic/glsl-optimizer,dellis1972/glsl-optimizer,zeux/glsl-optimizer,metora/MesaGLSLCompiler,bkaradzic/glsl-optimizer,bkaradzic/glsl-optimizer,zeux/glsl-optimizer,wolf96/glsl-optimizer,zz85/glsl-optimizer,mcanthony/glsl-optimizer,benaadams/glsl-optimizer,dellis1972/glsl-optimizer,jbarczak/glsl-optimizer,benaadams/glsl-optimizer,tokyovigilante/glsl-optimizer,zeux/glsl-optimizer,benaadams/glsl-optimizer,mcanthony/glsl-optimizer,metora/MesaGLSLCompiler,metora/MesaGLSLCompiler,mcanthony/glsl-optimizer,djreep81/glsl-optimizer,mcanthony/glsl-optimizer,wolf96/glsl-optimizer,jbarczak/glsl-optimizer,dellis1972/glsl-optimizer,jbarczak/glsl-optimizer