qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Chad Jablonski <chad@jablonski.xyz>
To: qemu-devel@nongnu.org
Cc: balaton@eik.bme.hu, Chad Jablonski <chad@jablonski.xyz>
Subject: [PATCH v3 08/11] ati-vga: Create 2d_blt destination setup helper
Date: Tue, 18 Nov 2025 10:48:09 -0500	[thread overview]
Message-ID: <20251118154812.57861-9-chad@jablonski.xyz> (raw)
In-Reply-To: <20251118154812.57861-1-chad@jablonski.xyz>

A large amount of the common setup involved in a blit deals with the
destination. This moves that setup to a helper function returning a
struct (ATIBlitDest) holding all of that state. The idea here is that
this setup will be shared between blits from memory as well as from
HOST_DATA and maybe others in the future.

The next patch refactors ati_2d_blt to use this new helper.

Signed-off-by: Chad Jablonski <chad@jablonski.xyz>
---
 hw/display/ati_2d.c | 54 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

diff --git a/hw/display/ati_2d.c b/hw/display/ati_2d.c
index 9c96ee155f..f2e01e28e9 100644
--- a/hw/display/ati_2d.c
+++ b/hw/display/ati_2d.c
@@ -67,6 +67,60 @@ static QemuRect sc_rect(ATIVGAState *s)
     return sc;
 }
 
+typedef struct {
+    QemuRect rect;
+    QemuRect visible;
+    uint32_t src_left_offset;
+    uint32_t src_top_offset;
+    int bpp;
+    int stride;
+    bool top_to_bottom;
+    bool left_to_right;
+    bool valid;
+    uint8_t *bits;
+} ATIBlitDest;
+
+static ATIBlitDest setup_2d_blt_dst(ATIVGAState *s)
+{
+    ATIBlitDest dst = { .valid = false };
+    uint8_t *end = s->vga.vram_ptr + s->vga.vram_size;
+    QemuRect scissor = sc_rect(s);
+
+    dst.rect = dst_rect(s);
+    if (!qemu_rect_intersect(&dst.rect, &scissor, &dst.visible)) {
+        /* Destination is completely clipped, nothing to draw */
+        return dst;
+    }
+    dst.bpp = ati_bpp_from_datatype(s);
+    if (!dst.bpp) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Invalid bpp\n");
+        return dst;
+    }
+    dst.stride = s->regs.dst_pitch;
+    if (!dst.stride) {
+        qemu_log_mask(LOG_GUEST_ERROR, "Zero dest pitch\n");
+        return dst;
+    }
+    dst.bits = s->vga.vram_ptr + s->regs.dst_offset;
+    if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
+        dst.bits += s->regs.crtc_offset & 0x07ffffff;
+        dst.stride *= dst.bpp;
+    }
+    if (dst.visible.x > 0x3fff || dst.visible.y > 0x3fff || dst.bits >= end
+        || dst.bits + dst.visible.x
+         + (dst.visible.y + dst.visible.height) * dst.stride >= end) {
+        qemu_log_mask(LOG_UNIMP, "blt outside vram not implemented\n");
+        return dst;
+    }
+    dst.src_left_offset = dst.visible.x - dst.rect.x;
+    dst.src_top_offset = dst.visible.y - dst.rect.y;
+    dst.left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
+    dst.top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
+    dst.valid = true;
+
+    return dst;
+}
+
 void ati_2d_blt(ATIVGAState *s)
 {
     /* FIXME it is probably more complex than this and may need to be */
-- 
2.51.0



  parent reply	other threads:[~2025-11-18 15:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-18 15:48 [PATCH v3 00/11] ati-vga: Implement HOST_DATA transfers to Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 01/11] ati-vga: Fix DST_PITCH and SRC_PITCH reads Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 02/11] ati-vga: Add scissor clipping register support Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 03/11] ati-vga: Implement foreground and background color register writes Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 04/11] ati-vga: Latch src and dst pitch and offset on master_cntl default Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 05/11] ati-vga: Fix DP_GUI_MASTER_CNTL register mask Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 06/11] ati-vga: Create dst and sc rectangle helpers Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 07/11] ati-vga: Implement scissor rectangle clipping for 2D operations Chad Jablonski
2025-11-18 15:48 ` Chad Jablonski [this message]
2025-11-18 15:48 ` [PATCH v3 09/11] ati-vga: Refactor ati_2d_blt to use dst setup helper Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 10/11] ati-vga: Implement HOST_DATA register writes Chad Jablonski
2025-11-18 15:48 ` [PATCH v3 11/11] ati-vga: Implement HOST_DATA flush to VRAM Chad Jablonski
2025-12-11  2:33 ` [PATCH v3 00/11] ati-vga: Implement HOST_DATA transfers to Chad Jablonski
2025-12-11 11:54   ` BALATON Zoltan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251118154812.57861-9-chad@jablonski.xyz \
    --to=chad@jablonski.xyz \
    --cc=balaton@eik.bme.hu \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).