ati-vga: Extract setup_2d_blt_ctx from ati_2d_blt
setup_2d_blt_ctx is responsible for knowing how to retrieve the state needed by ati_2d_blt from the registers and assigning it to the ATI2DCtx. This will be useful in a future patch when HOST_DATA needs to make small modifications to the ctx. Signed-off-by: Chad Jablonski <chad@jablonski.xyz> Reviewed-by: BALATON Zoltan <balaton@eik.bme.hu> [balaton: Fix build without pixman] Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu> Message-ID: <6e2dccba65d9b369e0db633c0149a77351827222.1773020351.git.balaton@eik.bme.hu> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Chad Jablonski committed
Mar 9, 2026 at 02:47 UTC
b6740448a22922a828be60c67c93877b2f5f401d
1 file changed
+36
-33
hw/display/ati_2d.c
+36
-33
@@ -25,7 +25,7 @@
25
* possible.
26
*/
27
28
-static int ati_bpp_from_datatype(ATIVGAState *s)
28
+static int ati_bpp_from_datatype(const ATIVGAState *s)
29
{
30
switch (s->regs.dp_datatype & 0xf) {
31
case 2:
@@ -80,73 +80,76 @@ static void ati_set_dirty(VGACommonState *vga, const ATI2DCtx *ctx)
80
}
81
}
82
83
-void ati_2d_blt(ATIVGAState *s)
83
+static void setup_2d_blt_ctx(const ATIVGAState *s, ATI2DCtx *ctx)
84
{
85
- /* FIXME it is probably more complex than this and may need to be */
86
- /* rewritten but for now as a start just to get some output: */
87
- ATI2DCtx ctx_;
88
- ATI2DCtx *ctx = &ctx_;
85
+ ctx->bpp = ati_bpp_from_datatype(s);
86
ctx->rop3 = s->regs.dp_mix & GMC_ROP3_MASK;
87
ctx->left_to_right = s->regs.dp_cntl & DST_X_LEFT_TO_RIGHT;
88
ctx->top_to_bottom = s->regs.dp_cntl & DST_Y_TOP_TO_BOTTOM;
89
ctx->frgd_clr = s->regs.dp_brush_frgd_clr;
90
ctx->palette = s->vga.palette;
91
ctx->dst_offset = s->regs.dst_offset;
92
+ ctx->vram_end = s->vga.vram_ptr + s->vga.vram_size;
93
+
94
ctx->dst.width = s->regs.dst_width;
95
ctx->dst.height = s->regs.dst_height;
96
ctx->dst.x = (ctx->left_to_right ?
97
s->regs.dst_x : s->regs.dst_x + 1 - ctx->dst.width);
98
ctx->dst.y = (ctx->top_to_bottom ?
99
s->regs.dst_y : s->regs.dst_y + 1 - ctx->dst.height);
101
- ctx->bpp = ati_bpp_from_datatype(s);
100
+ ctx->dst_stride = s->regs.dst_pitch;
101
+ ctx->dst_bits = s->vga.vram_ptr + s->regs.dst_offset;
102
+ if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
103
+ ctx->dst_bits += s->regs.crtc_offset & 0x07ffffff;
104
+ ctx->dst_stride *= ctx->bpp;
105
+ }
106
+
107
+ ctx->src.x = (ctx->left_to_right ?
108
+ s->regs.src_x : s->regs.src_x + 1 - ctx->dst.width);
109
+ ctx->src.y = (ctx->top_to_bottom ?
110
+ s->regs.src_y : s->regs.src_y + 1 - ctx->dst.height);
111
+ ctx->src_stride = s->regs.src_pitch;
112
+ ctx->src_bits = s->vga.vram_ptr + s->regs.src_offset;
113
+ if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
114
+ ctx->src_bits += s->regs.crtc_offset & 0x07ffffff;
115
+ ctx->src_stride *= ctx->bpp;
116
+ }
117
+ DPRINTF("%d %d %d, %d %d %d, (%d,%d) -> (%d,%d) %dx%d %c %c\n",
118
+ s->regs.src_offset, s->regs.dst_offset, s->regs.default_offset,
119
+ ctx->src_stride, ctx->dst_stride, s->regs.default_pitch,
120
+ ctx->src.x, ctx->src.y, ctx->dst.x, ctx->dst.y,
121
+ ctx->dst.width, ctx->dst.height,
122
+ (ctx->left_to_right ? '>' : '<'),
123
+ (ctx->top_to_bottom ? 'v' : '^'));
124
+}
125
+
126
+void ati_2d_blt(ATIVGAState *s)
127
+{
128
+ ATI2DCtx ctx_;
129
+ ATI2DCtx *ctx = &ctx_;
130
+ setup_2d_blt_ctx(s, ctx);
131
if (!ctx->bpp) {
132
qemu_log_mask(LOG_GUEST_ERROR, "Invalid bpp\n");
133
return;
134
}
106
- ctx->dst_stride = s->regs.dst_pitch;
135
if (!ctx->dst_stride) {
136
qemu_log_mask(LOG_GUEST_ERROR, "Zero dest pitch\n");
137
return;
138
}
111
- ctx->dst_bits = s->vga.vram_ptr + ctx->dst_offset;
112
-
113
- if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
114
- ctx->dst_bits += s->regs.crtc_offset & 0x07ffffff;
115
- ctx->dst_stride *= ctx->bpp;
116
- }
117
- ctx->vram_end = s->vga.vram_ptr + s->vga.vram_size;
139
if (ctx->dst.x > 0x3fff || ctx->dst.y > 0x3fff ||
140
ctx->dst_bits >= ctx->vram_end || ctx->dst_bits + ctx->dst.x +
141
(ctx->dst.y + ctx->dst.height) * ctx->dst_stride >= ctx->vram_end) {
142
qemu_log_mask(LOG_UNIMP, "blt outside vram not implemented\n");
143
return;
144
}
124
- DPRINTF("%d %d %d, %d %d %d, (%d,%d) -> (%d,%d) %dx%d %c %c\n",
125
- s->regs.src_offset, ctx->dst_offset, s->regs.default_offset,
126
- ctx->src_stride, ctx->dst_stride, s->regs.default_pitch,
127
- ctx->src.x, ctx->src.y, ctx->dst.x, ctx->dst.y,
128
- ctx->dst.width, ctx->dst.height,
129
- (ctx->left_to_right ? '>' : '<'),
130
- (ctx->top_to_bottom ? 'v' : '^'));
145
switch (ctx->rop3) {
146
case ROP3_SRCCOPY:
147
{
148
bool fallback = false;
135
- ctx->src.x = (ctx->left_to_right ?
136
- s->regs.src_x : s->regs.src_x + 1 - ctx->dst.width);
137
- ctx->src.y = (ctx->top_to_bottom ?
138
- s->regs.src_y : s->regs.src_y + 1 - ctx->dst.height);
139
- ctx->src_stride = s->regs.src_pitch;
149
if (!ctx->src_stride) {
150
qemu_log_mask(LOG_GUEST_ERROR, "Zero source pitch\n");
151
return;
152
}
144
- ctx->src_bits = s->vga.vram_ptr + s->regs.src_offset;
145
-
146
- if (s->dev_id == PCI_DEVICE_ID_ATI_RAGE128_PF) {
147
- ctx->src_bits += s->regs.crtc_offset & 0x07ffffff;
148
- ctx->src_stride *= ctx->bpp;
149
- }
153
if (ctx->src.x > 0x3fff || ctx->src.y > 0x3fff ||
154
ctx->src_bits >= ctx->vram_end ||
155
ctx->src_bits + ctx->src.x + (ctx->src.y + ctx->dst.height) *