Merge "sdm: Add support for rotator with DRM"
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index f3e9dd4..42416e8 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -254,6 +254,9 @@
             case HAL_PIXEL_FORMAT_RAW16:
                 aligned_w = ALIGN(width, 16);
                 break;
+            case HAL_PIXEL_FORMAT_RAW12:
+                aligned_w = ALIGN(width * 12 / 8, 8);
+                break;
             case HAL_PIXEL_FORMAT_RAW10:
                 aligned_w = ALIGN(width * 10 / 8, 8);
                 break;
@@ -562,6 +565,9 @@
         case HAL_PIXEL_FORMAT_RAW16:
             size = alignedw * alignedh * 2;
             break;
+        case HAL_PIXEL_FORMAT_RAW12:
+            size = ALIGN(alignedw * alignedh, 4096);
+            break;
         case HAL_PIXEL_FORMAT_RAW10:
             size = ALIGN(alignedw * alignedh, 4096);
             break;
@@ -802,6 +808,7 @@
         case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
         case HAL_PIXEL_FORMAT_NV21_ZSL:
         case HAL_PIXEL_FORMAT_RAW16:
+        case HAL_PIXEL_FORMAT_RAW12:
         case HAL_PIXEL_FORMAT_RAW10:
             getYuvSPPlaneInfo(hnd->base, width, height, 1, ycbcr);
             std::swap(ycbcr->cb, ycbcr->cr);
diff --git a/libgralloc1/gr_utils.cpp b/libgralloc1/gr_utils.cpp
index 98b6889..f3c4ba8 100644
--- a/libgralloc1/gr_utils.cpp
+++ b/libgralloc1/gr_utils.cpp
@@ -52,6 +52,7 @@
     case HAL_PIXEL_FORMAT_ABGR_2101010:
     case HAL_PIXEL_FORMAT_BGRX_1010102:
     case HAL_PIXEL_FORMAT_XBGR_2101010:
+    case HAL_PIXEL_FORMAT_RGBA_FP16:
       return true;
     default:
       break;
@@ -101,6 +102,9 @@
 uint32_t GetBppForUncompressedRGB(int format) {
   uint32_t bpp = 0;
   switch (format) {
+    case HAL_PIXEL_FORMAT_RGBA_FP16:
+      bpp = 8;
+      break;
     case HAL_PIXEL_FORMAT_RGBA_8888:
     case HAL_PIXEL_FORMAT_RGBX_8888:
     case HAL_PIXEL_FORMAT_BGRA_8888:
diff --git a/libgralloc1/gralloc_priv.h b/libgralloc1/gralloc_priv.h
index fa04b1b..758ac67 100644
--- a/libgralloc1/gralloc_priv.h
+++ b/libgralloc1/gralloc_priv.h
@@ -118,7 +118,6 @@
 #define HAL_PIXEL_FORMAT_BGR_565 0x115
 
 // 10 bit
-#define HAL_PIXEL_FORMAT_RGBA_1010102 0x116
 #define HAL_PIXEL_FORMAT_ARGB_2101010 0x117
 #define HAL_PIXEL_FORMAT_RGBX_1010102 0x118
 #define HAL_PIXEL_FORMAT_XRGB_2101010 0x119
diff --git a/sdm/include/utils/rect.h b/sdm/include/utils/rect.h
index 16a9ba9..ea6edfb 100644
--- a/sdm/include/utils/rect.h
+++ b/sdm/include/utils/rect.h
@@ -57,7 +57,8 @@
                       bool flip_horizontal, LayerRect *out_rects);
   void MapRect(const LayerRect &src_domain, const LayerRect &dst_domain, const LayerRect &in_rect,
                LayerRect *out_rect);
-  void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect, LayerRect *out_rect);
+  void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect,
+                   const LayerTransform &transform, LayerRect *out_rect);
   RectOrientation GetOrientation(const LayerRect &in_rect);
 }  // namespace sdm
 
diff --git a/sdm/libs/core/display_primary.cpp b/sdm/libs/core/display_primary.cpp
index 3a1541e..409d659 100644
--- a/sdm/libs/core/display_primary.cpp
+++ b/sdm/libs/core/display_primary.cpp
@@ -91,16 +91,19 @@
   bool needs_hv_flip = hw_panel_info_.panel_orientation.flip_horizontal &&
                           hw_panel_info_.panel_orientation.flip_vertical;
   LayerRect src_domain = {};
