示例#1
0
static int g2d_copy_test(struct exynos_device *dev, struct exynos_bo *src,
				struct exynos_bo *dst,
				enum e_g2d_buf_type type)
{
	struct g2d_context *ctx;
	struct g2d_image src_img = {0}, dst_img = {0};
	unsigned int src_x, src_y, dst_x, dst_y, img_w, img_h;
	unsigned long userptr, size;
	int ret;

	ctx = g2d_init(dev->fd);
	if (!ctx)
		return -EFAULT;

	dst_img.bo[0] = dst->handle;

	src_x = 0;
	src_y = 0;
	dst_x = 0;
	dst_y = 0;
	img_w = screen_width;
	img_h = screen_height;

	switch (type) {
	case G2D_IMGBUF_GEM:
		src_img.bo[0] = src->handle;
		break;
	case G2D_IMGBUF_USERPTR:
		size = img_w * img_h * 4;

		userptr = (unsigned long)malloc(size);
		if (!userptr) {
			fprintf(stderr, "failed to allocate userptr.\n");
			return -EFAULT;
		}

		src_img.user_ptr[0].userptr = userptr;
		src_img.user_ptr[0].size = size;
		break;
	default:
		type = G2D_IMGBUF_GEM;
		break;
	}

	printf("copy test with %s.\n",
			type == G2D_IMGBUF_GEM ? "gem" : "userptr");

	src_img.width = img_w;
	src_img.height = img_h;
	src_img.stride = src_img.width * 4;
	src_img.buf_type = type;
	src_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
	src_img.color = 0xffff0000;
	ret = g2d_solid_fill(ctx, &src_img, src_x, src_y, img_w, img_h);
	if (ret < 0)
		goto err_free_userptr;

	dst_img.width = img_w;
	dst_img.height = img_h;
	dst_img.stride = dst_img.width * 4;
	dst_img.buf_type = G2D_IMGBUF_GEM;
	dst_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;

	ret = g2d_copy(ctx, &src_img, &dst_img, src_x, src_y, dst_x, dst_y,
			img_w - 4, img_h - 4);
	if (ret < 0)
		goto err_free_userptr;

	g2d_exec(ctx);

err_free_userptr:
	if (type == G2D_IMGBUF_USERPTR)
		if (userptr)
			free((void *)userptr);

	g2d_fini(ctx);

	return ret;
}
示例#2
0
static int g2d_checkerboard_test(struct exynos_device *dev,
					struct exynos_bo *src,
					struct exynos_bo *dst,
					enum e_g2d_buf_type type)
{
	struct g2d_context *ctx;
	struct g2d_image src_img = {0}, dst_img = {0};
	unsigned int src_x, src_y, dst_x, dst_y, img_w, img_h;
	void *checkerboard = NULL;
	int ret;

	ctx = g2d_init(dev->fd);
	if (!ctx)
		return -EFAULT;

	dst_img.bo[0] = dst->handle;

	src_x = 0;
	src_y = 0;
	dst_x = 0;
	dst_y = 0;

	checkerboard = create_checkerboard_pattern(screen_width / 32, screen_height / 32, 32);
	if (checkerboard == NULL) {
		ret = -1;
		goto fail;
	}

	img_w = screen_width - (screen_width % 32);
	img_h = screen_height - (screen_height % 32);

	switch (type) {
	case G2D_IMGBUF_GEM:
		memcpy(src->vaddr, checkerboard, img_w * img_h * 4);
		src_img.bo[0] = src->handle;
		break;
	case G2D_IMGBUF_USERPTR:
		src_img.user_ptr[0].userptr = (unsigned long)checkerboard;
		src_img.user_ptr[0].size = img_w * img_h * 4;
		break;
	default:
		ret = -EFAULT;
		goto fail;
	}

	printf("checkerboard test with %s.\n",
			type == G2D_IMGBUF_GEM ? "gem" : "userptr");

	src_img.width = img_w;
	src_img.height = img_h;
	src_img.stride = src_img.width * 4;
	src_img.buf_type = type;
	src_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;

	dst_img.width = screen_width;
	dst_img.height = screen_height;
	dst_img.stride = dst_img.width * 4;
	dst_img.buf_type = G2D_IMGBUF_GEM;
	dst_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB;
	src_img.color = 0xff000000;
	ret = g2d_solid_fill(ctx, &dst_img, src_x, src_y, screen_width, screen_height);
	if (ret < 0)
		goto fail;

	ret = g2d_copy(ctx, &src_img, &dst_img, src_x, src_y, dst_x, dst_y,
			img_w, img_h);
	if (ret < 0)
		goto fail;

	g2d_exec(ctx);

fail:
	free(checkerboard);
	g2d_fini(ctx);

	return ret;
}
示例#3
0
JNIEXPORT void JNICALL Java_com_example_enzocamtest_CamView_loadNextFrame(JNIEnv* env,
		jobject thiz, jobject bitmap)
{
	AndroidBitmapInfo info;
	int result;

	if((result = AndroidBitmap_getInfo(env, bitmap, &info)) < 0) {
		err_msg("AndroidBitmap_getInfo() failed, error=%d", result);
		return;
	}

	if(info.format != ANDROID_BITMAP_FORMAT_RGB_565) {
		err_msg("Bitmap format is not RGBA_565 !");
		return;
	}

	char *colors;
	if((result = AndroidBitmap_lockPixels(env, bitmap, (void*)&colors)) < 0) {
		err_msg("AndroidBitmap_lockPixels() failed, error=%d", result);
	}

	//info_msg("Getting camera frame...\n");
	result = cameraGetFrame(usbCam, camData);
	if (result < 0) {
		err_msg("Could not get camera frame\n");
	}

	//info_msg("Decoding camera frame...\n");
	result = decoderDecodeFrame(mjpgDec, camData, yuvData);
	if (result < 0) {
		err_msg("Could not decode MJPG frame\n");
	}

	if(g2d_open(&g2d_handle)) {
		err_msg("Encoder: g2d_open fail.\n");
		return;
	}

	int y_size = info.width * info.height;

	y422_buf->buf_paddr = (unsigned char *)yuvData->pBufOut;
	y422_buf->buf_vaddr = (unsigned char *)yuvData->vBufOut;

	g2d_copy(g2d_handle, y420_buf, y422_buf, y_size);
	g2d_finish(g2d_handle);

	unsigned char *u_src;
	unsigned char *u_dst;
	int i = 0;

	u_src = y422_buf->buf_vaddr + y_size;
	u_dst = y420_buf->buf_vaddr + y_size;
	while (i < info.height) {
		memcpy(u_dst, u_src, info.width/2);
		u_dst += info.width/2;
		u_src += info.width;
		i++;
	}

	//info_msg("Converting frame to RGB565...\n");
	g2d_blit(g2d_handle, &y420_surf, &rgb_surf);
	g2d_finish(g2d_handle);
	g2d_close(g2d_handle);

	//info_msg("Copy RGB frame to bitmap...\n");
	memcpy(colors, rgb_buf->buf_vaddr, info.width * info.height * 2);

	AndroidBitmap_unlockPixels(env, bitmap);
}