コード例 #1
0
ファイル: wayland-shm.c プロジェクト: antognolli/wayland
static void
shm_pool_create_buffer(struct wl_client *client, struct wl_resource *resource,
		       uint32_t id, int32_t offset,
		       int32_t width, int32_t height,
		       int32_t stride, uint32_t format)
{
	struct wl_shm_pool *pool = wl_resource_get_user_data(resource);
	struct wl_shm_buffer *buffer;

	if (!format_is_supported(client, format)) {
		wl_resource_post_error(resource,
				       WL_SHM_ERROR_INVALID_FORMAT,
				       "invalid format 0x%x", format);
		return;
	}

	if (offset < 0 || width <= 0 || height <= 0 || stride < width ||
	    INT32_MAX / stride <= height ||
	    offset > pool->size - stride * height) {
		wl_resource_post_error(resource,
				       WL_SHM_ERROR_INVALID_STRIDE,
				       "invalid width, height or stride (%dx%d, %u)",
				       width, height, stride);
		return;
	}

	buffer = malloc(sizeof *buffer);
	if (buffer == NULL) {
		wl_client_post_no_memory(client);
		return;
	}

	buffer->width = width;
	buffer->height = height;
	buffer->format = format;
	buffer->stride = stride;
	buffer->offset = offset;
	buffer->pool = pool;
	pool->refcount++;

	buffer->resource =
		wl_resource_create(client, &wl_buffer_interface, 1, id);
	if (buffer->resource == NULL) {
		wl_client_post_no_memory(client);
		shm_pool_unref(pool);
		free(buffer);
		return;
	}

	wl_resource_set_implementation(buffer->resource,
				       &shm_buffer_interface,
				       buffer, destroy_buffer);
}
コード例 #2
0
ファイル: wayland-shm.c プロジェクト: antognolli/wayland
static void
shm_create_pool(struct wl_client *client, struct wl_resource *resource,
		uint32_t id, int fd, int32_t size)
{
	struct wl_shm_pool *pool;

	pool = malloc(sizeof *pool);
	if (pool == NULL) {
		wl_client_post_no_memory(client);
		goto err_close;
	}

	if (size <= 0) {
		wl_resource_post_error(resource,
				       WL_SHM_ERROR_INVALID_STRIDE,
				       "invalid size (%d)", size);
		goto err_free;
	}

	pool->refcount = 1;
	pool->size = size;
	pool->data = mmap(NULL, size,
			  PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	if (pool->data == MAP_FAILED) {
		wl_resource_post_error(resource,
				       WL_SHM_ERROR_INVALID_FD,
				       "failed mmap fd %d", fd);
		goto err_free;
	}
	close(fd);

	pool->resource =
		wl_resource_create(client, &wl_shm_pool_interface, 1, id);
	if (!pool->resource) {
		wl_client_post_no_memory(client);
		munmap(pool->data, pool->size);
		free(pool);
		return;
	}

	wl_resource_set_implementation(pool->resource,
				       &shm_pool_interface,
				       pool, destroy_pool);

	return;

err_close:
	close(fd);
err_free:
	free(pool);
}
コード例 #3
0
ファイル: shell.c プロジェクト: kempj/pclient
static void
shell_move(struct wl_client *client, struct wl_shell *shell,
	   struct wl_surface *surface,
	   struct wl_input_device *device, uint32_t time)
{
	struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
	struct wlsc_surface *es = (struct wlsc_surface *) surface;
	struct wlsc_move_grab *move;

	/* FIXME: Reject if fullscreen */

	move = malloc(sizeof *move);
	if (!move) {
		wl_client_post_no_memory(client);
		return;
	}

	move->grab.interface = &move_grab_interface;
	move->dx = es->x - wd->input_device.grab_x;
	move->dy = es->y - wd->input_device.grab_y;
	move->surface = es;

	if (wl_input_device_update_grab(&wd->input_device,
					&move->grab, surface, time) < 0)
		return;

	wlsc_input_device_set_pointer_image(wd, WLSC_POINTER_DRAGGING);
	wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
}
コード例 #4
0
static void
bind_runner(struct wl_client *client, void *data,
	    uint32_t version, uint32_t id)
{
	struct test_launcher *launcher = data;
	struct wl_resource *resource;

	resource = wl_resource_create(client, &weston_test_runner_interface,
				      1, id);
	if (!resource) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &runner_implementation,
				       launcher, destroy_runner);

	if (static_context.runner_resource != NULL) {
		weston_log("test FATAL: "
			   "attempting to run several tests in parallel.\n");
		wl_resource_post_error(resource,
				       WESTON_TEST_RUNNER_ERROR_TEST_FAILED,
				       "attempt to run parallel tests");
	}
}
コード例 #5
0
ファイル: keyboard.c プロジェクト: jekstrand/libwlb
void
wlb_keyboard_create_resource(struct wlb_keyboard *keyboard,
			     struct wl_client *client, uint32_t id)
{
	struct wl_resource *resource;
	int null_fd;

