| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Framebuffer device helper routines | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (c) 2009 CodeSourcery | 
					
						
							|  |  |  |  * Written by Paul Brook <paul@codesourcery.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * This code is licensed under the GNU GPLv2. | 
					
						
							| 
									
										
										
										
											2012-01-13 17:44:23 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Contributions after 2012-01-13 are licensed under the terms of the | 
					
						
							|  |  |  |  * GNU GPL, version 2 or (at your option) any later version. | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* TODO:
 | 
					
						
							|  |  |  |    - Do something similar for framebuffers with local ram | 
					
						
							|  |  |  |    - Handle rotation here instead of hacking dest_pitch | 
					
						
							|  |  |  |    - Use common pixel conversion routines instead of per-device drawfn | 
					
						
							|  |  |  |    - Remove all DisplayState knowledge from devices. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-26 18:17:13 +00:00
										 |  |  | #include "qemu/osdep.h"
 | 
					
						
							| 
									
										
										
										
											2012-11-28 12:06:30 +01:00
										 |  |  | #include "ui/console.h"
 | 
					
						
							| 
									
										
										
										
											2013-03-18 17:36:02 +01:00
										 |  |  | #include "framebuffer.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  | void framebuffer_update_memory_section( | 
					
						
							|  |  |  |     MemoryRegionSection *mem_section, | 
					
						
							|  |  |  |     MemoryRegion *root, | 
					
						
							|  |  |  |     hwaddr base, | 
					
						
							|  |  |  |     unsigned rows, | 
					
						
							|  |  |  |     unsigned src_width) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     hwaddr src_len = (hwaddr)rows * src_width; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (mem_section->mr) { | 
					
						
							|  |  |  |         memory_region_set_log(mem_section->mr, false, DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  |         memory_region_unref(mem_section->mr); | 
					
						
							|  |  |  |         mem_section->mr = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     *mem_section = memory_region_find(root, base, src_len); | 
					
						
							|  |  |  |     if (!mem_section->mr) { | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (int128_get64(mem_section->size) < src_len || | 
					
						
							|  |  |  |             !memory_region_is_ram(mem_section->mr)) { | 
					
						
							|  |  |  |         memory_region_unref(mem_section->mr); | 
					
						
							|  |  |  |         mem_section->mr = NULL; | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     memory_region_set_log(mem_section->mr, true, DIRTY_MEMORY_VGA); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  | /* Render an image from a shared memory framebuffer.  */ | 
					
						
							|  |  |  | void framebuffer_update_display( | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     DisplaySurface *ds, | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |     MemoryRegionSection *mem_section, | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     int cols, /* Width in pixels.  */ | 
					
						
							| 
									
										
										
										
											2012-08-11 21:32:02 +02:00
										 |  |  |     int rows, /* Height in pixels.  */ | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     int src_width, /* Length of source line, in bytes.  */ | 
					
						
							|  |  |  |     int dest_row_pitch, /* Bytes between adjacent horizontal output pixels.  */ | 
					
						
							|  |  |  |     int dest_col_pitch, /* Bytes between adjacent vertical output pixels.  */ | 
					
						
							|  |  |  |     int invalidate, /* nonzero to redraw the whole image.  */ | 
					
						
							|  |  |  |     drawfn fn, | 
					
						
							|  |  |  |     void *opaque, | 
					
						
							|  |  |  |     int *first_row, /* Input and output.  */ | 
					
						
							|  |  |  |     int *last_row /* Output only */) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-04-21 11:16:28 +02:00
										 |  |  |     DirtyBitmapSnapshot *snap; | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     uint8_t *dest; | 
					
						
							|  |  |  |     uint8_t *src; | 
					
						
							|  |  |  |     int first, last = 0; | 
					
						
							|  |  |  |     int dirty; | 
					
						
							|  |  |  |     int i; | 
					
						
							| 
									
										
										
										
											2009-10-01 16:12:16 -05:00
										 |  |  |     ram_addr_t addr; | 
					
						
							| 
									
										
										
										
											2011-12-08 16:00:54 +02:00
										 |  |  |     MemoryRegion *mem; | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     i = *first_row; | 
					
						
							|  |  |  |     *first_row = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |     mem = mem_section->mr; | 
					
						
							|  |  |  |     if (!mem) { | 
					
						
							|  |  |  |         return; | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2015-03-23 10:46:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |     addr = mem_section->offset_within_region; | 
					
						
							|  |  |  |     src = memory_region_get_ram_ptr(mem) + addr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-05 15:24:14 +01:00
										 |  |  |     dest = surface_data(ds); | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |     if (dest_col_pitch < 0) { | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |         dest -= dest_col_pitch * (cols - 1); | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |     } | 
					
						
							| 
									
										
										
										
											2011-06-17 13:04:36 +03:00
										 |  |  |     if (dest_row_pitch < 0) { | 
					
						
							|  |  |  |         dest -= dest_row_pitch * (rows - 1); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     first = -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     addr += i * src_width; | 
					
						
							|  |  |  |     src += i * src_width; | 
					
						
							|  |  |  |     dest += i * dest_row_pitch; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-21 11:16:28 +02:00
										 |  |  |     snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows, | 
					
						
							|  |  |  |                                                   DIRTY_MEMORY_VGA); | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     for (; i < rows; i++) { | 
					
						
							| 
									
										
										
										
											2017-04-21 11:16:28 +02:00
										 |  |  |         dirty = memory_region_snapshot_get_dirty(mem, snap, addr, src_width); | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |         if (dirty || invalidate) { | 
					
						
							|  |  |  |             fn(opaque, dest, src, cols, dest_col_pitch); | 
					
						
							|  |  |  |             if (first == -1) | 
					
						
							|  |  |  |                 first = i; | 
					
						
							|  |  |  |             last = i; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |         addr += src_width; | 
					
						
							|  |  |  |         src += src_width; | 
					
						
							|  |  |  |         dest += dest_row_pitch; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2017-04-21 11:16:28 +02:00
										 |  |  |     g_free(snap); | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     if (first < 0) { | 
					
						
							| 
									
										
										
										
											2015-07-13 12:00:29 +02:00
										 |  |  |         return; | 
					
						
							| 
									
										
										
										
											2009-04-01 12:27:59 +00:00
										 |  |  |     } | 
					
						
							|  |  |  |     *first_row = first; | 
					
						
							|  |  |  |     *last_row = last; | 
					
						
							|  |  |  | } |