surface.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. bool glswapped;
  22. #endif
  23. qemu_pixman_shareable share_handle;
  24. uint32_t share_handle_offset;
  25. } DisplaySurface;
  26. PixelFormat qemu_default_pixelformat(int bpp);
  27. DisplaySurface *qemu_create_displaysurface_from(int width, int height,
  28. pixman_format_code_t format,
  29. int linesize, uint8_t *data);
  30. DisplaySurface *qemu_create_displaysurface_pixman(pixman_image_t *image);
  31. DisplaySurface *qemu_create_placeholder_surface(int w, int h,
  32. const char *msg);
  33. void qemu_displaysurface_set_share_handle(DisplaySurface *surface,
  34. qemu_pixman_shareable handle,
  35. uint32_t offset);
  36. DisplaySurface *qemu_create_displaysurface(int width, int height);
  37. void qemu_free_displaysurface(DisplaySurface *surface);
  38. static inline int surface_is_allocated(DisplaySurface *surface)
  39. {
  40. return surface->flags & QEMU_ALLOCATED_FLAG;
  41. }
  42. static inline int surface_is_placeholder(DisplaySurface *surface)
  43. {
  44. return surface->flags & QEMU_PLACEHOLDER_FLAG;
  45. }
  46. static inline int surface_stride(DisplaySurface *s)
  47. {
  48. return pixman_image_get_stride(s->image);
  49. }
  50. static inline void *surface_data(DisplaySurface *s)
  51. {
  52. return pixman_image_get_data(s->image);
  53. }
  54. static inline int surface_width(DisplaySurface *s)
  55. {
  56. return pixman_image_get_width(s->image);
  57. }
  58. static inline int surface_height(DisplaySurface *s)
  59. {
  60. return pixman_image_get_height(s->image);
  61. }
  62. static inline pixman_format_code_t surface_format(DisplaySurface *s)
  63. {
  64. return pixman_image_get_format(s->image);
  65. }
  66. static inline int surface_bits_per_pixel(DisplaySurface *s)
  67. {
  68. int bits = PIXMAN_FORMAT_BPP(surface_format(s));
  69. return bits;
  70. }
  71. static inline int surface_bytes_per_pixel(DisplaySurface *s)
  72. {
  73. int bits = PIXMAN_FORMAT_BPP(surface_format(s));
  74. return DIV_ROUND_UP(bits, 8);
  75. }
  76. #endif