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 "ui/console.h"
22#include "framebuffer.h"
23
24void framebuffer_update_memory_section(
25 MemoryRegionSection *mem_section,
26 MemoryRegion *root,
27 hwaddr base,
28 unsigned rows,
29 unsigned src_width)
30{
31 hwaddr src_len = (hwaddr)rows * src_width;
32
33 if (mem_section->mr) {
34 memory_region_set_log(mem_section->mr, false, DIRTY_MEMORY_VGA);
35 memory_region_unref(mem_section->mr);
36 mem_section->mr = NULL;
37 }
38
39 *mem_section = memory_region_find(root, base, src_len);
40 if (!mem_section->mr) {
41 return;
42 }
43
44 if (int128_get64(mem_section->size) < src_len ||
45 !memory_region_is_ram(mem_section->mr)) {
46 memory_region_unref(mem_section->mr);
47 mem_section->mr = NULL;
48 return;
49 }
50
51 memory_region_set_log(mem_section->mr, true, DIRTY_MEMORY_VGA);
52}
53
54
55void framebuffer_update_display(
56 DisplaySurface *ds,
57 MemoryRegionSection *mem_section,
58 int cols,
59 int rows,
60 int src_width,
61 int dest_row_pitch,
62 int dest_col_pitch,
63 int invalidate,
64 drawfn fn,
65 void *opaque,
66 int *first_row,
67 int *last_row )
68{
69 DirtyBitmapSnapshot *snap;
70 uint8_t *dest;
71 uint8_t *src;
72 int first, last = 0;
73 int dirty;
74 int i;
75 ram_addr_t addr;
76 MemoryRegion *mem;
77
78 i = *first_row;
79 *first_row = -1;
80
81 mem = mem_section->mr;
82 if (!mem) {
83 return;
84 }
85
86 addr = mem_section->offset_within_region;
87 src = memory_region_get_ram_ptr(mem) + addr;
88
89 dest = surface_data(ds);
90 if (dest_col_pitch < 0) {
91 dest -= dest_col_pitch * (cols - 1);
92 }
93 if (dest_row_pitch < 0) {
94 dest -= dest_row_pitch * (rows - 1);
95 }
96 first = -1;
97
98 addr += i * src_width;
99 src += i * src_width;
100 dest += i * dest_row_pitch;
101
102 snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows,
103 DIRTY_MEMORY_VGA);
104 for (; i < rows; i++) {
105 dirty = memory_region_snapshot_get_dirty(mem, snap, addr, src_width);
106 if (dirty || invalidate) {
107 fn(opaque, dest, src, cols, dest_col_pitch);
108 if (first == -1)
109 first = i;
110 last = i;
111 }
112 addr += src_width;
113 src += src_width;
114 dest += dest_row_pitch;
115 }
116 g_free(snap);
117 if (first < 0) {
118 return;
119 }
120 *first_row = first;
121 *last_row = last;
122}
123