weston: add interface with meson display [1/1]
PD#SWPL-155659
Problem:
support interface for meson display to call
Solution:
support interface for meson display to call
Verify:
ah212
Change-Id: Ie86052dee3da6b6da509e99f08dbe361861ab14c
Signed-off-by: leng.fang <leng.fang@amlogic.com>
diff --git a/libweston/modepolicy/modepolicy_aml.cpp b/libweston/modepolicy/modepolicy_aml.cpp
index 8258ea3..de11399 100644
--- a/libweston/modepolicy/modepolicy_aml.cpp
+++ b/libweston/modepolicy/modepolicy_aml.cpp
@@ -12,6 +12,7 @@
if (!gCtx) {
gCtx = (weston_ctx *)calloc(1, sizeof(*gCtx));
gCtx->need_update_hdmi_param = false;
+ gCtx->scaling = -1;
wl_list_init(&gCtx->prop_list);
}
return gCtx;
@@ -400,10 +401,8 @@
if (value)
scaling = atoi(value);
- if (ctx && ctx->head && ctx->head->output) {
- if (ctx->head->output->current_scale != scaling)
- ctx->head->output->current_scale = scaling;
- }
+ if (ctx && ctx->scaling != scaling)
+ ctx->scaling = scaling;
}
CompositorFunctionCallBack callback = {
@@ -415,6 +414,118 @@
.set_scaling_position = weston_set_scaling_position,
};
+static char *get_color_space_by_value(int value)
+{
+ char *str;
+
+ switch ( value ) {
+ case 0:
+ str = "rgb";
+ break;
+ case 1:
+ str = "422";
+ break;
+ case 2:
+ str = "444";
+ break;
+ case 3:
+ default:
+ str = "420";
+ break;
+ }
+ return str;
+}
+
+static int get_property_value(char *name)
+{
+ prop_info *info;
+ weston_ctx *ctx = weston_get_ctx();
+
+ wl_list_for_each(info, &ctx->prop_list, link) {
+ if (!strcmp(name, info->name)) {
+ if (info->need_change == 1)
+ return info->value;
+ }
+ }
+ return -1;
+}
+
+static int get_id_by_name(const char *name)
+{
+ prop_info *info;
+ weston_ctx *ctx = weston_get_ctx();
+
+ wl_list_for_each(info, &ctx->prop_list, link) {
+ if (!strcmp(name, info->name))
+ return info->item_id;
+ }
+ return -1;
+}
+
+static int mode_policy_parse_other(const char *name, int value)
+{
+ weston_ctx *ctx = weston_get_ctx();
+ char attrvalue[32] = { 0 };
+
+ if (STRCMPS(name, "scaling") == 0) {
+ if (ctx && ctx->scaling != value)
+ ctx->scaling = value;
+
+ sprintf(attrvalue, "%d", value);
+ bootenv_update("scaling", attrvalue);
+ return 0;
+ }
+ return -1;
+}
+
+int mode_policy_set_property(const char *name, int value)
+{
+ char attrvalue[32] = { 0 };
+ int color_space = 0;
+ int color_depth = 0;
+ int id = get_id_by_name(name);
+ MESON_LOGI("id: %d, name: %s, value: %d", id, name, value);
+
+ if (value < 0 || id < 0)
+ return mode_policy_parse_other(name, value);
+
+ if (strncmp(name, "dv_mode", sizeof("dv_mode")) == 0) {
+ setDvMode(value == 0 ? 1 : (value == 1 ? 2 : 0));
+ return 0;
+ } else if (strncmp(name, "color_depth", sizeof("color_depth")) == 0) {
+ color_space = get_property_value("color_space");
+ if (color_space >= 0) {
+ sprintf(attrvalue, "%s,%dbit", get_color_space_by_value(color_space), value);
+ setColorSpace(attrvalue);
+ mode_policy_update_bestmode(false);
+ return 0;
+ }
+ } else if (strncmp(name, "color_space", sizeof("color_space")) == 0) {
+ color_depth = get_property_value("color_depth");
+ if (color_depth >= 0) {
+ sprintf(attrvalue, "%s,%dbit", get_color_space_by_value(value), color_depth);
+ setColorSpace(attrvalue);
+ mode_policy_update_bestmode(false);
+ return 0;
+ }
+ } else if (strncmp(name, "meson.crtc.hdr_policy", sizeof("meson.crtc.hdr_policy")) == 0) {
+ sprintf(attrvalue, "%d", value);
+ bootenv_update("hdr_policy", attrvalue);
+ }
+
+ return weston_set_property(id, name, value);
+}
+
+int mode_policy_get_scaling()
+{
+ weston_ctx *ctx = weston_get_ctx();
+
+ if (ctx->scaling < 0)
+ return 100;
+
+ return ctx->scaling;
+}
+
static drmModeCrtc *weston_get_crtc_for_conn(int drm_fd, drmModeConnector *conn)
{
drmModeEncoder *encoder;
@@ -470,6 +581,7 @@
weston_ctx *ctx = weston_get_ctx();
prop_info *info;
int err = 0, ret = 0;
+ int count = 0;
wl_list_for_each(info, &ctx->prop_list, link) {
if (info->need_change) {
@@ -479,10 +591,12 @@
info->name, err, errno);
info->need_change = 0;
ret |= (err <= 0) ? -1 : 0;
+ if (!ret)
+ count++;
ctx->need_update_hdmi_param = true;
}
}
- return ret;
+ return ret >= 0 ? count : ret;
}
void mode_policy_set_hotplug(int plug)
@@ -519,7 +633,7 @@
} else {
if (ctx->hotplug & (AML_WESTON_HOTPLUG_PLUG | AML_WESTON_HOTPLUG_UNPLUG))
onHotplug(ctx->hotplug & AML_WESTON_HOTPLUG_PLUG);
- else if (ctx->hotplug & AML_WESTON_HOTPLUG_BOOT)
+ else if (ctx->hotplug & (AML_WESTON_HOTPLUG_BOOT | AML_WESTON_HOTPLUG_SET))
initModePolicy(NULL, NULL, callback);
ctx->hotplug = AML_WESTON_HOTPLUG_INIT;
}
@@ -528,6 +642,11 @@
return NULL;
}
+void mode_policy_update_bestmode(bool bestmode)
+{
+ bootenv_update("is.bestmode", bestmode ? "true" : "false");
+}
+
static void * wstUpdatenvThread(void *arg )
{
long long delay = 16667LL;