2009-04-01 14:27:59 +02:00
|
|
|
/*
|
|
|
|
* Framebuffer device helper routines
|
|
|
|
*
|
|
|
|
* Copyright (c) 2009 CodeSourcery
|
|
|
|
* Written by Paul Brook <paul@codesourcery.com>
|
|
|
|
*
|
|
|
|
* This code is licensed under the GNU GPLv2.
|
2012-01-13 17:44:23 +01:00
|
|
|
*
|
|
|
|
* Contributions after 2012-01-13 are licensed under the terms of the
|
|
|
|
* GNU GPL, version 2 or (at your option) any later version.
|
2009-04-01 14:27:59 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* TODO:
|
|
|
|
- Do something similar for framebuffers with local ram
|
|
|
|
- Handle rotation here instead of hacking dest_pitch
|
|
|
|
- Use common pixel conversion routines instead of per-device drawfn
|
|
|
|
- Remove all DisplayState knowledge from devices.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "hw.h"
|
2012-11-28 12:06:30 +01:00
|
|
|
#include "ui/console.h"
|
2009-04-01 14:27:59 +02:00
|
|
|
#include "framebuffer.h"
|
|
|
|
|
|
|
|
/* Render an image from a shared memory framebuffer. */
|
|
|
|
|
|
|
|
void framebuffer_update_display(
|
|
|
|
DisplayState *ds,
|
2011-12-08 15:00:54 +01:00
|
|
|
MemoryRegion *address_space,
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr base,
|
2009-04-01 14:27:59 +02:00
|
|
|
int cols, /* Width in pixels. */
|
2012-08-11 21:32:02 +02:00
|
|
|
int rows, /* Height in pixels. */
|
2009-04-01 14:27:59 +02:00
|
|
|
int src_width, /* Length of source line, in bytes. */
|
|
|
|
int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */
|
|
|
|
int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */
|
|
|
|
int invalidate, /* nonzero to redraw the whole image. */
|
|
|
|
drawfn fn,
|
|
|
|
void *opaque,
|
|
|
|
int *first_row, /* Input and output. */
|
|
|
|
int *last_row /* Output only */)
|
|
|
|
{
|
2012-10-23 12:30:10 +02:00
|
|
|
hwaddr src_len;
|
2009-04-01 14:27:59 +02:00
|
|
|
uint8_t *dest;
|
|
|
|
uint8_t *src;
|
|
|
|
uint8_t *src_base;
|
|
|
|
int first, last = 0;
|
|
|
|
int dirty;
|
|
|
|
int i;
|
2009-10-01 23:12:16 +02:00
|
|
|
ram_addr_t addr;
|
2011-12-08 15:00:54 +01:00
|
|
|
MemoryRegionSection mem_section;
|
|
|
|
MemoryRegion *mem;
|
2009-04-01 14:27:59 +02:00
|
|
|
|
|
|
|
i = *first_row;
|
|
|
|
*first_row = -1;
|
|
|
|
src_len = src_width * rows;
|
|
|
|
|
2011-12-08 15:00:54 +01:00
|
|
|
mem_section = memory_region_find(address_space, base, src_len);
|
|
|
|
if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {
|
2009-04-01 14:27:59 +02:00
|
|
|
return;
|
|
|
|
}
|
2011-12-08 15:00:54 +01:00
|
|
|
mem = mem_section.mr;
|
|
|
|
assert(mem);
|
|
|
|
assert(mem_section.offset_within_address_space == base);
|
2009-04-01 14:27:59 +02:00
|
|
|
|
2011-12-15 15:07:48 +01:00
|
|
|
memory_region_sync_dirty_bitmap(mem);
|
2009-04-01 14:27:59 +02:00
|
|
|
src_base = cpu_physical_memory_map(base, &src_len, 0);
|
|
|
|
/* If we can't map the framebuffer then bail. We could try harder,
|
|
|
|
but it's not really worth it as dirty flag tracking will probably
|
|
|
|
already have failed above. */
|
|
|
|
if (!src_base)
|
|
|
|
return;
|
|
|
|
if (src_len != src_width * rows) {
|
|
|
|
cpu_physical_memory_unmap(src_base, src_len, 0, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
src = src_base;
|
|
|
|
dest = ds_get_data(ds);
|
|
|
|
if (dest_col_pitch < 0)
|
|
|
|
dest -= dest_col_pitch * (cols - 1);
|
2011-06-17 12:04:36 +02:00
|
|
|
if (dest_row_pitch < 0) {
|
|
|
|
dest -= dest_row_pitch * (rows - 1);
|
|
|
|
}
|
2009-04-01 14:27:59 +02:00
|
|
|
first = -1;
|
2011-12-08 15:00:54 +01:00
|
|
|
addr = mem_section.offset_within_region;
|
2009-04-01 14:27:59 +02:00
|
|
|
|
|
|
|
addr += i * src_width;
|
|
|
|
src += i * src_width;
|
|
|
|
dest += i * dest_row_pitch;
|
|
|
|
|
|
|
|
for (; i < rows; i++) {
|
2012-02-04 18:09:14 +01:00
|
|
|
dirty = memory_region_get_dirty(mem, addr, src_width,
|
2011-12-08 15:00:54 +01:00
|
|
|
DIRTY_MEMORY_VGA);
|
2009-04-01 14:27:59 +02:00
|
|
|
if (dirty || invalidate) {
|
|
|
|
fn(opaque, dest, src, cols, dest_col_pitch);
|
|
|
|
if (first == -1)
|
|
|
|
first = i;
|
|
|
|
last = i;
|
|
|
|
}
|
|
|
|
addr += src_width;
|
|
|
|
src += src_width;
|
|
|
|
dest += dest_row_pitch;
|
|
|
|
}
|
|
|
|
cpu_physical_memory_unmap(src_base, src_len, 0, 0);
|
|
|
|
if (first < 0) {
|
|
|
|
return;
|
|
|
|
}
|
2011-12-08 15:00:54 +01:00
|
|
|
memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
|
|
|
|
DIRTY_MEMORY_VGA);
|
2009-04-01 14:27:59 +02:00
|
|
|
*first_row = first;
|
|
|
|
*last_row = last;
|
|
|
|
}
|