[PATCH v2 1/2] shell & compositor: add parameters for set_fullsceen

juan.j.zhao at linux.intel.com juan.j.zhao at linux.intel.com
Mon Jan 9 06:54:19 PST 2012


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

For some appliation(e.g. xbmc) wanting actual fullscreen effect, compositor should change the
display mode to match the app UI rectangle. We add 2 parameters to set_fullscreen in order to
let client to choose the appropriate way to deal with dismatch between the client's surface and
display mode of output.
For "WL_SHELL_SURFACE_FULLSCREEN_MOTHED_SCALE", compositor will rescale the surface rectangle
to match the current output. For "WESTON_SURFACE_FULLSCREEN_FORCE", compositor will change to
a appropriate display mode to match the client's surface rectangle. For "WESTON_SURFACE_FULLSCREEN_FILL",
make the surface center on output.

We add a function pointer "set_mode" to struct weston_output which will be implemented by backend,
for now, just compositor-drm.c implemented this virtaul method.

In addition, we modified window.c to coordinate with new set_fullscreen api and added the simple-fullscreen
client for testing.
F12, F11, and F10 to set fullscreen by different method, F9 to set maximised, F8 to set toplevel to fallback

Signed-off-by: Juan Zhao <juan.j.zhao at linux.intel.com>
Signed-off-by: Alex Wu <zhiwen.wu at linux.intel.com>

---
 clients/Makefile.am         |    5 +-
 clients/simple-fullscreen.c |  614 +++++++++++++++++++++++++++++++++++++++++++
 clients/window.c            |    5 +-
 src/compositor-drm.c        |  169 ++++++++++++
 src/compositor.c            |  243 +++++++++++++++--
 src/compositor.h            |   21 ++
 src/shell.c                 |   69 ++++--
 7 files changed, 1077 insertions(+), 49 deletions(-)
 create mode 100644 clients/simple-fullscreen.c

diff --git a/clients/Makefile.am b/clients/Makefile.am
index e323de6..9bd4264 100644
--- a/clients/Makefile.am
+++ b/clients/Makefile.am
@@ -5,7 +5,7 @@ noinst_PROGRAMS = $(clients_programs) 		\
 libexec_PROGRAMS = $(desktop_shell) $(tablet_shell)
 
 if BUILD_SIMPLE_CLIENTS
-simple_clients_programs = simple-egl simple-shm simple-touch
+simple_clients_programs = simple-egl simple-shm simple-touch simple-fullscreen
 simple_egl_SOURCES = simple-egl.c
 simple_egl_LDADD = $(SIMPLE_CLIENT_LIBS) -lm
 
@@ -14,6 +14,9 @@ simple_shm_LDADD = $(SIMPLE_CLIENT_LIBS)
 
 simple_touch_SOURCES = simple-touch.c
 simple_touch_LDADD = $(SIMPLE_CLIENT_LIBS)
+
+simple_fullscreen_SOURCES = simple-fullscreen.c
+simple_fullscreen_LDADD = $(SIMPLE_CLIENT_LIBS) -lm -lxkbcommon
 endif
 
 if BUILD_CLIENTS