	resource = wl_resource_create(client, &wl_keyboard_interface, 1, id);
	if (!resource) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &keyboard_interface,
				       NULL, unlink_resource);

	wl_list_insert(&keyboard->resource_list, wl_resource_get_link(resource));

	if (keyboard->keymap.data) {
		wl_keyboard_send_keymap(resource, keyboard->keymap.format,
					keyboard->keymap.fd,
					keyboard->keymap.size);
	} else {
		null_fd = open("/dev/null", O_RDONLY);
		wl_keyboard_send_keymap(resource,
					WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP,
					null_fd, 0);
		close(null_fd);
	}
}
コード例 #6
0
ファイル: drm.c プロジェクト: daurnimator/arcan
static void
bind_drm(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
	struct wl_drm *drm = data;
	struct wl_resource *resource;
	uint32_t capabilities;

	resource = wl_resource_create(client,
		&wl_drm_interface, MIN(version, 2), id);
	if (!resource) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &drm_interface, data, NULL);

	wl_resource_post_event(resource, WL_DRM_DEVICE, drm->device_name);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_ARGB8888);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_XRGB8888);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_RGB565);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV410);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV411);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV420);
 	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV422);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUV444);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV12);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_NV16);
	wl_resource_post_event(resource, WL_DRM_FORMAT, WL_DRM_FORMAT_YUYV);

/* we only support render nodes, not GEM */
	capabilities = WL_DRM_CAPABILITY_PRIME;

	if (version >= 2)
		wl_resource_post_event(resource, WL_DRM_CAPABILITIES, capabilities);
}
コード例 #7
0
ファイル: panel_manager.c プロジェクト: ibab/swc
static void create_panel(struct wl_client * client,
                         struct wl_resource * resource, uint32_t id,
                         struct wl_resource * surface_resource)
{
    struct swc_surface * surface = wl_resource_get_user_data(surface_resource);

