/* Clear a buffer associated to a G2D image by doing a (fast) solid fill. */ static int exynos_clear_buffer(struct g2d_context *g2d, struct g2d_image *img) { int ret = g2d_solid_fill(g2d, img, 0, 0, img->width, img->height); if (ret == 0) ret = g2d_exec(g2d); if (ret != 0) RARCH_ERR("[video_exynos]: failed to clear buffer using G2D\n"); return ret; }
static int g2d_solid_fill_test(struct exynos_device *dev, struct exynos_bo *dst) { struct g2d_context *ctx; struct g2d_image img = {0}; unsigned int count, img_w, img_h; int ret = 0; ctx = g2d_init(dev->fd); if (!ctx) return -EFAULT; img.bo[0] = dst->handle; printf("solid fill test.\n"); srand(time(NULL)); img_w = screen_width; img_h = screen_height; for (count = 0; count < 2; count++) { unsigned int x, y, w, h; x = rand() % (img_w / 2); y = rand() % (img_h / 2); w = rand() % (img_w - x); h = rand() % (img_h - y); img.width = img_w; img.height = img_h; img.stride = img.width * 4; img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB; img.color = 0xff000000 + (random() & 0xffffff); ret = g2d_solid_fill(ctx, &img, x, y, w, h); if (ret < 0) goto err_fini; ret = g2d_exec(ctx); if (ret < 0) break; } err_fini: g2d_fini(ctx); return ret; }
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; }
static int g2d_blend_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("blend 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.select_mode = G2D_SELECT_MODE_NORMAL; src_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB; src_img.color = 0xffffffff; ret = g2d_solid_fill(ctx, &src_img, src_x, src_y, img_w, img_h); if (ret < 0) goto err_free_userptr; src_img.color = 0x770000ff; ret = g2d_solid_fill(ctx, &src_img, 5, 5, 200, 200); 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.select_mode = G2D_SELECT_MODE_NORMAL; dst_img.color_mode = G2D_COLOR_FMT_ARGB8888 | G2D_ORDER_AXRGB; dst_img.color = 0xffffffff; ret = g2d_solid_fill(ctx, &dst_img, dst_x, dst_y, img_w, img_h); if (ret < 0) goto err_free_userptr; dst_img.color = 0x77ff0000; ret = g2d_solid_fill(ctx, &dst_img, 105, 105, 200, 200); if (ret < 0) goto err_free_userptr; ret = g2d_blend(ctx, &src_img, &dst_img, 5, 5, 105, 105, 200, 200, G2D_OP_OVER); 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 0; }