Re: [PATCH V3 5/7] weston:Add the weston randr protocol implementation

2014-04-13 Thread Wang, Quanxian
Sorry to be later. Thanks for your comment.
On Wed, 2014-04-09 at 09:59 +0200, Hardening wrote:
> Le 08/04/2014 07:03, Quanxian Wang a écrit :
> > Signed-off-by: Quanxian Wang 
> > ---
> >   module/Makefile.am|3 +
> >   module/wrandr/Makefile.am |   32 ++
> >   module/wrandr/wrandr.c| 1262 
> > +
> >   3 files changed, 1297 insertions(+)
> >   create mode 100644 module/Makefile.am
> >   create mode 100644 module/wrandr/Makefile.am
> >   create mode 100644 module/wrandr/wrandr.c
> >
> > diff --git a/module/Makefile.am b/module/Makefile.am new file mode 
> > 100644 index 000..1a10e65
> > --- /dev/null
> > +++ b/module/Makefile.am
> > @@ -0,0 +1,3 @@
> > +SUBDIRS =
> > +
> > +SUBDIRS += wrandr
> > diff --git a/module/wrandr/Makefile.am b/module/wrandr/Makefile.am 
> > new file mode 100644 index 000..b0f2e6b
> > --- /dev/null
> > +++ b/module/wrandr/Makefile.am
> > @@ -0,0 +1,32 @@
> > +moduledir = $(libdir)/weston
> > +module_LTLIBRARIES = $(wrandr)
> > +
> > +AM_CPPFLAGS =  \
> > +   -I$(top_srcdir)/shared  \
> > +   -I$(top_srcdir)/src \
> > +   -I$(top_builddir)/src   \
> > +   -DDATADIR='"$(datadir)"'\
> > +   -DMODULEDIR='"$(moduledir)"'\
> > +   -DLIBEXECDIR='"$(libexecdir)"'  \
> > +   -DIN_WESTON
> > +
> 
> [...]
> 
> > +static void
> > +update_region(struct weston_compositor *ec,
> > + struct weston_output *target_output) {
> > +   pixman_region32_t old_output_region;
> > +
> > +   /* Update output region and transformation matrix. */
> > +   pixman_region32_init(&old_output_region);
> > +   pixman_region32_copy(&old_output_region, &target_output->region);
> > +   weston_output_transform_scale_init(target_output,
> > +  target_output->transform,
> > +  target_output->current_scale);
> > +
> > +   pixman_region32_init(&target_output->previous_damage);
> > +   pixman_region32_init_rect(&target_output->region,
> > + target_output->x, target_output->y,
> > + target_output->width, target_output->height);
> > +
> > +   weston_output_update_matrix(target_output);
> > +
> > +   adjust_pointer(target_output, &old_output_region);
> > +   pixman_region32_fini(&old_output_region);
> > +
> > +   /* Damage the output region in primary_plane */
> > +   pixman_region32_union(&ec->primary_plane.damage,
> > + &ec->primary_plane.damage,
> > + &target_output->region);
> > +
> > +   target_output->dirty = 1;
> > +}
> > +
> > +static void
> > +randr_switch_mode(struct randr_output_request *request,
> > + uint32_t *results)
> > +{
> > +   time_t time = 0;
> > +   int i = 0, found = 0;
> > +   int result = WRANDR_TYPE_RET_NOACT;
> > +   int timing_mode = 0;
> > +   int move_bits = 0;
> > +   struct weston_mode *mode;
> > +   struct weston_output *output = request->output;
> > +
> > +   if (request->flags & 1< > +   timing_mode = 1;
> > +   time = request->modenum.modi_time;
> > +   *results |= result<<
> > +  (WRANDR_TYPE_OOP_MODENUM * 2);
> > +   }
> > +
> > +   if (request->flags & 1< > +   *results |= result<<
> > +  (WRANDR_TYPE_OOP_MODE * 2);
> > +   if (request->mode->modi_time > time) {
> > +   time = request->mode->modi_time;
> > +   timing_mode = 2;
> > +   }
> > +   }
> 
> [Hardening] Perhaps the case where request->flags has not bits set 
> should be treated with an error returned ?
No need to return error. In this function, we just check these two methods. 
Others will be processed in other function. If no flag, that is fine, no 
operation is needed.
> 
> > +
> > +   switch (timing_mode) {
> > +   case 1:
> > +   i = 0;
> > +   wl_list_for_each(mode, &output->mode_list, link) {
> > +   i++;
> > +   if (i == request->modenum.num) {
> > +   found = 1;
> > +   break;
> > +   }
> > +   }
> > +
> > +   if (found != 1)
> > +   mode = NULL;
> > +   break;
> > +   case 2:
> > +   mode = randr_find_mode(output,
> > +  request->mode->width,
> > +  request->mode->height,
> > +  request->mode->refresh);
> > +   break;
> > +   default:
> > +   return;
> > +   }
> 
> [Hardening] related to my remark above, *results should be set in the 
> "default:" handling, as it catches the case where timing_mode == 0 
> which means no flags where set.
If timing_mode is 0, that means, no operation need to be done for switch mode. 
Just return is enough.
> 
> > +
> > +
> > + 

Re: [PATCH V3 5/7] weston:Add the weston randr protocol implementation

2014-04-09 Thread Hardening

Le 08/04/2014 07:03, Quanxian Wang a écrit :

Signed-off-by: Quanxian Wang 
---
  module/Makefile.am|3 +
  module/wrandr/Makefile.am |   32 ++
  module/wrandr/wrandr.c| 1262 +
  3 files changed, 1297 insertions(+)
  create mode 100644 module/Makefile.am
  create mode 100644 module/wrandr/Makefile.am
  create mode 100644 module/wrandr/wrandr.c

diff --git a/module/Makefile.am b/module/Makefile.am
new file mode 100644
index 000..1a10e65
--- /dev/null
+++ b/module/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS =
+
+SUBDIRS += wrandr
diff --git a/module/wrandr/Makefile.am b/module/wrandr/Makefile.am
new file mode 100644
index 000..b0f2e6b
--- /dev/null
+++ b/module/wrandr/Makefile.am
@@ -0,0 +1,32 @@
+moduledir = $(libdir)/weston
+module_LTLIBRARIES = $(wrandr)
+
+AM_CPPFLAGS =  \
+   -I$(top_srcdir)/shared  \
+   -I$(top_srcdir)/src \
+   -I$(top_builddir)/src   \
+   -DDATADIR='"$(datadir)"'  \
+   -DMODULEDIR='"$(moduledir)"'  \
+   -DLIBEXECDIR='"$(libexecdir)"'\
+   -DIN_WESTON
+


[...]


+static void
+update_region(struct weston_compositor *ec,
+ struct weston_output *target_output)
+{
+   pixman_region32_t old_output_region;
+
+   /* Update output region and transformation matrix. */
+   pixman_region32_init(&old_output_region);
+   pixman_region32_copy(&old_output_region, &target_output->region);
+   weston_output_transform_scale_init(target_output,
+  target_output->transform,
+  target_output->current_scale);
+
+   pixman_region32_init(&target_output->previous_damage);
+   pixman_region32_init_rect(&target_output->region,
+ target_output->x, target_output->y,
+ target_output->width, target_output->height);
+
+   weston_output_update_matrix(target_output);
+
+   adjust_pointer(target_output, &old_output_region);
+   pixman_region32_fini(&old_output_region);
+
+   /* Damage the output region in primary_plane */
+   pixman_region32_union(&ec->primary_plane.damage,
+ &ec->primary_plane.damage,
+ &target_output->region);
+
+   target_output->dirty = 1;
+}
+
+static void
+randr_switch_mode(struct randr_output_request *request,
+ uint32_t *results)
+{
+   time_t time = 0;
+   int i = 0, found = 0;
+   int result = WRANDR_TYPE_RET_NOACT;
+   int timing_mode = 0;
+   int move_bits = 0;
+   struct weston_mode *mode;
+   struct weston_output *output = request->output;
+
+   if (request->flags & 1flags & 1modi_time > time) {
+   time = request->mode->modi_time;
+   timing_mode = 2;
+   }
+   }


[Hardening] Perhaps the case where request->flags has not bits set 
should be treated with an error returned ?



+
+   switch (timing_mode) {
+   case 1:
+   i = 0;
+   wl_list_for_each(mode, &output->mode_list, link) {
+   i++;
+   if (i == request->modenum.num) {
+   found = 1;
+   break;
+   }
+   }
+
+   if (found != 1)
+   mode = NULL;
+   break;
+   case 2:
+   mode = randr_find_mode(output,
+  request->mode->width,
+  request->mode->height,
+  request->mode->refresh);
+   break;
+   default:
+   return;
+   }


[Hardening] related to my remark above, *results should be set in the 
"default:" handling, as it catches the case where timing_mode == 0 which 
means no flags where set.



+
+
+   if (!mode) {
+   result = WRANDR_TYPE_RET_FAIL;
+   } else {
+   if (!(mode->flags & WL_OUTPUT_MODE_CURRENT) &&
+   output->switch_mode) {
+   result = output->switch_mode(output, mode);
+   if (result < 0)
+   result = WRANDR_TYPE_RET_FAIL;
+   else
+   result = WRANDR_TYPE_RET_SUCCESS;
+   } else
+   result = WRANDR_TYPE_RET_NOACT;
+   }
+
+   move_bits = WRANDR_TYPE_OOP_MODENUM + timing_mode - 1;
+   *results &= ~(RESULT_MASK<<(move_bits * 2));
+   *results |= result<<(move_bits * 2);
+}
+



