meson_display: get mode support attrlist [1/1]

PD#SWPL-179798

Problem:
get mode support attrlist.
add get/set hdr priority api

Solution:
get mode support attrlist.
add get/set hdr priority api.

Verify:
AH212

Change-Id: I93f9b7cc40ebe3f7eaeb92a7da866a5303158f89
Signed-off-by: chen.wang1 <chen.wang1@amlogic.com>
diff --git a/display_framework/src/extension/display_settings/display_settings.h b/display_framework/src/extension/display_settings/display_settings.h
index 2539f0c..38d4c73 100644
--- a/display_framework/src/extension/display_settings/display_settings.h
+++ b/display_framework/src/extension/display_settings/display_settings.h
@@ -168,7 +168,7 @@
 uint32_t getDisplayHDRSupportList(DISPLAY_CONNECTOR_TYPE connType);
 uint32_t getDisplayDvCap(DISPLAY_CONNECTOR_TYPE connType);
 uint32_t getDisplayRxSupportHdrList(DISPLAY_CONNECTOR_TYPE connType);
-int getDisplaySupportAttrList(DisplayModeInfo* modeInfo,DISPLAY_CONNECTOR_TYPE connType);
+char* getDisplayModeSupportAttrList(char* modeName,DISPLAY_CONNECTOR_TYPE connType);
 int getDisplayDpmsStatus(DISPLAY_CONNECTOR_TYPE connType);
 float getDisplayFrameRate( DISPLAY_CONNECTOR_TYPE connType);
 int getDisplayPlaneSize( int* width, int* height );
@@ -191,6 +191,8 @@
 int getDisplayRxSupportedHdcpVersion(DISPLAY_CONNECTOR_TYPE connType);
 int getDisplayAutoFrmMode(int* value);
 int setDisplayAutoFrmMode(int value);
+int setDisplayHdrPriority(int value);
+int getDisplayHdrPriority(int* value);
 
 int display_meson_get_open();
 int display_meson_set_open();
diff --git a/display_framework/src/extension/display_settings/displayattribute/display_attribute.c b/display_framework/src/extension/display_settings/displayattribute/display_attribute.c
index 66fadba..e8c21d1 100644
--- a/display_framework/src/extension/display_settings/displayattribute/display_attribute.c
+++ b/display_framework/src/extension/display_settings/displayattribute/display_attribute.c
@@ -522,71 +522,52 @@
     return ret;
 }
 
