[PATCH] Make RDP backend supports arbitrary modes

Hardening rdp.effort at gmail.com
Tue Mar 18 10:15:54 PDT 2014


This patch removes the extra modes parameter for the RDP compositor. And
make it support any mode that is requested (be aware that RDP client may not
support all possible modes, especially odd resolution).
This is definitely useful for the fullscreen shell.
---
 src/compositor-rdp.c | 105 +++++++++++++++++++--------------------------------
 src/compositor.c     |   1 -
 2 files changed, 38 insertions(+), 68 deletions(-)

diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
index e8e4a8d..22380cb 100644
--- a/src/compositor-rdp.c
+++ b/src/compositor-rdp.c
@@ -49,6 +49,7 @@
 
 #define MAX_FREERDP_FDS 32
 #define DEFAULT_AXIS_STEP_DISTANCE wl_fixed_from_int(10)
+#define RDP_MODE_FREQ 60 * 1000
 
 struct rdp_compositor_config {
 	int width;
@@ -58,7 +59,6 @@ struct rdp_compositor_config {
 	char *rdp_key;
 	char *server_cert;
 	char *server_key;
-	char *extra_modes;
 	int env_socket;
 };
 
@@ -121,7 +121,6 @@ rdp_compositor_config_init(struct rdp_compositor_config *config) {
 	config->rdp_key = NULL;
 	config->server_cert = NULL;
 	config->server_key = NULL;
-	config->extra_modes = NULL;
 	config->env_socket = 0;
 }
 
@@ -320,11 +319,13 @@ rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
 	pixman_renderer_output_set_buffer(output_base, output->shadow_surface);
 	ec->renderer->repaint_output(&output->base, damage);
 
-	wl_list_for_each(outputPeer, &output->peers, link) {
-		if ((outputPeer->flags & RDP_PEER_ACTIVATED) &&
-				(outputPeer->flags & RDP_PEER_OUTPUT_ENABLED))
-		{
-			rdp_peer_refresh_region(damage, outputPeer->peer);
+	if (pixman_region32_n_rects(damage)) {
+		wl_list_for_each(outputPeer, &output->peers, link) {
+			if ((outputPeer->flags & RDP_PEER_ACTIVATED) &&
+					(outputPeer->flags & RDP_PEER_OUTPUT_ENABLED))
+			{
+				rdp_peer_refresh_region(damage, outputPeer->peer);
+			}
 		}
 	}
 
@@ -352,16 +353,29 @@ finish_frame_handler(void *data)
 	return 1;
 }
 
+static struct weston_mode *
+rdp_insert_new_mode(struct weston_output *output, int width, int height, int rate) {
+	struct weston_mode *ret;
+	ret = zalloc(sizeof *ret);
+	if(!ret)
+		return ret;
+	ret->width = width;
+	ret->height = height;
+	ret->refresh = rate;
+	wl_list_insert(&output->mode_list, &ret->link);
+	return ret;
+}
 
 static struct weston_mode *
-find_matching_mode(struct weston_output *output, struct weston_mode *target) {
+ensure_matching_mode(struct weston_output *output, struct weston_mode *target) {
 	struct weston_mode *local;
 
 	wl_list_for_each(local, &output->mode_list, link) {
 		if((local->width == target->width) && (local->height == target->height))
 			return local;
 	}
-	return 0;
+
+	return rdp_insert_new_mode(output, target->width, target->height, RDP_MODE_FREQ);
 }
 
 static int
@@ -372,7 +386,7 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
 	pixman_image_t *new_shadow_buffer;
 	struct weston_mode *local_mode;
 
-	local_mode = find_matching_mode(output, target_mode);
+	local_mode = ensure_matching_mode(output, target_mode);
 	if(!local_mode) {
 		weston_log("mode %dx%d not available\n", target_mode->width, target_mode->height);
 		return -ENOENT;
@@ -398,6 +412,9 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
 
 	wl_list_for_each(rdpPeer, &rdpOutput->peers, link) {
 		settings = rdpPeer->peer->settings;
+		if (settings->DesktopWidth == target_mode->width && settings->DesktopHeight == target_mode->height)
+			continue;
+
 		if(!settings->DesktopResize) {
 			/* too bad this peer does not support desktop resize */
 			rdpPeer->peer->Close(rdpPeer->peer);
@@ -411,49 +428,12 @@ rdp_switch_mode(struct weston_output *output, struct weston_mode *target_mode) {
 }
 
 static int
-parse_extra_modes(const char *modes_str, struct rdp_output *output) {
-	const char *startAt = modes_str;
-	const char *nextPos;
-	int w, h;
-	struct weston_mode *mode;
-
-	while(startAt && *startAt) {
-		nextPos = strchr(startAt, 'x');
-		if(!nextPos)
-			return -1;
-
-		w = strtoul(startAt, NULL, 0);
-		startAt = nextPos + 1;
-		if(!*startAt)
-			return -1;
-
-		h = strtoul(startAt, NULL, 0);
-
-		if(!w || (w > 3000) || !h || (h > 3000))
-			return -1;
-		mode = malloc(sizeof *mode);
-		if(!mode)
-			return -1;
-
-		mode->width = w;
-		mode->height = h;
-		mode->refresh = 5;
-		mode->flags = 0;
-		wl_list_insert(&output->base.mode_list, &mode->link);
-
-		startAt = strchr(startAt, ',');
-		if(startAt && *startAt == ',')
-			startAt++;
-	}
-	return 0;
-}
-static int
-rdp_compositor_create_output(struct rdp_compositor *c, int width, int height,
-		const char *extraModes)
+rdp_compositor_create_output(struct rdp_compositor *c, int width, int height)
 {
 	struct rdp_output *output;
 	struct wl_event_loop *loop;
-	struct weston_mode *currentMode, *next;
+	struct weston_mode *currentMode;
+	struct weston_mode initMode;
 
 	output = zalloc(sizeof *output);
 	if (output == NULL)
@@ -462,19 +442,14 @@ rdp_compositor_create_output(struct rdp_compositor *c, int width, int height,
 	wl_list_init(&output->peers);
 	wl_list_init(&output->base.mode_list);
 
-	currentMode = malloc(sizeof *currentMode);
+	initMode.flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+	initMode.width = width;
+	initMode.height = height;
+	initMode.refresh = RDP_MODE_FREQ;
+
+	currentMode = ensure_matching_mode(&output->base, &initMode);
 	if(!currentMode)
 		goto out_free_output;
-	currentMode->flags = WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
-	currentMode->width = width;
-	currentMode->height = height;
-	currentMode->refresh = 5;
-	wl_list_insert(&output->base.mode_list, &currentMode->link);
-
-	if(parse_extra_modes(extraModes, output) < 0) {
-		weston_log("invalid extra modes\n");
-		goto out_free_output_and_modes;
-	}
 
 	output->base.current_mode = output->base.native_mode = currentMode;
 	weston_output_init(&output->base, &c->base, 0, 0, width, height,
@@ -513,9 +488,6 @@ out_shadow_surface:
 	pixman_image_unref(output->shadow_surface);
 out_output:
 	weston_output_destroy(&output->base);
-out_free_output_and_modes:
-	wl_list_for_each_safe(currentMode, next, &output->base.mode_list, link)
-		free(currentMode);
 out_free_output:
 	free(output);
 	return -1;
@@ -704,7 +676,7 @@ xf_peer_post_connect(freerdp_peer* client)
 		struct weston_mode *target_mode;
 		new_mode.width = (int)settings->DesktopWidth;
 		new_mode.height = (int)settings->DesktopHeight;
-		target_mode = find_matching_mode(&output->base, &new_mode);
+		target_mode = ensure_matching_mode(&output->base, &new_mode);
 		if (!target_mode) {
 			weston_log("client mode not found\n");
 			return FALSE;
@@ -1030,7 +1002,7 @@ rdp_compositor_create(struct wl_display *display,
 	if (pixman_renderer_init(&c->base) < 0)
 		goto err_compositor;
 
-	if (rdp_compositor_create_output(c, config->width, config->height, config->extra_modes) < 0)
+	if (rdp_compositor_create_output(c, config->width, config->height) < 0)
 		goto err_compositor;
 
 	if(!config->env_socket) {
@@ -1093,7 +1065,6 @@ backend_init(struct wl_display *display, int *argc, char *argv[],
 		{ WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
 		{ WESTON_OPTION_INTEGER, "width", 0, &config.width },
 		{ WESTON_OPTION_INTEGER, "height", 0, &config.height },
-		{ WESTON_OPTION_STRING,  "extra-modes", 0, &config.extra_modes },
 		{ WESTON_OPTION_STRING,  "address", 0, &config.bind_address },
 		{ WESTON_OPTION_INTEGER, "port", 0, &config.port },
 		{ WESTON_OPTION_STRING,  "rdp4-key", 0, &config.rdp_key },
diff --git a/src/compositor.c b/src/compositor.c
index 7c29d51..803cda6 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -3972,7 +3972,6 @@ usage(int error_code)
        "Options for rdp-backend.so:\n\n"
        "  --width=WIDTH\t\tWidth of desktop\n"
        "  --height=HEIGHT\tHeight of desktop\n"
-       "  --extra-modes=MODES\t\n"
        "  --env-socket=SOCKET\tUse that socket as peer connection\n"
        "  --address=ADDR\tThe address to bind\n"
        "  --port=PORT\tThe port to listen on\n"
-- 
1.8.1.2



More information about the wayland-devel mailing list