+  LayerTransform panel_transform = {};
   DisplayConfigVariableInfo variable_info = {};
 
   if (needs_hv_flip) {
     DisplayBase::GetFrameBufferConfig(&variable_info);
     src_domain.right = variable_info.x_pixels;
     src_domain.bottom = variable_info.y_pixels;
+    panel_transform.flip_horizontal = hw_panel_info_.panel_orientation.flip_horizontal;
+    panel_transform.flip_vertical = hw_panel_info_.panel_orientation.flip_vertical;
 
     for (Layer *layer : layer_stack->layers) {
       // Modify destination based on panel flip
-      TransformHV(src_domain, layer->dst_rect, &layer->dst_rect);
+      TransformHV(src_domain, layer->dst_rect, panel_transform, &layer->dst_rect);
 
       if (layer->flags.solid_fill) {
         continue;
diff --git a/sdm/libs/hwc/hwc_display_primary.cpp b/sdm/libs/hwc/hwc_display_primary.cpp
index d12897e..8b0a6f2 100644
--- a/sdm/libs/hwc/hwc_display_primary.cpp
+++ b/sdm/libs/hwc/hwc_display_primary.cpp
@@ -211,7 +211,7 @@
     DisplayConfigFixedInfo display_config;
     display_intf_->GetConfig(&display_config);
     if (display_config.is_cmdmode) {
-      DLOGI("Skipping null commit on cmd mode panel");
+      DLOGV("Skipping null commit on cmd mode panel");
     } else {
       flush_ = true;
     }
@@ -232,7 +232,7 @@
   DisplayConfigFixedInfo display_config;
   display_intf_->GetConfig(&display_config);
   if (content_list->numHwLayers <= 1 && display_config.is_cmdmode) {
-    DLOGI("Skipping null commit on cmd mode panel");
+    DLOGV("Skipping null commit on cmd mode panel");
     return 0;
   }
 
diff --git a/sdm/libs/hwc/hwc_session.cpp b/sdm/libs/hwc/hwc_session.cpp
index ff6b2a7..a324856 100644
--- a/sdm/libs/hwc/hwc_session.cpp
+++ b/sdm/libs/hwc/hwc_session.cpp
@@ -140,6 +140,12 @@
     return -EINVAL;
   }
 
+  if (pthread_create(&uevent_thread_, NULL, &HWCUeventThread, this) < 0) {
+    DLOGE("Failed to start = %s, error = %s", uevent_thread_name_, strerror(errno));
+    CoreInterface::DestroyCore();
+    return -errno;
+  }
+
   // Read which display is first, and create it and store it in primary slot
   HWDisplayInterfaceInfo hw_disp_info;
   error = core_intf_->GetFirstDisplayInterfaceType(&hw_disp_info);
@@ -171,6 +177,8 @@
 
   if (status) {
     CoreInterface::DestroyCore();
+    uevent_thread_exit_ = true;
+    pthread_join(uevent_thread_, NULL);
     return status;
   }
 
@@ -179,14 +187,6 @@
     DLOGW("Failed to load HWCColorManager.");
   }
 
-  if (pthread_create(&uevent_thread_, NULL, &HWCUeventThread, this) < 0) {
-    DLOGE("Failed to start = %s, error = %s", uevent_thread_name_, strerror(errno));
-    HWCDisplayPrimary::Destroy(hwc_display_[HWC_DISPLAY_PRIMARY]);
-    hwc_display_[HWC_DISPLAY_PRIMARY] = 0;
-    CoreInterface::DestroyCore();
-    return -errno;
-  }
-
   connected_displays_[HWC_DISPLAY_PRIMARY] = 1;
   struct rlimit fd_limit = {};
   getrlimit(RLIMIT_NOFILE, &fd_limit);
@@ -1222,7 +1222,7 @@
     return 0;
   }
 
-  std::vector<int32_t> supported_hdr_types = {};
+  std::vector<int32_t> supported_hdr_types;
   // Only HDR10 supported now, in future add other supported HDR formats(HLG, DolbyVision)
   supported_hdr_types.push_back(HAL_HDR_HDR10);
 
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index b497a36..d514e74 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -32,6 +32,7 @@
 #include <utils/debug.h>
 #include <sync/sync.h>
 #include <profiler.h>
+#include <algorithm>
 #include <string>
 #include <bitset>
 
@@ -283,9 +284,10 @@
     return;
   }
   auto *hwc_session = static_cast<HWCSession *>(device);
+  const size_t max_dump_size = 8192;
 
   if (out_buffer == nullptr) {
-    *out_size = 8192;  // TODO(user): Adjust required dump size
+    *out_size = max_dump_size;
   } else {
     char sdm_dump[4096];
     DumpInterface::GetDump(sdm_dump, 4096);  // TODO(user): Fix this workaround
@@ -296,8 +298,8 @@
       }
     }
     s += sdm_dump;
-    s.copy(out_buffer, s.size(), 0);
-    *out_size = sizeof(out_buffer);
+    auto copied = s.copy(out_buffer, std::min(s.size(), max_dump_size), 0);
+    *out_size = UINT32(copied);
   }
 }
 
diff --git a/sdm/libs/utils/rect.cpp b/sdm/libs/utils/rect.cpp
index dd5a872..b0cd536 100644
--- a/sdm/libs/utils/rect.cpp
+++ b/sdm/libs/utils/rect.cpp
@@ -223,18 +223,27 @@
   out_rect->bottom = dst_domain.top + (height_ratio * modified_in_rect.bottom);
 }
 
-void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect, LayerRect *out_rect) {
+void TransformHV(const LayerRect &src_domain, const LayerRect &in_rect,
+                 const LayerTransform &transform, LayerRect *out_rect) {
   if (!IsValid(src_domain) || !IsValid(in_rect)) {
     return;
   }
 
   float in_width = in_rect.right - in_rect.left;
   float in_height = in_rect.bottom - in_rect.top;
+  float x_offset = in_rect.left - src_domain.left;
+  float y_offset = in_rect.top - src_domain.top;
+  *out_rect = in_rect;
 
-  out_rect->right = src_domain.right - in_rect.left;
-  out_rect->bottom = src_domain.bottom - in_rect.top;
-  out_rect->left = out_rect->right - in_width;
-  out_rect->top = out_rect->bottom - in_height;
+  if (transform.flip_horizontal) {
+    out_rect->right = src_domain.right - x_offset;
+    out_rect->left = out_rect->right - in_width;
+  }
+
+  if (transform.flip_vertical) {
+    out_rect->bottom = src_domain.bottom - y_offset;
+    out_rect->top = out_rect->bottom - in_height;
+  }
 }
 
 RectOrientation GetOrientation(const LayerRect &in_rect) {