[PATCH 3/3] shell: Implement "driver" method of fullsceen.

zhiwen.wu at linux.intel.com zhiwen.wu at linux.intel.com
Tue Apr 17 02:20:49 PDT 2012


From: Alex Wu <zhiwen.wu at linux.intel.com>

Switching display mode may happen when:
1. The fullscreen surface is at top most in fullscreen layer and with
   "driver" method. Shell will switch output mode to match the surface
   size. If no matched mode found, fall back to "fill" method.
2. The top fullscreen surface is destroyed or unset. Switch back to the
   origin mode.
---
 src/compositor-drm.c     |    1 +
 src/compositor-openwfd.c |    1 +
 src/compositor-wayland.c |    1 +
 src/compositor-x11.c     |    1 +
 src/compositor.h         |    1 +
 src/shell.c              |   91 ++++++++++++++++++++++++++++++++++++----------
 6 files changed, 77 insertions(+), 19 deletions(-)

diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index deda815..6c06438 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1308,6 +1308,7 @@ create_output_for_connector(struct drm_compositor *ec,
 		output_handle_pending_scanout_buffer_destroy;
 
 	output->next_fb_id = 0;
+	output->base.origin = output->base.current;
 	output->base.repaint = drm_output_repaint;
 	output->base.destroy = drm_output_destroy;
 	output->base.assign_planes = drm_assign_planes;
diff --git a/src/compositor-openwfd.c b/src/compositor-openwfd.c
index bbf1067..3548dfb 100644
--- a/src/compositor-openwfd.c
+++ b/src/compositor-openwfd.c
@@ -401,6 +401,7 @@ create_output_for_port(struct wfd_compositor *ec,
 
 	wfdDeviceCommit(ec->dev, WFD_COMMIT_ENTIRE_DEVICE, WFD_INVALID_HANDLE);
 
+	output->base.origin = output->base.current;
 	output->base.repaint = wfd_output_repaint;
 	output->base.prepare_scanout_surface =
 		wfd_output_prepare_scanout_surface;
diff --git a/src/compositor-wayland.c b/src/compositor-wayland.c
index 561a68c..2bfed7d 100644
--- a/src/compositor-wayland.c
+++ b/src/compositor-wayland.c
@@ -455,6 +455,7 @@ wayland_compositor_create_output(struct wayland_compositor *c,
 	/* FIXME: add shell_surface listener for resizing */
 	wl_shell_surface_set_toplevel(output->parent.shell_surface);
 
+	output->base.origin = output->base.current;
 	output->base.repaint = wayland_output_repaint;
 	output->base.destroy = wayland_output_destroy;
 	output->base.assign_planes = NULL;
diff --git a/src/compositor-x11.c b/src/compositor-x11.c
index 4a487d7..f464ef1 100644
--- a/src/compositor-x11.c
+++ b/src/compositor-x11.c
@@ -465,6 +465,7 @@ x11_compositor_create_output(struct x11_compositor *c, int x, int y,
 	output->finish_frame_timer =
 		wl_event_loop_add_timer(loop, finish_frame_handler, output);
 
+	output->base.origin = output->base.current;
 	output->base.repaint = x11_output_repaint;
 	output->base.destroy = x11_output_destroy;
 	output->base.assign_planes = NULL;
diff --git a/src/compositor.h b/src/compositor.h
index a0eb84b..88c586f 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -91,6 +91,7 @@ struct weston_output {
 	uint32_t subpixel;
 	
 	struct weston_mode *current;
+	struct weston_mode *origin;
 	struct wl_list mode_list;
 
 	void (*repaint)(struct weston_output *output,
diff --git a/src/shell.c b/src/shell.c
index 02061c6..b412d8c 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -155,6 +155,29 @@ struct rotate_grab {
 	} center;
 };
 
+static struct shell_surface *
+get_shell_surface(struct weston_surface *surface);
+
+static struct desktop_shell *
+shell_surface_get_shell(struct shell_surface *shsurf);
+
+static bool
+shell_surface_is_top_fullscreen(struct shell_surface *shsurf)
+{
+	struct desktop_shell *shell;
+	struct weston_surface *top_fs_es;
+
+	shell = shell_surface_get_shell(shsurf);
+	
+	if (wl_list_empty(&shell->fullscreen_layer.surface_list))
+		return false;
+
+	top_fs_es = container_of(shell->fullscreen_layer.surface_list.next,
+			         struct weston_surface, 
+				 layer_link);
+	return (shsurf == get_shell_surface(top_fs_es));
+}
+
 static void
 destroy_shell_grab_shsurf(struct wl_listener *listener, void *data)
 {
@@ -189,9 +212,6 @@ static void
 center_on_output(struct weston_surface *surface,
 		 struct weston_output *output);
 
-static struct shell_surface *
-get_shell_surface(struct weston_surface *surface);
-
 static void
 shell_configuration(struct desktop_shell *shell)
 {
@@ -434,11 +454,17 @@ static void
 shell_unset_fullscreen(struct shell_surface *shsurf)
 {
 	/* undo all fullscreen things here */
+	if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
+	    shell_surface_is_top_fullscreen(shsurf)) {
+		weston_output_switch_mode(shsurf->fullscreen_output,
+		                          shsurf->fullscreen_output->origin);
+	}
 	shsurf->fullscreen.type = WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT;
 	shsurf->fullscreen.framerate = 0;
 	wl_list_remove(&shsurf->fullscreen.transform.link);
 	wl_list_init(&shsurf->fullscreen.transform.link);
-	weston_surface_destroy(shsurf->fullscreen.black_surface);
+	if (shsurf->fullscreen.black_surface)
+		weston_surface_destroy(shsurf->fullscreen.black_surface);
 	shsurf->fullscreen.black_surface = NULL;
 	shsurf->fullscreen_output = NULL;
 	shsurf->force_configure = 1;
@@ -638,6 +664,21 @@ shell_configure_fullscreen(struct shell_surface *shsurf)
 		weston_surface_set_position(surface, output->x, output->y);
 		break;
 	case WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER:
+		if (shell_surface_is_top_fullscreen(shsurf)) {
+			struct weston_mode mode = {0, 
+				surface->geometry.width,
+				surface->geometry.height,
+				shsurf->fullscreen.framerate};
+
+			if (weston_output_switch_mode(output, &mode) == 0) {
+				weston_surface_configure(shsurf->fullscreen.black_surface, 
+					                 output->x, output->y,
+							 output->current->width,
+							 output->current->height);
+				weston_surface_set_position(surface, output->x, output->y);
+				break;
+			}
+		}
 		break;
 	case WL_SHELL_SURFACE_FULLSCREEN_METHOD_FILL:
 		break;
@@ -650,26 +691,34 @@ shell_configure_fullscreen(struct shell_surface *shsurf)
 static void
 shell_stack_fullscreen(struct shell_surface *shsurf)
 {
+	struct weston_output *output = shsurf->fullscreen_output;
 	struct weston_surface *surface = shsurf->surface;
 	struct desktop_shell *shell = shell_surface_get_shell(shsurf);
 
 	wl_list_remove(&surface->layer_link);
-	wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
-
 	wl_list_insert(&shell->fullscreen_layer.surface_list,
 		       &surface->layer_link);
+	weston_surface_damage(surface);
+
+	if (!shsurf->fullscreen.black_surface)
+		shsurf->fullscreen.black_surface =
+			create_black_surface(surface->compositor,
+					     surface,
+					     output->x, output->y,
+					     output->current->width,
+					     output->current->height);
+
+	wl_list_remove(&shsurf->fullscreen.black_surface->layer_link);
 	wl_list_insert(&surface->layer_link,
 		       &shsurf->fullscreen.black_surface->layer_link);
-
-	weston_surface_damage(surface);
 	weston_surface_damage(shsurf->fullscreen.black_surface);
 }
 
 static void
 shell_map_fullscreen(struct shell_surface *shsurf)
 {
-	shell_configure_fullscreen(shsurf);
 	shell_stack_fullscreen(shsurf);
+	shell_configure_fullscreen(shsurf);
 }
 
 static void
@@ -844,15 +893,21 @@ destroy_shell_surface(struct wl_resource *resource)
 	if (shsurf->popup.grab.input_device)
 		wl_input_device_end_pointer_grab(shsurf->popup.grab.input_device);
 
-	/* in case cleaning up a dead client destroys shell_surface first */
-	if (shsurf->surface) {
-		wl_list_remove(&shsurf->surface_destroy_listener.link);
-		shsurf->surface->configure = NULL;
+	if (shsurf->fullscreen.type == WL_SHELL_SURFACE_FULLSCREEN_METHOD_DRIVER &&
+	    shell_surface_is_top_fullscreen(shsurf)) {
+		weston_output_switch_mode(shsurf->fullscreen_output,
+					  shsurf->fullscreen_output->origin);
 	}
 
 	if (shsurf->fullscreen.black_surface)
 		weston_surface_destroy(shsurf->fullscreen.black_surface);
 
+	/* As destroy_resource() use wl_list_for_each_safe(),
+	 * we can always remove the listener.
+	 */
+	wl_list_remove(&shsurf->surface_destroy_listener.link);
+	shsurf->surface->configure = NULL;
+
 	wl_list_remove(&shsurf->link);
 	free(shsurf);
 }
@@ -864,7 +919,6 @@ shell_handle_surface_destroy(struct wl_listener *listener, void *data)
 						    struct shell_surface,
 						    surface_destroy_listener);
 
-	shsurf->surface = NULL;
 	wl_resource_destroy(&shsurf->resource);
 }
 
@@ -897,7 +951,7 @@ shell_get_shell_surface(struct wl_client *client,
 	if (get_shell_surface(surface)) {
 		wl_resource_post_error(surface_resource,
 			WL_DISPLAY_ERROR_INVALID_OBJECT,
-			"wl_shell::get_shell_surface already requested");
+			"desktop_shell::get_shell_surface already requested");
 		return;
 	}
 
@@ -1499,9 +1553,10 @@ activate(struct desktop_shell *shell, struct weston_surface *es,
 	case SHELL_SURFACE_FULLSCREEN:
 		/* should on top of panels */
 		shell_stack_fullscreen(get_shell_surface(es));
+		shell_configure_fullscreen(get_shell_surface(es));
 		break;
 	default:
-                /* move the fullscreen surfaces down into the toplevel layer */
+		/* move the fullscreen surfaces down into the toplevel layer */
 		if (!wl_list_empty(&shell->fullscreen_layer.surface_list)) {
 			wl_list_for_each_reverse_safe(surf,
 						      prev, 
@@ -1764,7 +1819,6 @@ configure(struct desktop_shell *shell, struct weston_surface *surface,
 	  GLfloat x, GLfloat y, int32_t width, int32_t height)
 {
 	enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
-	enum shell_surface_type prev_surface_type = SHELL_SURFACE_NONE;
 	struct shell_surface *shsurf;
 
 	shsurf = get_shell_surface(surface);
@@ -1782,9 +1836,8 @@ configure(struct desktop_shell *shell, struct weston_surface *surface,
 		center_on_output(surface, shsurf->fullscreen_output);
 		break;
 	case SHELL_SURFACE_FULLSCREEN:
+		shell_stack_fullscreen(shsurf);
 		shell_configure_fullscreen(shsurf);
-		if (prev_surface_type != SHELL_SURFACE_FULLSCREEN)
-			shell_stack_fullscreen(shsurf);
 		break;
 	case SHELL_SURFACE_MAXIMIZED:
 		/* setting x, y and using configure to change that geometry */
-- 
1.7.5.4



More information about the wayland-devel mailing list