]> git.proxmox.com Git - mirror_qemu.git/blame - hw/framebuffer.c
virtio-console: no need to remove char handlers explicitly
[mirror_qemu.git] / hw / framebuffer.c
CommitLineData
714fa308
PB
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"
714fa308
PB
20
21/* Render an image from a shared memory framebuffer. */
22
23void framebuffer_update_display(
24 DisplayState *ds,
75c9d6c2 25 MemoryRegion *address_space,
c227f099 26 target_phys_addr_t base,
714fa308
PB
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{
c227f099 38 target_phys_addr_t src_len;
714fa308
PB
39 uint8_t *dest;
40 uint8_t *src;
41 uint8_t *src_base;
42 int first, last = 0;
43 int dirty;
44 int i;
c227f099 45 ram_addr_t addr;
75c9d6c2
AK
46 MemoryRegionSection mem_section;
47 MemoryRegion *mem;
714fa308
PB
48
49 i = *first_row;
50 *first_row = -1;
51 src_len = src_width * rows;
52
75c9d6c2
AK
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)) {
714fa308
PB
55 return;
56 }
75c9d6c2
AK
57 mem = mem_section.mr;
58 assert(mem);
59 assert(mem_section.offset_within_address_space == base);
714fa308 60
c1cd0b2c 61 memory_region_sync_dirty_bitmap(mem);
714fa308
PB
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);
9312805d
VK
76 if (dest_row_pitch < 0) {
77 dest -= dest_row_pitch * (rows - 1);
78 }
714fa308 79 first = -1;
75c9d6c2 80 addr = mem_section.offset_within_region;
714fa308
PB
81
82 addr += i * src_width;
83 src += i * src_width;
84 dest += i * dest_row_pitch;
85
86 for (; i < rows; i++) {
c227f099 87 target_phys_addr_t dirty_offset;
714fa308
PB
88 dirty = 0;
89 dirty_offset = 0;
90 while (addr + dirty_offset < TARGET_PAGE_ALIGN(addr + src_width)) {
75c9d6c2
AK
91 dirty |= memory_region_get_dirty(mem, addr + dirty_offset,
92 DIRTY_MEMORY_VGA);
714fa308
PB
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 }
75c9d6c2
AK
110 memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
111 DIRTY_MEMORY_VGA);
714fa308
PB
112 *first_row = first;
113 *last_row = last;
114 return;
115}