    if (!panel_new(client, wl_resource_get_version(resource), id, surface))
        wl_client_post_no_memory(client);
}
コード例 #8
0
ファイル: dpms_interface.cpp プロジェクト: KDE/kwayland
void DpmsManagerInterface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
    auto c = display->getConnection(client);
    wl_resource *dpms = c->createResource(&org_kde_kwin_dpms_manager_interface, qMin(version, s_version), id);
    if (!dpms) {
        wl_client_post_no_memory(client);
        return;
    }
    wl_resource_set_implementation(dpms, &s_interface, this, nullptr);
}
コード例 #9
0
void PointerConstraintsUnstableV1Interface::Private::bind(wl_client *client, uint32_t version, uint32_t id)
{
    auto c = display->getConnection(client);
    wl_resource *resource = c->createResource(&zwp_pointer_constraints_v1_interface, qMin(version, s_version), id);
    if (!resource) {
        wl_client_post_no_memory(client);
        return;
    }
    wl_resource_set_implementation(resource, &s_interface, this, unbind);
    // TODO: should we track?
}
コード例 #10
0
static void
bind_gdl(struct wl_client *client, void *data, uint32_t version, uint32_t id)
{
	struct wl_resource *resource;

	resource = wl_resource_create(client, &wl_gdl_interface, 1, id);
	if (!resource) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &gdl_interface, data, NULL);
}
コード例 #11
0
ファイル: extensions.c プロジェクト: hhw/sway
static void swaylock_bind(struct wl_client *client, void *data,
                          unsigned int version, unsigned int id) {
    if (version > 1) {
        // Unsupported version
        return;
    }

    struct wl_resource *resource = wl_resource_create(client, &lock_interface, version, id);
    if (!resource) {
        wl_client_post_no_memory(client);
    }

    wl_resource_set_implementation(resource, &swaylock_implementation, NULL, NULL);
}
コード例 #12
0
ファイル: wayland-drm.c プロジェクト: nikai3d/mesa
static void
drm_create_buffer(struct wl_client *client, struct wl_drm *drm,
		  uint32_t id, uint32_t name, int32_t width, int32_t height,
		  uint32_t stride, struct wl_visual *visual)
{
	struct wl_drm_buffer *buffer;

	buffer = calloc(1, sizeof *buffer);
	if (buffer == NULL) {
		wl_client_post_no_memory(client);
		return;
	}

	buffer->drm = drm;
	buffer->buffer.width = width;
	buffer->buffer.height = height;
	buffer->buffer.visual = visual;
	buffer->buffer.client = client;

	if (!visual || visual->object.interface != &wl_visual_interface) {
		wl_client_post_error(client, &drm->object,
				     WL_DRM_ERROR_INVALID_VISUAL,
				     "invalid visual");
		free(buffer);
		return;
	}

	buffer->driver_buffer =
		drm->callbacks->reference_buffer(drm->user_data, name,
						 width, height,
						 stride, visual);

	if (buffer->driver_buffer == NULL) {
		wl_client_post_error(client, &drm->object,
				     WL_DRM_ERROR_INVALID_NAME,
				     "invalid name");
		return;
	}

	buffer->buffer.resource.object.id = id;
	buffer->buffer.resource.object.interface = &wl_buffer_interface;
	buffer->buffer.resource.object.implementation = (void (**)(void))
		&drm_buffer_interface;

	buffer->buffer.resource.destroy = destroy_buffer;

	wl_client_add_resource(client, &buffer->buffer.resource);
}
コード例 #13
0
/// Wayland protocol: Handle request for interface to compositor object.
void noia_wayland_compositor_bind(struct wl_client* client,
                                  void* data,
                                  uint32_t version,
                                  uint32_t id)
{
    LOG_WAYL2("Binding Wayland compositor (version: %u, id: %u)", version, id);

    struct wl_resource* rc;
    rc = wl_resource_create(client, &wl_compositor_interface, version, id);
    NOIA_ENSURE(rc, wl_client_post_no_memory(client); return);

    wl_resource_set_implementation(rc, &scCompositorImplementation,
                                   data, noia_wayland_compositor_unbind);

    noia_wayland_facade_add_general_resource(NOIA_RESOURCE_OTHER, rc);
}
コード例 #14
0
ファイル: wayland_buffer.c プロジェクト: DmitryHetman/swc
struct wl_resource *
wayland_buffer_create_resource(struct wl_client *client, uint32_t version, uint32_t id, struct wld_buffer *buffer)
{
	struct wl_resource *resource;

	resource = wl_resource_create(client, &wl_buffer_interface, version, id);

	if (!resource) {
		wl_client_post_no_memory(client);
		return NULL;
	}

	wl_resource_set_implementation(resource, &buffer_implementation, buffer, &destroy_buffer);

	return resource;
}
コード例 #15
0
ファイル: data-device.c プロジェクト: antognolli/weston
static void
bind_manager(struct wl_client *client,
	     void *data, uint32_t version, uint32_t id)
{
	struct wl_resource *resource;

	resource =
		wl_resource_create(client,
				   &wl_data_device_manager_interface, 1, id);
	if (resource == NULL) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &manager_interface,
				       NULL, NULL);
}
コード例 #16
0
ファイル: linux-dmabuf.c プロジェクト: ChristophHaag/weston
static void
bind_linux_dmabuf(struct wl_client *client,
		  void *data, uint32_t version, uint32_t id)
{
	struct weston_compositor *compositor = data;
	struct wl_resource *resource;

	resource = wl_resource_create(client, &zwp_linux_dmabuf_v1_interface,
				      version, id);
	if (resource == NULL) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &linux_dmabuf_implementation,
				       compositor, NULL);

	/* EGL_EXT_image_dma_buf_import does not provide a way to query the
	 * supported pixel formats. */
	/* XXX: send formats */
}
コード例 #17
0
ファイル: tag.c プロジェクト: Kinokoio/velox
static void bind_tag(struct wl_client * client, void * data,
                     uint32_t version, uint32_t id)
{
    struct tag * tag = data;
    struct wl_resource * resource;

    if (version >= 1)
        version = 1;

    resource = wl_resource_create(client, &velox_tag_interface, version, id);

    if (!resource)
    {
        wl_client_post_no_memory(client);
        return;
    }

    wl_resource_set_destructor(resource, &remove_resource);
    wl_list_insert(&tag->resources, wl_resource_get_link(resource));
    velox_tag_send_name(resource, tag->name);
    tag_send_screen(tag, client, resource, NULL);
}
コード例 #18
0
ファイル: wayland-shm.c プロジェクト: antognolli/wayland
static void
bind_shm(struct wl_client *client,
	 void *data, uint32_t version, uint32_t id)
{
	struct wl_resource *resource;
	struct wl_display *display = wl_client_get_display(client);
	struct wl_array *additional_formats;
	uint32_t *p;

	resource = wl_resource_create(client, &wl_shm_interface, 1, id);
	if (!resource) {
		wl_client_post_no_memory(client);
		return;
	}

	wl_resource_set_implementation(resource, &shm_interface, data, NULL);

	wl_shm_send_format(resource, WL_SHM_FORMAT_ARGB8888);
	wl_shm_send_format(resource, WL_SHM_FORMAT_XRGB8888);

	additional_formats = wl_display_get_additional_shm_formats(display);
	wl_array_for_each(p, additional_formats)
		wl_shm_send_format(resource, *p);
}
コード例 #19
0
ファイル: shell.c プロジェクト: kempj/pclient
static void
shell_resize(struct wl_client *client, struct wl_shell *shell,
	     struct wl_surface *surface,
	     struct wl_input_device *device, uint32_t time, uint32_t edges)
{
	struct wlsc_input_device *wd = (struct wlsc_input_device *) device;
	struct wlsc_resize_grab *resize;
	enum wlsc_pointer_type pointer = WLSC_POINTER_LEFT_PTR;
	struct wlsc_surface *es = (struct wlsc_surface *) surface;

