Use XGetWindowAttributes for window size

Use XGetWindowAttributes in place of glXQueryDrawable.
Mesa glXQueryDrawable has trouble reading width and height.
Condition state capture and restore of state related to ARB_imaging extension.

Some drivers (such as Mesa) do not support GL_ARB_imaging extension. Make the
state capture and restore of state added by this extension be conditional based
on driver support of the extension.