Make sure there is room before copying a scanout

If a CRTC is removed or shrunk, pOMAP->scanout may shrink such that it no
longer contains ANY of one or more of the pOMAP->scanouts.  In this case,
make sure not to copy anything from the pOMAP->scanouts.

This patch fixes two bugs:
 (a) the omap_bo_*() functions return uint32_t, so the subtraction was
     resulting in a large positive number, instead of a negative.  Thus,
     the min() would choose to copy all of scanout.
 (b) even if the subtraction was cast to int, the copy operation would
     still do the wrong thing when given a negative range.

It also refactors how we copy between the overlapping regions of bo's.
And, while we are at it, we use the same function to copy from fb to scanout.

BUG=chrome-os-partner:15240
TEST=manually:
  1. Attach external monitor using HDMI-HDMI cable
  2. boot
  3. DISPLAY=:0.0 xrandr --output --off
  4. Wait for both screens to come back on (~40 seconds)
  5. DISPLAY=:0.0 xrandr --output --off
  6. Ensure no "Segmentation fault" in /var/log/Xorg.0.log

Original-Change-Id: Idc927fe6ef3e5076790f4734a1ccbc73bb719c4d
(cherry picked from commit b6e43787be025cd4a5082b7bbbe75bd3cc8f0e84)
Signed-off-by: Daniel Kurtz <djkurtz@chromium.org>

Change-Id: Id452b55e736f9997c7e0f50d1413239dce533277
Reviewed-on: https://gerrit.chromium.org/gerrit/36170
Reviewed-by: Daniel Kurtz <djkurtz@chromium.org>
Tested-by: Daniel Kurtz <djkurtz@chromium.org>
1 file changed