hwc2: Translate legacy dataspace to new values properly

Set and Get ClientTarget API's needs to translate the dataspace
to the new values before using to avoid incorrect translation to
standard/range/transfer.

Change-Id: I800d4c391975757a78a7d9794267ba0c54f69899
Crs-fixed: 2241721
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index 8f45c6d..aec6e90 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -763,6 +763,7 @@
                                                int32_t dataspace) {
   ColorMetaData color_metadata = {};
   if (dataspace != HAL_DATASPACE_UNKNOWN) {
+    dataspace = TranslateFromLegacyDataspace(dataspace);
     GetColorPrimary(dataspace, &(color_metadata.colorPrimaries));
     GetTransfer(dataspace, &(color_metadata.transfer));
     GetRange(dataspace, &(color_metadata.range));
@@ -936,7 +937,8 @@
     client_target_->SetLayerDataspace(dataspace);
     Layer *sdm_layer = client_target_->GetSDMLayer();
     // Data space would be validated at GetClientTargetSupport, so just use here.
-    sdm::GetSDMColorSpace(dataspace, &sdm_layer->input_buffer.color_metadata);
+    sdm::GetSDMColorSpace(client_target_->GetLayerDataspace(),
+                          &sdm_layer->input_buffer.color_metadata);
   }
 
   return HWC2::Error::None;
diff --git a/sdm/libs/hwc2/hwc_layers.cpp b/sdm/libs/hwc2/hwc_layers.cpp
index 6a1c82c..322259a 100644
--- a/sdm/libs/hwc2/hwc_layers.cpp
+++ b/sdm/libs/hwc2/hwc_layers.cpp
@@ -86,7 +86,7 @@
       *color_primary = ColorPrimaries_BT2020;
       break;
     default:
-      DLOGV_IF(kTagClient, "Unsupported Standard Request = %d", standard);
+      DLOGW_IF(kTagClient, "Unsupported Standard Request = %d", standard);
       supported_csc = false;
   }
   return supported_csc;
@@ -118,7 +118,7 @@
       *gamma_transfer = Transfer_Gamma2_8;
       break;
     default:
-      DLOGV_IF(kTagClient, "Unsupported Transfer Request = %d", transfer);
+      DLOGW_IF(kTagClient, "Unsupported Transfer Request = %d", transfer);
       supported_transfer = false;
   }
   return supported_transfer;
@@ -137,7 +137,7 @@
       *color_range = Range_Extended;
       break;
     default:
-      DLOGV_IF(kTagClient, "Unsupported Range Request = %d", range);
+      DLOGW_IF(kTagClient, "Unsupported Range Request = %d", range);
       return false;
   }
   return true;
@@ -153,6 +153,38 @@
   }
 }
 
+int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds) {
+  int32_t dataspace = legacy_ds;
+
+  if (dataspace & 0xffff) {
+    switch (dataspace & 0xffff) {
+      case HAL_DATASPACE_SRGB:
+        dataspace = HAL_DATASPACE_V0_SRGB;
+        break;
+      case HAL_DATASPACE_JFIF:
+        dataspace = HAL_DATASPACE_V0_JFIF;
+        break;
+      case HAL_DATASPACE_SRGB_LINEAR:
+        dataspace = HAL_DATASPACE_V0_SRGB_LINEAR;
+        break;
+      case HAL_DATASPACE_BT601_625:
+        dataspace = HAL_DATASPACE_V0_BT601_625;
+        break;
+      case HAL_DATASPACE_BT601_525:
+        dataspace = HAL_DATASPACE_V0_BT601_525;
+        break;
+      case HAL_DATASPACE_BT709:
+        dataspace = HAL_DATASPACE_V0_BT709;
+        break;
+      default:
+        // unknown legacy dataspace
+        DLOGW_IF(kTagClient, "Unsupported dataspace type %d", dataspace);
+    }
+  }
+
+  return dataspace;
+}
+
 // Retrieve ColorMetaData from android_data_space_t (STANDARD|TRANSFER|RANGE)
 bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata) {
   bool valid = false;
@@ -355,33 +387,8 @@
 }
 
 HWC2::Error HWCLayer::SetLayerDataspace(int32_t dataspace) {
-  // Map deprecated dataspace values to appropriate
-  // new enums
-  if (dataspace & 0xffff) {
-    switch (dataspace & 0xffff) {
-      case HAL_DATASPACE_SRGB:
-        dataspace = HAL_DATASPACE_V0_SRGB;
-        break;
-      case HAL_DATASPACE_JFIF:
-        dataspace = HAL_DATASPACE_V0_JFIF;
-        break;
-      case HAL_DATASPACE_SRGB_LINEAR:
-        dataspace = HAL_DATASPACE_V0_SRGB_LINEAR;
-        break;
-      case HAL_DATASPACE_BT601_625:
-        dataspace = HAL_DATASPACE_V0_BT601_625;
-        break;
-      case HAL_DATASPACE_BT601_525:
-        dataspace = HAL_DATASPACE_V0_BT601_525;
-        break;
-      case HAL_DATASPACE_BT709:
-        dataspace = HAL_DATASPACE_V0_BT709;
-        break;
-      default:
-        // unknown legacy dataspace
-        DLOGW_IF(kTagClient, "Unsupported dataspace type %d", dataspace);
-    }
-  }
+  // Map deprecated dataspace values to appropriate new enums
+  dataspace = TranslateFromLegacyDataspace(dataspace);
 
   // cache the dataspace, to be used later to update SDM ColorMetaData
   if (dataspace_ != dataspace) {
diff --git a/sdm/libs/hwc2/hwc_layers.h b/sdm/libs/hwc2/hwc_layers.h
index 7d978c8..eec038a 100644
--- a/sdm/libs/hwc2/hwc_layers.h
+++ b/sdm/libs/hwc2/hwc_layers.h
@@ -45,6 +45,8 @@
 bool GetRange(const int32_t &dataspace, ColorRange *color_range);
 bool GetSDMColorSpace(const int32_t &dataspace, ColorMetaData *color_metadata);
 bool IsBT2020(const ColorPrimaries &color_primary);
+int32_t TranslateFromLegacyDataspace(const int32_t &legacy_ds);
+
 enum GeometryChanges {
   kNone         = 0x000,
   kBlendMode    = 0x001,