Skip to content

Commit

Permalink
console: stop using DisplayState in gfx hardware emulation
Browse files Browse the repository at this point in the history
Use QemuConsole instead.  Updates interfaces in console.[ch] and adapts
gfx hardware emulation code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
  • Loading branch information
kraxel committed Mar 18, 2013
1 parent bc2ed97 commit c78f713
Show file tree
Hide file tree
Showing 31 changed files with 525 additions and 435 deletions.
20 changes: 11 additions & 9 deletions hw/arm/musicpal.c
Expand Up @@ -462,7 +462,7 @@ typedef struct musicpal_lcd_state {
uint32_t irqctrl;
uint32_t page;
uint32_t page_off;
DisplayState *ds;
QemuConsole *con;
uint8_t video_ram[128*64/8];
} musicpal_lcd_state;

Expand All @@ -483,7 +483,8 @@ static inline void glue(set_lcd_pixel, depth) \
(musicpal_lcd_state *s, int x, int y, type col) \
{ \
int dx, dy; \
type *pixel = &((type *) ds_get_data(s->ds))[(y * 128 * 3 + x) * 3]; \
DisplaySurface *surface = qemu_console_surface(s->con); \
type *pixel = &((type *) surface_data(surface))[(y * 128 * 3 + x) * 3]; \
\
for (dy = 0; dy < 3; dy++, pixel += 127 * 3) \
for (dx = 0; dx < 3; dx++, pixel++) \
Expand All @@ -496,9 +497,10 @@ SET_LCD_PIXEL(32, uint32_t)
static void lcd_refresh(void *opaque)
{
musicpal_lcd_state *s = opaque;
DisplaySurface *surface = qemu_console_surface(s->con);
int x, y, col;

switch (ds_get_bits_per_pixel(s->ds)) {
switch (surface_bits_per_pixel(surface)) {
case 0:
return;
#define LCD_REFRESH(depth, func) \
Expand All @@ -518,14 +520,14 @@ static void lcd_refresh(void *opaque)
break;
LCD_REFRESH(8, rgb_to_pixel8)
LCD_REFRESH(16, rgb_to_pixel16)
LCD_REFRESH(32, (is_surface_bgr(s->ds->surface) ?
LCD_REFRESH(32, (is_surface_bgr(surface) ?
rgb_to_pixel32bgr : rgb_to_pixel32))
default:
hw_error("unsupported colour depth %i\n",
ds_get_bits_per_pixel(s->ds));
surface_bits_per_pixel(surface));
}

dpy_gfx_update(s->ds, 0, 0, 128*3, 64*3);
dpy_gfx_update(s->con, 0, 0, 128*3, 64*3);
}

static void lcd_invalidate(void *opaque)
Expand Down Expand Up @@ -609,9 +611,9 @@ static int musicpal_lcd_init(SysBusDevice *dev)
"musicpal-lcd", MP_LCD_SIZE);
sysbus_init_mmio(dev, &s->iomem);

s->ds = graphic_console_init(lcd_refresh, lcd_invalidate,
NULL, NULL, s);
qemu_console_resize(s->ds, 128*3, 64*3);
s->con = graphic_console_init(lcd_refresh, lcd_invalidate,
NULL, NULL, s);
qemu_console_resize(s->con, 128*3, 64*3);

qdev_init_gpio_in(&dev->qdev, musicpal_lcd_gpio_brigthness_in, 3);

Expand Down
37 changes: 22 additions & 15 deletions hw/blizzard.c
Expand Up @@ -69,7 +69,7 @@ typedef struct {
uint8_t effect;
uint8_t iformat;
uint8_t source;
DisplayState *state;
QemuConsole *con;
blizzard_fn_t *line_fn_tab[2];
void *fb;

Expand Down Expand Up @@ -144,6 +144,7 @@ static inline void blizzard_rgb2yuv(int r, int g, int b,

static void blizzard_window(BlizzardState *s)
{
DisplaySurface *surface = qemu_console_surface(s->con);
uint8_t *src, *dst;
int bypp[2];
int bypl[3];
Expand All @@ -162,7 +163,7 @@ static void blizzard_window(BlizzardState *s)
s->my[1] = s->data.y + s->data.dy;

bypp[0] = s->bpp;
bypp[1] = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
bypp[1] = surface_bytes_per_pixel(surface);
bypl[0] = bypp[0] * s->data.pitch;
bypl[1] = bypp[1] * s->x;
bypl[2] = bypp[0] * s->data.dx;
Expand Down Expand Up @@ -883,23 +884,25 @@ void s1d13745_write_block(void *opaque, int dc,
static void blizzard_update_display(void *opaque)
{
BlizzardState *s = (BlizzardState *) opaque;
DisplaySurface *surface = qemu_console_surface(s->con);
int y, bypp, bypl, bwidth;
uint8_t *src, *dst;

if (!s->enable)
return;

if (s->x != ds_get_width(s->state) || s->y != ds_get_height(s->state)) {
if (s->x != surface_width(surface) || s->y != surface_height(surface)) {
s->invalidate = 1;
qemu_console_resize(s->state, s->x, s->y);
qemu_console_resize(s->con, s->x, s->y);
surface = qemu_console_surface(s->con);
}

if (s->invalidate) {
s->invalidate = 0;

if (s->blank) {
bypp = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
memset(ds_get_data(s->state), 0, bypp * s->x * s->y);
bypp = surface_bytes_per_pixel(surface);
memset(surface_data(surface), 0, bypp * s->x * s->y);
return;
}

Expand All @@ -912,16 +915,16 @@ static void blizzard_update_display(void *opaque)
if (s->mx[1] <= s->mx[0])
return;

bypp = (ds_get_bits_per_pixel(s->state) + 7) >> 3;
bypp = surface_bytes_per_pixel(surface);
bypl = bypp * s->x;
bwidth = bypp * (s->mx[1] - s->mx[0]);
y = s->my[0];
src = s->fb + bypl * y + bypp * s->mx[0];
dst = ds_get_data(s->state) + bypl * y + bypp * s->mx[0];
dst = surface_data(surface) + bypl * y + bypp * s->mx[0];
for (; y < s->my[1]; y ++, src += bypl, dst += bypl)
memcpy(dst, src, bwidth);

dpy_gfx_update(s->state, s->mx[0], s->my[0],
dpy_gfx_update(s->con, s->mx[0], s->my[0],
s->mx[1] - s->mx[0], y - s->my[0]);

s->mx[0] = s->x;
Expand All @@ -934,10 +937,12 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
bool cswitch, Error **errp)
{
BlizzardState *s = (BlizzardState *) opaque;
DisplaySurface *surface = qemu_console_surface(s->con);

blizzard_update_display(opaque);
if (s && ds_get_data(s->state))
ppm_save(filename, s->state->surface, errp);
if (s && surface_data(surface)) {
ppm_save(filename, surface, errp);
}
}

#define DEPTH 8
Expand All @@ -954,14 +959,16 @@ static void blizzard_screen_dump(void *opaque, const char *filename,
void *s1d13745_init(qemu_irq gpio_int)
{
BlizzardState *s = (BlizzardState *) g_malloc0(sizeof(*s));
DisplaySurface *surface;

s->fb = g_malloc(0x180000);

s->state = graphic_console_init(blizzard_update_display,
blizzard_invalidate_display,
blizzard_screen_dump, NULL, s);
s->con = graphic_console_init(blizzard_update_display,
blizzard_invalidate_display,
blizzard_screen_dump, NULL, s);
surface = qemu_console_surface(s->con);

switch (ds_get_bits_per_pixel(s->state)) {
switch (surface_bits_per_pixel(surface)) {
case 0:
s->line_fn_tab[0] = s->line_fn_tab[1] =
g_malloc0(sizeof(blizzard_fn_t) * 0x10);
Expand Down
22 changes: 12 additions & 10 deletions hw/cirrus_vga.c
Expand Up @@ -729,11 +729,12 @@ static void cirrus_do_copy(CirrusVGAState *s, int dst, int src, int w, int h)
s->cirrus_blt_dstpitch, s->cirrus_blt_srcpitch,
s->cirrus_blt_width, s->cirrus_blt_height);

if (notify)
qemu_console_copy(s->vga.ds,
if (notify) {
qemu_console_copy(s->vga.con,
sx, sy, dx, dy,
s->cirrus_blt_width / depth,
s->cirrus_blt_height);
}

/* we don't have to notify the display that this portion has
changed since qemu_console_copy implies this */
Expand Down Expand Up @@ -2176,6 +2177,7 @@ static void cirrus_cursor_invalidate(VGACommonState *s1)
static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
{
CirrusVGAState *s = container_of(s1, CirrusVGAState, vga);
DisplaySurface *surface = qemu_console_surface(s->vga.con);
int w, h, bpp, x1, x2, poffset;
unsigned int color0, color1;
const uint8_t *palette, *src;
Expand Down Expand Up @@ -2228,9 +2230,9 @@ static void cirrus_cursor_draw_line(VGACommonState *s1, uint8_t *d1, int scr_y)
color1 = s->vga.rgb_to_pixel(c6_to_8(palette[0xf * 3]),
c6_to_8(palette[0xf * 3 + 1]),
c6_to_8(palette[0xf * 3 + 2]));
bpp = ((ds_get_bits_per_pixel(s->vga.ds) + 7) >> 3);
bpp = surface_bytes_per_pixel(surface);
d1 += x1 * bpp;
switch(ds_get_bits_per_pixel(s->vga.ds)) {
switch (surface_bits_per_pixel(surface)) {
default:
break;
case 8:
Expand Down Expand Up @@ -2908,9 +2910,9 @@ static int vga_initfn(ISADevice *dev)
vga_common_init(s);
cirrus_init_common(&d->cirrus_vga, CIRRUS_ID_CLGD5430, 0,
isa_address_space(dev), isa_address_space_io(dev));
s->ds = graphic_console_init(s->update, s->invalidate,
s->screen_dump, s->text_update,
s);
s->con = graphic_console_init(s->update, s->invalidate,
s->screen_dump, s->text_update,
s);
rom_add_vga(VGABIOS_CIRRUS_FILENAME);
/* XXX ISA-LFB support */
/* FIXME not qdev yet */
Expand Down Expand Up @@ -2957,9 +2959,9 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev)
vga_common_init(&s->vga);
cirrus_init_common(s, device_id, 1, pci_address_space(dev),
pci_address_space_io(dev));
s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
s->vga.screen_dump, s->vga.text_update,
&s->vga);
s->vga.con = graphic_console_init(s->vga.update, s->vga.invalidate,
s->vga.screen_dump, s->vga.text_update,
&s->vga);

/* setup PCI */

Expand Down
17 changes: 10 additions & 7 deletions hw/exynos4210_fimd.c
Expand Up @@ -296,7 +296,7 @@ struct Exynos4210fimdWindow {
typedef struct {
SysBusDevice busdev;
MemoryRegion iomem;
DisplayState *console;
QemuConsole *console;
qemu_irq irq[3];

uint32_t vidcon[4]; /* Video main control registers 0-3 */
Expand Down Expand Up @@ -1221,16 +1221,18 @@ static void exynos4210_fimd_invalidate(void *opaque)

static void exynos4210_update_resolution(Exynos4210fimdState *s)
{
DisplaySurface *surface = qemu_console_surface(s->console);

/* LCD resolution is stored in VIDEO TIME CONTROL REGISTER 2 */
uint32_t width = ((s->vidtcon[2] >> FIMD_VIDTCON2_HOR_SHIFT) &
FIMD_VIDTCON2_SIZE_MASK) + 1;
uint32_t height = ((s->vidtcon[2] >> FIMD_VIDTCON2_VER_SHIFT) &
FIMD_VIDTCON2_SIZE_MASK) + 1;

if (s->ifb == NULL || ds_get_width(s->console) != width ||
ds_get_height(s->console) != height) {
if (s->ifb == NULL || surface_width(surface) != width ||
surface_height(surface) != height) {
DPRINT_L1("Resolution changed from %ux%u to %ux%u\n",
ds_get_width(s->console), ds_get_height(s->console), width, height);
surface_width(surface), surface_height(surface), width, height);
qemu_console_resize(s->console, width, height);
s->ifb = g_realloc(s->ifb, width * height * RGBA_SIZE + 1);
memset(s->ifb, 0, width * height * RGBA_SIZE + 1);
Expand All @@ -1241,6 +1243,7 @@ static void exynos4210_update_resolution(Exynos4210fimdState *s)
static void exynos4210_fimd_update(void *opaque)
{
Exynos4210fimdState *s = (Exynos4210fimdState *)opaque;
DisplaySurface *surface = qemu_console_surface(s->console);
Exynos4210fimdWindow *w;
int i, line;
hwaddr fb_line_addr, inc_size;
Expand All @@ -1253,7 +1256,7 @@ static void exynos4210_fimd_update(void *opaque)
const int global_height = ((s->vidtcon[2] >> FIMD_VIDTCON2_VER_SHIFT) &
FIMD_VIDTCON2_SIZE_MASK) + 1;

if (!s || !s->console || !ds_get_bits_per_pixel(s->console) ||
if (!s || !s->console || !surface_bits_per_pixel(surface) ||
!s->enabled) {
return;
}
Expand Down Expand Up @@ -1299,10 +1302,10 @@ static void exynos4210_fimd_update(void *opaque)
uint8_t *d;
int bpp;

bpp = ds_get_bits_per_pixel(s->console);
bpp = surface_bits_per_pixel(surface);
fimd_update_putpix_qemu(bpp);
bpp = (bpp + 1) >> 3;
d = ds_get_data(s->console);
d = surface_data(surface);
for (line = first_line; line <= last_line; line++) {
fimd_copy_line_toqemu(global_width, s->ifb + global_width * line *
RGBA_SIZE, d + global_width * line * bpp);
Expand Down
4 changes: 2 additions & 2 deletions hw/framebuffer.c
Expand Up @@ -24,7 +24,7 @@
/* Render an image from a shared memory framebuffer. */

void framebuffer_update_display(
DisplayState *ds,
DisplaySurface *ds,
MemoryRegion *address_space,
hwaddr base,
int cols, /* Width in pixels. */
Expand Down Expand Up @@ -73,7 +73,7 @@ void framebuffer_update_display(
return;
}
src = src_base;
dest = ds_get_data(ds);
dest = surface_data(ds);
if (dest_col_pitch < 0)
dest -= dest_col_pitch * (cols - 1);
if (dest_row_pitch < 0) {
Expand Down
2 changes: 1 addition & 1 deletion hw/framebuffer.h
Expand Up @@ -8,7 +8,7 @@
typedef void (*drawfn)(void *, uint8_t *, const uint8_t *, int, int);

void framebuffer_update_display(
DisplayState *ds,
DisplaySurface *ds,
MemoryRegion *address_space,
hwaddr base,
int cols,
Expand Down

0 comments on commit c78f713

Please sign in to comment.