surface.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /*
  2. * SPDX-License-Identifier: GPL-2.0-or-later
  3. * QEMU UI Console
  4. */
  5. #ifndef SURFACE_H
  6. #define SURFACE_H
  7. #include "ui/qemu-pixman.h"
  8. #ifdef CONFIG_OPENGL
  9. # include <epoxy/gl.h>
  10. # include "ui/shader.h"
  11. #endif
  12. #define QEMU_ALLOCATED_FLAG 0x01
  13. #define QEMU_PLACEHOLDER_FLAG 0x02
  14. typedef struct DisplaySurface {
  15. pixman_image_t *image;
  16. uint8_t flags;
  17. #ifdef CONFIG_OPENGL
  18. GLenum glformat;
  19. GLenum gltype;
  20. GLuint texture;
  21. #endif
  22. #ifdef WIN32
  23. HANDLE handle;
  24. uint32_t handle_offset;
  25. #endif
  26. } DisplaySurface;
  27. PixelFormat qemu_default_pixelformat(int bpp);
  28. DisplaySurface *qemu_create_displaysurface_from(int width, int height,
  29. pixman_format_code_t format,
  30. int linesize, uint8_t *data);
  31. DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
  32. DisplaySurface *qemu_create_placeholder_surface(int w, int h,
  33. const char *msg);
  34. #ifdef WIN32
  35. void qemu_displaysurface_win32_set_handle(DisplaySurface *surface,
  36. HANDLE h, uint32_t offset);
  37. #endif
  38. DisplaySurface *qemu_create_displaysurface(int width, int height);
  39. void qemu_free_displaysurface(DisplaySurface *surface);
  40. static inline int is_buffer_shared(DisplaySurface *surface)
  41. {
  42. return !(surface->flags & QEMU_ALLOCATED_FLAG);
  43. }
  44. static inline int surface_is_placeholder(DisplaySurface *surface)
  45. {
  46. return surface->flags & QEMU_PLACEHOLDER_FLAG;
  47. }
  48. static inline int surface_stride(DisplaySurface *s)
  49. {
  50. return pixman_image_get_stride(s->image);
  51. }
  52. static inline void *surface_data(DisplaySurface *s)
  53. {
  54. return pixman_image_get_data(s->image);
  55. }
  56. static inline int surface_width(DisplaySurface *s)
  57. {
  58. return pixman_image_get_width(s->image);
  59. }
  60. static inline int surface_height(DisplaySurface *s)
  61. {
  62. return pixman_image_get_height(s->image);
  63. }
  64. static inline pixman_format_code_t surface_format(DisplaySurface *s)
  65. {
  66. return pixman_image_get_format(s->image);
  67. }
  68. static inline int surface_bits_per_pixel(DisplaySurface *s)
  69. {
  70. int bits = PIXMAN_FORMAT_BPP(surface_format(s));
  71. return bits;
  72. }
  73. static inline int surface_bytes_per_pixel(DisplaySurface *s)
  74. {
  75. int bits = PIXMAN_FORMAT_BPP(surface_format(s));
  76. return DIV_ROUND_UP(bits, 8);
  77. }
  78. #endif