1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "hw/hw.h"
22#include "ui/console.h"
23#include "framebuffer.h"
24
25void 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
55
56void framebuffer_update_display(
57 DisplaySurface *ds,
58 MemoryRegionSection *mem_section,
59 int cols,
60 int rows,
61 int src_width,
62 int dest_row_pitch,
63 int dest_col_pitch,
64 int invalidate,
65 drawfn fn,
66 void *opaque,
67 int *first_row,
68 int *last_row )
69{
70 hwaddr src_len;
71 uint8_t *dest;
72 uint8_t *src;
73 int first, last = 0;
74 int dirty;
75 int i;
76 ram_addr_t addr;
77 MemoryRegion *mem;
78
79 i = *first_row;
80 *first_row = -1;
81 src_len = src_width * rows;
82
83 mem = mem_section->mr;
84 if (!mem) {
85 return;
86 }
87 memory_region_sync_dirty_bitmap(mem);
88
89 addr = mem_section->offset_within_region;
90 src = memory_region_get_ram_ptr(mem) + addr;
91
92 dest = surface_data(ds);
93 if (dest_col_pitch < 0) {
94 dest -= dest_col_pitch * (cols - 1);
95 }
96 if (dest_row_pitch < 0) {
97 dest -= dest_row_pitch * (rows - 1);
98 }
99 first = -1;
100
101 addr += i * src_width;
102 src += i * src_width;
103 dest += i * dest_row_pitch;
104
105 for (; i < rows; i++) {
106 dirty = memory_region_get_dirty(mem, addr, src_width,
107 DIRTY_MEMORY_VGA);
108 if (dirty || invalidate) {
109 fn(opaque, dest, src, cols, dest_col_pitch);
110 if (first == -1)
111 first = i;
112 last = i;
113 }
114 addr += src_width;
115 src += src_width;
116 dest += dest_row_pitch;
117 }
118 if (first < 0) {
119 return;
120 }
121 memory_region_reset_dirty(mem, mem_section->offset_within_region, src_len,
122 DIRTY_MEMORY_VGA);
123 *first_row = first;
124 *last_row = last;
125}
126