Esempio n. 1
0
struct texture_t * sw_render_alloc_texture(struct render_t * render, void * pixels, u32_t w, u32_t h, enum pixel_format_t format)
{
	struct texture_t * texture;
	pixman_image_t * img;
	u32_t pitch;

	if(!render)
		return NULL;

	if( (w <= 0) && (h <= 0) )
		return NULL;

	texture = (struct texture_t *)malloc(sizeof(struct texture_t));
	if(! texture)
		return NULL;

	switch(format)
	{
	case PIXEL_FORMAT_ARGB32:
		pitch = w * 4;
		break;
	case PIXEL_FORMAT_RGB24:
		pitch = w * 3;
		break;
	case PIXEL_FORMAT_A8:
		pitch = w * 1;
		break;
	case PIXEL_FORMAT_A1:
		pitch = (w + 7) / 8;
		break;
	case PIXEL_FORMAT_RGB16_565:
		pitch = w * 2;
		break;
	case PIXEL_FORMAT_RGB30:
		pitch = w * 4;
		break;
	default:
		pitch = w * 4;
		break;
	}
	pitch = (pitch + 0x3) & ~0x3;

	img = pixman_image_create_bits_no_clear(pixel_format_to_pixman_format_code(format), w, h, pixels, pitch);
	if(!img)
	{
		free(texture);
		return NULL;
	}

	texture->width = w;
	texture->height = h;
	texture->pitch = pitch;
	texture->format = format;
	texture->pixels = pixman_image_get_data(img);
	texture->priv = img;

	return texture;
}
Esempio n. 2
0
static void
composite_clipped(pixman_image_t *src,
		  pixman_image_t *mask,
		  pixman_image_t *dest,
		  const pixman_transform_t *transform,
		  pixman_filter_t filter,
		  pixman_region32_t *src_clip)
{
	int n_box;
	pixman_box32_t *boxes;
	int32_t dest_width;
	int32_t dest_height;
	int src_stride;
	int bitspp;
	pixman_format_code_t src_format;
	void *src_data;
	int i;

	/* Hardcoded to use PIXMAN_OP_OVER, because sampling outside of
	 * a Pixman image produces (0,0,0,0) instead of discarding the
	 * fragment.
	 */

	dest_width = pixman_image_get_width(dest);
	dest_height = pixman_image_get_height(dest);
	src_format = pixman_image_get_format(src);
	src_stride = pixman_image_get_stride(src);
	bitspp = PIXMAN_FORMAT_BPP(src_format);
	src_data = pixman_image_get_data(src);

	assert(src_format);

	/* This would be massive overdraw, except when n_box is 1. */
	boxes = pixman_region32_rectangles(src_clip, &n_box);
	for (i = 0; i < n_box; i++) {
		uint8_t *ptr = src_data;
		pixman_image_t *boximg;
		pixman_transform_t adj = *transform;

		ptr += boxes[i].y1 * src_stride;
		ptr += boxes[i].x1 * bitspp / 8;
		boximg = pixman_image_create_bits_no_clear(src_format,
					boxes[i].x2 - boxes[i].x1,
					boxes[i].y2 - boxes[i].y1,
					(uint32_t *)ptr, src_stride);

		pixman_transform_translate(&adj, NULL,
					   pixman_int_to_fixed(-boxes[i].x1),
					   pixman_int_to_fixed(-boxes[i].y1));
		pixman_image_set_transform(boximg, &adj);

		pixman_image_set_filter(boximg, filter, NULL, 0);
		pixman_image_composite32(PIXMAN_OP_OVER, boximg, mask, dest,
					 0, 0, /* src_x, src_y */
					 0, 0, /* mask_x, mask_y */
					 0, 0, /* dest_x, dest_y */
					 dest_width, dest_height);

		pixman_image_unref(boximg);
	}

	if (n_box > 1) {
		static bool warned = false;

		if (!warned)
			weston_log("Pixman-renderer warning: %dx overdraw\n",
				   n_box);
		warned = true;
	}
}