Restructure the D3D9 GPU flush: after presenting, first wait for previous frame's query, then issue new query. To prevent a loop of device loss and window flicker, do not attempt to render on D3D9 when the window is minimized in fullscreen mode.