Migrated randr protocol patch to weston git upstream

Leslie Zhai xiang.zhai at i-soft.com.cn
Wed Apr 8 23:42:33 PDT 2015


Hi wayland developers,

I found that Quanxian Wang had implemented randr protocol in 2014 
http://lists.freedesktop.org/archives/wayland-devel/2014-April/014091.html

But I could not find randr relative branch in weston official git 
http://cgit.freedesktop.org/wayland/weston/?h=XXX

I will forked weston official git to my github 
https://github.com/xiangzhai/weston to fix randr issue if there is ;-)
And weston had already changed its architecture, so Quanxian`s patch 
failed to work for weston git upstream, then I simply migrated it shown 
as below:

diff --git a/Makefile.am b/Makefile.am
index 42d616b..ca99dcc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -388,6 +388,10 @@ libexec_PROGRAMS +=                \
      weston-ivi-shell-user-interface
  endif

+if ENABLE_WRANDR
+libexec_PROGRAMS += weston-wrandr
+endif
+
  demo_clients =                    \
      weston-flower                \
      weston-image                \
@@ -642,6 +646,15 @@ weston_ivi_shell_user_interface_LDADD = 
libtoytoolkit.la
  weston_ivi_shell_user_interface_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
  endif

+if ENABLE_WRANDR
+weston_wrandr_SOURCES = clients/wrandr.c
+nodist_weston_wrandr_SOURCES = protocol/randr-protocol.c    \
+                               protocol/randr-client-protocol.h
+weston_wrandr_LDADD = libtoytoolkit.la
+weston_wrandr_CFLAGS = $(AM_CFLAGS)    \
+                       $(CLIENT_CFLAGS)
+endif
+
  if BUILD_FULL_GL_CLIENTS
  demo_clients += weston-gears
  weston_gears_SOURCES = clients/gears.c
@@ -791,6 +804,29 @@ nodist_fullscreen_shell_la_SOURCES = \
  BUILT_SOURCES += $(nodist_fullscreen_shell_la_SOURCES)
  endif

+if ENABLE_WRANDR
+
+module_LTLIBRARIES += wrandr.la
+
+wrandr_la_CPPFLAGS = -I$(top_builddir)/protocol    \
+                     -I$(top_srcdir)/shared    \
+                     -I$(top_srcdir)/src    \
+                     -I$(top_builddir)/src    \
+                     -DIN_WESTON
+
+wrandr_la_SOURCES = wrandr/wrandr.c
+nodist_wrandr_la_SOURCES = protocol/randr-protocol.c    \
+                           protocol/randr-server-protocol.h    \
+                           protocol/randr-client-protocol.h
+wrandr_la_CFLAGS = $(GCC_CFLAGS)    \
+                   $(COMPOSITOR_CFLAGS)
+wrandr_la_LDFLAGS = -module -avoid-version
+wrandr_la_LIBADD = $(COMPOSITOR_LIBS)  \
+                   libshared.la
+
+BUILT_SOURCES += $(nodist_wrandr_la_SOURCES)
+endif
+
  if ENABLE_IVI_SHELL

  module_LTLIBRARIES +=                \
@@ -1127,7 +1163,8 @@ EXTRA_DIST +=                    \
      protocol/presentation_timing.xml    \
      protocol/scaler.xml            \
      protocol/ivi-application.xml        \
-    protocol/ivi-hmi-controller.xml
+    protocol/ivi-hmi-controller.xml    \
+    protocol/randr.xml

  #
  # manual test modules in tests subdirectory
diff --git a/configure.ac b/configure.ac
index d9d8d8f..0514859 100644
--- a/configure.ac
+++ b/configure.ac
@@ -429,6 +429,12 @@ if test "x$enable_dbus" != "xno"; then
  fi
  AM_CONDITIONAL(ENABLE_DBUS, test "x$enable_dbus" = "xyes")

+AC_ARG_ENABLE(wrandr, [  --disable-wrandr],, enable_wrandr=no)
+AM_CONDITIONAL(ENABLE_WRANDR, test x$enable_wrandr = xyes)
+if test x$enable_wrandr = xyes; then
+  AC_DEFINE([BUILD_WRANDR], [1], [Build the wrandr])
+fi
+
  # ivi-shell support
  AC_ARG_ENABLE(ivi-shell,
                AS_HELP_STRING([--disable-ivi-shell],
@@ -524,6 +530,8 @@ AC_MSG_RESULT([
      XWayland            ${enable_xwayland}
      dbus                ${enable_dbus}

+    wrandr               ${enable_wrandr}
+
      ivi-shell            ${enable_ivi_shell}

      Build wcap utility        ${enable_wcap_tools}
diff --git a/src/compositor-drm.c b/src/compositor-drm.c
index 43197a8..153ca5d 100644
--- a/src/compositor-drm.c
+++ b/src/compositor-drm.c
@@ -1464,6 +1464,80 @@ drm_output_add_mode(struct drm_output *output, 
drmModeModeInfo *info)
  }

  static int
+drm_output_compare_timing(struct weston_mode *mode,
+             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 drm_mode *drmmode = (struct drm_mode *)mode;
+   drmModeModeInfo *modeinfo = &drmmode->mode_info;
+
+   return (modeinfo->clock == clock &&
+       modeinfo->hdisplay == hdisplay &&
+       modeinfo->hsync_start == hsync_start &&
+       modeinfo->hsync_end == hsync_end &&
+       modeinfo->htotal == htotal &&
+       modeinfo->vdisplay == vdisplay &&
+       modeinfo->vsync_start == vsync_start &&
+       modeinfo->vsync_end == vsync_end &&
+       modeinfo->vtotal == vtotal &&
+       modeinfo->vscan == vscan &&
+       modeinfo->flags == flags);
+}
+
+static struct weston_mode *
+drm_output_new_timing(struct weston_output *output,
+             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)
+{
+   drmModeModeInfo *modeinfo;
+   struct drm_mode *mode = NULL;
+
+   modeinfo = malloc(sizeof(*modeinfo));
+   if (modeinfo == NULL)
+       return NULL;
+   memset(modeinfo, 0x0, sizeof(*modeinfo));
+
+   modeinfo->type = DRM_MODE_TYPE_USERDEF;
+   modeinfo->hskew = 0;
+   modeinfo->vrefresh = 0;
+   modeinfo->hdisplay = hdisplay;
+   modeinfo->hsync_start = hsync_start;
+   modeinfo->hsync_end = hsync_end;
+   modeinfo->htotal = htotal;
+   modeinfo->vdisplay = vdisplay;
+   modeinfo->vsync_start = vsync_start;
+   modeinfo->vsync_end = vsync_end;
+   modeinfo->vtotal = vtotal;
+   modeinfo->vscan = vscan;
+   modeinfo->flags = flags;
+   modeinfo->clock = clock;
+
+   mode = drm_output_add_mode((struct drm_output *)output, modeinfo);
+   if (mode)
+       return &mode->base;
+   else
+       return NULL;
+}
+
+static int
  drm_subpixel_to_wayland(int drm_value)
  {
      switch (drm_value) {
@@ -2138,6 +2212,9 @@ create_output_for_connector(struct drm_compositor *ec,
      output->base.set_dpms = drm_set_dpms;
      output->base.switch_mode = drm_output_switch_mode;

+    output->base.new_timing = drm_output_new_timing;
+    output->base.compare_timing = drm_output_compare_timing;
+
      output->base.gamma_size = output->original_crtc->gamma_size;
      output->base.set_gamma = drm_output_set_gamma;

diff --git a/src/compositor.c b/src/compositor.c
index e6a60bd..6fbb8e8 100644
--- a/src/compositor.c
+++ b/src/compositor.c
@@ -115,7 +115,7 @@ sigchld_handler(int signal_number, void *data)
      return 1;
  }

-static void
+WL_EXPORT void
  weston_output_transform_scale_init(struct weston_output *output,
                     uint32_t transform, uint32_t scale);

@@ -4007,7 +4007,7 @@ weston_output_update_matrix(struct weston_output 
*output)
      weston_matrix_invert(&output->inverse_matrix, &output->matrix);
  }

-static void
+WL_EXPORT void
  weston_output_transform_scale_init(struct weston_output *output, 
uint32_t transform, uint32_t scale)
  {
      output->transform = transform;
@@ -5271,6 +5271,7 @@ int main(int argc, char *argv[])
      int32_t idle_time = -1;
      int32_t help = 0;
      char *socket_name = NULL;
+    int32_t enable_wrandr = 0;
      int32_t version = 0;
      int32_t noconfig = 0;
      int32_t numlock_on;
@@ -5287,7 +5288,8 @@ int main(int argc, char *argv[])
          { WESTON_OPTION_STRING, "socket", 'S', &socket_name },
          { WESTON_OPTION_INTEGER, "idle-time", 'i', &idle_time },
          { WESTON_OPTION_STRING, "modules", 0, &option_modules },
-        { WESTON_OPTION_STRING, "log", 0, &log },
+        { WESTON_OPTION_STRING, "enable-wrandr", 0, &enable_wrandr},
+        { WESTON_OPTION_STRING, "log", 0, &log },
          { WESTON_OPTION_BOOLEAN, "help", 'h', &help },
          { WESTON_OPTION_BOOLEAN, "version", 0, &version },
          { WESTON_OPTION_BOOLEAN, "no-config", 0, &noconfig },
@@ -5366,6 +5368,14 @@ int main(int argc, char *argv[])
      ec->default_pointer_grab = NULL;
      ec->exit_code = EXIT_SUCCESS;

+    /* Add wrandr module */
+    if (enable_wrandr) {
+        if (!option_modules)
+            option_modules = strdup("wrandr.so");
+ else
+            option_modules = strcat(option_modules, ",wrandr.so");
+    }
+
      weston_compositor_log_capabilities(ec);

      server_socket = getenv("WAYLAND_SERVER_SOCKET");
diff --git a/src/compositor.h b/src/compositor.h
index 5f49237..862b589 100644
--- a/src/compositor.h
+++ b/src/compositor.h
@@ -173,6 +173,17 @@ enum dpms_enum {
      WESTON_DPMS_OFF
  };

+struct wrandr {
+   struct weston_compositor *compositor;
+   struct wl_global *global;
+   struct wl_resource *resource;
+   struct wl_listener destroy_listener;
+   struct {
+       struct wl_list request_list;
+       struct wl_list randr_callback_list;
+   } pending;
+};
+
  struct weston_output {
      uint32_t id;
      char *name;
@@ -229,6 +240,34 @@ struct weston_output {
      void (*destroy)(struct weston_output *output);
      void (*assign_planes)(struct weston_output *output);
      int (*switch_mode)(struct weston_output *output, struct 
weston_mode *mode);
+
+    struct weston_mode * (*new_timing)(struct weston_output *output,
+                      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);
+
+   int (*compare_timing)(struct weston_mode *mode,
+                 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 weston_mode * (*new_mode)(int width, int height, int refresh);

      /* backlight values are on 0-255 range, where higher is brighter */
      int32_t backlight_current;
@@ -683,6 +722,8 @@ struct weston_compositor {
      /* Raw keyboard processing (no libxkbcommon initialization or 
handling) */
      int use_xkbcommon;

+    struct wrandr *randr;
+
      int32_t kb_repeat_rate;
      int32_t kb_repeat_delay;

@@ -1338,6 +1379,10 @@ weston_buffer_reference(struct 
weston_buffer_reference *ref,
  uint32_t
  weston_compositor_get_time(void);

+void
+weston_output_transform_scale_init(struct weston_output *output,
+                  uint32_t transform, uint32_t scale);
+
  int
  weston_compositor_init(struct weston_compositor *ec, struct wl_display 
*display,
                 int *argc, char *argv[], struct weston_config *config);

-- 
Regards,
Leslie Zhai





More information about the wayland-devel mailing list