2 * QEMU ATI SVGA emulation
5 * Copyright (c) 2019 BALATON Zoltan
7 * This work is licensed under the GNU GPL license version 2 or later.
10 #include "qemu/osdep.h"
14 #include "ui/pixel_ops.h"
18 * This is 2D _acceleration_ and supposed to be fast. Therefore, don't try to
19 * reinvent the wheel (unlikely to get better with a naive implementation than
20 * existing libraries) and avoid (poorly) reimplementing gfx primitives.
21 * That is unnecessary and would become a performance problem. Instead, try to
22 * map to and reuse existing optimised facilities (e.g. pixman) wherever
26 static int ati_bpp_from_datatype(ATIVGAState
*s
)
28 switch (s
->regs
.dp_datatype
& 0xf) {
39 qemu_log_mask(LOG_UNIMP
, "Unknown dst datatype %d\n",
40 s
->regs
.dp_datatype
& 0xf);
45 void ati_2d_blt(ATIVGAState
*s
)
47 /* FIXME it is probably more complex than this and may need to be */
48 /* rewritten but for now as a start just to get some output: */
49 DisplaySurface
*ds
= qemu_console_surface(s
->vga
.con
);
50 DPRINTF("%p %u ds: %p %d %d rop: %x\n", s
->vga
.vram_ptr
,
51 s
->vga
.vbe_start_addr
, surface_data(ds
), surface_stride(ds
),
52 surface_bits_per_pixel(ds
),
53 (s
->regs
.dp_mix
& GMC_ROP3_MASK
) >> 16);
54 DPRINTF("%d %d, %d %d, (%d,%d) -> (%d,%d) %dx%d\n", s
->regs
.src_offset
,
55 s
->regs
.dst_offset
, s
->regs
.src_pitch
, s
->regs
.dst_pitch
,
56 s
->regs
.src_x
, s
->regs
.src_y
, s
->regs
.dst_x
, s
->regs
.dst_y
,
57 s
->regs
.dst_width
, s
->regs
.dst_height
);
58 switch (s
->regs
.dp_mix
& GMC_ROP3_MASK
) {
61 uint8_t *src_bits
, *dst_bits
, *end
;
62 int src_stride
, dst_stride
, bpp
= ati_bpp_from_datatype(s
);
63 src_bits
= s
->vga
.vram_ptr
+ s
->regs
.src_offset
;
64 dst_bits
= s
->vga
.vram_ptr
+ s
->regs
.dst_offset
;
65 src_stride
= s
->regs
.src_pitch
;
66 dst_stride
= s
->regs
.dst_pitch
;
68 if (s
->dev_id
== PCI_DEVICE_ID_ATI_RAGE128_PF
) {
69 src_bits
+= s
->regs
.crtc_offset
& 0x07ffffff;
70 dst_bits
+= s
->regs
.crtc_offset
& 0x07ffffff;
74 src_stride
/= sizeof(uint32_t);
75 dst_stride
/= sizeof(uint32_t);
77 DPRINTF("pixman_blt(%p, %p, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)\n",
78 src_bits
, dst_bits
, src_stride
, dst_stride
, bpp
, bpp
,
79 s
->regs
.src_x
, s
->regs
.src_y
, s
->regs
.dst_x
, s
->regs
.dst_y
,
80 s
->regs
.dst_width
, s
->regs
.dst_height
);
81 end
= s
->vga
.vram_ptr
+ s
->vga
.vram_size
;
82 if (src_bits
>= end
|| dst_bits
>= end
||
83 src_bits
+ s
->regs
.src_x
+ (s
->regs
.src_y
+ s
->regs
.dst_height
) *
84 src_stride
* sizeof(uint32_t) >= end
||
85 dst_bits
+ s
->regs
.dst_x
+ (s
->regs
.dst_y
+ s
->regs
.dst_height
) *
86 dst_stride
* sizeof(uint32_t) >= end
) {
87 qemu_log_mask(LOG_UNIMP
, "blt outside vram not implemented\n");
90 pixman_blt((uint32_t *)src_bits
, (uint32_t *)dst_bits
,
91 src_stride
, dst_stride
, bpp
, bpp
,
92 s
->regs
.src_x
, s
->regs
.src_y
,
93 s
->regs
.dst_x
, s
->regs
.dst_y
,
94 s
->regs
.dst_width
, s
->regs
.dst_height
);
95 if (dst_bits
>= s
->vga
.vram_ptr
+ s
->vga
.vbe_start_addr
&&
96 dst_bits
< s
->vga
.vram_ptr
+ s
->vga
.vbe_start_addr
+
97 s
->vga
.vbe_regs
[VBE_DISPI_INDEX_YRES
] * s
->vga
.vbe_line_offset
) {
98 memory_region_set_dirty(&s
->vga
.vram
, s
->vga
.vbe_start_addr
+
100 s
->regs
.dst_y
* surface_stride(ds
),
101 s
->regs
.dst_height
* surface_stride(ds
));
103 s
->regs
.dst_x
+= s
->regs
.dst_width
;
104 s
->regs
.dst_y
+= s
->regs
.dst_height
;
111 uint8_t *dst_bits
, *end
;
112 int dst_stride
, bpp
= ati_bpp_from_datatype(s
);
114 dst_bits
= s
->vga
.vram_ptr
+ s
->regs
.dst_offset
;
115 dst_stride
= s
->regs
.dst_pitch
;
117 if (s
->dev_id
== PCI_DEVICE_ID_ATI_RAGE128_PF
) {
118 dst_bits
+= s
->regs
.crtc_offset
& 0x07ffffff;
121 dst_stride
/= sizeof(uint32_t);
123 switch (s
->regs
.dp_mix
& GMC_ROP3_MASK
) {
125 filler
= bswap32(s
->regs
.dp_brush_frgd_clr
);
128 filler
= rgb_to_pixel32(s
->vga
.palette
[0], s
->vga
.palette
[1],
129 s
->vga
.palette
[2]) << 8 | 0xff;
132 filler
= rgb_to_pixel32(s
->vga
.palette
[3], s
->vga
.palette
[4],
133 s
->vga
.palette
[5]) << 8 | 0xff;
137 DPRINTF("pixman_fill(%p, %d, %d, %d, %d, %d, %d, %x)\n",
138 dst_bits
, dst_stride
, bpp
,
139 s
->regs
.dst_x
, s
->regs
.dst_y
,
140 s
->regs
.dst_width
, s
->regs
.dst_height
,
142 end
= s
->vga
.vram_ptr
+ s
->vga
.vram_size
;
143 if (dst_bits
>= end
||
144 dst_bits
+ s
->regs
.dst_x
+ (s
->regs
.dst_y
+ s
->regs
.dst_height
) *
145 dst_stride
* sizeof(uint32_t) >= end
) {
146 qemu_log_mask(LOG_UNIMP
, "blt outside vram not implemented\n");
149 pixman_fill((uint32_t *)dst_bits
, dst_stride
, bpp
,
150 s
->regs
.dst_x
, s
->regs
.dst_y
,
151 s
->regs
.dst_width
, s
->regs
.dst_height
,
153 if (dst_bits
>= s
->vga
.vram_ptr
+ s
->vga
.vbe_start_addr
&&
154 dst_bits
< s
->vga
.vram_ptr
+ s
->vga
.vbe_start_addr
+
155 s
->vga
.vbe_regs
[VBE_DISPI_INDEX_YRES
] * s
->vga
.vbe_line_offset
) {
156 memory_region_set_dirty(&s
->vga
.vram
, s
->vga
.vbe_start_addr
+
158 s
->regs
.dst_y
* surface_stride(ds
),
159 s
->regs
.dst_height
* surface_stride(ds
));
161 s
->regs
.dst_y
+= s
->regs
.dst_height
;
165 qemu_log_mask(LOG_UNIMP
, "Unimplemented ati_2d blt op %x\n",
166 (s
->regs
.dp_mix
& GMC_ROP3_MASK
) >> 16);