	/* FIXME: Reject if fullscreen */

	resize = malloc(sizeof *resize);
	if (!resize) {
		wl_client_post_no_memory(client);
		return;
	}

	resize->grab.interface = &resize_grab_interface;
	resize->edges = edges;
	resize->dx = es->x - wd->input_device.grab_x;
	resize->dy = es->y - wd->input_device.grab_y;
	resize->width = es->width;
	resize->height = es->height;
	resize->surface = es;
	resize->shell = shell;

	if (edges == 0 || edges > 15 ||
	    (edges & 3) == 3 || (edges & 12) == 12)
		return;

	switch (edges) {
	case WL_SHELL_RESIZE_TOP:
		pointer = WLSC_POINTER_TOP;
		break;
	case WL_SHELL_RESIZE_BOTTOM:
		pointer = WLSC_POINTER_BOTTOM;
		break;
	case WL_SHELL_RESIZE_LEFT:
		pointer = WLSC_POINTER_LEFT;
		break;
	case WL_SHELL_RESIZE_TOP_LEFT:
		pointer = WLSC_POINTER_TOP_LEFT;
		break;
	case WL_SHELL_RESIZE_BOTTOM_LEFT:
		pointer = WLSC_POINTER_BOTTOM_LEFT;
		break;
	case WL_SHELL_RESIZE_RIGHT:
		pointer = WLSC_POINTER_RIGHT;
		break;
	case WL_SHELL_RESIZE_TOP_RIGHT:
		pointer = WLSC_POINTER_TOP_RIGHT;
		break;
	case WL_SHELL_RESIZE_BOTTOM_RIGHT:
		pointer = WLSC_POINTER_BOTTOM_RIGHT;
		break;
	}

	if (wl_input_device_update_grab(&wd->input_device,
					&resize->grab, surface, time) < 0)
		return;

	wlsc_input_device_set_pointer_image(wd, pointer);
	wl_input_device_set_pointer_focus(device, NULL, time, 0, 0, 0, 0);
}