OSDN Git Service

drm_hwcomposer: Don't close same handle several times.
authorRoman Stratiienko <r.stratiienko@gmail.com>
Wed, 25 Aug 2021 03:15:42 +0000 (06:15 +0300)
committerRoman Stratiienko <r.stratiienko@gmail.com>
Wed, 25 Aug 2021 09:44:41 +0000 (12:44 +0300)
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>
drm/DrmFbImporter.cpp

index 592fc48..8440093 100644 (file)
@@ -101,14 +101,17 @@ DrmFbIdHandle::~DrmFbIdHandle() {
    * 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);
     }
   }
 }