qp_surface.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2022 Nick Brassel (@tzarc)
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include "qp_internal.h"
  5. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. // Quantum Painter surface helpers
  7. // Helper for determining buffer size required for a surface
  8. #define SURFACE_REQUIRED_BUFFER_BYTE_SIZE(w, h, bpp) ((((w) * (h) * (bpp)) + 7) / 8)
  9. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. // Quantum Painter surface configurables (add to your keyboard's config.h)
  11. #ifndef SURFACE_NUM_DEVICES
  12. /**
  13. * @def This controls the maximum number of surface devices that Quantum Painter can use at any one time.
  14. * Increasing this number allows for multiple framebuffers to be used. Each requires its own RAM allocation.
  15. */
  16. # define SURFACE_NUM_DEVICES 1
  17. #endif
  18. ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  19. // Forward declarations
  20. #ifdef QUANTUM_PAINTER_SURFACE_ENABLE
  21. // Surface struct
  22. struct surface_painter_device_t;
  23. typedef struct surface_painter_device_t surface_painter_device_t;
  24. /**
  25. * Factory method for an RGB565 surface (aka framebuffer).
  26. *
  27. * @param panel_width[in] the width of the display panel
  28. * @param panel_height[in] the height of the display panel
  29. * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
  30. * @return the device handle used with all drawing routines in Quantum Painter
  31. */
  32. painter_device_t qp_make_rgb565_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
  33. /**
  34. * Factory method for a 1bpp monochrome surface (aka framebuffer).
  35. *
  36. * @param panel_width[in] the width of the display panel
  37. * @param panel_height[in] the height of the display panel
  38. * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 1)`
  39. * @return the device handle used with all drawing routines in Quantum Painter
  40. */
  41. painter_device_t qp_make_mono1bpp_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
  42. /**
  43. * Factory method for an RGB888 surface (aka framebuffer).
  44. *
  45. * @param panel_width[in] the width of the display panel
  46. * @param panel_height[in] the height of the display panel
  47. * @param buffer[in] pointer to a preallocated uint8_t buffer of size `SURFACE_REQUIRED_BUFFER_BYTE_SIZE(panel_width, panel_height, 16)`
  48. * @return the device handle used with all drawing routines in Quantum Painter
  49. */
  50. painter_device_t qp_make_rgb888_surface(uint16_t panel_width, uint16_t panel_height, void *buffer);
  51. /**
  52. * Helper method to draw the contents of the framebuffer to the target device.
  53. *
  54. * After successful completion, the dirty area is reset.
  55. *
  56. * @param surface[in] the surface to copy from
  57. * @param target[in] the target device to copy into
  58. * @param x[in] the x-location of the original position of the framebuffer
  59. * @param y[in] the y-location of the original position of the framebuffer
  60. * @param entire_surface[in] whether the entire surface should be drawn, instead of just the dirty region
  61. * @return whether the draw operation completed successfully
  62. */
  63. bool qp_surface_draw(painter_device_t surface, painter_device_t target, uint16_t x, uint16_t y, bool entire_surface);
  64. #endif // QUANTUM_PAINTER_SURFACE_ENABLE