]> git.proxmox.com Git - qemu.git/blob - hw/framebuffer.c
Merge remote-tracking branch 'amit/master' into staging
[qemu.git] / hw / framebuffer.c
1 /*
2 * Framebuffer device helper routines
3 *
4 * Copyright (c) 2009 CodeSourcery
5 * Written by Paul Brook <paul@codesourcery.com>
6 *
7 * This code is licensed under the GNU GPLv2.
8 */
9
10 /* TODO:
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.
15 */
16
17 #include "hw.h"
18 #include "console.h"
19 #include "framebuffer.h"
20
21 /* Render an image from a shared memory framebuffer. */
22
23 void framebuffer_update_display(
24 DisplayState *ds,
25 MemoryRegion *address_space,
26 target_phys_addr_t base,
27 int cols, /* Width in pixels. */
28 int rows, /* Leight in pixels. */
29 int src_width, /* Length of source line, in bytes. */
30 int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */
31 int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */
32 int invalidate, /* nonzero to redraw the whole image. */
33 drawfn fn,
34 void *opaque,
35 int *first_row, /* Input and output. */
36 int *last_row /* Output only */)
37 {
38 target_phys_addr_t src_len;
39 uint8_t *dest;
40 uint8_t *src;
41 uint8_t *src_base;
42 int first, last = 0;
43 int dirty;
44 int i;
45 ram_addr_t addr;
46 MemoryRegionSection mem_section;
47 MemoryRegion *mem;
48
49 i = *first_row;
50 *first_row = -1;
51 src_len = src_width * rows;
52
53 mem_section = memory_region_find(address_space, base, src_len);
54 if (mem_section.size != src_len || !memory_region_is_ram(mem_section.mr)) {
55 return;
56 }
57 mem = mem_section.mr;
58 assert(mem);
59 assert(mem_section.offset_within_address_space == base);
60
61 memory_region_sync_dirty_bitmap(mem);
62 src_base = cpu_physical_memory_map(base, &src_len, 0);
63 /* If we can't map the framebuffer then bail. We could try harder,
64 but it's not really worth it as dirty flag tracking will probably
65 already have failed above. */
66 if (!src_base)
67 return;
68 if (src_len != src_width * rows) {
69 cpu_physical_memory_unmap(src_base, src_len, 0, 0);
70 return;
71 }
72 src = src_base;
73 dest = ds_get_data(ds);
74 if (dest_col_pitch < 0)
75 dest -= dest_col_pitch * (cols - 1);
76 if (dest_row_pitch < 0) {
77 dest -= dest_row_pitch * (rows - 1);
78 }
79 first = -1;
80 addr = mem_section.offset_within_region;
81
82 addr += i * src_width;
83 src += i * src_width;
84 dest += i * dest_row_pitch;
85
86 for (; i < rows; i++) {
87 target_phys_addr_t dirty_offset;
88 dirty = 0;
89 dirty_offset = 0;
90 while (addr + dirty_offset < TARGET_PAGE_ALIGN(addr + src_width)) {
91 dirty |= memory_region_get_dirty(mem, addr + dirty_offset,
92 DIRTY_MEMORY_VGA);
93 dirty_offset += TARGET_PAGE_SIZE;
94 }
95
96 if (dirty || invalidate) {
97 fn(opaque, dest, src, cols, dest_col_pitch);
98 if (first == -1)
99 first = i;
100 last = i;
101 }
102 addr += src_width;
103 src += src_width;
104 dest += dest_row_pitch;
105 }
106 cpu_physical_memory_unmap(src_base, src_len, 0, 0);
107 if (first < 0) {
108 return;
109 }
110 memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
111 DIRTY_MEMORY_VGA);
112 *first_row = first;
113 *last_row = last;
114 return;
115 }