root / hw / framebuffer.c @ 4870852c
History | View | Annotate | Download (3.5 kB)
1 | 714fa308 | pbrook | /*
|
---|---|---|---|
2 | 714fa308 | pbrook | * Framebuffer device helper routines
|
3 | 714fa308 | pbrook | *
|
4 | 714fa308 | pbrook | * Copyright (c) 2009 CodeSourcery
|
5 | 714fa308 | pbrook | * Written by Paul Brook <paul@codesourcery.com>
|
6 | 714fa308 | pbrook | *
|
7 | 714fa308 | pbrook | * This code is licensed under the GNU GPLv2.
|
8 | 714fa308 | pbrook | */
|
9 | 714fa308 | pbrook | |
10 | 714fa308 | pbrook | /* TODO:
|
11 | 714fa308 | pbrook | - Do something similar for framebuffers with local ram
|
12 | 714fa308 | pbrook | - Handle rotation here instead of hacking dest_pitch
|
13 | 714fa308 | pbrook | - Use common pixel conversion routines instead of per-device drawfn
|
14 | 714fa308 | pbrook | - Remove all DisplayState knowledge from devices.
|
15 | 714fa308 | pbrook | */
|
16 | 714fa308 | pbrook | |
17 | 714fa308 | pbrook | #include "hw.h" |
18 | 714fa308 | pbrook | #include "console.h" |
19 | 714fa308 | pbrook | #include "framebuffer.h" |
20 | 714fa308 | pbrook | #include "kvm.h" |
21 | 714fa308 | pbrook | |
22 | 714fa308 | pbrook | /* Render an image from a shared memory framebuffer. */
|
23 | 714fa308 | pbrook | |
24 | 714fa308 | pbrook | void framebuffer_update_display(
|
25 | 714fa308 | pbrook | DisplayState *ds, |
26 | 714fa308 | pbrook | target_phys_addr_t base, |
27 | 714fa308 | pbrook | int cols, /* Width in pixels. */ |
28 | 714fa308 | pbrook | int rows, /* Leight in pixels. */ |
29 | 714fa308 | pbrook | int src_width, /* Length of source line, in bytes. */ |
30 | 714fa308 | pbrook | int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */ |
31 | 714fa308 | pbrook | int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */ |
32 | 714fa308 | pbrook | int invalidate, /* nonzero to redraw the whole image. */ |
33 | 714fa308 | pbrook | drawfn fn, |
34 | 714fa308 | pbrook | void *opaque,
|
35 | 714fa308 | pbrook | int *first_row, /* Input and output. */ |
36 | 714fa308 | pbrook | int *last_row /* Output only */) |
37 | 714fa308 | pbrook | { |
38 | 714fa308 | pbrook | target_phys_addr_t src_len; |
39 | 714fa308 | pbrook | uint8_t *dest; |
40 | 714fa308 | pbrook | uint8_t *src; |
41 | 714fa308 | pbrook | uint8_t *src_base; |
42 | 714fa308 | pbrook | int first, last = 0; |
43 | 714fa308 | pbrook | int dirty;
|
44 | 714fa308 | pbrook | int i;
|
45 | 714fa308 | pbrook | ram_addr_t addr; |
46 | 714fa308 | pbrook | ram_addr_t pd; |
47 | 714fa308 | pbrook | ram_addr_t pd2; |
48 | 714fa308 | pbrook | |
49 | 714fa308 | pbrook | i = *first_row; |
50 | 714fa308 | pbrook | *first_row = -1;
|
51 | 714fa308 | pbrook | src_len = src_width * rows; |
52 | 714fa308 | pbrook | |
53 | 714fa308 | pbrook | if (kvm_enabled()) {
|
54 | 714fa308 | pbrook | kvm_physical_sync_dirty_bitmap(base, src_len); |
55 | 714fa308 | pbrook | } |
56 | 714fa308 | pbrook | pd = cpu_get_physical_page_desc(base); |
57 | 714fa308 | pbrook | pd2 = cpu_get_physical_page_desc(base + src_len - 1);
|
58 | 714fa308 | pbrook | /* We should reall check that this is a continuous ram region.
|
59 | 714fa308 | pbrook | Instead we just check that the first and last pages are
|
60 | 714fa308 | pbrook | both ram, and the right distance apart. */
|
61 | 714fa308 | pbrook | if ((pd & ~TARGET_PAGE_MASK) > IO_MEM_ROM
|
62 | 714fa308 | pbrook | || (pd2 & ~TARGET_PAGE_MASK) > IO_MEM_ROM) { |
63 | 714fa308 | pbrook | return;
|
64 | 714fa308 | pbrook | } |
65 | 714fa308 | pbrook | pd = (pd & TARGET_PAGE_MASK) + (base & ~TARGET_PAGE_MASK); |
66 | 714fa308 | pbrook | if (((pd + src_len - 1) & TARGET_PAGE_MASK) != (pd2 & TARGET_PAGE_MASK)) { |
67 | 714fa308 | pbrook | return;
|
68 | 714fa308 | pbrook | } |
69 | 714fa308 | pbrook | |
70 | 714fa308 | pbrook | src_base = cpu_physical_memory_map(base, &src_len, 0);
|
71 | 714fa308 | pbrook | /* If we can't map the framebuffer then bail. We could try harder,
|
72 | 714fa308 | pbrook | but it's not really worth it as dirty flag tracking will probably
|
73 | 714fa308 | pbrook | already have failed above. */
|
74 | 714fa308 | pbrook | if (!src_base)
|
75 | 714fa308 | pbrook | return;
|
76 | 714fa308 | pbrook | if (src_len != src_width * rows) {
|
77 | 714fa308 | pbrook | cpu_physical_memory_unmap(src_base, src_len, 0, 0); |
78 | 714fa308 | pbrook | return;
|
79 | 714fa308 | pbrook | } |
80 | 714fa308 | pbrook | src = src_base; |
81 | 714fa308 | pbrook | dest = ds_get_data(ds); |
82 | 714fa308 | pbrook | if (dest_col_pitch < 0) |
83 | 714fa308 | pbrook | dest -= dest_col_pitch * (cols - 1);
|
84 | 714fa308 | pbrook | first = -1;
|
85 | 714fa308 | pbrook | addr = pd; |
86 | 714fa308 | pbrook | |
87 | 714fa308 | pbrook | addr += i * src_width; |
88 | 714fa308 | pbrook | src += i * src_width; |
89 | 714fa308 | pbrook | dest += i * dest_row_pitch; |
90 | 714fa308 | pbrook | |
91 | 714fa308 | pbrook | for (; i < rows; i++) {
|
92 | 714fa308 | pbrook | target_phys_addr_t dirty_offset; |
93 | 714fa308 | pbrook | dirty = 0;
|
94 | 714fa308 | pbrook | dirty_offset = 0;
|
95 | 714fa308 | pbrook | while (addr + dirty_offset < TARGET_PAGE_ALIGN(addr + src_width)) {
|
96 | 714fa308 | pbrook | dirty |= cpu_physical_memory_get_dirty(addr + dirty_offset, |
97 | 714fa308 | pbrook | VGA_DIRTY_FLAG); |
98 | 714fa308 | pbrook | dirty_offset += TARGET_PAGE_SIZE; |
99 | 714fa308 | pbrook | } |
100 | 714fa308 | pbrook | |
101 | 714fa308 | pbrook | if (dirty || invalidate) {
|
102 | 714fa308 | pbrook | fn(opaque, dest, src, cols, dest_col_pitch); |
103 | 714fa308 | pbrook | if (first == -1) |
104 | 714fa308 | pbrook | first = i; |
105 | 714fa308 | pbrook | last = i; |
106 | 714fa308 | pbrook | } |
107 | 714fa308 | pbrook | addr += src_width; |
108 | 714fa308 | pbrook | src += src_width; |
109 | 714fa308 | pbrook | dest += dest_row_pitch; |
110 | 714fa308 | pbrook | } |
111 | 714fa308 | pbrook | cpu_physical_memory_unmap(src_base, src_len, 0, 0); |
112 | 714fa308 | pbrook | if (first < 0) { |
113 | 714fa308 | pbrook | return;
|
114 | 714fa308 | pbrook | } |
115 | 714fa308 | pbrook | cpu_physical_memory_reset_dirty(pd, pd + src_len, VGA_DIRTY_FLAG); |
116 | 714fa308 | pbrook | *first_row = first; |
117 | 714fa308 | pbrook | *last_row = last; |
118 | 714fa308 | pbrook | return;
|
119 | 714fa308 | pbrook | } |