2
* Framebuffer device helper routines
4
* Copyright (c) 2009 CodeSourcery
5
* Written by Paul Brook <paul@codesourcery.com>
7
* This code is licensed under the GNU GPLv2.
11
- Do something similar for framebuffers with local ram
12
- Handle rotation here instead of hacking dest_pitch
13
- Use common pixel conversion routines instead of per-device drawfn
14
- Remove all DisplayState knowledge from devices.
19
#include "framebuffer.h"
21
/* Render an image from a shared memory framebuffer. */
23
void framebuffer_update_display(
25
target_phys_addr_t base,
26
int cols, /* Width in pixels. */
27
int rows, /* Leight in pixels. */
28
int src_width, /* Length of source line, in bytes. */
29
int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */
30
int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */
31
int invalidate, /* nonzero to redraw the whole image. */
34
int *first_row, /* Input and output. */
35
int *last_row /* Output only */)
37
target_phys_addr_t src_len;
50
src_len = src_width * rows;
52
cpu_physical_sync_dirty_bitmap(base, base + src_len);
53
pd = cpu_get_physical_page_desc(base);
54
pd2 = cpu_get_physical_page_desc(base + src_len - 1);
55
/* We should reall check that this is a continuous ram region.
56
Instead we just check that the first and last pages are
57
both ram, and the right distance apart. */
58
if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM
59
|| (pd2 & ~TARGET_PAGE_MASK) > IO_MEM_ROM) {
62
pd = (pd & TARGET_PAGE_MASK) + (base & ~TARGET_PAGE_MASK);
63
if (((pd + src_len - 1) & TARGET_PAGE_MASK) != (pd2 & TARGET_PAGE_MASK)) {
67
src_base = cpu_physical_memory_map(base, &src_len, 0);
68
/* If we can't map the framebuffer then bail. We could try harder,
69
but it's not really worth it as dirty flag tracking will probably
70
already have failed above. */
73
if (src_len != src_width * rows) {
74
cpu_physical_memory_unmap(src_base, src_len, 0, 0);
78
dest = ds_get_data(ds);
79
if (dest_col_pitch < 0)
80
dest -= dest_col_pitch * (cols - 1);
84
addr += i * src_width;
86
dest += i * dest_row_pitch;
88
for (; i < rows; i++) {
89
target_phys_addr_t dirty_offset;
92
while (addr + dirty_offset < TARGET_PAGE_ALIGN(addr + src_width)) {
93
dirty |= cpu_physical_memory_get_dirty(addr + dirty_offset,
95
dirty_offset += TARGET_PAGE_SIZE;
98
if (dirty || invalidate) {
99
fn(opaque, dest, src, cols, dest_col_pitch);
106
dest += dest_row_pitch;
108
cpu_physical_memory_unmap(src_base, src_len, 0, 0);
112
cpu_physical_memory_reset_dirty(pd, pd + src_len, VGA_DIRTY_FLAG);