]>
Commit | Line | Data |
---|---|---|
714fa308 PB |
1 | /* |
2 | * Framebuffer device helper routines | |
3 | * | |
4 | * Copyright (c) 2009 CodeSourcery | |
5 | * Written by Paul Brook <[email protected]> | |
6 | * | |
7 | * This code is licensed under the GNU GPLv2. | |
6b620ca3 PB |
8 | * |
9 | * Contributions after 2012-01-13 are licensed under the terms of the | |
10 | * GNU GPL, version 2 or (at your option) any later version. | |
714fa308 PB |
11 | */ |
12 | ||
13 | /* TODO: | |
14 | - Do something similar for framebuffers with local ram | |
15 | - Handle rotation here instead of hacking dest_pitch | |
16 | - Use common pixel conversion routines instead of per-device drawfn | |
17 | - Remove all DisplayState knowledge from devices. | |
18 | */ | |
19 | ||
47df5154 | 20 | #include "qemu/osdep.h" |
83c9f4ca | 21 | #include "hw/hw.h" |
28ecbaee | 22 | #include "ui/console.h" |
47b43a1f | 23 | #include "framebuffer.h" |
714fa308 | 24 | |
c1076c3e PB |
25 | void framebuffer_update_memory_section( |
26 | MemoryRegionSection *mem_section, | |
27 | MemoryRegion *root, | |
28 | hwaddr base, | |
29 | unsigned rows, | |
30 | unsigned src_width) | |
31 | { | |
32 | hwaddr src_len = (hwaddr)rows * src_width; | |
33 | ||
34 | if (mem_section->mr) { | |
35 | memory_region_set_log(mem_section->mr, false, DIRTY_MEMORY_VGA); | |
36 | memory_region_unref(mem_section->mr); | |
37 | mem_section->mr = NULL; | |
38 | } | |
39 | ||
40 | *mem_section = memory_region_find(root, base, src_len); | |
41 | if (!mem_section->mr) { | |
42 | return; | |
43 | } | |
44 | ||
45 | if (int128_get64(mem_section->size) < src_len || | |
46 | !memory_region_is_ram(mem_section->mr)) { | |
47 | memory_region_unref(mem_section->mr); | |
48 | mem_section->mr = NULL; | |
49 | return; | |
50 | } | |
51 | ||
52 | memory_region_set_log(mem_section->mr, true, DIRTY_MEMORY_VGA); | |
53 | } | |
54 | ||
714fa308 | 55 | /* Render an image from a shared memory framebuffer. */ |
714fa308 | 56 | void framebuffer_update_display( |
c78f7137 | 57 | DisplaySurface *ds, |
c1076c3e | 58 | MemoryRegionSection *mem_section, |
714fa308 | 59 | int cols, /* Width in pixels. */ |
9c6bb55b | 60 | int rows, /* Height in pixels. */ |
714fa308 PB |
61 | int src_width, /* Length of source line, in bytes. */ |
62 | int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */ | |
63 | int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */ | |
64 | int invalidate, /* nonzero to redraw the whole image. */ | |
65 | drawfn fn, | |
66 | void *opaque, | |
67 | int *first_row, /* Input and output. */ | |
68 | int *last_row /* Output only */) | |
69 | { | |
167e9c79 | 70 | DirtyBitmapSnapshot *snap; |
714fa308 PB |
71 | uint8_t *dest; |
72 | uint8_t *src; | |
714fa308 PB |
73 | int first, last = 0; |
74 | int dirty; | |
75 | int i; | |
c227f099 | 76 | ram_addr_t addr; |
75c9d6c2 | 77 | MemoryRegion *mem; |
714fa308 PB |
78 | |
79 | i = *first_row; | |
80 | *first_row = -1; | |
714fa308 | 81 | |
c1076c3e PB |
82 | mem = mem_section->mr; |
83 | if (!mem) { | |
84 | return; | |
714fa308 | 85 | } |
d55d4207 | 86 | |
c1076c3e PB |
87 | addr = mem_section->offset_within_region; |
88 | src = memory_region_get_ram_ptr(mem) + addr; | |
89 | ||
c78f7137 | 90 | dest = surface_data(ds); |
c1076c3e | 91 | if (dest_col_pitch < 0) { |
714fa308 | 92 | dest -= dest_col_pitch * (cols - 1); |
c1076c3e | 93 | } |
9312805d VK |
94 | if (dest_row_pitch < 0) { |
95 | dest -= dest_row_pitch * (rows - 1); | |
96 | } | |
714fa308 | 97 | first = -1; |
714fa308 PB |
98 | |
99 | addr += i * src_width; | |
100 | src += i * src_width; | |
101 | dest += i * dest_row_pitch; | |
102 | ||
167e9c79 GH |
103 | snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows, |
104 | DIRTY_MEMORY_VGA); | |
714fa308 | 105 | for (; i < rows; i++) { |
167e9c79 | 106 | dirty = memory_region_snapshot_get_dirty(mem, snap, addr, src_width); |
714fa308 PB |
107 | if (dirty || invalidate) { |
108 | fn(opaque, dest, src, cols, dest_col_pitch); | |
109 | if (first == -1) | |
110 | first = i; | |
111 | last = i; | |
112 | } | |
113 | addr += src_width; | |
114 | src += src_width; | |
115 | dest += dest_row_pitch; | |
116 | } | |
167e9c79 | 117 | g_free(snap); |
714fa308 | 118 | if (first < 0) { |
c1076c3e | 119 | return; |
714fa308 | 120 | } |
714fa308 PB |
121 | *first_row = first; |
122 | *last_row = last; | |
714fa308 | 123 | } |