2017-12-05 09:33:05 +00:00
|
|
|
/*
|
|
|
|
Looking Glass - KVM FrameRelay (KVMFR) Client
|
|
|
|
Copyright (C) 2017 Geoffrey McRae <geoff@hostfission.com>
|
2017-12-11 17:30:47 +00:00
|
|
|
https://looking-glass.hostfission.com
|
2017-12-05 09:33:05 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU General Public License as published by the Free Software
|
|
|
|
Foundation; either version 2 of the License, or (at your option) any later
|
|
|
|
version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
|
|
|
|
PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
|
|
|
Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
#include <SDL2/SDL.h>
|
2017-12-14 11:05:32 +00:00
|
|
|
#include <SDL2/SDL_ttf.h>
|
2017-12-05 09:33:05 +00:00
|
|
|
|
|
|
|
#define IS_LG_RENDERER_VALID(x) \
|
2017-12-12 15:22:47 +00:00
|
|
|
((x)->get_name && \
|
2017-12-17 11:21:59 +00:00
|
|
|
(x)->create && \
|
2017-12-12 15:22:47 +00:00
|
|
|
(x)->initialize && \
|
|
|
|
(x)->deinitialize && \
|
|
|
|
(x)->on_resize && \
|
2017-12-12 16:08:13 +00:00
|
|
|
(x)->on_mouse_shape && \
|
2017-12-12 15:22:47 +00:00
|
|
|
(x)->on_mouse_event && \
|
2018-05-28 22:57:09 +00:00
|
|
|
(x)->on_alert && \
|
2017-12-05 09:33:05 +00:00
|
|
|
(x)->render)
|
|
|
|
|
2017-12-17 11:21:59 +00:00
|
|
|
#define LGR_OPTION_COUNT(x) (sizeof(x) / sizeof(LG_RendererOpt))
|
|
|
|
|
|
|
|
typedef bool(* LG_RendererOptValidator)(const char * value);
|
|
|
|
typedef void(* LG_RendererOptHandler )(void * opaque, const char * value);
|
|
|
|
|
|
|
|
typedef struct LG_RendererOpt
|
|
|
|
{
|
|
|
|
const char * name;
|
|
|
|
const char * desc;
|
|
|
|
LG_RendererOptValidator validator;
|
|
|
|
LG_RendererOptHandler handler;
|
|
|
|
}
|
|
|
|
LG_RendererOpt;
|
|
|
|
|
|
|
|
typedef struct LG_RendererOptValue
|
|
|
|
{
|
2017-12-28 08:55:13 +00:00
|
|
|
const LG_RendererOpt * opt;
|
|
|
|
char * value;
|
2017-12-17 11:21:59 +00:00
|
|
|
} LG_RendererOptValue;
|
|
|
|
|
|
|
|
typedef LG_RendererOpt * LG_RendererOptions;
|
|
|
|
|
2017-12-05 09:33:05 +00:00
|
|
|
typedef struct LG_RendererParams
|
|
|
|
{
|
2017-12-17 11:21:59 +00:00
|
|
|
TTF_Font * font;
|
|
|
|
bool showFPS;
|
2017-12-05 09:33:05 +00:00
|
|
|
}
|
|
|
|
LG_RendererParams;
|
|
|
|
|
2017-12-29 10:20:51 +00:00
|
|
|
typedef enum LG_RendererComp
|
|
|
|
{
|
|
|
|
LG_COMPRESSION_NONE,
|
|
|
|
LG_COMPRESSION_H264
|
|
|
|
}
|
|
|
|
LG_RendererComp;
|
|
|
|
|
2017-12-05 09:33:05 +00:00
|
|
|
typedef struct LG_RendererFormat
|
|
|
|
{
|
2017-12-29 10:20:51 +00:00
|
|
|
LG_RendererComp comp; // compression format
|
|
|
|
unsigned int width; // image width
|
|
|
|
unsigned int height; // image height
|
|
|
|
unsigned int stride; // scanline width (zero if compresed)
|
|
|
|
unsigned int pitch; // scanline bytes (or compressed size)
|
|
|
|
unsigned int bpp; // bits per pixel (zero if compressed)
|
2017-12-05 09:33:05 +00:00
|
|
|
}
|
|
|
|
LG_RendererFormat;
|
|
|
|
|
|
|
|
typedef struct LG_RendererRect
|
|
|
|
{
|
|
|
|
int x;
|
|
|
|
int y;
|
|
|
|
unsigned int w;
|
|
|
|
unsigned int h;
|
|
|
|
}
|
|
|
|
LG_RendererRect;
|
|
|
|
|
2017-12-12 16:08:13 +00:00
|
|
|
typedef enum LG_RendererCursor
|
|
|
|
{
|
|
|
|
LG_CURSOR_COLOR ,
|
|
|
|
LG_CURSOR_MONOCHROME ,
|
|
|
|
LG_CURSOR_MASKED_COLOR
|
|
|
|
}
|
|
|
|
LG_RendererCursor;
|
|
|
|
|
2018-05-28 22:57:09 +00:00
|
|
|
typedef enum LG_RendererOnAlert
|
|
|
|
{
|
|
|
|
LG_ALERT_INFO ,
|
|
|
|
LG_ALERT_SUCCESS,
|
|
|
|
LG_ALERT_WARNING,
|
|
|
|
LG_ALERT_ERROR
|
|
|
|
}
|
|
|
|
LG_RendererAlert;
|
|
|
|
|
2017-12-19 04:37:19 +00:00
|
|
|
typedef const char * (* LG_RendererGetName )();
|
|
|
|
typedef bool (* LG_RendererCreate )(void ** opaque, const LG_RendererParams params);
|
|
|
|
typedef bool (* LG_RendererInitialize )(void * opaque, Uint32 * sdlFlags);
|
|
|
|
typedef void (* LG_RendererDeInitialize)(void * opaque);
|
|
|
|
typedef void (* LG_RendererOnResize )(void * opaque, const int width, const int height, const LG_RendererRect destRect);
|
|
|
|
typedef bool (* LG_RendererOnMouseShape)(void * opaque, const LG_RendererCursor cursor, const int width, const int height, const int pitch, const uint8_t * data);
|
|
|
|
typedef bool (* LG_RendererOnMouseEvent)(void * opaque, const bool visible , const int x, const int y);
|
2017-12-19 13:53:45 +00:00
|
|
|
typedef bool (* LG_RendererOnFrameEvent)(void * opaque, const LG_RendererFormat format, const uint8_t * data);
|
2018-05-28 22:57:09 +00:00
|
|
|
typedef void (* LG_RendererOnAlert )(void * opaque, const LG_RendererAlert alert, const char * message);
|
2017-12-19 13:53:45 +00:00
|
|
|
typedef bool (* LG_RendererRender )(void * opaque, SDL_Window *window);
|
2017-12-05 09:33:05 +00:00
|
|
|
|
|
|
|
typedef struct LG_Renderer
|
|
|
|
{
|
2017-12-17 11:21:59 +00:00
|
|
|
LG_RendererCreate create;
|
2017-12-05 09:33:05 +00:00
|
|
|
LG_RendererGetName get_name;
|
2017-12-17 11:21:59 +00:00
|
|
|
LG_RendererOptions options;
|
|
|
|
unsigned int option_count;
|
2017-12-05 09:33:05 +00:00
|
|
|
LG_RendererInitialize initialize;
|
|
|
|
LG_RendererDeInitialize deinitialize;
|
2017-12-10 14:31:52 +00:00
|
|
|
LG_RendererOnResize on_resize;
|
2017-12-12 16:08:13 +00:00
|
|
|
LG_RendererOnMouseShape on_mouse_shape;
|
2017-12-12 15:22:47 +00:00
|
|
|
LG_RendererOnMouseEvent on_mouse_event;
|
|
|
|
LG_RendererOnFrameEvent on_frame_event;
|
2018-05-28 22:57:09 +00:00
|
|
|
LG_RendererOnAlert on_alert;
|
2017-12-05 09:33:05 +00:00
|
|
|
LG_RendererRender render;
|
|
|
|
}
|
2017-12-17 11:21:59 +00:00
|
|
|
LG_Renderer;
|
|
|
|
|
|
|
|
// generic option helpers
|
|
|
|
bool LG_RendererValidatorBool(const char * value);
|
|
|
|
bool LG_RendererValueToBool (const char * value);
|