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 void framebuffer_update_memory_section(
25 MemoryRegionSection
*mem_section
,
31 hwaddr src_len
= (hwaddr
)rows
* src_width
;
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
;
39 *mem_section
= memory_region_find(root
, base
, src_len
);
40 if (!mem_section
->mr
) {
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
;
51 memory_region_set_log(mem_section
->mr
, true, DIRTY_MEMORY_VGA
);
54 /* Render an image from a shared memory framebuffer. */
55 void framebuffer_update_display(
57 MemoryRegionSection
*mem_section
,
58 int cols
, /* Width in pixels. */
59 int rows
, /* Height in pixels. */
60 int src_width
, /* Length of source line, in bytes. */
61 int dest_row_pitch
, /* Bytes between adjacent horizontal output pixels. */
62 int dest_col_pitch
, /* Bytes between adjacent vertical output pixels. */
63 int invalidate
, /* nonzero to redraw the whole image. */
66 int *first_row
, /* Input and output. */
67 int *last_row
/* Output only */)
80 src_len
= src_width
* rows
;
82 mem
= mem_section
->mr
;
86 memory_region_sync_dirty_bitmap(mem
);
88 addr
= mem_section
->offset_within_region
;
89 src
= memory_region_get_ram_ptr(mem
) + addr
;
91 dest
= surface_data(ds
);
92 if (dest_col_pitch
< 0) {
93 dest
-= dest_col_pitch
* (cols
- 1);
95 if (dest_row_pitch
< 0) {
96 dest
-= dest_row_pitch
* (rows
- 1);
100 addr
+= i
* src_width
;
101 src
+= i
* src_width
;
102 dest
+= i
* dest_row_pitch
;
104 for (; i
< rows
; i
++) {
105 dirty
= memory_region_get_dirty(mem
, addr
, src_width
,
107 if (dirty
|| invalidate
) {
108 fn(opaque
, dest
, src
, cols
, dest_col_pitch
);
115 dest
+= dest_row_pitch
;
120 memory_region_reset_dirty(mem
, mem_section
->offset_within_region
, src_len
,