delay closing of DRM connection as much as possible

ply-image disables all monitors but "main" before it plays boto splash
animation. after it disables the monitors it calls drmClose which causes
kernel to restore previous video mode, re-enabling disabled monitors.
if the monitor syncs before X server starts user can see boot-splash
animation on 2nd monitor. This change moves drmClose to
ply_frame_buffer_close which is never called anyway because we depend
on kernel to teardown everything.

BUG=chrome-os-partner:25917
TEST=boot rambi with HDMI monitor attached. splash screen on 2nd monitor
should be visible for shorter time.

Change-Id: I27cbc046248f9e07227134695db93991032c2f58
Signed-off-by: Dominik Behr <dbehr@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/189124
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/src/ply-frame-buffer.c b/src/ply-frame-buffer.c
index 6fbb163..1160c85 100644
--- a/src/ply-frame-buffer.c
+++ b/src/ply-frame-buffer.c
@@ -326,6 +326,7 @@
   buffer->areas_to_flush = ply_list_new();
 
   buffer->pause_count = 0;
+  buffer->drm_device_fd = -1;
 
   return buffer;
 }
@@ -439,6 +440,7 @@
   buffer->area.y = 0;
   buffer->area.width = 0;
   buffer->area.height = 0;
+  ply_monitor_close(buffer);
 }
 
 void ply_frame_buffer_get_size(ply_frame_buffer_t      *buffer,
diff --git a/src/ply-frame-buffer.h b/src/ply-frame-buffer.h
index d81b8ef..d99027c 100644
--- a/src/ply-frame-buffer.h
+++ b/src/ply-frame-buffer.h
@@ -42,6 +42,7 @@
 struct _ply_frame_buffer {
   char *device_name;
   int   device_fd;
+  int   drm_device_fd;
 
   char *map_address;
   size_t size;
diff --git a/src/ply-monitor.c b/src/ply-monitor.c
index badc39a..ad29bdc 100644
--- a/src/ply-monitor.c
+++ b/src/ply-monitor.c
@@ -219,9 +219,17 @@
   drmModeFreeCrtc(crtc);
   drmModeFreeConnector(main_monitor_connector);
   drmModeFreeResources(resources);
-  drmClose(fd);
+  buffer->drm_device_fd = fd;
 
   return true;
 }
 
+void ply_monitor_close(ply_frame_buffer_t *buffer)
+{
+  if (buffer->drm_device_fd >= 0) {
+    drmClose(buffer->drm_device_fd);
+    buffer->drm_device_fd = -1;
+  }
+}
+
 
diff --git a/src/ply-monitor.h b/src/ply-monitor.h
index 64e2762..2d9a2ba 100644
--- a/src/ply-monitor.h
+++ b/src/ply-monitor.h
@@ -32,7 +32,8 @@
  * (by looking for a connected output, by order of priority: LVDS, eDP,
  * any other), and then will turn off all the other monitors.
  */
-bool ply_monitor_setup(ply_frame_buffer_t *area);
+bool ply_monitor_setup(ply_frame_buffer_t *buffer);
+void ply_monitor_close(ply_frame_buffer_t *buffer);
 
 #endif /* PLY_MONITOR_H */