GFXprim
2D bitmap graphics library with emphasis on speed and correctness
Loading...
Searching...
No Matches
gp_backend.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later
2/*
3 * Copyright (C) 2009-2010 Jiri "BlueBear" Dluhos
4 * <jiri.bluebear.dluhos@gmail.com>
5 *
6 * Copyright (C) 2009-2024 Cyril Hrubis <metan@ucw.cz>
7 */
8
25#ifndef BACKENDS_GP_BACKEND_H
26#define BACKENDS_GP_BACKEND_H
27
28#include <core/gp_types.h>
29
30#include <utils/gp_timer.h>
31#include <utils/gp_list.h>
32#include <utils/gp_poll.h>
33
34#include <input/gp_ev_queue.h>
35#include <input/gp_task.h>
36
37#include <backends/gp_types.h>
38
68
99
118
139
155
157 const char *name;
158
167 void (*flip)(gp_backend *self);
168
177 void (*update_rect)(gp_backend *self,
178 gp_coord x0, gp_coord y0,
179 gp_coord x1, gp_coord y1);
180
194 enum gp_backend_ret (*set_attr)(gp_backend *self,
195 enum gp_backend_attr attr,
196 const void *vals);
197
198 /*
199 * Resize acknowledge callback. This must be called
200 * after you got resize event in order to resize
201 * backend buffers.
202 */
203 int (*resize_ack)(gp_backend *self);
204
208 void (*exit)(gp_backend *self);
209
216 void (*poll)(gp_backend *self);
217
218 /*
219 * Clipboard handler.
220 */
221 int (*clipboard)(gp_backend *self, gp_clipboard *op);
222
233 void (*wait)(gp_backend *self);
234
237
238 /* @brief Queue to store input events. */
239 gp_ev_queue *event_queue;
240
243
246
255
256 void *clipboard_data;
257
261 unsigned int dpi;
262
263 /* Backed private data */
264 char priv[];
265};
266
267#define GP_BACKEND_PRIV(backend) ((void*)(backend)->priv)
268
279static inline void gp_backend_flip(gp_backend *self)
280{
281 if (self->flip)
282 self->flip(self);
283}
284
300 gp_coord x0, gp_coord y0,
301 gp_coord x1, gp_coord y1);
302
314static inline void gp_backend_update_rect(gp_backend *self,
315 gp_coord x0, gp_coord y0,
316 gp_coord x1, gp_coord y1)
317{
318 return gp_backend_update_rect_xyxy(self, x0, y0, x1, y1);
319}
320
333 gp_coord x, gp_coord y,
334 gp_size w, gp_size h)
335{
336 gp_backend_update_rect_xyxy(self, x, y, x + w - 1, y + h - 1);
337}
338
345static inline void gp_backend_poll_add(gp_backend *self, gp_fd *fd)
346{
347 gp_poll_add(&self->fds, fd);
348}
349
356static inline void gp_backend_poll_rem(gp_backend *self, gp_fd *fd)
357{
358 gp_poll_rem(&self->fds, fd);
359}
360
367static inline gp_fd *gp_backend_poll_rem_by_fd(gp_backend *self, int fd)
368{
369 return gp_poll_rem_by_fd(&self->fds, fd);
370}
371
385 enum gp_backend_cursor_req cursor)
386{
387 if (self->set_attr)
388 return self->set_attr(self, GP_BACKEND_ATTR_CURSOR, &cursor);
389
390 return GP_BACKEND_NOTSUPP;
391}
392
406
416
443
468
492
503
511
517static inline unsigned int gp_backend_timers_queued(gp_backend *self)
518{
519 return gp_timer_queue_size(self->timers);
520}
521
531
541 const char *caption)
542{
543 if (!backend->set_attr)
544 return GP_BACKEND_NOTSUPP;
545
546 return backend->set_attr(backend, GP_BACKEND_ATTR_TITLE, caption);
547}
548
563int gp_backend_resize(gp_backend *backend, uint32_t w, uint32_t h);
564
578{
579 if (!backend->set_attr)
580 return GP_BACKEND_NOTSUPP;
581
582 return backend->set_attr(backend, GP_BACKEND_ATTR_FULLSCREEN, &req);
583}
584
606
620
628
640
646static inline void gp_backend_ev_flush(gp_backend *self)
647{
648 return gp_ev_queue_flush(self->event_queue);
649}
650
658static inline unsigned int gp_backend_ev_queued(gp_backend *self)
659{
660 return gp_ev_queue_events(self->event_queue);
661}
662
674{
675 return gp_ev_queue_get(self->event_queue);
676}
677
691{
692 return gp_ev_queue_peek(self->event_queue);
693}
694
707static inline void gp_backend_ev_put_back(gp_backend *self, gp_event *ev)
708{
709 gp_ev_queue_put_back(self->event_queue, ev);
710}
711
712#endif /* BACKENDS_GP_BACKEND_H */
A common types.
int gp_coord
Integer type for coordinates i.e. x, y, ...
Definition gp_types.h:19
unsigned int gp_size
Integer type for sizes i.e. w, h, ...
Definition gp_types.h:24
int gp_backend_timer_timeout(gp_backend *self)
Returns time to the closest timer timeout.
static void gp_backend_ev_put_back(gp_backend *self, gp_event *ev)
Puts back an event that has been just removed from the queue.
Definition gp_backend.h:707
void gp_backend_timer_add(gp_backend *self, gp_timer *timer)
Adds a timer to backend.
static void gp_backend_flip(gp_backend *self)
Copies whole backend pixmap to a display.
Definition gp_backend.h:279
int gp_backend_resize_ack(gp_backend *self)
Resize acknowledge.
gp_backend_fullscreen_req
Fullscreen request type.
Definition gp_backend.h:103
@ GP_BACKEND_FULLSCREEN_QUERY
Query fullscreen state.
Definition gp_backend.h:116
@ GP_BACKEND_FULLSCREEN_OFF
Request fullscreen to be turned off.
Definition gp_backend.h:105
@ GP_BACKEND_FULLSCREEN_ON
Request fullscreen to be turned on.
Definition gp_backend.h:107
@ GP_BACKEND_FULLSCREEN_TOGGLE
Toggle fullscreen state.
Definition gp_backend.h:109
gp_backend_cursor_req
Cursor types.
Definition gp_backend.h:122
@ GP_BACKEND_CURSOR_SHOW
Shows cursor.
Definition gp_backend.h:135
@ GP_BACKEND_CURSOR_TEXT_EDIT
Text edit cursor.
Definition gp_backend.h:126
@ GP_BACKEND_CURSOR_HIDE
Hides cursor.
Definition gp_backend.h:137
@ GP_BACKEND_CURSOR_MAX
Last cursor + 1.
Definition gp_backend.h:132
@ GP_BACKEND_CURSOR_HAND
Used typicaly while howering over links.
Definition gp_backend.h:130
@ GP_BACKEND_CURSOR_CROSSHAIR
Crosshair.
Definition gp_backend.h:128
@ GP_BACKEND_CURSOR_ARROW
Arrow default cursor type.
Definition gp_backend.h:124
static void gp_backend_update_rect(gp_backend *self, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1)
Copies a rectangle from backend pixmap to a display.
Definition gp_backend.h:314
static void gp_backend_update_rect_xywh(gp_backend *self, gp_coord x, gp_coord y, gp_size w, gp_size h)
Copies a rectangle from backend pixmap to a display.
Definition gp_backend.h:332
void gp_backend_update_rect_xyxy(gp_backend *self, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1)
Copies a rectangle from backend pixmap to a display.
void gp_backend_timer_rem(gp_backend *self, gp_timer *timer)
Removes timer from backend timer queue.
void gp_backend_poll(gp_backend *self)
Polls a backend for events.
void gp_backend_exit(gp_backend *self)
Exits the backend.
gp_backend_ret
A return value from the backend set_attr callback.
Definition gp_backend.h:76
@ GP_BACKEND_NOTSUPP
Unsupported attribute.
Definition gp_backend.h:88
@ GP_BACKEND_OK
Atrribute set succesfully.
Definition gp_backend.h:78
@ GP_BACKEND_CONNERR
Connection error.
Definition gp_backend.h:97
@ GP_BACKEND_ON
Attribute is enabled.
Definition gp_backend.h:82
@ GP_BACKEND_EINVAL
Invalid value.
Definition gp_backend.h:95
@ GP_BACKEND_OFF
Attribute is disabled.
Definition gp_backend.h:80
int gp_backend_resize(gp_backend *backend, uint32_t w, uint32_t h)
Request backend resize.
static gp_event * gp_backend_ev_peek(gp_backend *self)
Returns a pointer to a first event in the queue.
Definition gp_backend.h:690
void gp_backend_task_queue_set(gp_backend *self, gp_task_queue *task_queue)
Sets the backend task_queue and starts task processing.
void gp_backend_wait(gp_backend *self)
Waits for a backend events.
gp_event * gp_backend_ev_wait(gp_backend *self)
Returns an event from the queue, wait the backend for events if the queue is empty.
static enum gp_backend_ret gp_backend_cursor_set(gp_backend *self, enum gp_backend_cursor_req cursor)
Sets backend cursor type.
Definition gp_backend.h:384
void gp_backend_task_ins(gp_backend *self, gp_task *task)
Inserts a task into the task queue.
static void gp_backend_ev_flush(gp_backend *self)
Removes all events from the event queue.
Definition gp_backend.h:646
void gp_backend_task_rem(gp_backend *self, gp_task *task)
Removes a task from the task queue.
static enum gp_backend_ret gp_backend_set_caption(gp_backend *backend, const char *caption)
Sets backend caption, if supported.
Definition gp_backend.h:540
static unsigned int gp_backend_timers_queued(gp_backend *self)
Returns number of timers scheduled in backend.
Definition gp_backend.h:517
static enum gp_backend_ret gp_backend_fullscreen(gp_backend *backend, enum gp_backend_fullscreen_req req)
Reuqests to change fullscreen mode.
Definition gp_backend.h:576
static void gp_backend_poll_add(gp_backend *self, gp_fd *fd)
Add a file descriptor to the backend poll loop.
Definition gp_backend.h:345
gp_backend_attr
Backend attributes.
Definition gp_backend.h:42
@ GP_BACKEND_ATTR_SIZE
Window change request.
Definition gp_backend.h:48
@ GP_BACKEND_ATTR_TITLE
Window title change request.
Definition gp_backend.h:54
@ GP_BACKEND_ATTR_CURSOR
Cursor modifications.
Definition gp_backend.h:66
@ GP_BACKEND_ATTR_FULLSCREEN
Fullscreen mode change request.
Definition gp_backend.h:60
gp_event * gp_backend_ev_poll(gp_backend *self)
Returns an event from the queue, polls the backend for events if the queue is empty.
static void gp_backend_poll_rem(gp_backend *self, gp_fd *fd)
Removes a file descriptor to the backend poll loop.
Definition gp_backend.h:356
static unsigned int gp_backend_ev_queued(gp_backend *self)
Returns a number of events in the backend event queue.
Definition gp_backend.h:658
static gp_fd * gp_backend_poll_rem_by_fd(gp_backend *self, int fd)
Removes a file descriptor to the backend poll loop.
Definition gp_backend.h:367
static gp_event * gp_backend_ev_get(gp_backend *self)
Removes and returns a pointer to a first event in the queue.
Definition gp_backend.h:673
Event Queue.
void gp_ev_queue_put_back(gp_ev_queue *self, gp_event *ev)
Pushes back an event to the event queue.
gp_event * gp_ev_queue_peek(gp_ev_queue *self)
Peeks at a top event from the queue.
gp_event * gp_ev_queue_get(gp_ev_queue *self)
Remoes and returns pointer to a top event from the queue.
unsigned int gp_ev_queue_events(gp_ev_queue *self)
Returns number of events queued in the queue.
void gp_ev_queue_flush(gp_ev_queue *self)
Removes all events from the queue.
A linked list implementation.
A simple epoll wrapper.
int gp_poll_add(gp_poll *self, gp_fd *fd)
Adds a file descriptor.
gp_fd * gp_poll_rem_by_fd(gp_poll *self, int fd)
Looks up and removes a gp_fd by a fd.
int gp_poll_rem(gp_poll *self, gp_fd *fd)
Removes a file descriptor.
Application tasks.
Timers and timer queue implementation.
static unsigned int gp_timer_queue_size(gp_timer *queue)
Returns size of the queue, i.e. number of timers.
Definition gp_timer.h:139
A backend.
Definition gp_backend.h:145
gp_poll fds
File descriptors to poll for.
Definition gp_backend.h:236
void(* poll)(gp_backend *self)
Non-blocking event loop.
Definition gp_backend.h:216
const char * name
Backend name, e.g. "X11".
Definition gp_backend.h:157
gp_timer * timers
Priority queue for timers.
Definition gp_backend.h:242
gp_task_queue * task_queue
Task queue.
Definition gp_backend.h:245
gp_dlist input_drivers
List of input drivers feeding the ev_queue.
Definition gp_backend.h:254
void(* exit)(gp_backend *self)
Exits the backend.
Definition gp_backend.h:208
void(* update_rect)(gp_backend *self, gp_coord x0, gp_coord y0, gp_coord x1, gp_coord y1)
Updates display rectangle.
Definition gp_backend.h:177
void(* flip)(gp_backend *self)
Updates display.
Definition gp_backend.h:167
gp_pixmap * pixmap
Pointer to pixmap app should draw to.
Definition gp_backend.h:154
unsigned int dpi
A backend DPI if unknown it's set to 0.
Definition gp_backend.h:261
void(* wait)(gp_backend *self)
Blocking event loop. Blocks until events are ready.
Definition gp_backend.h:233
enum gp_backend_ret(* set_attr)(gp_backend *self, enum gp_backend_attr attr, const void *vals)
Attribute change callback.
Definition gp_backend.h:194
A double linked list pointers.
Definition gp_list.h:56
An event queue.
Definition gp_ev_queue.h:24
An input event.
Definition gp_event.h:153
An epoll file descriptor.
Definition gp_poll.h:70
A pixmap buffer.
Definition gp_pixmap.h:33
An epoll instance.
Definition gp_poll.h:46
A task queue.
Definition gp_task.h:28
A task.
Definition gp_task.h:48
A timer.
Definition gp_timer.h:26