dri2: update scanouts in SwapComplete even if DRI2Drawable is gone

When a DRI2 client leaves, the DRI2 layer:
 (a) unregisters its DRI2Drawable
 (b) calls DDX.DRI2Info->DestroyBuffer() on all of its DRI2Buffers

If the DRI2 client leaves after submitting DRI2SwapBuffers, but before
the DDX processes SwapComplete(), then during SwapComplete():
 (c) the dixLookupDrawable() will return BadDrawable, and
 (d) the cmd->pSrcPixmap and cmd->pDstPixmaps will have already had their
reference counts decremented when their corresponding DRI2Buffer's were
destroyed in (b) above.

Due to (c), SwapComplete() was not updating the scanouts in this scenario.
In particular:
 (e) it wasn't doing Pixmap exchange, so the destination Pixmap didn't
get updated to the source Pixmap's original BO, and
 (f) it wasn't updating the per-crtc scanout to point to the destination
Pixmap's new bo (i.e., the old source BO).

Due to (d), when SwapComplete() dropped the extra refcnt on the SrcPixmap
(taken in ScheduleSwap()), it actually ended up dropping the last reference
on the BO that we had just flipped to, and was therefore currently being
scanned out.  The omap_bo layer removed its FB, during which the kernel would
dutifully clean up the mess made by user space, by blanking the screen.
As a side-effect, all subsequent page flip requests (on drm/rockchip, at
least) would fail.

In truth,  SwapComplete() only needs to skip calling DRI2SwapComplete() if
our DRI2Drawable has gone away.  It should still update the Pixmaps and
per-crtc scanouts to ensure that reference count is non-zero for the
just-flipped-to BO.

Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>

BUG=chrome-os-partner:34892
TEST=On pinky-rev2; at login screen, make sure cursor is blinking
     Enable ARMSOC Debug Option in /etc/X11/xorg.conf.d/rk32.conf
     Click "Browse as Guest" just as the cursor is displayed
     Chrome should start (no black screen)
     => If you time it right, /var/log/xorg/Xorg.log should have
     "dixLookupDrawable failed: 9"

Change-Id: I9aed898a01c47888bce658d55ded45817ce68ffb
Reviewed-on: https://chromium-review.googlesource.com/238193
Reviewed-by: Dominik Behr <dbehr@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
Commit-Queue: Daniel Kurtz <djkurtz@chromium.org>
Trybot-Ready: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
1 file changed