-int getDisplaySupportAttrList(DisplayModeInfo* modeInfo,DISPLAY_CONNECTOR_TYPE connType) {
+char* getDisplayModeSupportAttrList(char* modeName,DISPLAY_CONNECTOR_TYPE connType) {
     char attr[32] = {'\0'};
-    char array[215][255] = {{'\0'}};
-    int  index = 0;
+    char buffer[215] = {'\0'};
+    int index = 0;
+    bool hdrStatus = false;
     char color[5] = {'\0'};
     int supportedcheck = -1;
-    int ret = -1;
-    int ColorDepth = 0;
-    drmModeAtomicReq *req = NULL;
-    if (modeInfo == NULL) {
-        ERROR("%s %d invalid parameter return",__FUNCTION__,__LINE__);
-        return ret;
-    }
     int fd = display_meson_get_open();
-    ret = meson_drm_getModeInfo(fd, connType, modeInfo);
-    if (ret == -1) {
-        ERROR("%s %d get modeInfo fail",__FUNCTION__,__LINE__);
-        return ret;
+    ENUM_DISPLAY_HDR_MODE displayHdrMode = getDisplayHdrStatus(connType);
+    if (displayHdrMode == MESON_DISPLAY_HDR10PLUS || displayHdrMode == MESON_DISPLAY_HDR10_ST2084 ||
+                 displayHdrMode == MESON_DISPLAY_HDR10_TRADITIONAL ||displayHdrMode == MESON_DISPLAY_HDR_HLG) {
+        hdrStatus = true;
     }
-    DEBUG("%s %d modeInfoName %s",__FUNCTION__,__LINE__, modeInfo->name);
+    DEBUG("%s %d current modeName: %s hdrStatus: %d",__FUNCTION__,__LINE__, modeName, hdrStatus);
     for (int ColorSpace = 0; ColorSpace < DISPLAY_COLOR_SPACE_RESERVED; ColorSpace++) {
         for (int colordepth = 0; colordepth < 3; colordepth++) {
-            switch ( colordepth ) {
-                case 0:
-                    ColorDepth = 8;
+            if ((ColorSpace == 1 && (colordepth == 0 || colordepth == 1))) {
+                continue;
+            }
+            int ColorDepth = (colordepth == 0) ? 8 : (colordepth == 1) ? 10 : 12;
+            if (hdrStatus && ColorDepth == 8) {
+                continue;
+            }
+            supportedcheck = modeAttrSupportedCheck(modeName, ColorSpace, ColorDepth, connType);
+            if (supportedcheck == 1) {
+                strncpy(color, (ColorSpace == 0) ? "rgb" : (ColorSpace == 1) ? "422" : (ColorSpace == 2) ? "444" : "420", sizeof(color));
+                snprintf(attr, sizeof(attr) - 1, "%s,%dbit", color, ColorDepth);
+                strcpy(buffer + index, attr);
+                index += strlen(attr);
+                if (index < sizeof(buffer) - 1) {
+                    buffer[index++] = ' ';
+                } else {
+                    ERROR("%s %d Error: Not enough space in buffer\n",__FUNCTION__,__LINE__);
                     break;
-                case 1:
-                    ColorDepth = 10;
-                    break;
-                case 2:
-                    ColorDepth = 12;
-                    break;
-                default:
-                    break;
-             }
-             supportedcheck = modeAttrSupportedCheck(modeInfo->name,ColorSpace,ColorDepth,connType );
-             if (supportedcheck == 1) {
-                 switch ( ColorSpace ) {
-                     case 0:
-                         sprintf(color, "rgb");
-                         break;
-                     case 1:
-                         sprintf(color, "422");
-                         break;
-                     case 2:
-                         sprintf(color, "444");
-                         break;
-                     case 3:
-                         sprintf(color, "420");
-                         break;
-                     default:
-                         break;
-             }
-             snprintf(attr, sizeof(attr)-1, "%s,%dbit", color, ColorDepth);
-             strcpy(array[index++], attr);
-             ret = 0;
+                }
             }
         }
     }
-    DEBUG("%s %d attr list count: %d",__FUNCTION__,__LINE__,index);
-    for (int i = 0; i < index; i++) {
-        DEBUG_EDID("%s\n",array[i]);
+    buffer[index] = '\0';
+    int len = strlen(buffer) + 1;
+    char* new_str = (char*)malloc(len * sizeof(char));
+    if (new_str == NULL) {
+        return NULL;
     }
-    meson_close_drm(fd);
-    return ret;
+    strncpy(new_str, buffer, len);
+    return new_str;
 }
 
 int getDisplaySupportedDvMode( DISPLAY_CONNECTOR_TYPE connType ) {
diff --git a/display_framework/src/extension/display_settings/meson/meson_settings_Test.c b/display_framework/src/extension/display_settings/meson/meson_settings_Test.c
index d9dc2c8..f9e9ed3 100644
--- a/display_framework/src/extension/display_settings/meson/meson_settings_Test.c
+++ b/display_framework/src/extension/display_settings/meson/meson_settings_Test.c
@@ -154,16 +154,16 @@
                     printf("\n scanf fail\n");
                 }
         } else if (set == 5 && len == 1) {
-                uint32_t colorSpace = 0;
-                uint32_t colorDepth = 0;
-                printf("\n Please set <colorDepth, colorSpace> property value:\n");
-                scanf("%d %d", &colorDepth,&colorSpace);
-                int ret = setDisplayColorSpacedDepth(colorDepth, colorSpace, DISPLAY_CONNECTOR_HDMIA);
-                if (ret == 0) {
-                    printf("\n set <colorDepth, colorSpace> Success!\n");
-                } else {
-                    printf("\n set value Fail!\n");
-                }
+            uint32_t colorSpace = 0;
+            uint32_t colorDepth = 0;
+            printf("\n Please set <colorDepth, colorSpace> property value:\n");
+            scanf("%d %d", &colorDepth,&colorSpace);
+            int ret = setDisplayColorSpacedDepth(colorDepth, colorSpace, DISPLAY_CONNECTOR_HDMIA);
+            if (ret == 0) {
+                printf("\n set <colorDepth, colorSpace> Success!\n");
+            } else {
+                printf("\n set value Fail!\n");
+            }
         } else if (set == 6 && len == 1) {
             printf("\n HDCP Content Type:\n");
             int HDCPContentType = 0;
@@ -566,14 +566,23 @@
             int value = getDisplayDpmsStatus( DISPLAY_CONNECTOR_HDMIA );
             printf("\n get dpms status: %d\n",value);
         } else if(get == 26 && len == 1) {
-            int num = getDisplaySupportAttrList( modeInfo, DISPLAY_CONNECTOR_HDMIA);
-            if (num == 0) {
-                printf("\n getDisplaySupportAttrList Success");
+            char mode[32] = {'\0'};
+            printf("\n please input mode name:\n");
+            scanf("%s", mode);
+            printf("\n mode: %s\n",mode);
+            char* attrs = getDisplayModeSupportAttrList(mode, DISPLAY_CONNECTOR_HDMIA);
+            if (attrs) {
+                printf("%s\n", attrs);
+                printf("get current mode support attribute list:\n");
+                char* token = strtok(attrs, " ");
+                while (token != NULL) {
+                    printf("%s\n", token);
+                    token = strtok(NULL, " ");
+                }
+                free(attrs);
             } else {
-                printf("\n getDisplaySupportAttrList Fail");
+                printf("Failed to get attribute list.");
             }
-            if (modeInfo)
-                free(modeInfo);
         } else if(get == 27 && len == 1) {
             //name:FRAC_RATE_POLICY value:0 整数mode, value:1 小数mode , 大部分情况下默认开机是小数
             float value = getDisplayFrameRate(DISPLAY_CONNECTOR_HDMIA);
diff --git a/display_framework/src/extension/display_settings/westeros/westeros_settings_Test.c b/display_framework/src/extension/display_settings/westeros/westeros_settings_Test.c
index 6bc2b43..67ebad2 100644
--- a/display_framework/src/extension/display_settings/westeros/westeros_settings_Test.c
+++ b/display_framework/src/extension/display_settings/westeros/westeros_settings_Test.c
@@ -120,16 +120,16 @@
                     printf("\n scanf fail\n");
                 }
         } else if (set == 5 && len == 1) {
-                uint32_t colorSpace = 0;
-                uint32_t colorDepth = 0;
-                printf("\n Please set <colorDepth, colorSpace> property value:\n");
-                scanf("%d %d", &colorDepth,&colorSpace);
-                int ret = setDisplayColorSpacedDepth(colorDepth, colorSpace, DISPLAY_CONNECTOR_HDMIA);
-                if (ret == 0) {
-                    printf("\n set <colorDepth, colorSpace> Success!\n");
-                } else {
-                    printf("\n set value Fail!\n");
-                }
+            uint32_t colorSpace = 0;
+            uint32_t colorDepth = 0;
+            printf("\n Please set <colorDepth, colorSpace> property value:\n");
+            scanf("%d %d", &colorDepth,&colorSpace);
+            int ret = setDisplayColorSpacedDepth(colorDepth, colorSpace, DISPLAY_CONNECTOR_HDMIA);
+            if (ret == 0) {
+                printf("\n set <colorDepth, colorSpace> Success!\n");
+            } else {
+                printf("\n set value Fail!\n");
+            }
         } else if (set == 6 && len == 1) {
             printf("\n HDCP Content Type:\n");
             int HDCPContentType = 0;
@@ -497,14 +497,23 @@
             int value = getDisplayDpmsStatus( DISPLAY_CONNECTOR_HDMIA );
             printf("\n get dpms status: %d\n",value);
         } else if(get == 28 && len == 1) {
-            int num = getDisplaySupportAttrList( modeInfo, DISPLAY_CONNECTOR_HDMIA);
-            if (num == 0) {
-                printf("\n getDisplaySupportAttrList Success\n");
+            char mode[32] = {'\0'};
+            printf("\n please input mode name:\n");
+            scanf("%s", mode);
+            printf("\n mode: %s\n",mode);
+            char* attrs = getDisplayModeSupportAttrList(mode,DISPLAY_CONNECTOR_HDMIA);
+            if (attrs) {
+                printf("%s\n", attrs);
+                printf("get current mode support attribute list:\n");
+                char* token = strtok(attrs, " ");
+                while (token != NULL) {
+                    printf("%s\n", token);
+                    token = strtok(NULL, " ");
+                }
+                free(attrs);
             } else {
-                printf("\n getDisplaySupportAttrList Fail\n");
+                printf("Failed to get attribute list.");
             }
-            if (modeInfo)
-                free(modeInfo);
         } else if(get == 29 && len == 1) {
             //name:FRAC_RATE_POLICY value:0 整数mode, value:1 小数mode , 大部分情况下默认开机是小数
             float value = getDisplayFrameRate( DISPLAY_CONNECTOR_HDMIA);
diff --git a/display_framework/src/extension/display_settings/weston/weston_settings.c b/display_framework/src/extension/display_settings/weston/weston_settings.c
index bb0835f..0e16526 100644
--- a/display_framework/src/extension/display_settings/weston/weston_settings.c
+++ b/display_framework/src/extension/display_settings/weston/weston_settings.c
@@ -684,6 +684,41 @@
     return rc;
 }
 
+int setDisplayHdrPriority(int value) {
+    int ret = -1;
+    int rc = -1;
+    char resp[CMDBUF_SIZE] = {'\0'};
+    char cmdBuf[CMDBUF_SIZE] = {'\0'};
+
+    snprintf(cmdBuf, sizeof(cmdBuf) - 1, "-r \"set hdr_priority %d\"", value);
+    rc = wstDisplaySendMessage(cmdBuf,resp);
+    if (rc >= 0) {
+        ret = 0;
+    } else {
+        ERROR("%s %d send message fail", __FUNCTION__, __LINE__);
+    }
+    return ret;
+}
+
+int getDisplayHdrPriority(int* value) {
+    char resp[CMDBUF_SIZE] = {'\0'};
+    char cmdBuf[CMDBUF_SIZE] = {'\0'};
+    int rc = -1;
+    if (value == NULL) {
+        ERROR("%s %d Error: pointers are NULL.\n",__FUNCTION__,__LINE__);
+        return rc;
+    }
+    snprintf(cmdBuf, sizeof(cmdBuf)-1, "-r \"get hdr_priority\"");
+    rc = wstDisplaySendMessage(cmdBuf,resp);
+    if (rc >= 0) {
+        *value = getValueFromOutputString(resp, "priority");
+        DEBUG("%s %d get hdr_priority %d",__FUNCTION__,__LINE__,*value);
+    } else {
+        ERROR("%s %d send message fail",__FUNCTION__,__LINE__);
+    }
+    return rc;
+}
+
 int getDisplayScaling(int* value) {
     char resp[CMDBUF_SIZE] = {'\0'};
     char cmdBuf[CMDBUF_SIZE] = {'\0'};
diff --git a/display_framework/src/extension/display_settings/weston/weston_settings_Test.c b/display_framework/src/extension/display_settings/weston/weston_settings_Test.c
index 775a02f..3ace0e0 100644
--- a/display_framework/src/extension/display_settings/weston/weston_settings_Test.c
+++ b/display_framework/src/extension/display_settings/weston/weston_settings_Test.c
@@ -46,7 +46,7 @@
         printf("set:0->hdmi mode 1->cvbs mode 2->hdr policy 3->av mute 4->HDMI HDCP enable 5-><colorDepth, colorSpace>"
         "6->HDCP Content Type 7->DvEnable 8->active 9->vrr Enable 10->auto mode 11->dummy mode 12->aspect ratio 13->mode attr"
         "14->dv mode 15->cvbs video mute 16->frac rate policy 17->scaling 18->auto-frm-mode 19->frac mode 20->the status of display"
-        "21->allm\n");
+        "21->allm 22->hdr_priority\n");
         len = scanf("%d",&set);
         if (set == 0 && len == 1) {
             printf("please input modeInfo: interlace, w, h, vrefresh\n");
@@ -286,6 +286,15 @@
             } else {
                     printf("\n scanf fail\n");
             }
+        } else if (set == 22 && len == 1) {
+            printf("please enter hdr_priority value: \n");
+            int enable = -1;
+            scanf("%d", &enable);
+            if (setDisplayHdrPriority(enable) == 0) {
+                printf("\n setDisplayHdrPriority Success\n");
+            }else{
+                printf("setDisplayHdrPriority Fail\n");
+            }
         }
     }
     else if(select_s == 1 && select_len == 1) {
@@ -296,7 +305,7 @@
          " 24->DvCap 25->dpms status 26->mode support attrlist 27->framrate 28->primar plane fb size "
          " 29>physical size 30->Timing information 31->dv mode 32->rx supported hdcp version 33->cvbs video mute "
          " 34->frac rate policy 35->hdcp topo info 36->scaling 37->auto-frm-mode 38->display enabled 39->is bestmode"
-         " 40->Rx supported hdr list 41->allm 42->vrr_capable\n");
+         " 40->Rx supported hdr list 41->allm 42->vrr_capable 43->hdr_priority\n");
         len = scanf("%d",&get);
         if (get == 0 && len == 1) {
             ENUM_DISPLAY_HDR_POLICY value = getDisplayHDRPolicy( DISPLAY_CONNECTOR_HDMIA);
@@ -494,14 +503,23 @@
             int value = getDisplayDpmsStatus( DISPLAY_CONNECTOR_HDMIA );
             printf("\n get dpms status: %d\n",value);
         } else if(get == 26 && len == 1) {
-            int num = getDisplaySupportAttrList( modeInfo, DISPLAY_CONNECTOR_HDMIA);
-            if (num == 0) {
-                printf("\n getDisplaySupportAttrList Success");
+            char mode[32] = {'\0'};
+            printf("\n please input mode name:\n");
+            scanf("%s", mode);
+            printf("\n mode: %s\n",mode);
+            char* attrs = getDisplayModeSupportAttrList(mode,DISPLAY_CONNECTOR_HDMIA);
+            if (attrs) {
+                printf("%s\n", attrs);
+                printf("get current mode support attribute list: \n");
+                char* token = strtok(attrs, " ");
+                while (token != NULL) {
+                    printf("%s\n", token);
+                    token = strtok(NULL, " ");
+                }
+                free(attrs);
             } else {
-                printf("\n getDisplaySupportAttrList Fail");
+                printf("Failed to get attribute list.");
             }
-            if (modeInfo)
-                free(modeInfo);
         } else if(get == 27 && len == 1) {
             float value = getDisplayFrameRate( DISPLAY_CONNECTOR_HDMIA);
             printf("\n get framrate %.2f",value);
@@ -621,6 +639,13 @@
         } else if (get == 42 && len == 1) {
             int value = getDisplayVrrCapable( DISPLAY_CONNECTOR_HDMIA);
             printf("\n VrrCapable value: %d\n",value);
+        }  else if (get == 43 && len == 1) {
+            int enabled = 0;
+            if (getDisplayHdrPriority(&enabled)< 0) {
+                printf("send message fail, cause get the status of display fail\n");
+            } else {
+                printf("get hdr_priority value %d\n",enabled);
+            }
         }
     }
     else {