Actual source code: sdl3impl.h

  1: /*
  2:    Defines the internal data structures for the SDL3
  3:    implementation of the graphics functionality in PETSc.
  4: */

  6: #pragma once
  7: #include <petsc/private/drawimpl.h>

  9: #include <SDL3/SDL.h>
 10: #include <SDL3_ttf/SDL_ttf.h>

 12: /*
 13:   Each MPI process draws on its own offscreen surface. Cleared pixels are white with zero alpha. Drawn pixels have
 14:   nonzero alpha, so an MPI_MAX reduction of the ARGB8888 pixel values combines the images of all processes.
 15:   The first process displays the combined image in its window.
 16: */
 17: typedef struct {
 18:   SDL_Window     *win;       // window, only on the first process of a draw that is not virtual
 19:   SDL_Renderer   *wrenderer; // renderer of the window
 20:   SDL_Texture    *display;   // texture holding the combined image displayed in the window
 21:   unsigned int   *image;     // combined image of all processes, only on the first process
 22:   SDL_Surface    *surface;   // offscreen surface this process draws on
 23:   unsigned int   *pixels;    // ARGB8888 pixel storage of surface, w*h contiguous values
 24:   SDL_Renderer   *renderer;  // software renderer targeting surface
 25:   SDL_Texture    *palette;   // PETSC_DRAW_MAXCOLOR x 1 colormap texture, for interpolating colors in colormap index space
 26:   TTF_TextEngine *engine;    // text engine associated with renderer
 27:   TTF_Font       *font;      // current font
 28:   int             font_w, font_h;
 29:   int             font_descent;
 30:   unsigned char   cpalette[PETSC_DRAW_MAXCOLOR][3]; // map color -> RGB value
 31:   int             x, y, w, h;                       // location and size of window
 32:   PetscBool       isvirtual;                        // no window, the combined image is only available with PetscDrawGetImage_SDL3()
 33:   PetscBool       shared;                           // surface, renderer, and window are shared with the parent of a singleton
 34:   PetscBool       ownfont;                          // font was opened by this draw, which must close it
 35:   PetscBool       drawn;                            // this process drew on surface since it was last cleared completely
 36:   PetscBool      *pdrawn;                           // where drawing is recorded, drawn of the parent for a singleton
 37: } PetscDraw_SDL3;

 39: #if PetscDefined(USE_DEBUG)
 40:   #define PetscDrawSDL3ValidColor(sdl, color) PetscCheck((color) >= 0 && (color) < PETSC_DRAW_MAXCOLOR, PETSC_COMM_SELF, PETSC_ERR_ARG_OUTOFRANGE, "Color value %d out of range [0..%d]", color, PETSC_DRAW_MAXCOLOR - 1)
 41: #else
 42:   #define PetscDrawSDL3ValidColor(sdl, color) \
 43:     do { \
 44:     } while (0)
 45: #endif

 47: // record that this process drew, so PetscDrawSDL3Combine() must include its surface
 48: #define PetscDrawSDL3MarkDrawn(sdl) (*(sdl)->pdrawn = PETSC_TRUE)

 50: #define PetscDrawSDL3SetColor(sdl, color) \
 51:   do { \
 52:     PetscDrawSDL3ValidColor(sdl, color); \
 53:     (void)SDL_SetRenderDrawColor((sdl)->renderer, (sdl)->cpalette[(color)][0], (sdl)->cpalette[(color)][1], (sdl)->cpalette[(color)][2], SDL_ALPHA_OPAQUE); \
 54:   } while (0)

 56: PETSC_INTERN PetscErrorCode PetscDrawSDL3SetUpColormap(PetscDraw_SDL3 *);
 57: PETSC_INTERN PetscErrorCode PetscDrawSDL3OpenWindow(PetscDraw_SDL3 *, const char[], int, int, int, int);
 58: PETSC_INTERN PetscErrorCode PetscDrawSDL3CreateDisplay(PetscDraw_SDL3 *);
 59: PETSC_INTERN PetscErrorCode PetscDrawSDL3OpenSurface(PetscDraw_SDL3 *, int, int);
 60: PETSC_INTERN PetscErrorCode PetscDrawSDL3CloseSurface(PetscDraw_SDL3 *);
 61: PETSC_INTERN PetscErrorCode PetscDrawSDL3ClearRect(PetscDraw_SDL3 *, const SDL_FRect *);
 62: PETSC_INTERN PetscErrorCode PetscDrawSDL3Close(PetscDraw_SDL3 *);
 63: PETSC_INTERN PetscErrorCode PetscDrawSDL3VideoAcquire(PetscBool *);
 64: PETSC_INTERN PetscErrorCode PetscDrawSDL3VideoRelease(void);
 65: PETSC_INTERN PetscErrorCode PetscDrawSDL3GetDisplaySize(int *, int *);
 66: PETSC_INTERN PetscErrorCode PetscDrawSDL3SetFont(PetscDraw, int, int);
 67: PETSC_INTERN PetscErrorCode PetscDrawSDL3Combine(PetscDraw, unsigned int **);
 68: PETSC_INTERN PetscErrorCode PetscDrawGetImage_SDL3(PetscDraw, unsigned char[PETSC_DRAW_MAXCOLOR][3], unsigned int *, unsigned int *, unsigned char *[]);