qemu-virt64-aarch64/qemu-virt64-riscv支持SDL2 (#8130)

This commit is contained in:
fangjianzhou 2023-10-17 13:03:03 +08:00 committed by GitHub
parent 1e0f406b4f
commit 7d64cdcf58
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 128 additions and 8 deletions

View File

@ -103,8 +103,7 @@ void graphic_thread(void *param)
{
int i = 0;
rt_memset(graphic_info.framebuffer, 0xff,
graphic_info.width * graphic_info.height * graphic_info.bits_per_pixel);
rt_memset(graphic_info.framebuffer, 0xff, graphic_info.pitch * graphic_info.height);
cur_last_points[0] = graphic_info.width / 2;
cur_last_points[1] = graphic_info.height / 2;
@ -207,7 +206,7 @@ _graphic_fail:
}
}
int graphic_init(void)
int graphic_test(void)
{
rt_thread_t graphic_tid = rt_thread_create("graphic work", graphic_thread, RT_NULL,
GRAPHIC_THREAD_STACK_SIZE, GRAPHIC_THREAD_PRIORITY, GRAPHIC_THREAD_TIMESLICE);
@ -221,8 +220,4 @@ int graphic_init(void)
return -RT_ERROR;
}
#ifdef RT_USING_SMP
INIT_ENV_EXPORT(graphic_init);
#else
MSH_CMD_EXPORT(graphic_init, Graphic initialize);
#endif
MSH_CMD_EXPORT(graphic_test, Graphic test);

View File

@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2021-11-11 GuEe-GUI the first version
* 2023-10-12 fangjianzhou support SDL2
*/
#include <rtthread.h>
@ -322,3 +323,127 @@ void virtio_fill_desc(struct virtio_device *dev, rt_uint32_t queue_index, rt_uin
desc->flags = flags;
desc->next = next;
}
#ifdef RT_USING_SMART
#ifdef RT_USING_VIRTIO_GPU
#include <virtio_gpu.h>
#include "drivers/lcd.h"
#include <dfs_file.h>
#include <lwp_user_mm.h>
static struct rt_device_graphic_info _graphic_info;
static struct rt_device_rect_info _rect_info;
static struct rt_device _fb = {};
static rt_device_t _gpu_dev = RT_NULL;
static rt_err_t fb_open(rt_device_t dev, rt_uint16_t oflag)
{
return RT_EOK;
}
static rt_err_t fb_close(rt_device_t dev)
{
return RT_EOK;
}
static rt_err_t fb_control(rt_device_t dev, int cmd, void *args)
{
switch(cmd)
{
case FBIOPAN_DISPLAY:
{
rt_hw_cpu_dcache_clean(_graphic_info.framebuffer, _graphic_info.smem_len);
rt_device_control(_gpu_dev, RTGRAPHIC_CTRL_RECT_UPDATE, &_rect_info);
break;
}
case FBIOGET_FSCREENINFO:
{
struct fb_fix_screeninfo *info = (struct fb_fix_screeninfo *)args;
strncpy(info->id, "lcd", sizeof(info->id));
info->smem_len = _graphic_info.smem_len;
break;
}
case FBIOGET_VSCREENINFO:
{
struct fb_var_screeninfo *info = (struct fb_var_screeninfo *)args;
info->bits_per_pixel = _graphic_info.bits_per_pixel;
info->xres = _graphic_info.width;
info->yres = _graphic_info.height;
break;
}
case RT_FIOMMAP2:
{
struct dfs_mmap2_args *mmap2 = (struct dfs_mmap2_args *)args;
if(mmap2)
{
mmap2->ret = lwp_map_user_phy(lwp_self(), RT_NULL, rt_kmem_v2p(_graphic_info.framebuffer), mmap2->length, 1);
}
else
{
return -EIO;
}
break;
}
default:
break;
}
return RT_EOK;
}
#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops fb_ops =
{
RT_NULL,
fb_open,
fb_close,
RT_NULL,
RT_NULL,
fb_control
};
#endif
static int fb_init()
{
_gpu_dev = rt_device_find("virtio-gpu0");
RT_ASSERT(_gpu_dev);
if(_gpu_dev != RT_NULL && rt_device_open(_gpu_dev, 0) == RT_EOK)
{
rt_memset(&_graphic_info, 0, sizeof(_graphic_info));
rt_memset(&_rect_info, 0, sizeof(_rect_info));
rt_device_control(_gpu_dev, VIRTIO_DEVICE_CTRL_GPU_SET_PRIMARY, RT_NULL);
rt_device_control(_gpu_dev, VIRTIO_DEVICE_CTRL_GPU_CREATE_2D, (void *)RTGRAPHIC_PIXEL_FORMAT_RGB888);
rt_device_control(_gpu_dev, RTGRAPHIC_CTRL_GET_INFO, &_graphic_info);
_rect_info.x = 0;
_rect_info.y = 0;
_rect_info.width = _graphic_info.width;
_rect_info.height = _graphic_info.height;
memset(_graphic_info.framebuffer, 0xff, _graphic_info.smem_len);
rt_device_control(_gpu_dev, RTGRAPHIC_CTRL_RECT_UPDATE, &_rect_info);
}
RT_ASSERT(!rt_device_find("fb0"));
_fb.type = RT_Device_Class_Miscellaneous;
#ifdef RT_USING_DEVICE_OPS
_fb.ops = &fb_ops;
#else
_fb.init = RT_NULL;
_fb.open = fb_open;
_fb.close = fb_close;
_fb.read = RT_NULL;
_fb.write = RT_NULL;
_fb.control = fb_control;
_fb.user_data = RT_NULL;
#endif
rt_device_register(&_fb, "fb0", RT_DEVICE_FLAG_RDWR);
return RT_EOK;
}
INIT_COMPONENT_EXPORT(fb_init);
#endif
#endif