2 * Framebuffer device helper routines
4 * Copyright (c) 2009 CodeSourcery
5 * Written by Paul Brook <paul@codesourcery.com>
7 * This code is licensed under the GNU GPLv2.
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.
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.
21 #include "ui/console.h"
22 #include "framebuffer.h"
24 /* Render an image from a shared memory framebuffer. */
26 void framebuffer_update_display(
28 MemoryRegion
*address_space
,
30 int cols
, /* Width in pixels. */
31 int rows
, /* Height in pixels. */
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. */
38 int *first_row
, /* Input and output. */
39 int *last_row
/* Output only */)
49 MemoryRegionSection mem_section
;
54 src_len
= src_width
* rows
;
56 mem_section
= memory_region_find(address_space
, base
, src_len
);
57 if (mem_section
.size
!= src_len
|| !memory_region_is_ram(mem_section
.mr
)) {
62 assert(mem_section
.offset_within_address_space
== base
);
64 memory_region_sync_dirty_bitmap(mem
);
65 src_base
= cpu_physical_memory_map(base
, &src_len
, 0);
66 /* If we can't map the framebuffer then bail. We could try harder,
67 but it's not really worth it as dirty flag tracking will probably
68 already have failed above. */
71 if (src_len
!= src_width
* rows
) {
72 cpu_physical_memory_unmap(src_base
, src_len
, 0, 0);
76 dest
= surface_data(ds
);
77 if (dest_col_pitch
< 0)
78 dest
-= dest_col_pitch
* (cols
- 1);
79 if (dest_row_pitch
< 0) {
80 dest
-= dest_row_pitch
* (rows
- 1);
83 addr
= mem_section
.offset_within_region
;
85 addr
+= i
* src_width
;
87 dest
+= i
* dest_row_pitch
;
89 for (; i
< rows
; i
++) {
90 dirty
= memory_region_get_dirty(mem
, addr
, src_width
,
92 if (dirty
|| invalidate
) {
93 fn(opaque
, dest
, src
, cols
, dest_col_pitch
);
100 dest
+= dest_row_pitch
;
102 cpu_physical_memory_unmap(src_base
, src_len
, 0, 0);
106 memory_region_reset_dirty(mem
, mem_section
.offset_within_region
, src_len
,