2
0

framebuffer.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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.
  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.
  11. */
  12. /* TODO:
  13. - Do something similar for framebuffers with local ram
  14. - Handle rotation here instead of hacking dest_pitch
  15. - Use common pixel conversion routines instead of per-device drawfn
  16. - Remove all DisplayState knowledge from devices.
  17. */
  18. #include "qemu/osdep.h"
  19. #include "ui/console.h"
  20. #include "framebuffer.h"
  21. void framebuffer_update_memory_section(
  22. MemoryRegionSection *mem_section,
  23. MemoryRegion *root,
  24. hwaddr base,
  25. unsigned rows,
  26. unsigned src_width)
  27. {
  28. hwaddr src_len = (hwaddr)rows * src_width;
  29. if (mem_section->mr) {
  30. memory_region_set_log(mem_section->mr, false, DIRTY_MEMORY_VGA);
  31. memory_region_unref(mem_section->mr);
  32. mem_section->mr = NULL;
  33. }
  34. *mem_section = memory_region_find(root, base, src_len);
  35. if (!mem_section->mr) {
  36. return;
  37. }
  38. if (int128_get64(mem_section->size) < src_len ||
  39. !memory_region_is_ram(mem_section->mr)) {
  40. memory_region_unref(mem_section->mr);
  41. mem_section->mr = NULL;
  42. return;
  43. }
  44. memory_region_set_log(mem_section->mr, true, DIRTY_MEMORY_VGA);
  45. }
  46. /* Render an image from a shared memory framebuffer. */
  47. void framebuffer_update_display(
  48. DisplaySurface *ds,
  49. MemoryRegionSection *mem_section,
  50. int cols, /* Width in pixels. */
  51. int rows, /* Height in pixels. */
  52. int src_width, /* Length of source line, in bytes. */
  53. int dest_row_pitch, /* Bytes between adjacent horizontal output pixels. */
  54. int dest_col_pitch, /* Bytes between adjacent vertical output pixels. */
  55. int invalidate, /* nonzero to redraw the whole image. */
  56. drawfn fn,
  57. void *opaque,
  58. int *first_row, /* Input and output. */
  59. int *last_row /* Output only */)
  60. {
  61. DirtyBitmapSnapshot *snap;
  62. uint8_t *dest;
  63. uint8_t *src;
  64. int first, last = 0;
  65. int dirty;
  66. int i;
  67. ram_addr_t addr;
  68. MemoryRegion *mem;
  69. i = *first_row;
  70. *first_row = -1;
  71. mem = mem_section->mr;
  72. if (!mem) {
  73. return;
  74. }
  75. addr = mem_section->offset_within_region;
  76. src = memory_region_get_ram_ptr(mem) + addr;
  77. dest = surface_data(ds);
  78. if (dest_col_pitch < 0) {
  79. dest -= dest_col_pitch * (cols - 1);
  80. }
  81. if (dest_row_pitch < 0) {
  82. dest -= dest_row_pitch * (rows - 1);
  83. }
  84. first = -1;
  85. addr += i * src_width;
  86. src += i * src_width;
  87. dest += i * dest_row_pitch;
  88. snap = memory_region_snapshot_and_clear_dirty(mem, addr, src_width * rows,
  89. DIRTY_MEMORY_VGA);
  90. for (; i < rows; i++) {
  91. dirty = memory_region_snapshot_get_dirty(mem, snap, addr, src_width);
  92. if (dirty || invalidate) {
  93. fn(opaque, dest, src, cols, dest_col_pitch);
  94. if (first == -1)
  95. first = i;
  96. last = i;
  97. }
  98. addr += src_width;
  99. src += src_width;
  100. dest += dest_row_pitch;
  101. }
  102. g_free(snap);
  103. if (first < 0) {
  104. return;
  105. }
  106. *first_row = first;
  107. *last_row = last;
  108. }