[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 08/19] virtio-gpu: replace PIXMAN for region/rect test
From: |
marcandre . lureau |
Subject: |
[PATCH v4 08/19] virtio-gpu: replace PIXMAN for region/rect test |
Date: |
Wed, 18 Oct 2023 17:38:09 +0400 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
Use a simpler implementation for rectangle geometry & intersect, drop
the need for (more complex) PIXMAN functions.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
include/ui/rect.h | 59 +++++++++++++++++++++++++++++++++++++++++
hw/display/virtio-gpu.c | 30 ++++++++-------------
2 files changed, 70 insertions(+), 19 deletions(-)
create mode 100644 include/ui/rect.h
diff --git a/include/ui/rect.h b/include/ui/rect.h
new file mode 100644
index 0000000000..94898f92d0
--- /dev/null
+++ b/include/ui/rect.h
@@ -0,0 +1,59 @@
+/*
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef QEMU_RECT_H
+#define QEMU_RECT_H
+
+#include <stdint.h>
+#include <stdbool.h>
+
+typedef struct QemuRect {
+ int16_t x;
+ int16_t y;
+ uint16_t width;
+ uint16_t height;
+} QemuRect;
+
+static inline void qemu_rect_init(QemuRect *rect,
+ int16_t x, int16_t y,
+ uint16_t width, uint16_t height)
+{
+ rect->x = x;
+ rect->y = x;
+ rect->width = width;
+ rect->height = height;
+}
+
+static inline void qemu_rect_translate(QemuRect *rect,
+ int16_t dx, int16_t dy)
+{
+ rect->x += dx;
+ rect->y += dy;
+}
+
+static inline bool qemu_rect_intersect(const QemuRect *a, const QemuRect *b,
+ QemuRect *res)
+{
+ int16_t x1, x2, y1, y2;
+
+ x1 = MAX(a->x, b->x);
+ y1 = MAX(a->y, b->y);
+ x2 = MIN(a->x + a->width, b->x + b->width);
+ y2 = MIN(a->y + a->height, b->y + b->height);
+
+ if (x1 >= x2 || y1 >= y2) {
+ if (res) {
+ qemu_rect_init(res, 0, 0, 0, 0);
+ }
+
+ return false;
+ }
+
+ if (res) {
+ qemu_rect_init(res, x1, y1, x2 - x1, y2 - y1);
+ }
+
+ return true;
+}
+
+#endif
diff --git a/hw/display/virtio-gpu.c b/hw/display/virtio-gpu.c
index 6efd15b6ae..59f0881ba6 100644
--- a/hw/display/virtio-gpu.c
+++ b/hw/display/virtio-gpu.c
@@ -16,6 +16,7 @@
#include "qemu/iov.h"
#include "sysemu/cpus.h"
#include "ui/console.h"
+#include "ui/rect.h"
#include "trace.h"
#include "sysemu/dma.h"
#include "sysemu/sysemu.h"
@@ -503,7 +504,7 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g,
struct virtio_gpu_simple_resource *res;
struct virtio_gpu_resource_flush rf;
struct virtio_gpu_scanout *scanout;
- pixman_region16_t flush_region;
+ QemuRect flush_rect;
bool within_bounds = false;
bool update_submitted = false;
int i;
@@ -565,34 +566,25 @@ static void virtio_gpu_resource_flush(VirtIOGPU *g,
return;
}
- pixman_region_init_rect(&flush_region,
- rf.r.x, rf.r.y, rf.r.width, rf.r.height);
+ qemu_rect_init(&flush_rect, rf.r.x, rf.r.y, rf.r.width, rf.r.height);
for (i = 0; i < g->parent_obj.conf.max_outputs; i++) {
- pixman_region16_t region, finalregion;
- pixman_box16_t *extents;
+ QemuRect rect;
if (!(res->scanout_bitmask & (1 << i))) {
continue;
}
scanout = &g->parent_obj.scanout[i];
- pixman_region_init(&finalregion);
- pixman_region_init_rect(®ion, scanout->x, scanout->y,
- scanout->width, scanout->height);
+ qemu_rect_init(&rect, scanout->x, scanout->y,
+ scanout->width, scanout->height);
- pixman_region_intersect(&finalregion, &flush_region, ®ion);
- pixman_region_translate(&finalregion, -scanout->x, -scanout->y);
- extents = pixman_region_extents(&finalregion);
/* work out the area we need to update for each console */
- dpy_gfx_update(g->parent_obj.scanout[i].con,
- extents->x1, extents->y1,
- extents->x2 - extents->x1,
- extents->y2 - extents->y1);
-
- pixman_region_fini(®ion);
- pixman_region_fini(&finalregion);
+ if (qemu_rect_intersect(&flush_rect, &rect, &rect)) {
+ qemu_rect_translate(&rect, -scanout->x, -scanout->y);
+ dpy_gfx_update(g->parent_obj.scanout[i].con,
+ rect.x, rect.y, rect.width, rect.height);
+ }
}
- pixman_region_fini(&flush_region);
}
static void virtio_unref_resource(pixman_image_t *image, void *data)
--
2.41.0
- [PATCH v4 00/19] Make Pixman an optional dependency, marcandre . lureau, 2023/10/18
- [PATCH v4 01/19] build-sys: add a "pixman" feature, marcandre . lureau, 2023/10/18
- [PATCH v4 02/19] ui: compile out some qemu-pixman functions when !PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 04/19] vl: move display early init before default devices, marcandre . lureau, 2023/10/18
- [PATCH v4 03/19] ui: add pixman-compat.h, marcandre . lureau, 2023/10/18
- [PATCH v4 06/19] ui/vc: console-vc requires PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 05/19] ui/console: allow to override the default VC, marcandre . lureau, 2023/10/18
- [PATCH v4 07/19] qmp/hmp: disable screendump if PIXMAN is missing, marcandre . lureau, 2023/10/18
- [PATCH v4 08/19] virtio-gpu: replace PIXMAN for region/rect test,
marcandre . lureau <=
- [PATCH v4 09/19] ui/console: when PIXMAN is unavailable, don't draw placeholder msg, marcandre . lureau, 2023/10/18
- [PATCH v4 10/19] vhost-user-gpu: skip VHOST_USER_GPU_UPDATE when !PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 11/19] ui/gl: opengl doesn't require PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 12/19] ui/vnc: VNC requires PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 14/19] ui/gtk: -display gtk requires PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 15/19] ui/dbus: do not require PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 13/19] ui/spice: SPICE/QXL requires PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 16/19] arm/kconfig: XLNX_ZYNQMP_ARM depends on PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 18/19] hw/display: make ATI_VGA depend on PIXMAN, marcandre . lureau, 2023/10/18
- [PATCH v4 17/19] hw/sm501: allow compiling without PIXMAN, marcandre . lureau, 2023/10/18