2
0

framebuffer.c 3.3 KB

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