virtio-gpu: move update_cursor_data
[qemu/ar7.git] / hw / display / virtio-gpu-gl.c
blobb4303cc5bb41db7373e876ba9d2ba8e7bc54ece8
1 /*
2 * Virtio GPU Device
4 * Copyright Red Hat, Inc. 2013-2014
6 * Authors:
7 * Dave Airlie <airlied@redhat.com>
8 * Gerd Hoffmann <kraxel@redhat.com>
10 * This work is licensed under the terms of the GNU GPL, version 2 or later.
11 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
15 #include "qemu/iov.h"
16 #include "qemu/module.h"
17 #include "qemu/error-report.h"
18 #include "qapi/error.h"
19 #include "sysemu/sysemu.h"
20 #include "hw/virtio/virtio.h"
21 #include "hw/virtio/virtio-gpu.h"
22 #include "hw/virtio/virtio-gpu-bswap.h"
23 #include "hw/virtio/virtio-gpu-pixman.h"
24 #include "hw/qdev-properties.h"
26 #include <virglrenderer.h>
28 static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
29 struct virtio_gpu_scanout *s,
30 uint32_t resource_id)
32 uint32_t width, height;
33 uint32_t pixels, *data;
35 if (g->parent_obj.use_virgl_renderer) {
36 data = virgl_renderer_get_cursor_data(resource_id, &width, &height);
37 if (!data) {
38 return;
41 if (width != s->current_cursor->width ||
42 height != s->current_cursor->height) {
43 free(data);
44 return;
47 pixels = s->current_cursor->width * s->current_cursor->height;
48 memcpy(s->current_cursor->data, data, pixels * sizeof(uint32_t));
49 free(data);
50 return;
52 virtio_gpu_update_cursor_data(g, s, resource_id);
55 static void virtio_gpu_gl_process_cmd(VirtIOGPU *g,
56 struct virtio_gpu_ctrl_command *cmd)
58 if (g->parent_obj.use_virgl_renderer) {
59 virtio_gpu_virgl_process_cmd(g, cmd);
60 return;
62 virtio_gpu_simple_process_cmd(g, cmd);
65 static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
67 VirtIOGPU *g = VIRTIO_GPU(b);
69 if (g->renderer_reset) {
70 g->renderer_reset = false;
71 virtio_gpu_virgl_reset(g);
73 virtio_gpu_process_cmdq(g);
76 static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
78 VirtIOGPU *g = VIRTIO_GPU(vdev);
79 struct virtio_gpu_ctrl_command *cmd;
81 if (!virtio_queue_ready(vq)) {
82 return;
85 if (!g->renderer_inited && g->parent_obj.use_virgl_renderer) {
86 virtio_gpu_virgl_init(g);
87 g->renderer_inited = true;
90 cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
91 while (cmd) {
92 cmd->vq = vq;
93 cmd->error = 0;
94 cmd->finished = false;
95 QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
96 cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
99 virtio_gpu_process_cmdq(g);
101 if (g->parent_obj.use_virgl_renderer) {
102 virtio_gpu_virgl_fence_poll(g);
106 static void virtio_gpu_gl_reset(VirtIODevice *vdev)
108 VirtIOGPU *g = VIRTIO_GPU(vdev);
110 virtio_gpu_reset(vdev);
112 if (g->parent_obj.use_virgl_renderer) {
113 if (g->parent_obj.renderer_blocked) {
114 g->renderer_reset = true;
115 } else {
116 virtio_gpu_virgl_reset(g);
118 g->parent_obj.use_virgl_renderer = false;
122 static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
124 VirtIOGPU *g = VIRTIO_GPU(qdev);
126 #if defined(HOST_WORDS_BIGENDIAN)
127 error_setg(errp, "virgl is not supported on bigendian platforms");
128 return;
129 #endif
131 if (!display_opengl) {
132 error_setg(errp, "opengl is not available");
133 return;
136 g->parent_obj.conf.flags |= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED);
137 VIRTIO_GPU_BASE(g)->virtio_config.num_capsets =
138 virtio_gpu_virgl_get_num_capsets(g);
140 virtio_gpu_device_realize(qdev, errp);
143 static Property virtio_gpu_gl_properties[] = {
144 DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
145 VIRTIO_GPU_FLAG_STATS_ENABLED, false),
146 DEFINE_PROP_END_OF_LIST(),
149 static void virtio_gpu_gl_class_init(ObjectClass *klass, void *data)
151 DeviceClass *dc = DEVICE_CLASS(klass);
152 VirtioDeviceClass *vdc = VIRTIO_DEVICE_CLASS(klass);
153 VirtIOGPUBaseClass *vbc = VIRTIO_GPU_BASE_CLASS(klass);
154 VirtIOGPUClass *vgc = VIRTIO_GPU_CLASS(klass);
156 vbc->gl_flushed = virtio_gpu_gl_flushed;
157 vgc->handle_ctrl = virtio_gpu_gl_handle_ctrl;
158 vgc->process_cmd = virtio_gpu_gl_process_cmd;
159 vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
161 vdc->realize = virtio_gpu_gl_device_realize;
162 vdc->reset = virtio_gpu_gl_reset;
163 device_class_set_props(dc, virtio_gpu_gl_properties);
166 static const TypeInfo virtio_gpu_gl_info = {
167 .name = TYPE_VIRTIO_GPU_GL,
168 .parent = TYPE_VIRTIO_GPU,
169 .instance_size = sizeof(VirtIOGPUGL),
170 .class_init = virtio_gpu_gl_class_init,
173 static void virtio_register_types(void)
175 type_register_static(&virtio_gpu_gl_info);
178 type_init(virtio_register_types)