Ejemplo n.º 1
0
static struct wl_cursor *
wl_cursor_create_from_xcursor_images(XcursorImages *images,
				     struct wl_cursor_theme *theme)
{
	struct cursor *cursor;
	struct cursor_image *image;
	int i, size;

	cursor = malloc(sizeof *cursor);
	if (!cursor)
		return NULL;

	cursor->cursor.images =
		malloc(images->nimage * sizeof cursor->cursor.images[0]);
	if (!cursor->cursor.images) {
		free(cursor);
		return NULL;
	}

	cursor->cursor.name = strdup(images->name);
	cursor->total_delay = 0;

	for (i = 0; i < images->nimage; i++) {
		image = malloc(sizeof *image);
		if (image == NULL)
			break;

		image->theme = theme;
		image->buffer = NULL;

		image->image.width = images->images[i]->width;
		image->image.height = images->images[i]->height;
		image->image.hotspot_x = images->images[i]->xhot;
		image->image.hotspot_y = images->images[i]->yhot;
		image->image.delay = images->images[i]->delay;

		size = image->image.width * image->image.height * 4;
		image->offset = shm_pool_allocate(theme->pool, size);
		if (image->offset < 0) {
			free(image);
			break;
		}

		/* copy pixels to shm pool */
		memcpy(theme->pool->data + image->offset,
		       images->images[i]->pixels, size);
		cursor->total_delay += image->image.delay;
		cursor->cursor.images[i] = (struct wl_cursor_image *) image;
	}
	cursor->cursor.image_count = i;

	if (cursor->cursor.image_count == 0) {
		free(cursor->cursor.name);
		free(cursor->cursor.images);
		free(cursor);
		return NULL;
	}

	return &cursor->cursor;
}
Ejemplo n.º 2
0
static struct wl_cursor *
wl_cursor_create_from_data(struct cursor_metadata *metadata,
			   struct wl_cursor_theme *theme)
{
	struct cursor *cursor;
	struct cursor_image *image;
	int size;

	cursor = malloc(sizeof *cursor);
	if (!cursor)
		return NULL;

	cursor->cursor.image_count = 1;
	cursor->cursor.images = malloc(sizeof *cursor->cursor.images);
	if (!cursor->cursor.images)
		goto err_free_cursor;

	cursor->cursor.name = strdup(metadata->name);
	cursor->total_delay = 0;

	image = malloc(sizeof *image);
	if (!image)
		goto err_free_images;

	cursor->cursor.images[0] = (struct wl_cursor_image *) image;
	image->theme = theme;
	image->buffer = NULL;
	image->image.width = metadata->width;
	image->image.height = metadata->height;
	image->image.hotspot_x = metadata->hotspot_x;
	image->image.hotspot_y = metadata->hotspot_y;
	image->image.delay = 0;

	size = metadata->width * metadata->height * sizeof(uint32_t);
	image->offset = shm_pool_allocate(theme->pool, size);

	if (image->offset < 0)
		goto err_free_image;

	memcpy(theme->pool->data + image->offset,
	       cursor_data + metadata->offset, size);

	return &cursor->cursor;

err_free_image:
	free(image);

err_free_images:
	free(cursor->cursor.name);
	free(cursor->cursor.images);

err_free_cursor:
	free(cursor);
	return NULL;
}
Ejemplo n.º 3
0
static GstWlMeta *
gst_buffer_add_wayland_meta (GstBuffer * buffer, GstWaylandBufferPool * wpool)
{
  GstWlMeta *wmeta;
  GstWaylandSink *sink;
  void *data;
  gint offset;
  guint stride = 0;
  guint size = 0;

  sink = wpool->sink;
  stride = wpool->width * 4;
  size = stride * wpool->height;

  wmeta = (GstWlMeta *) gst_buffer_add_meta (buffer, GST_WL_META_INFO, NULL);
  wmeta->sink = gst_object_ref (sink);

  /*Fixme: size calculation should be more grcefull, have to consider the padding */
  if (!sink->shm_pool) {
    sink->shm_pool = shm_pool_create (sink->display, size * 15);
    shm_pool_reset (sink->shm_pool);
  }

  if (!sink->shm_pool) {
    GST_ERROR ("Failed to create shm_pool");
    return NULL;
  }

  data = shm_pool_allocate (sink->shm_pool, size, &offset);
  if (!data)
    return NULL;

  wmeta->wbuffer = wl_shm_pool_create_buffer (sink->shm_pool->pool, offset,
      sink->video_width, sink->video_height, stride, sink->format);

  wmeta->data = data;
  wmeta->size = size;

  gst_buffer_append_memory (buffer,
      gst_memory_new_wrapped (GST_MEMORY_FLAG_NO_SHARE, data,
          size, 0, size, NULL, NULL));


  return wmeta;
}