drm_hwcomposer: Don't close same handle several times.

Video (YUV) frames can have several planes in the same buffer,
in this case all the planes will be represented by the same
gem_handle, which must be closed only once.

Fixes logcat noise during video playback.

Reported-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
diff --git a/drm/DrmFbImporter.cpp b/drm/DrmFbImporter.cpp
index 592fc48..8440093 100644
--- a/drm/DrmFbImporter.cpp
+++ b/drm/DrmFbImporter.cpp
@@ -101,14 +101,17 @@
    * request via system properties)
    */
   struct drm_gem_close gem_close {};
-  for (unsigned int gem_handle : gem_handles_) {
-    if (gem_handle == 0) {
+  for (int i = 0; i < gem_handles_.size(); i++) {
+    /* Don't close invalid handle. Close handle only once in cases
+     * where several YUV planes located in the single buffer. */
+    if (gem_handles_[i] == 0 ||
+        (i != 0 && gem_handles_[i] == gem_handles_[0])) {
       continue;
     }
-    gem_close.handle = gem_handle;
+    gem_close.handle = gem_handles_[i];
     int32_t err = drmIoctl(drm_->fd(), DRM_IOCTL_GEM_CLOSE, &gem_close);
     if (err != 0) {
-      ALOGE("Failed to close gem handle %d, errno: %d", gem_handle, errno);
+      ALOGE("Failed to close gem handle %d, errno: %d", gem_handles_[i], errno);
     }
   }
 }