compositor-drm: get desktop shell window size from config

get desktop shell window size from config section "shell"
instead of from environment variable

Upstream-Status: Inappropriate [i.MX-specific]

Signed-off-by: Haihua Hu <jared.hu@nxp.com>
diff --git a/desktop-shell/shell.c b/desktop-shell/shell.c
index 9a44715..e5c3ef9 100644
--- a/desktop-shell/shell.c
+++ b/desktop-shell/shell.c
@@ -3001,6 +3001,7 @@
 		wl_resource_get_user_data(surface_resource);
 	struct shell_output *sh_output;
 	struct weston_view *view, *next;
+	struct weston_config_section *section;
 
 	if (surface->committed) {
 		wl_resource_post_error(surface_resource,
@@ -3018,6 +3019,26 @@
 	weston_surface_set_label_func(surface, background_get_label);
 	surface->output = weston_head_from_resource(output_resource)->output;
 	weston_view_set_output(view, surface->output);
+	
+	section = weston_config_get_section(wet_get_config(shell->compositor),
+					    "shell", NULL, NULL);
+	if (section) {
+		char *size;
+		int n;
+		int32_t width, height;
+
+		weston_config_section_get_string(section, "size", &size, NULL);
+
+		if(size){
+			n = sscanf(size, "%dx%d", &width, &height);
+			if (n == 2) {
+				if (surface->output->width > width)
+					surface->output->width = width;
+				if (surface->output->height > height)
+					surface->output->height = height;
+			}
+		}
+	}
 
 	sh_output = find_shell_output_from_weston_output(shell, surface->output);
 	if (sh_output->background_surface) {
@@ -3098,6 +3119,7 @@
 		wl_resource_get_user_data(surface_resource);
 	struct weston_view *view, *next;
 	struct shell_output *sh_output;
+	struct weston_config_section *section;
 
 	if (surface->committed) {
 		wl_resource_post_error(surface_resource,
@@ -3116,6 +3138,26 @@
 	surface->output = weston_head_from_resource(output_resource)->output;
 	weston_view_set_output(view, surface->output);
 
+	section = weston_config_get_section(wet_get_config(shell->compositor),
+					    "shell", NULL, NULL);
+	if (section) {
+		char *size;
+		int n;
+		int32_t width, height;
+
+		weston_config_section_get_string(section, "size", &size, NULL);
+
+		if(size){
+			n = sscanf(size, "%dx%d", &width, &height);
+			if (n == 2) {
+				if (surface->output->width > width)
+					surface->output->width = width;
+				if (surface->output->height > height)
+					surface->output->height = height;
+			}
+		}
+	}
+
 	sh_output = find_shell_output_from_weston_output(shell, surface->output);
 	if (sh_output->panel_surface) {
 		/* The output already has a panel, tell our helper
diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
index 8e34847..b2c3d12 100644
--- a/libweston/compositor-drm.c
+++ b/libweston/compositor-drm.c
@@ -49,6 +49,7 @@
 #include <gbm.h>
 #include <libudev.h>
 
+#include "compositor/weston.h"
 #include "compositor.h"
 #include "compositor-drm.h"
 #include "shared/helpers.h"
@@ -2176,6 +2177,7 @@
 	struct drm_plane *scanout_plane = output->scanout_plane;
 	struct drm_backend *b = to_drm_backend(c);
 	struct drm_fb *fb;
+	struct weston_config_section *section;
 
 	/* If we already have a client buffer promoted to scanout, then we don't
 	 * want to render. */
@@ -2236,6 +2238,25 @@
 	scanout_state->dest_w = scanout_state->src_w >> 16;
 	scanout_state->dest_h = scanout_state->src_h >> 16;
 
+	section = weston_config_get_section(wet_get_config(c),
+					    "shell", NULL, NULL);
+	if (section) {
+		char *size;
+		int n;
+		uint32_t width, height;
+
+		weston_config_section_get_string(section, "size", &size, NULL);
+
+		if(size){
+			n = sscanf(size, "%dx%d", &width, &height);
+			if (n == 2) {
+				if (scanout_state->src_w > (width << 16))
+					scanout_state->src_w = width << 16;
+				if (scanout_state->src_h > (height << 16))
+					scanout_state->src_h = height << 16;
+			}
+		}
+	}
 
 	pixman_region32_subtract(&c->primary_plane.damage,
 				 &c->primary_plane.damage, damage);