display: metadata fixes

* Do not log error on invalid metadata fds, such usages are
possible in some scenarios
* Correct usage of metadata API for some cases.

CRs-Fixed: 2122143
Change-Id: Id9cc7f4d27ef1890668f414d92b96cd419b6a066
diff --git a/libgralloc1/gr_buf_mgr.cpp b/libgralloc1/gr_buf_mgr.cpp
index 35c4b02..eb97f15 100644
--- a/libgralloc1/gr_buf_mgr.cpp
+++ b/libgralloc1/gr_buf_mgr.cpp
@@ -725,7 +725,7 @@
         return GRALLOC1_ERROR_BAD_VALUE;
       }
 
-      if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) == 0) {
+      if (getMetaData(hnd, GET_MAP_SECURE_BUFFER, map_secure_buffer) != 0) {
         *map_secure_buffer = 0;
       }
     } break;
@@ -853,8 +853,8 @@
     return GRALLOC1_ERROR_UNSUPPORTED;
   }
 
-  android_ycbcr ycbcr;
-  int err = GetYUVPlaneInfo(hnd, &ycbcr);
+  android_ycbcr yuvPlaneInfo[2];
+  int err = GetYUVPlaneInfo(hnd, yuvPlaneInfo);
 
   if (err != 0) {
     return GRALLOC1_ERROR_BAD_HANDLE;
@@ -872,6 +872,8 @@
     layout->planes[i].v_subsampling = 2;
   }
 
+  // We are only returning flex layout for progressive or single field formats.
+  struct android_ycbcr ycbcr = yuvPlaneInfo[0];
   layout->planes[0].top_left = static_cast<uint8_t *>(ycbcr.y);
   layout->planes[0].component = FLEX_COMPONENT_Y;
   layout->planes[0].v_increment = static_cast<int32_t>(ycbcr.ystride);