diff --git a/clients/simple-fullscreen.c b/clients/simple-fullscreen.c
new file mode 100644
index 0000000..ea477e0
--- /dev/null
+++ b/clients/simple-fullscreen.c
@@ -0,0 +1,614 @@
+/*
+ * Copyright © 2011 Benjamin Franzke
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that copyright
+ * notice and this permission notice appear in supporting documentation, and
+ * that the name of the copyright holders not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission.  The copyright holders make no representations
+ * about the suitability of this software for any purpose.  It is provided "as
+ * is" without express or implied warranty.
+ *
+ * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
+ * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
+ * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+ * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+ * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+ * OF THIS SOFTWARE.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <math.h>
+#include <assert.h>
+#include <linux/input.h>
+#include <X11/extensions/XKBcommon.h>
+#include <X11/keysym.h>
+#include <glib.h>
+
+#include <wayland-client.h>
+#include <wayland-egl.h>
+
+#include <GLES2/gl2.h>
+#include <EGL/egl.h>
+static void
+redraw(void *data, struct wl_callback *callback, uint32_t time);
+
+struct display {
+	struct wl_display *display;
+	struct wl_compositor *compositor;
+	struct wl_shell *shell;
+	struct {
+		EGLDisplay dpy;
+		EGLContext ctx;
+		EGLConfig conf;
+	} egl;
+	uint32_t mask;
+
+	struct xkb_desc *xkb;
+};
+
+struct window {
+	struct display *display;
+	struct {
+		int width, height;
+	} geometry;
+	struct {
+		GLuint fbo;
+		GLuint color_rbo;
+
+		GLuint program;
+		GLuint rotation_uniform;
+
+		GLuint pos;
+		GLuint col;
+	} gl;
+
+	struct wl_egl_window *native;
+	struct wl_surface *surface;
+	struct wl_shell_surface *shell_surface;
+	EGLSurface egl_surface;
+
+	//struct input *keyboard_device;
+};
+
+
+struct input {
+	struct display *display;
+	struct wl_input_device *input_device;
+	uint32_t modifiers;
+	int32_t x, y, sx, sy;
+	struct wl_list link;
+	struct window *keyboard_focus;
+
+};
+
+static const char *vert_shader_text =
+	"uniform mat4 rotation;\n"
+	"attribute vec4 pos;\n"
+	"attribute vec4 color;\n"
+	"varying vec4 v_color;\n"
+	"void main() {\n"
+	"  gl_Position = rotation * pos;\n"
+	"  v_color = color;\n"
+	"}\n";
+
+static const char *frag_shader_text =
+	"precision mediump float;\n"
+	"varying vec4 v_color;\n"
+	"void main() {\n"
+	"  gl_FragColor = v_color;\n"
+	"}\n";
+
+
+
+static void
+handle_configure(void *data, struct wl_shell_surface *shell_surface,
+		 uint32_t time, uint32_t edges,
+		 int32_t width, int32_t height)
+{
+	struct window *window = data;
+	uint32_t ret;
+	static const EGLint surface_attribs[] = {
+		EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE,
+		EGL_NONE
+	};
+	/* FIXME: this is probably the wrong place to check for width
+	 * or height <= 0, but it prevents the compositor from crashing
+	 */
+	if (width <= 0 || height <= 0)
+		return;
+
+	window->geometry.width = width;
+	window->geometry.height = height;
+	eglMakeCurrent(window->display->egl.dpy, NULL,
+			     NULL, window->display->egl.ctx);
+
+
+	if( window->egl_surface ) {
+		eglDestroySurface(window->display->egl.dpy, window->egl_surface);
+		window->egl_surface = NULL;
+	}
+	if( window->native ) {
+		wl_egl_window_destroy(window->native);
+		window->native = NULL;
+	}
+
+	window->native =
+		wl_egl_window_create(window->surface,
+				     window->geometry.width,
+				     window->geometry.height);
+
+	window->egl_surface =
+		eglCreateWindowSurface(window->display->egl.dpy,
+				       window->display->egl.conf,
+				       window->native,
+				       surface_attribs);
+
+	ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
+			     window->egl_surface, window->display->egl.ctx);
+	assert(ret == EGL_TRUE);
+
+	glViewport(0, 0, window->geometry.width, window->geometry.height);
+	redraw(window, NULL, 0);
+}
+
+static const struct wl_shell_surface_listener shell_surface_listener = {
+	handle_configure,
+};
+
+static void
+init_egl(struct display *display)
+{
+	static const EGLint context_attribs[] = {
+		EGL_CONTEXT_CLIENT_VERSION, 2,
+		EGL_NONE
+	};
+
+	static const EGLint config_attribs[] = {
+		EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_VG_ALPHA_FORMAT_PRE_BIT,
+		EGL_RED_SIZE, 1,
+		EGL_GREEN_SIZE, 1,
+		EGL_BLUE_SIZE, 1,
+		EGL_ALPHA_SIZE, 1,
+		EGL_DEPTH_SIZE, 1,
+		EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
+		EGL_NONE
+	};
+
+	EGLint major, minor, n;
+	EGLBoolean ret;
+
+	display->egl.dpy = eglGetDisplay(display->display);
+	assert(display->egl.dpy);
+
+	ret = eglInitialize(display->egl.dpy, &major, &minor);
+	assert(ret == EGL_TRUE);
+	ret = eglBindAPI(EGL_OPENGL_ES_API);
+	assert(ret == EGL_TRUE);
+
+	assert(eglChooseConfig(display->egl.dpy, config_attribs,
+			       &display->egl.conf, 1, &n) && n == 1);
+
+	display->egl.ctx = eglCreateContext(display->egl.dpy,
+					    display->egl.conf,
+					    EGL_NO_CONTEXT, context_attribs);
+	assert(display->egl.ctx);
+
+}
+
+static GLuint
+create_shader(struct window *window, const char *source, GLenum shader_type)
+{
+	GLuint shader;
+	GLint status;
+
+	shader = glCreateShader(shader_type);
+	assert(shader != 0);
+
+	glShaderSource(shader, 1, (const char **) &source, NULL);
+	glCompileShader(shader);
+
+	glGetShaderiv(shader, GL_COMPILE_STATUS, &status);
+	if (!status) {
+		char log[1000];
+		GLsizei len;
+		glGetShaderInfoLog(shader, 1000, &len, log);
+		fprintf(stderr, "Error: compiling %s: %*s\n",
+			shader_type == GL_VERTEX_SHADER ? "vertex" : "fragment",
+			len, log);
+		exit(1);
+	}
+
+	return shader;
+}
+
+static void
+init_gl(struct window *window)
+{
+	GLuint frag, vert;
+	GLint status;
+
+	glViewport(0, 0, window->geometry.width, window->geometry.height);
+
+	frag = create_shader(window, frag_shader_text, GL_FRAGMENT_SHADER);
+	vert = create_shader(window, vert_shader_text, GL_VERTEX_SHADER);
+
+	window->gl.program = glCreateProgram();
+	glAttachShader(window->gl.program, frag);
+	glAttachShader(window->gl.program, vert);
+	glLinkProgram(window->gl.program);
+
+	glGetProgramiv(window->gl.program, GL_LINK_STATUS, &status);
+	if (!status) {
+		char log[1000];
+		GLsizei len;
+		glGetProgramInfoLog(window->gl.program, 1000, &len, log);
+		fprintf(stderr, "Error: linking:\n%*s\n", len, log);
+		exit(1);
+	}
+
+	glUseProgram(window->gl.program);
+	
+	window->gl.pos = 0;
+	window->gl.pos = 1;
+
+	glBindAttribLocation(window->gl.program, window->gl.pos, "pos");
+	glBindAttribLocation(window->gl.program, window->gl.col, "color");
+	glLinkProgram(window->gl.program);
+
+	window->gl.rotation_uniform =
+		glGetUniformLocation(window->gl.program, "rotation");
+}
+
+static void
+create_surface(struct window *window)
+{
+	struct display *display = window->display;
+	EGLBoolean ret;
+	static const EGLint surface_attribs[] = {
+		EGL_ALPHA_FORMAT, EGL_ALPHA_FORMAT_PRE,
+		EGL_NONE
+	};
+	
+	window->surface = wl_compositor_create_surface(display->compositor);
+	wl_surface_set_user_data(window->surface, window);
+	window->shell_surface = wl_shell_get_shell_surface(display->shell,
+							   window->surface);
+	wl_shell_surface_set_user_data(window->shell_surface, window);
+	window->native =
+		wl_egl_window_create(window->surface,
+				     window->geometry.width,
+				     window->geometry.height);
+	window->egl_surface =
+		eglCreateWindowSurface(display->egl.dpy,
+				       display->egl.conf,
+				       window->native,
+				       surface_attribs);
+
+	wl_shell_surface_add_listener(window->shell_surface,
+				      &shell_surface_listener, window);
+
+	wl_shell_surface_set_toplevel(window->shell_surface);
+
+	ret = eglMakeCurrent(window->display->egl.dpy, window->egl_surface,
+			     window->egl_surface, window->display->egl.ctx);
+	assert(ret == EGL_TRUE);
+}
+
+static const struct wl_callback_listener frame_listener;
+
+static void
+redraw(void *data, struct wl_callback *callback, uint32_t time)
+{
+	struct window *window = data;
+	static const GLfloat verts[4][2] = {
+		{ -1, -1 },
+		{  1, -1 },
+		{  1,  1 },
+		{ -1,  1 }
+	};
+	static const GLfloat colors[3][3] = {
+		{ 1, 0, 0 },
+		{ 0, 1, 0 },
+		{ 0, 1, 1 },
+		{ 0, 0, 1 }
+	};
+	GLfloat angle;
+	GLfloat rotation[4][4] = {
+		{ 1, 0, 0, 0 },
+		{ 0, 1, 0, 0 },
+		{ 0, 0, 1, 0 },
+		{ 0, 0, 0, 1 }
+	};
+	static const int32_t speed_div = 5;
+	static uint32_t start_time = 0;
+
+	if (start_time == 0)
+		start_time = time;
+
+	//angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
+	angle = 0;
+	rotation[0][0] =  cos(angle);
+	rotation[0][2] =  sin(angle);
+	rotation[2][0] = -sin(angle);
+	rotation[2][2] =  cos(angle);
+
+	glUniformMatrix4fv(window->gl.rotation_uniform, 1, GL_FALSE,
+			   (GLfloat *) rotation);
+
+	glClearColor(0.0, 0.0, 0.0, 0.5);
+	glClear(GL_COLOR_BUFFER_BIT);
+
+	glVertexAttribPointer(window->gl.pos, 2, GL_FLOAT, GL_FALSE, 0, verts);
+	glVertexAttribPointer(window->gl.col, 3, GL_FLOAT, GL_FALSE, 0, colors);
+	glEnableVertexAttribArray(window->gl.pos);
+	glEnableVertexAttribArray(window->gl.col);
+
+	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
+
+	glDisableVertexAttribArray(window->gl.pos);
+	glDisableVertexAttribArray(window->gl.col);
+
+	glFlush();
+
+	eglSwapBuffers(window->display->egl.dpy, window->egl_surface);
+	if (callback)
+		wl_callback_destroy(callback);
+
+//	callback = wl_surface_frame(window->surface);
+//	wl_callback_add_listener(callback, &frame_listener, window);
+}
+
+static const struct wl_callback_listener frame_listener = {
+	redraw
+};
+
+static void
+key_handler(struct input *input, uint32_t time,
+	    uint32_t key, uint32_t sym, uint32_t state)
+{
+	struct window *window = input->keyboard_focus;
+	uint32_t modifiers = input->modifiers;
+	uint32_t fs_method = 0;
+
+	if ((modifiers & XKB_COMMON_CONTROL_MASK) &&
+	    (modifiers & XKB_COMMON_SHIFT_MASK) &&
+	    state)
+		return;
+
+#define FRAMERATE 60
+	switch (sym) {
+		case XK_F12:
+			if (!state)
+				break;
+			fs_method = WL_SHELL_SURFACE_FULLSCREEN_MOTHED_FORCE;
+			wl_shell_surface_set_fullscreen(window->shell_surface,
+				FRAMERATE, fs_method);
+			break;
+		case XK_F11:
+			if (!state)
+				break;
+			fs_method = WL_SHELL_SURFACE_FULLSCREEN_MOTHED_SCALE;
+			wl_shell_surface_set_fullscreen(window->shell_surface,
+							FRAMERATE, fs_method);
+			break;
+		case XK_F10:
+			if (!state)
+				break;
+			fs_method = WL_SHELL_SURFACE_FULLSCREEN_MOTHED_FILL;
+			wl_shell_surface_set_fullscreen(window->shell_surface,
+							FRAMERATE, fs_method);
+			break;
+    case XK_F8:
+			if (!state)
+				break;
+			wl_shell_surface_set_toplevel(window->shell_surface);
+			break;
+		default:
+			break;
+	}
+}
+
+static void
+handle_key(void *data, struct wl_input_device *input_device,
+		  uint32_t time, uint32_t key, uint32_t state)
+{
+	struct input *input = data;
+	struct window *window = input->keyboard_focus;
+	struct display *d = input->display;
+	uint32_t code, sym, level;
+
+	code = key + d->xkb->min_key_code;
+	if (!window)
+		return;
+
+	level = 0;
+	if (input->modifiers & XKB_COMMON_SHIFT_MASK &&
+	    XkbKeyGroupWidth(d->xkb, code, 0) > 1)
+		level = 1;
+
+	sym = XkbKeySymEntry(d->xkb, code, level, 0);
+
+	if (state)
+		input->modifiers |= d->xkb->map->modmap[code];
+	else
+		input->modifiers &= ~d->xkb->map->modmap[code];
+
+  key_handler(input, time, key, sym, state);
+}
+
+static void
+handle_keyboard_focus(void *data,
+			     struct wl_input_device *input_device,
+			     uint32_t time,
+			     struct wl_surface *surface,
+			     struct wl_array *keys)
+{
+	struct input *input = data;
+	struct display *d = input->display;
+	uint32_t *k, *end;
+
+	if (surface)
+		input->keyboard_focus = wl_surface_get_user_data(surface);
+	else
+		input->keyboard_focus = NULL;
+
+	end = keys->data + keys->size;
+	input->modifiers = 0;
+	for (k = keys->data; k < end; k++)
+		input->modifiers |= d->xkb->map->modmap[*k];
+}
+
+static void
+fake_handle_motion(void *data, struct wl_input_device *input_device,
+		     uint32_t time,
+		     int32_t x, int32_t y, int32_t sx, int32_t sy)
+{
+  printf ("%s: fake function\n", __FUNCTION__);
+}
+
+static void
+fake_handle_button(void *data,
+		     struct wl_input_device *input_device,
+		     uint32_t time, uint32_t button, uint32_t state)
+{
+  printf ("%s: fake function\n", __FUNCTION__);
+}
+
+static void
+fake_handle_pointer_focus(void *data,
+			    struct wl_input_device *input_device,
+			    uint32_t time, struct wl_surface *surface,
+			    int32_t x, int32_t y, int32_t sx, int32_t sy)
+{
+	printf ("%s: fake function\n", __FUNCTION__);
+}
+
+static const struct wl_input_device_listener input_device_listener = {
+	fake_handle_motion,
+	fake_handle_button,
+	handle_key,
+	fake_handle_pointer_focus,
+	handle_keyboard_focus,
+};
+
+
+static void
+display_add_input(struct display *d, uint32_t id)
+{
+	struct input *input;
+
+	input = malloc(sizeof *input);
+	if (input == NULL)
+		return;
+
+	memset(input, 0, sizeof *input);
+	input->display = d;
+	input->input_device =
+		wl_display_bind(d->display, id, &wl_input_device_interface);
+
+	wl_input_device_add_listener(input->input_device,
+				     &input_device_listener, input);
+	wl_input_device_set_user_data(input->input_device, input);
+}
+
+static void
+display_handle_global(struct wl_display *display, uint32_t id,
+		      const char *interface, uint32_t version, void *data)
+{
+	struct display *d = data;
+
+	if (strcmp(interface, "wl_compositor") == 0) {
+		d->compositor =
+			wl_display_bind(display, id, &wl_compositor_interface);
+	} else if (strcmp(interface, "wl_input_device") == 0) {
+		display_add_input(d, id);
+	} else if (strcmp(interface, "wl_shell") == 0) {
+		d->shell = wl_display_bind(display, id, &wl_shell_interface);
+	}
+}
+
+static int
+event_mask_update(uint32_t mask, void *data)
+{
+	struct display *d = data;
+
+	d->mask = mask;
+
+	return 0;
+}
+
+const char *option_xkb_layout = "us";
+const char *option_xkb_variant = "";
+const char *option_xkb_options = "";
+
+static const GOptionEntry xkb_option_entries[] = {
+	{ "xkb-layout", 0, 0, G_OPTION_ARG_STRING,
+	  &option_xkb_layout, "XKB Layout" },
+	{ "xkb-variant", 0, 0, G_OPTION_ARG_STRING,
+	  &option_xkb_variant, "XKB Variant" },
+	{ "xkb-options", 0, 0, G_OPTION_ARG_STRING,
+	  &option_xkb_options, "XKB Options" },
+	{ NULL }
+};
+
+
+
+static void
+init_xkb(struct display *d)
+{
+	struct xkb_rule_names names;
+
+	names.rules = "evdev";
+	names.model = "pc105";
+	names.layout = option_xkb_layout;
+	names.variant = option_xkb_variant;
+	names.options = option_xkb_options;
+
+	d->xkb = xkb_compile_keymap_from_rules(&names);
+	if (!d->xkb) {
+		fprintf(stderr, "Failed to compile keymap\n");
+		exit(1);
+	}
+}
+
+int
+main(int argc, char **argv)
+{
+	struct display display = { 0 };
+	struct window  window  = { 0 };
+
+	memset(&display, 0, sizeof display);
+	memset(&window,  0, sizeof window);
+
+	window.display = &display;
+	window.geometry.width  = 1280;
+	window.geometry.height = 1024;
+
+	init_xkb(&display);
+	display.display = wl_display_connect(NULL);
+	assert(display.display);
+
+	wl_display_add_global_listener(display.display,
+				       display_handle_global, &display);
+
+	wl_display_get_fd(display.display, event_mask_update, &display);
+	wl_display_iterate(display.display, WL_DISPLAY_READABLE);
+
+	init_egl(&display);
+	create_surface(&window);
+	init_gl(&window);
+
+	redraw(&window, NULL, 0);
+
+	while (true)
+		wl_display_iterate(display.display, display.mask);
+
+	return 0;
+}
diff --git a/clients/window.c b/clients/window.c
index a101204..bee15ea 100644
--- a/clients/window.c
+++ b/clients/window.c
@@ -782,12 +782,15 @@ window_get_resize_dx_dy(struct window *window, int *x, int *y)
 static void
 window_set_type(struct window *window)
 {
+	uint32_t fs_mode = WL_SHELL_SURFACE_FULLSCREEN_MOTHED_NONE;
+
 	if (!window->shell_surface)
 		return;
 
+#define FRAMERATE 60
 	switch (window->type) {
 	case TYPE_FULLSCREEN:
-		wl_shell_surface_set_fullscreen(window->shell_surface);
+		wl_shell_surface_set_fullscreen(window->shell_surface, FRAMERATE, fs_mode);
 		break;
 	case TYPE_TOPLEVEL:
 		wl_shell_surface_set_toplevel(window->shell_surface);
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index a6cedd5..4a4c70d 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -78,6 +78,30 @@ struct drm_output {
 	uint32_t pending_fs_surf_fb_id;
 };
 
+static struct drm_mode *
+choose_mode (struct drm_output *output, char *resolution, uint32_t refresh)
+{
+	struct drm_mode *tmp_mode = NULL, *mode, *next;
+	printf ("%s: mode to choose: resolution=%s, refresh=%u\n", __FUNCTION__, resolution, refresh);
+
+	wl_list_for_each_safe(mode, next,
+      &output->base.mode_list,base.link) {
+    if (!strcmp (mode->mode_info.name, resolution)) {
+      if (mode->mode_info.vrefresh == refresh)
+        return mode;
+      else if (!tmp_mode) 
+        tmp_mode = mode;
+    }
+  }
+
+  if (tmp_mode)
+    printf ("%s: no matched refresh, choose mode: resolution=%s, refresh=%u\n", 
+        __FUNCTION__, tmp_mode->mode_info.name, tmp_mode->mode_info.vrefresh);
+  else 
+    printf ("%s: no matched mode\n");
+	return tmp_mode;
+}
+
 static int
 drm_output_prepare_render(struct weston_output *output_base)
 {
@@ -258,6 +282,147 @@ out:
 	return ret;
 }
 
+static int
+drm_output_set_mode (struct weston_output *output_base, char *resolution, uint32_t refresh)
+{
+	struct drm_output *output;
+	struct drm_mode *drm_mode, *next;
+	drmModeEncoder *encoder;
+	int i, ret;
+	unsigned handle, stride;
+	struct drm_compositor *ec;
+
+	ec = (struct drm_compositor *)output_base->compositor;
+	output = (struct drm_output *)output_base;
+	if (output == NULL) {
+		return -1;
+	}
+
+	drm_mode  = (struct drm_mode *)(output->base.current);
+
+	printf ("current mode: %s, w=%d, h=%d, refresh=%u, flags=%u\n",
+			drm_mode->mode_info.name, drm_mode->base.width,
+			drm_mode->base.height, drm_mode->base.refresh,
+			drm_mode->base.flags);
+
+	drm_mode  = choose_mode (output, resolution, refresh);
+
+	if (!drm_mode) {
+		printf ("%s, invalid resolution:%s\n", __FUNCTION__, resolution);
+		return -1;
+	}
+
+	printf ("next mode: %s, w=%d, h=%d, refresh=%u, flags=%u\n",
+			drm_mode->mode_info.name, drm_mode->base.width,
+			drm_mode->base.height, drm_mode->base.refresh,
+			drm_mode->base.flags);
+
+
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+				  GL_COLOR_ATTACHMENT0,
+				  GL_RENDERBUFFER, 0);
+
+
+	/* Destroy output buffers */
+	for (i = 0; i < 2; i++) {
+		drmModeRmFB(ec->drm.fd, output->fb_id[i]);
+		ec->base.destroy_image(ec->base.display, output->image[i]);
+		gbm_bo_destroy(output->bo[i]);
+	}
+
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+	glDeleteRenderbuffers(2, output->rbo);
+	weston_output_destroy(output);
+
+	output->base.current = &drm_mode->base;
+	drm_mode->base.flags =
+		WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
+
+	/* create new output buffers */
+	glGenRenderbuffers(2, output->rbo);
+	for (i = 0; i < 2; i++) {
+		glBindRenderbuffer(GL_RENDERBUFFER, output->rbo[i]);
+
+		output->bo[i] =
+		gbm_bo_create(ec->gbm,
+			      output->base.current->width,
+			      output->base.current->height,
+			      GBM_BO_FORMAT_XRGB8888,
+			      GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING);
+
+		if (!output->bo[i])
+			goto err_bufs;
+
+		output->image[i] = ec->base.create_image(ec->base.display,
+							 NULL,
+							 EGL_NATIVE_PIXMAP_KHR,
+							 output->bo[i], NULL);
+		if (!output->image[i])
+			goto err_bufs;
+
+		ec->base.image_target_renderbuffer_storage(GL_RENDERBUFFER,
+							   output->image[i]);
+		stride = gbm_bo_get_pitch(output->bo[i]);
+		handle = gbm_bo_get_handle(output->bo[i]).u32;
+
+		ret = drmModeAddFB(ec->drm.fd,
+				   output->base.current->width,
+				   output->base.current->height,
+				   24, 32, stride, handle, &output->fb_id[i]);
+
+		if (ret) {
+			fprintf(stderr, "failed to add fb %d: %m\n", i);
+			goto err_bufs;
+		}
+	}
+
+	output->current = 0;
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+				  GL_COLOR_ATTACHMENT0,
+				  GL_RENDERBUFFER,
+				  output->rbo[output->current]);
+
+	ret = drmModeSetCrtc(ec->drm.fd,
+			     output->crtc_id,
+			     output->fb_id[output->current ^ 1], 0, 0,
+			     &output->connector_id, 1, &drm_mode->mode_info);
+
+	if (ret) {
+		fprintf(stderr, "failed to set mode: %m\n");
+		goto err_fb;
+	}
+
+	output->base.x = 0;
+	output->base.y = 0;
+	output->base.mm_width = output->base.current->width;
+	output->base.mm_height = output->base.current->height;
+	weston_output_move(&output->base, 0, 0);
+
+	printf ("%s: ret 0\n", __FUNCTION__);
+	return 0;
+
+err_fb:
+	glFramebufferRenderbuffer(GL_FRAMEBUFFER,
+				  GL_COLOR_ATTACHMENT0,
+				  GL_RENDERBUFFER, 0);
+err_bufs:
+	for (i = 0; i < 2; i++) {
+		if (output->fb_id[i] != -1)
+			drmModeRmFB(ec->drm.fd, output->fb_id[i]);
+		if (output->image[i])
+			ec->base.destroy_image(ec->base.display,
+					       output->image[i]);
+		if (output->bo[i])
+			gbm_bo_destroy(output->bo[i]);
+	}
+	glBindRenderbuffer(GL_RENDERBUFFER, 0);
+	glDeleteRenderbuffers(2, output->rbo);
+
+	printf ("%s: ret -1\n", __FUNCTION__);
+	return -1;
+}
+
+
 static void
 drm_output_destroy(struct weston_output *output_base)
 {
@@ -488,7 +653,10 @@ create_output_for_connector(struct drm_compositor *ec,
 
 	drm_mode = container_of(output->base.mode_list.next,
 				struct drm_mode, base.link);
+
 	output->base.current = &drm_mode->base;
+	output->base.saved_mode = NULL;
+	output->base.fs_dirty = NULL;
 	drm_mode->base.flags =
 		WL_OUTPUT_MODE_CURRENT | WL_OUTPUT_MODE_PREFERRED;
 
@@ -553,6 +721,7 @@ create_output_for_connector(struct drm_compositor *ec,
 	output->base.prepare_scanout_surface =
 		drm_output_prepare_scanout_surface;
 	output->base.set_hardware_cursor = drm_output_set_cursor;
+	output->base.set_mode = drm_output_set_mode;
 	output->base.destroy = drm_output_destroy;
 
 	return 0;
diff --git a/src/compositor.c b/src/compositor.c
index b33ed8a..2b01a65 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -75,6 +75,33 @@ sigchld_handler(int signal_number, void *data)
 	return 1;
 }
 
+static int
+weston_output_restore_mode (struct weston_output *output)
+{
+	int ret;
+	char saved_mode[16];
+
+	if(!output->saved_mode ||
+	    (output->saved_mode->width == output->current->width &&
+	     output->saved_mode->height == output->current->height))
+		return 0;
+	memset(saved_mode, 0, sizeof saved_mode);
+	sprintf(saved_mode, "%dx%d",
+		output->saved_mode->width, output->saved_mode->height);
+
+	if (output->set_mode) {
+		if ((ret = output->set_mode(output, saved_mode, output->saved_mode->refresh)) == 0)
+			output->saved_mode = NULL;
+	}
+	else {
+		fprintf(stderr, "Can't restore display mode\n");
+		ret = -1;
+	}
+
+	printf("set mode '%s', ret %d\n",  saved_mode, ret);
+	return ret;
+}
+
 WL_EXPORT void
 weston_watch_process(struct weston_process *process)
 {
@@ -228,9 +255,12 @@ weston_surface_create(struct weston_compositor *compositor,
 	surface->height = height;
 	surface->alpha = 255;
 
-	surface->fullscreen_output = NULL;
+	surface->fs_support.fullscreen_output = NULL;
+	surface->fs_support.fs_method = WESTON_SURFACE_FULLSCREEN_NONE;
+	surface->fs_support.fs_transform = NULL;
 	surface->buffer = NULL;
 	surface->output = NULL;
+	surface->type = WESTON_SURFACE_TYPE_GENERAL;
 
 	pixman_region32_init(&surface->damage);
 	pixman_region32_init(&surface->opaque);
@@ -307,6 +337,86 @@ weston_surface_configure(struct weston_surface *surface,
 		pixman_region32_init(&surface->opaque);
 }
 
+WL_EXPORT void
+weston_surface_center_on_output( struct weston_surface *surface,
+			       struct weston_output *output )
+{
+	struct weston_mode *mode = output->current;
+
+	surface->x = output->x + (mode->width - surface->width) / 2;
+	surface->y = output->y + (mode->height - surface->height) / 2;
+}
+
+int
+weston_surface_set_fullscreen( struct weston_output *output,
+			     struct weston_surface *surface)
+{
+	char mode[16];
+	struct weston_transform *fs_transform=surface->fs_support.fs_transform;
+
+	switch(surface->fs_support.fs_method) {
+		case WESTON_SURFACE_FULLSCREEN_NONE:
+			output->fs_dirty = 1;
+			weston_surface_damage(surface);
+			break;
+		case WESTON_SURFACE_FULLSCREEN_SCALE:
+			if(output->current->width == surface->width &&
+			    output->current->height == surface->height)
+				return 0;
+			output->fs_dirty = 1;
+			/*do not forgot to release them, Juan*/
+			if(!fs_transform) {
+				fs_transform = malloc(sizeof *fs_transform);
+				surface->fs_support.fs_transform = fs_transform;
+			}
+			weston_matrix_init(&fs_transform->matrix);
+			weston_matrix_scale(&fs_transform->matrix,
+					  (float)output->current->width/(float)surface->width,
+					  (float)output->current->height/(float)surface->height,
+					  1.0);
+			weston_surface_damage(surface);
+			break;
+		case WESTON_SURFACE_FULLSCREEN_FORCE:
+			if(output->current->width == surface->width &&
+			    output->current->height == surface->height)
+				return 0;
+			memset(mode, 0, sizeof(mode));
+			sprintf(mode, "%dx%d",surface->width,surface->height);
+			output->saved_mode = output->current;
+      uint32_t refresh = surface->fs_support.framerate;
+			if (!output->set_mode) {
+				output->saved_mode = NULL;
+				fprintf(stderr,
+					"set_mode not implemented,   \
+					 fallback to FILL method\n");
+			} else if(output->set_mode(output, mode, refresh) == 0) {
+				weston_surface_damage(surface);
+				break;
+			} else {
+				/*did not find the mode, fall back */
+				output->current = output->saved_mode;
+				output->saved_mode = NULL;
+				sprintf(mode, "%dx%d",
+					output->current->width,
+					output->current->height);
+				output->set_mode(output, mode, output->current->refresh);
+				fprintf(stderr,
+					"failed to set mode,         \
+					 fallback to FILL method\n");
+			}
+		case WESTON_SURFACE_FULLSCREEN_FILL:
+			/*make it on the center at first*/
+			output->fs_dirty = 1;
+			weston_surface_center_on_output(surface, output);
+			weston_surface_damage(surface);
+			break;
+		default:
+			break;
+	}
+
+	return 0;
+}
+
 static void
 weston_surface_transform(struct weston_surface *surface,
 		       int32_t x, int32_t y, int32_t *sx, int32_t *sy)
@@ -496,7 +606,7 @@ texture_region(struct weston_surface *es, pixman_region32_t *region)
 
 static void
 transform_vertex(struct weston_surface *surface,
-		 GLfloat x, GLfloat y, GLfloat u, GLfloat v, GLfloat *r)
+		 GLfloat x, GLfloat y, GLfloat u, GLfloat v, GLfloat *r, uint32_t fs_scale)
 {
 	struct weston_vector t;
 
@@ -505,7 +615,11 @@ transform_vertex(struct weston_surface *surface,
 	t.f[2] = 0.0;
 	t.f[3] = 1.0;
 
-	weston_matrix_transform(&surface->transform->matrix, &t);
+	if(!fs_scale)
+		weston_matrix_transform(&surface->transform->matrix, &t);
+	else
+		weston_matrix_transform(&surface->fs_support.fs_transform->matrix,
+				      &t);
 
 	r[ 0] = t.f[0];
 	r[ 1] = t.f[1];
@@ -514,7 +628,7 @@ transform_vertex(struct weston_surface *surface,
 }
 
 static int
-texture_transformed_surface(struct weston_surface *es)
+texture_transformed_surface(struct weston_surface *es, uint32_t fs_scale)
 {
 	struct weston_compositor *ec = es->compositor;
 	GLfloat *v;
@@ -523,11 +637,11 @@ texture_transformed_surface(struct weston_surface *es)
 	v = wl_array_add(&ec->vertices, 16 * sizeof *v);
 	p = wl_array_add(&ec->indices, 6 * sizeof *p);
 
-	transform_vertex(es, es->x, es->y, 0.0, 0.0, &v[0]);
-	transform_vertex(es, es->x, es->y + es->height, 0.0, 1.0, &v[4]);
-	transform_vertex(es, es->x + es->width, es->y, 1.0, 0.0, &v[8]);
+	transform_vertex(es, es->x, es->y, 0.0, 0.0, &v[0], fs_scale);
+	transform_vertex(es, es->x, es->y + es->height, 0.0, 1.0, &v[4], fs_scale);
+	transform_vertex(es, es->x + es->width, es->y, 1.0, 0.0, &v[8], fs_scale);
 	transform_vertex(es, es->x + es->width, es->y + es->height,
-			 1.0, 1.0, &v[12]);
+			 1.0, 1.0, &v[12], fs_scale);
 
 	p[0] = 0;
 	p[1] = 1;
@@ -552,7 +666,7 @@ weston_surface_draw(struct weston_surface *es,
 	pixman_region32_init_rect(&repaint,
 				  es->x, es->y, es->width, es->height);
 	pixman_region32_intersect(&repaint, &repaint, clip);
-	if (!pixman_region32_not_empty(&repaint))
+	if (!pixman_region32_not_empty(&repaint) || !ec)
 		return;
 
 	switch (es->visual) {
@@ -578,14 +692,20 @@ weston_surface_draw(struct weston_surface *es,
 		ec->current_alpha = es->alpha;
 	}
 
-	if (es->transform == NULL) {
+	if ((es->transform == NULL) && (es->fs_support.fs_transform == NULL)) {
 		filter = GL_NEAREST;
 		n = texture_region(es, &repaint);
+		fprintf(stderr, "no transform...\n");
+	} else if (es->fs_support.fs_transform) {
+		filter = GL_LINEAR;
+		n = texture_transformed_surface(es, 1);
+		fprintf(stderr, "11222332432\n");
 	} else {
 		filter = GL_LINEAR;
-		n = texture_transformed_surface(es);
+		n = texture_transformed_surface(es, 0);
 	}
 
+
 	glBindTexture(GL_TEXTURE_2D, es->texture);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
 	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
@@ -687,6 +807,10 @@ fade_output(struct weston_output *output,
 	surface.height = output->current->height;
 	surface.texture = GL_NONE;
 	surface.transform = NULL;
+	surface.fs_support.fullscreen_output = NULL;
+	surface.fs_support.fs_method = WESTON_SURFACE_FULLSCREEN_NONE;
+	surface.fs_support.fs_transform = NULL;
+
 	surface.alpha = compositor->current_alpha;
 
 	if (tint <= 1.0)
@@ -773,12 +897,11 @@ weston_output_repaint(struct weston_output *output)
 {
 	struct weston_compositor *ec = output->compositor;
 	struct weston_surface *es;
+	struct weston__surface *cursorsurface = NULL, *panelsurface = NULL;
 	pixman_region32_t opaque, new_damage, total_damage, repaint;
 
 	output->prepare_render(output);
 
-	glViewport(0, 0, output->current->width, output->current->height);
-
 	glUseProgram(ec->texture_shader.program);
 	glUniformMatrix4fv(ec->texture_shader.proj_uniform,
 			   1, GL_FALSE, output->matrix.d);
@@ -807,29 +930,88 @@ weston_output_repaint(struct weston_output *output)
 
 	es = container_of(ec->surface_list.next, struct weston_surface, link);
 
+	struct wl_list *tlist=(struct wl_list *)ec->surface_list.next;
+	int count=0;
+
+	while((es->type != WESTON_SURFACE_TYPE_GENERAL) && count <1024){
+		tlist=tlist->next;
+		if((tlist == (struct wl_list *)ec->surface_list.next) &&
+		   count!=0)
+			break;
+		switch(es->type){
+			case WESTON_SURFACE_TYPE_CURSOR:
+				cursorsurface = es;
+				break;
+			case WESTON_SURFACE_TYPE_PANEL:
+				panelsurface = es;
+				break;
+			default:
+				fprintf(stderr,"unkown surface type!\n");
+				return;
+		}
+		es = container_of(tlist->next, struct weston_surface, link);
+		count++;
+	}
+	if(count == 1024) {
+		fprintf(stderr,"too many surfaces!\n");
+		return -1;
+	}
+
 	if (setup_scanout_surface(output, es) == 0)
 		/* We're drawing nothing, just let the damage accumulate */
 		return;
 
-	if (es->fullscreen_output == output) {
-		if (es->width < output->current->width ||
-		    es->height < output->current->height)
-			glClear(GL_COLOR_BUFFER_BIT);
+	if (es->fs_support.fullscreen_output == output ) {
+		if (es->width != output->current->width ||
+		     es->height != output->current->height) {
+			weston_surface_set_fullscreen(output, es);
+			output->prepare_render(output);
+			glViewport( 0, 0, (GLint) output->current->width,
+				    (GLint) output->current->height);
+			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+		}
 		weston_surface_draw(es, output, &total_damage);
+		if(cursorsurface)
+			weston_surface_draw(cursorsurface, output, &total_damage);
 	} else {
-		wl_list_for_each(es, &ec->surface_list, link) {
-			pixman_region32_copy(&es->damage, &total_damage);
-			pixman_region32_subtract(&total_damage, &total_damage, &es->opaque);
-		}
-
-		wl_list_for_each_reverse(es, &ec->surface_list, link) {
-			pixman_region32_init(&repaint);
-			pixman_region32_intersect(&repaint, &output->region,
-						  &es->damage);
-			weston_surface_draw(es, output, &repaint);
-			pixman_region32_subtract(&es->damage,
-						 &es->damage, &output->region);
-			pixman_region32_fini(&repaint);
+		if( output->saved_mode &&
+		    (output->saved_mode->width!=output->current->width ||
+		     output->saved_mode->height!=output->current->height) ) {
+			weston_output_restore_mode(output);
+			output->saved_mode = NULL;
+			output->fs_dirty = NULL;
+			output->prepare_render(output);
+			glViewport( 0, 0,
+				    (GLint) output->current->width,
+				    (GLint) output->current->height);
+			glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
+			weston_output_damage(output);
+			weston_output_repaint(output);
+		} else if (output->fs_dirty) {
+			output->fs_dirty = NULL;
+			weston_output_damage(output);
+			weston_output_repaint(output);
+		} else {
+			glViewport(0, 0,
+				   output->current->width,
+				   output->current->height);
+			wl_list_for_each(es, &ec->surface_list, link) {
+				pixman_region32_copy(&es->damage,
+						     &total_damage);
+				pixman_region32_subtract(&total_damage,
+							 &total_damage,
+							 &es->opaque);
+			}
+			wl_list_for_each_reverse(es, &ec->surface_list, link) {
+				pixman_region32_init(&repaint);
+				pixman_region32_intersect(&repaint,
+							  &output->region,
+							  &es->damage);
+				weston_surface_draw(es, output, &repaint);
+				pixman_region32_subtract(&es->damage,
+							 &es->damage,
+							 &output->region);
+			}
 		}
 	}
 
@@ -1554,6 +1736,7 @@ input_device_attach(struct wl_client *client,
 			weston_surface_create(compositor,
 					    device->input_device.x,
 					    device->input_device.y, 32, 32);
+		device->sprite->type = WESTON_SURFACE_TYPE_CURSOR;
 		wl_list_init(&device->sprite->link);
 	}
 
diff --git a/src/compositor.h b/src/compositor.h
index 031b7d4..9907abb 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -32,6 +32,15 @@
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
 
+#define WESTON_SURFACE_FULLSCREEN_NONE 0
+#define WESTON_SURFACE_FULLSCREEN_SCALE 1
+#define WESTON_SURFACE_FULLSCREEN_FORCE 2
+#define WESTON_SURFACE_FULLSCREEN_FILL 3
+#define WESTON_SURFACE_TYPE_CURSOR 0
+#define WESTON_SURFACE_TYPE_PANEL 1
+#define WESTON_SURFACE_TYPE_GENERAL 2
+
+
 struct weston_matrix {
 	GLfloat d[16];
 };
@@ -79,8 +88,10 @@ struct weston_output {
 
 	char *make, *model;
 	uint32_t subpixel;
+	uint32_t fs_dirty;
 	
 	struct weston_mode *current;
+	struct weston_mode *saved_mode;
 	struct wl_list mode_list;
 	struct wl_buffer *scanout_buffer;
 	struct wl_listener scanout_buffer_destroy_listener;
@@ -94,6 +105,7 @@ struct weston_output {
 	int (*set_hardware_cursor)(struct weston_output *output,
 				   struct weston_input_device *input);
 	void (*destroy)(struct weston_output *output);
+	int (*set_mode)(struct weston_output *output_base, char *mode, uint32_t refresh);
 };
 
 struct weston_input_device {
@@ -242,6 +254,15 @@ struct weston_surface {
 	struct weston_transform *transform;
 	uint32_t alpha;
 	uint32_t visual;
+	uint32_t type;
+
+	struct {
+		uint32_t framerate;
+		uint32_t fs_method;
+		struct weston_transform *fs_transform;
+		struct weston_output *fullscreen_output;
+	} fs_support;
+
 
 	/*
 	 * Which output to vsync this surface to.
diff --git a/src/shell.c b/src/shell.c
index 9386d1e..d12bc1a 100644
--- a/src/shell.c
+++ b/src/shell.c
@@ -330,7 +330,11 @@ reset_shell_surface_type(struct shell_surface *surface)
 	case SHELL_SURFACE_FULLSCREEN:
 		surface->surface->x = surface->saved_x;
 		surface->surface->y = surface->saved_y;
-		surface->surface->fullscreen_output = NULL;
+		surface->surface->fs_support.fullscreen_output = NULL;
+		if(surface->surface->fs_support.fs_transform) {
+			free(surface->surface->fs_support.fs_transform);
+			surface->surface->fs_support.fs_transform = NULL;
+		}
 		break;
 	case SHELL_SURFACE_PANEL:
 	case SHELL_SURFACE_BACKGROUND:
@@ -345,6 +349,10 @@ reset_shell_surface_type(struct shell_surface *surface)
 		return -1;
 	case SHELL_SURFACE_NONE:
 	case SHELL_SURFACE_TOPLEVEL:
+		if(surface->saved_x || surface->saved_y) {
+			surface->surface->x = surface->saved_x;
+			surface->surface->y = surface->saved_y;
+		}
 	case SHELL_SURFACE_TRANSIENT:
 	case SHELL_SURFACE_POPUP:
 		break;
@@ -401,7 +409,8 @@ get_default_output(struct weston_compositor *compositor)
 
 static void
 shell_surface_set_fullscreen(struct wl_client *client,
-			     struct wl_resource *resource)
+			     struct wl_resource *resource, uint32_t framerate,
+			     uint32_t flags)
 
 {
 	struct shell_surface *shsurf = resource->data;
@@ -411,6 +420,7 @@ shell_surface_set_fullscreen(struct wl_client *client,
 	if (reset_shell_surface_type(shsurf))
 		return;
 
+
 	/* FIXME: Fullscreen on first output */
 	/* FIXME: Handle output going away */
 	output = get_default_output(es->compositor);
@@ -420,9 +430,37 @@ shell_surface_set_fullscreen(struct wl_client *client,
 	shsurf->saved_y = es->y;
 	es->x = (output->current->width - es->width) / 2;
 	es->y = (output->current->height - es->height) / 2;
-	es->fullscreen_output = output;
-	weston_surface_damage(es);
+	es->fs_support.fullscreen_output = output;
+	es->fs_support.framerate = framerate;
 	shsurf->type = SHELL_SURFACE_FULLSCREEN;
+	switch(flags){
+		case WL_SHELL_SURFACE_FULLSCREEN_MOTHED_NONE:
+			weston_surface_damage(es);
+			es->fs_support.fs_method = WESTON_SURFACE_FULLSCREEN_NONE;
+			break;
+		case WL_SHELL_SURFACE_FULLSCREEN_MOTHED_SCALE:
+			es->x = 0;
+			es->y = 0;
+			weston_surface_damage(es);
+			es->fs_support.fs_method = WESTON_SURFACE_FULLSCREEN_SCALE;
+			break;
+		case WL_SHELL_SURFACE_FULLSCREEN_MOTHED_FORCE:
+			es->x = 0;
+			es->y = 0;
+			weston_surface_damage(es);
+			es->fs_support.fs_method =
+					WESTON_SURFACE_FULLSCREEN_FORCE;
+			break;
+		case WL_SHELL_SURFACE_FULLSCREEN_MOTHED_FILL:
+			weston_surface_damage(es);
+			es->fs_support.fs_method = WESTON_SURFACE_FULLSCREEN_FILL;
+		default :
+			fprintf(stderr,
+				"unknown parameter for fullscreen support\n");
+			break;
+	}
+	/*will do the real action on the map or paint function*/
+
 }
 
 static void
@@ -750,6 +788,7 @@ desktop_shell_set_panel(struct wl_client *client,
 	}
 
 	shsurf->type = SHELL_SURFACE_PANEL;
+	surface->type = WESTON_SURFACE_TYPE_PANEL;
 	shsurf->output = output_resource->data;
 
 	wl_list_insert(&shell->panels, &shsurf->link);
@@ -1092,15 +1131,6 @@ unlock(struct weston_shell *base)
 }
 
 static void
-center_on_output(struct weston_surface *surface, struct weston_output *output)
-{
-	struct weston_mode *mode = output->current;
-
-	surface->x = output->x + (mode->width - surface->width) / 2;
-	surface->y = output->y + (mode->height - surface->height) / 2;
-}
-
-static void
 map(struct weston_shell *base,
     struct weston_surface *surface, int32_t width, int32_t height)
 {
@@ -1108,6 +1138,7 @@ map(struct weston_shell *base,
 	struct weston_compositor *compositor = shell->compositor;
 	struct wl_list *list;
 	struct shell_surface *shsurf;
+	struct weston_output *fs_output = surface->fs_support.fullscreen_output;
 	enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
 	int do_configure;
 
@@ -1134,10 +1165,11 @@ map(struct weston_shell *base,
 		break;
 	case SHELL_SURFACE_SCREENSAVER:
 	case SHELL_SURFACE_FULLSCREEN:
-		center_on_output(surface, surface->fullscreen_output);
+		weston_surface_set_fullscreen(fs_output, surface);
 		break;
 	case SHELL_SURFACE_LOCK:
-		center_on_output(surface, get_default_output(compositor));
+		weston_surface_center_on_output(surface,
+					      get_default_output(compositor));
 		break;
 	default:
 		;
@@ -1231,6 +1263,9 @@ configure(struct weston_shell *base, struct weston_surface *surface,
 	int do_configure = !shell->locked;
 	enum shell_surface_type surface_type = SHELL_SURFACE_NONE;
 	struct shell_surface *shsurf;
+	struct weston_output *fs_output;
+
+	fs_output = surface->fs_support.fullscreen_output;
 
 	shsurf = get_shell_surface(surface);
 	if (shsurf)
@@ -1244,7 +1279,7 @@ configure(struct weston_shell *base, struct weston_surface *surface,
 		do_configure = !do_configure;
 		/* fall through */
 	case SHELL_SURFACE_FULLSCREEN:
-		center_on_output(surface, surface->fullscreen_output);
+		weston_surface_center_on_output(surface, fs_output);
 		break;
 	default:
 		break;
@@ -1348,7 +1383,7 @@ screensaver_set_surface(struct wl_client *client,
 
 	surface->type = SHELL_SURFACE_SCREENSAVER;
 
-	surface->surface->fullscreen_output = output;
+	surface->surface->fs_support.fullscreen_output = output;
 	surface->output = output;
 	wl_list_insert(shell->screensaver.surfaces.prev, &surface->link);
 }
-- 
1.7.5.4



More information about the wayland-devel mailing list