]> git.proxmox.com Git - qemu.git/blame - hw/display/framebuffer.c
Merge git://github.com/hw-claudio/qemu-aarch64-queue into tcg-next
[qemu.git] / hw / display / 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.
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
83c9f4ca 20#include "hw/hw.h"
28ecbaee 21#include "ui/console.h"
47b43a1f 22#include "framebuffer.h"
714fa308
PB
23
24/* Render an image from a shared memory framebuffer. */
25
26void framebuffer_update_display(
c78f7137 27 DisplaySurface *ds,
75c9d6c2 28 MemoryRegion *address_space,
a8170e5e 29 hwaddr base,
714fa308 30 int cols, /* Width in pixels. */
9c6bb55b 31 int rows, /* Height in pixels. */
714fa308
PB
32 int src_width, /* Length of source line, in bytes. */
33 int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */
34 int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */
35 int invalidate, /* nonzero to redraw the whole image. */
36 drawfn fn,
37 void *opaque,
38 int *first_row, /* Input and output. */
39 int *last_row /* Output only */)
40{
a8170e5e 41 hwaddr src_len;
714fa308
PB
42 uint8_t *dest;
43 uint8_t *src;
44 uint8_t *src_base;
45 int first, last = 0;
46 int dirty;
47 int i;
c227f099 48 ram_addr_t addr;
75c9d6c2
AK
49 MemoryRegionSection mem_section;
50 MemoryRegion *mem;
714fa308
PB
51
52 i = *first_row;
53 *first_row = -1;
54 src_len = src_width * rows;
55
75c9d6c2 56 mem_section = memory_region_find(address_space, base, src_len);
dfde4e6e 57 mem = mem_section.mr;
052e87b0
PB
58 if (int128_get64(mem_section.size) != src_len ||
59 !memory_region_is_ram(mem_section.mr)) {
dfde4e6e 60 goto out;
714fa308 61 }
75c9d6c2
AK
62 assert(mem);
63 assert(mem_section.offset_within_address_space == base);
714fa308 64
c1cd0b2c 65 memory_region_sync_dirty_bitmap(mem);
714fa308
PB
66 src_base = cpu_physical_memory_map(base, &src_len, 0);
67 /* If we can't map the framebuffer then bail. We could try harder,
68 but it's not really worth it as dirty flag tracking will probably
69 already have failed above. */
70 if (!src_base)
dfde4e6e 71 goto out;
714fa308
PB
72 if (src_len != src_width * rows) {
73 cpu_physical_memory_unmap(src_base, src_len, 0, 0);
dfde4e6e 74 goto out;
714fa308
PB
75 }
76 src = src_base;
c78f7137 77 dest = surface_data(ds);
714fa308
PB
78 if (dest_col_pitch < 0)
79 dest -= dest_col_pitch * (cols - 1);
9312805d
VK
80 if (dest_row_pitch < 0) {
81 dest -= dest_row_pitch * (rows - 1);
82 }
714fa308 83 first = -1;
75c9d6c2 84 addr = mem_section.offset_within_region;
714fa308
PB
85
86 addr += i * src_width;
87 src += i * src_width;
88 dest += i * dest_row_pitch;
89
90 for (; i < rows; i++) {
d1f3dd34 91 dirty = memory_region_get_dirty(mem, addr, src_width,
75c9d6c2 92 DIRTY_MEMORY_VGA);
714fa308
PB
93 if (dirty || invalidate) {
94 fn(opaque, dest, src, cols, dest_col_pitch);
95 if (first == -1)
96 first = i;
97 last = i;
98 }
99 addr += src_width;
100 src += src_width;
101 dest += dest_row_pitch;
102 }
103 cpu_physical_memory_unmap(src_base, src_len, 0, 0);
104 if (first < 0) {
dfde4e6e 105 goto out;
714fa308 106 }
75c9d6c2
AK
107 memory_region_reset_dirty(mem, mem_section.offset_within_region, src_len,
108 DIRTY_MEMORY_VGA);
714fa308
PB
109 *first_row = first;
110 *last_row = last;
dfde4e6e
PB
111out:
112 memory_region_unref(mem);
714fa308 113}