compositor: add stub scaler resources
authorJonny Lamb <jonny.lamb@collabora.co.uk>
Tue, 26 Nov 2013 17:19:45 +0000 (18:19 +0100)
committerKristian Høgsberg <krh@bitplanet.net>
Tue, 17 Dec 2013 06:36:11 +0000 (22:36 -0800)
This registers the wl_scaler global object and lets clients create
wl_surface_scaler objects for surfaces. wl_surface_scaler.set is not
implemented so this doesn't really do anything useful yet.

src/.gitignore
src/Makefile.am
src/compositor.c

index 90ac2c3..024594c 100644 (file)
@@ -13,3 +13,5 @@ workspaces-protocol.c
 workspaces-server-protocol.h
 input-method-protocol.c
 input-method-server-protocol.h
+scaler-server-protocol.h
+scaler-protocol.c
index 34b7048..446639c 100644 (file)
@@ -36,6 +36,8 @@ weston_SOURCES =                              \
        input-method-server-protocol.h          \
        workspaces-protocol.c                   \
        workspaces-server-protocol.h            \
+       scaler-protocol.c                       \
+       scaler-server-protocol.h                \
        bindings.c                              \
        animation.c                             \
        noop-renderer.c                         \
@@ -321,6 +323,8 @@ BUILT_SOURCES =                                     \
        input-method-server-protocol.h          \
        workspaces-server-protocol.h            \
        workspaces-protocol.c                   \
+       scaler-server-protocol.h                \
+       scaler-protocol.c                       \
        git-version.h
 
 CLEANFILES = $(BUILT_SOURCES)
index d273e3f..8a6ff38 100644 (file)
@@ -53,6 +53,7 @@
 #endif
 
 #include "compositor.h"
+#include "scaler-server-protocol.h"
 #include "../shared/os-compatibility.h"
 #include "git-version.h"
 #include "version.h"
@@ -3402,6 +3403,104 @@ weston_output_transform_coordinate(struct weston_output *output,
 }
 
 static void
+destroy_surface_scaler(struct wl_resource *resource)
+{
+}
+
+static void
+surface_scaler_destroy(struct wl_client *client,
+                      struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+surface_scaler_set(struct wl_client *client,
+                  struct wl_resource *resource,
+                  wl_fixed_t src_x,
+                  wl_fixed_t src_y,
+                  wl_fixed_t src_width,
+                  wl_fixed_t src_height,
+                  int32_t dst_width,
+                  int32_t dst_height)
+{
+       if (wl_fixed_to_double(src_width) < 0 ||
+           wl_fixed_to_double(src_height) < 0) {
+               wl_resource_post_error(resource,
+                       WL_SURFACE_SCALER_ERROR_BAD_VALUE,
+                       "source dimensions must be non-negative (%fx%f)",
+                       wl_fixed_to_double(src_width),
+                       wl_fixed_to_double(src_height));
+               return;
+       }
+
+       if (dst_width <= 0 || dst_height <= 0) {
+               wl_resource_post_error(resource,
+                       WL_SURFACE_SCALER_ERROR_BAD_VALUE,
+                       "destination dimensions must be positive (%dx%d)",
+                       dst_width, dst_height);
+               return;
+       }
+
+       /* TODO */
+}
+
+static const struct wl_surface_scaler_interface surface_scaler_interface = {
+       surface_scaler_destroy,
+       surface_scaler_set
+};
+
+static void
+scaler_destroy(struct wl_client *client,
+              struct wl_resource *resource)
+{
+       wl_resource_destroy(resource);
+}
+
+static void
+scaler_get_surface_scaler(struct wl_client *client,
+                         struct wl_resource *scaler,
+                         uint32_t id,
+                         struct wl_resource *surface_resource)
+{
+       struct weston_surface *surface = wl_resource_get_user_data(surface_resource);
+       struct wl_resource *resource;
+
+       /* TODO: check we don't already have one for this surface */
+       resource = wl_resource_create(client, &wl_surface_scaler_interface,
+                                     1, id);
+       if (resource == NULL) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource, &surface_scaler_interface,
+                                      surface, destroy_surface_scaler);
+}
+
+static const struct wl_scaler_interface scaler_interface = {
+       scaler_destroy,
+       scaler_get_surface_scaler
+};
+
+static void
+bind_scaler(struct wl_client *client,
+           void *data, uint32_t version, uint32_t id)
+{
+       struct wl_resource *resource;
+
+       resource = wl_resource_create(client, &wl_scaler_interface,
+                                     1, id);
+       if (resource == NULL) {
+               wl_client_post_no_memory(client);
+               return;
+       }
+
+       wl_resource_set_implementation(resource, &scaler_interface,
+                                      NULL, NULL);
+}
+
+static void
 compositor_bind(struct wl_client *client,
                void *data, uint32_t version, uint32_t id)
 {
@@ -3489,6 +3588,10 @@ weston_compositor_init(struct weston_compositor *ec,
                              ec, bind_subcompositor))
                return -1;
 
+       if (!wl_global_create(ec->wl_display, &wl_scaler_interface, 1,
+                             ec, bind_scaler))
+               return -1;
+
        wl_list_init(&ec->view_list);
        wl_list_init(&ec->plane_list);
        wl_list_init(&ec->layer_list);