[...]

Regards

--
David FORT
website: http://www.harde

[PATCH V3 5/7] weston:Add the weston randr protocol implementation

2014-04-07 Thread Quanxian Wang
Signed-off-by: Quanxian Wang 
---
 module/Makefile.am|3 +
 module/wrandr/Makefile.am |   32 ++
 module/wrandr/wrandr.c| 1262 +
 3 files changed, 1297 insertions(+)
 create mode 100644 module/Makefile.am
 create mode 100644 module/wrandr/Makefile.am
 create mode 100644 module/wrandr/wrandr.c

diff --git a/module/Makefile.am b/module/Makefile.am
new file mode 100644
index 000..1a10e65
--- /dev/null
+++ b/module/Makefile.am
@@ -0,0 +1,3 @@
+SUBDIRS =
+
+SUBDIRS += wrandr
diff --git a/module/wrandr/Makefile.am b/module/wrandr/Makefile.am
new file mode 100644
index 000..b0f2e6b
--- /dev/null
+++ b/module/wrandr/Makefile.am
@@ -0,0 +1,32 @@
+moduledir = $(libdir)/weston
+module_LTLIBRARIES = $(wrandr)
+
+AM_CPPFLAGS =  \
+   -I$(top_srcdir)/shared  \
+   -I$(top_srcdir)/src \
+   -I$(top_builddir)/src   \
+   -DDATADIR='"$(datadir)"'\
+   -DMODULEDIR='"$(moduledir)"'\
+   -DLIBEXECDIR='"$(libexecdir)"'  \
+   -DIN_WESTON
+
+if BUILD_WRANDR
+wrandr = wrandr.la
+wrandr_la_LDFLAGS = -module -avoid-version
+wrandr_la_LIBADD = $(COMPOSITOR_LIBS)  \
+   $(top_srcdir)/shared/libshared.la
+wrandr_la_CFLAGS = $(GCC_CFLAGS) $(COMPOSITOR_CFLAGS)
+wrandr_la_SOURCES =\
+   wrandr.c\
+   randr-protocol.c\
+   randr-server-protocol.h
+endif
+
+BUILT_SOURCES =\
+   randr-protocol.c\
+   randr-server-protocol.h
+
+CLEANFILES = $(BUILT_SOURCES)
+
+wayland_protocoldir = $(top_srcdir)/protocol
+include $(top_srcdir)/wayland-scanner.mk
diff --git a/module/wrandr/wrandr.c b/module/wrandr/wrandr.c
new file mode 100644
index 000..baa5628
--- /dev/null
+++ b/module/wrandr/wrandr.c
@@ -0,0 +1,1262 @@
+/*
+ * Copyright © 2014 Quanxian Wang
+ * Copyright © 2014 Intel Corporation
+
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "compositor.h"
+#include "randr-server-protocol.h"
+
+#define RESULT_MASK 0x3
+
+struct randr_mode {
+   int width;
+   int height;
+   int refresh;
+   time_t modi_time;
+};
+
+struct randr_timing {
+   uint32_t clock;
+   int hdisplay;
+   int hsync_start;
+   int hsync_end;
+   int htotal;
+   int vdisplay;
+   int vsync_start;
+   int vsync_end;
+   int vtotal;
+   int vscan;
+   uint32_t flags;
+};
+
+struct randr_request {
+   struct wl_list link;
+   struct wl_client *client;
+   struct wl_list output_request_list;
+   char *config_file;
+   int flags;
+};
+
+struct randr_output_request {
+   struct wl_list link;
+   struct weston_output *output;
+   int flags;
+
+   struct weston_output *loutput;
+   struct weston_output *routput;
+   struct weston_output *aoutput;
+   struct weston_output *boutput;
+
+   struct randr_mode *mode;
+
+   struct {
+   time_t modi_time;
+   int num;
+   } modenum;
+
+   int delmodenum;
+   struct randr_mode *delmode;
+
+   int scale;
+   int32_t transform;
+   struct randr_mode *newmode;
+   struct randr_timing *newtiming;
+};
+
+static void
+del_orequest(struct randr_output_request *orequest)
+{
+   wl_list_remove(&orequest->link);
+
+   if (orequest->mode)
+   free(orequest->mode);
+
+   if (orequest->delmode)
+   free(orequest->delmode);
+
+   if (orequest->newmode)
+   free(orequest->newmode);
+
+   if (orequest->newtiming)
+   free(orequest->newtiming);
+
+   free(orequest);