vt: Add vd_bitblt_argb

This blit an ARGB image on the dedicated vd.
This also adds vt_fb_bitblt_argb which will works for most of the vt backends

Differential Revision:	https://reviews.freebsd.org/D45929
Reviewed by:		tsoome
Sponsored by:		Beckhoff Automation GmbH & Co. KG
This commit is contained in:
Emmanuel Vadot 2024-07-09 14:35:12 +02:00
parent d4ca001544
commit b93028d8cd
10 changed files with 104 additions and 0 deletions

View file

@ -102,6 +102,7 @@ static vd_bitblt_text_t vtgpu_fb_bitblt_text;
static vd_bitblt_bmp_t vtgpu_fb_bitblt_bitmap;
static vd_drawrect_t vtgpu_fb_drawrect;
static vd_setpixel_t vtgpu_fb_setpixel;
static vd_bitblt_argb_t vtgpu_fb_bitblt_argb;
static struct vt_driver vtgpu_fb_driver = {
.vd_name = "virtio_gpu",
@ -111,6 +112,7 @@ static struct vt_driver vtgpu_fb_driver = {
.vd_bitblt_text = vtgpu_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vtgpu_fb_bitblt_bitmap,
.vd_bitblt_argb = vtgpu_fb_bitblt_argb,
.vd_drawrect = vtgpu_fb_drawrect,
.vd_setpixel = vtgpu_fb_setpixel,
.vd_postswitch = vt_fb_postswitch,
@ -180,6 +182,16 @@ vtgpu_fb_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw,
vtgpu_resource_flush(sc, x, y, width, height);
}
static int
vtgpu_fb_bitblt_argb(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y)
{
return (EOPNOTSUPP);
}
static void
vtgpu_fb_drawrect(struct vt_device *vd, int x1, int y1, int x2, int y2,
int fill, term_color_t color)

View file

@ -58,6 +58,7 @@ static struct vt_driver vt_efifb_driver = {
.vd_bitblt_text = vt_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
.vd_bitblt_argb = vt_fb_bitblt_argb,
.vd_drawrect = vt_fb_drawrect,
.vd_setpixel = vt_fb_setpixel,
.vd_fb_ioctl = vt_fb_ioctl,

View file

@ -58,6 +58,7 @@ static struct vt_driver vt_fb_early_driver = {
.vd_bitblt_text = vt_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
.vd_bitblt_argb = vt_fb_bitblt_argb,
.vd_drawrect = vt_fb_drawrect,
.vd_setpixel = vt_fb_setpixel,
.vd_priority = VD_PRIORITY_GENERIC,

View file

@ -49,6 +49,7 @@ static struct vt_driver vt_fb_driver = {
.vd_bitblt_text = vt_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
.vd_bitblt_argb = vt_fb_bitblt_argb,
.vd_drawrect = vt_fb_drawrect,
.vd_setpixel = vt_fb_setpixel,
.vd_postswitch = vt_fb_postswitch,
@ -332,6 +333,52 @@ vt_fb_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw,
}
}
int
vt_fb_bitblt_argb(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y)
{
struct fb_info *info;
uint32_t o, cc;
int bpp, xi, yi;
info = vd->vd_softc;
bpp = FBTYPE_GET_BYTESPP(info);
if (bpp != 4)
return (EOPNOTSUPP);
if (info->fb_flags & FB_FLAG_NOWRITE)
return (0);
KASSERT((info->fb_vbase != 0), ("Unmapped framebuffer"));
/* Bound by right and bottom edges. */
if (y + height > vw->vw_draw_area.tr_end.tp_row) {
if (y >= vw->vw_draw_area.tr_end.tp_row)
return (EINVAL);
height = vw->vw_draw_area.tr_end.tp_row - y;
}
if (x + width > vw->vw_draw_area.tr_end.tp_col) {
if (x >= vw->vw_draw_area.tr_end.tp_col)
return (EINVAL);
width = vw->vw_draw_area.tr_end.tp_col - x;
}
for (yi = 0; yi < height; yi++) {
for (xi = 0; xi < (width * 4); xi += 4) {
o = (y + yi) * info->fb_stride + (x + (xi / 4)) * bpp;
o += vd->vd_transpose;
cc = (argb[yi * width * 4 + xi] << 16) |
(argb[yi * width * 4 + xi + 1] << 8) |
(argb[yi * width * 4 + xi + 2]) |
(argb[yi * width * 4 + xi + 3] << 24);
vt_fb_mem_wr4(info, o, cc);
}
}
return (0);
}
void
vt_fb_bitblt_text(struct vt_device *vd, const struct vt_window *vw,
const term_rect_t *area)

View file

@ -42,6 +42,7 @@ vd_blank_t vt_fb_blank;
vd_bitblt_text_t vt_fb_bitblt_text;
vd_invalidate_text_t vt_fb_invalidate_text;
vd_bitblt_bmp_t vt_fb_bitblt_bitmap;
vd_bitblt_argb_t vt_fb_bitblt_argb;
vd_drawrect_t vt_fb_drawrect;
vd_setpixel_t vt_fb_setpixel;
vd_postswitch_t vt_fb_postswitch;

View file

@ -66,6 +66,7 @@ static vd_probe_t ofwfb_probe;
static vd_init_t ofwfb_init;
static vd_bitblt_text_t ofwfb_bitblt_text;
static vd_bitblt_bmp_t ofwfb_bitblt_bitmap;
static vd_bitblt_argb_t ofwfb_bitblt_argb;
static const struct vt_driver vt_ofwfb_driver = {
.vd_name = "ofwfb",
@ -74,6 +75,7 @@ static const struct vt_driver vt_ofwfb_driver = {
.vd_blank = vt_fb_blank,
.vd_bitblt_text = ofwfb_bitblt_text,
.vd_bitblt_bmp = ofwfb_bitblt_bitmap,
.vd_bitblt_argb = ofwfb_bitblt_argb,
.vd_fb_ioctl = vt_fb_ioctl,
.vd_fb_mmap = vt_fb_mmap,
.vd_priority = VD_PRIORITY_GENERIC+1,
@ -242,6 +244,16 @@ ofwfb_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw,
}
}
static int
ofwfb_bitblt_argb(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y)
{
return (EOPNOTSUPP);
}
void
ofwfb_bitblt_text(struct vt_device *vd, const struct vt_window *vw,
const term_rect_t *area)

View file

@ -49,6 +49,7 @@
static vd_init_t vt_simplefb_init;
static vd_fini_t vt_simplefb_fini;
static vd_probe_t vt_simplefb_probe;
static vd_bitblt_argb_t vt_simplefb_bitblt_argb;
static struct vt_driver vt_simplefb_driver = {
.vd_name = "simplefb",
@ -59,6 +60,7 @@ static struct vt_driver vt_simplefb_driver = {
.vd_bitblt_text = vt_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
.vd_bitblt_argb = vt_simplefb_bitblt_argb,
.vd_drawrect = vt_fb_drawrect,
.vd_setpixel = vt_fb_setpixel,
.vd_fb_ioctl = vt_fb_ioctl,
@ -221,3 +223,13 @@ vt_simplefb_fini(struct vt_device *vd, void *softc)
vt_fb_fini(vd, softc);
pmap_unmapdev((void *)sc->fb_vbase, sc->fb_size);
}
static int
vt_simplefb_bitblt_argb(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y)
{
return (EOPNOTSUPP);
}

View file

@ -58,6 +58,7 @@ static struct vt_driver vt_vbefb_driver = {
.vd_bitblt_text = vt_fb_bitblt_text,
.vd_invalidate_text = vt_fb_invalidate_text,
.vd_bitblt_bmp = vt_fb_bitblt_bitmap,
.vd_bitblt_argb = vt_fb_bitblt_argb,
.vd_drawrect = vt_fb_drawrect,
.vd_setpixel = vt_fb_setpixel,
.vd_fb_ioctl = vt_fb_ioctl,

View file

@ -96,6 +96,7 @@ static vd_blank_t vga_blank;
static vd_bitblt_text_t vga_bitblt_text;
static vd_invalidate_text_t vga_invalidate_text;
static vd_bitblt_bmp_t vga_bitblt_bitmap;
static vd_bitblt_argb_t vga_bitblt_argb;
static vd_drawrect_t vga_drawrect;
static vd_setpixel_t vga_setpixel;
static vd_postswitch_t vga_postswitch;
@ -108,6 +109,7 @@ static const struct vt_driver vt_vga_driver = {
.vd_bitblt_text = vga_bitblt_text,
.vd_invalidate_text = vga_invalidate_text,
.vd_bitblt_bmp = vga_bitblt_bitmap,
.vd_bitblt_argb = vga_bitblt_argb,
.vd_drawrect = vga_drawrect,
.vd_setpixel = vga_setpixel,
.vd_postswitch = vga_postswitch,
@ -998,6 +1000,16 @@ vga_bitblt_bitmap(struct vt_device *vd, const struct vt_window *vw,
}
}
static int
vga_bitblt_argb(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y)
{
return (EOPNOTSUPP);
}
static void
vga_initialize_graphics(struct vt_device *vd)
{

View file

@ -345,6 +345,10 @@ typedef void vd_bitblt_bmp_t(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *pattern, const uint8_t *mask,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y, term_color_t fg, term_color_t bg);
typedef int vd_bitblt_argb_t(struct vt_device *vd, const struct vt_window *vw,
const uint8_t *argb,
unsigned int width, unsigned int height,
unsigned int x, unsigned int y);
typedef int vd_fb_ioctl_t(struct vt_device *, u_long, caddr_t, struct thread *);
typedef int vd_fb_mmap_t(struct vt_device *, vm_ooffset_t, vm_paddr_t *, int,
vm_memattr_t *);
@ -368,6 +372,7 @@ struct vt_driver {
vd_bitblt_text_t *vd_bitblt_text;
vd_invalidate_text_t *vd_invalidate_text;
vd_bitblt_bmp_t *vd_bitblt_bmp;
vd_bitblt_argb_t *vd_bitblt_argb;
/* Framebuffer ioctls, if present. */
vd_fb_ioctl_t *vd_fb_ioctl;