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-2025 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#include <core/gp_pixmap.h>
30
31#include <utils/gp_timer.h>
32#include <utils/gp_list.h>
33#include <utils/gp_poll.h>
34
35#include <input/gp_ev_queue.h>
36#include <input/gp_task.h>
37
38#include <backends/gp_types.h>
39
76
107
126
147
169
185
187 const char *name;
188
197 void (*flip)(gp_backend *self);
198
207 void (*update_rect)(gp_backend *self,
208 gp_coord x0, gp_coord y0,
209 gp_coord x1, gp_coord y1);
210
224 enum gp_backend_ret (*set_attr)(gp_backend *self,
225 enum gp_backend_attr attr,
226 const void *vals);
227
228 /*
229 * Resize acknowledge callback. This must be called
230 * after you got resize event in order to resize
231 * backend buffers.
232 */
233 int (*resize_ack)(gp_backend *self);
234
238 void (*exit)(gp_backend *self);
239
246 void (*poll)(gp_backend *self);
247
248 /*
249 * Clipboard handler.
250 */
251 int (*clipboard)(gp_backend *self, gp_clipboard *op);
252
263 void (*wait)(gp_backend *self);
264
267
270
273
276
285
292
296 unsigned int dpi;
297
298 /* Backed private data */
299 char priv[];
300};
301
302#define GP_BACKEND_PRIV(backend) ((void*)(backend)->priv)
303
310static inline gp_size gp_backend_w(gp_backend *self)
311{
312 return gp_pixmap_w(self->pixmap);
313}
314
321static inline gp_size gp_backend_h(gp_backend *self)
322{
323 return gp_pixmap_h(self->pixmap);
324}
325
333{
334 return self->pixmap->pixel_type;
335}
336
347static inline void gp_backend_flip(gp_backend *self)
348{
349 if (self->flip)
350 self->flip(self);
351}
352
368 gp_coord x0, gp_coord y0,
369 gp_coord x1, gp_coord y1);
370
382static inline void gp_backend_update_rect(gp_backend *self,
383 gp_coord x0, gp_coord y0,
384 gp_coord x1, gp_coord y1)
385{
386 return gp_backend_update_rect_xyxy(self, x0, y0, x1, y1);
387}
388
401 gp_coord x, gp_coord y,
402 gp_size w, gp_size h)
403{
404 gp_backend_update_rect_xyxy(self, x, y, x + w - 1, y + h - 1);
405}
406
413static inline void gp_backend_poll_add(gp_backend *self, gp_fd *fd)
414{
415 gp_poll_add(&self->fds, fd);
416}
417
424static inline void gp_backend_poll_rem(gp_backend *self, gp_fd *fd)
425{
426 gp_poll_rem(&self->fds, fd);
427}
428
435static inline gp_fd *gp_backend_poll_rem_by_fd(gp_backend *self, int fd)
436{
437 return gp_poll_rem_by_fd(&self->fds, fd);
438}
439
453 enum gp_backend_cursor_req cursor)
454{
455 if (self->set_attr)
456 return self->set_attr(self, GP_BACKEND_ATTR_CURSOR, &cursor);
457
458 return GP_BACKEND_NOTSUPP;
459}
460
471static inline int gp_backend_backlight_inc(gp_backend *self)
472{
474
475 if (self->set_attr)
476 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
477
478 return GP_BACKEND_NOTSUPP;
479}
480
491static inline int gp_backend_backlight_dec(gp_backend *self)
492{
494
495 if (self->set_attr)
496 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
497
498 return GP_BACKEND_NOTSUPP;
499}
500
511static inline int gp_backend_backlight_get(gp_backend *self)
512{
514
515 if (self->set_attr)
516 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
517
518 return GP_BACKEND_NOTSUPP;
519}
520
534
544
571
596
620
631
639
645static inline unsigned int gp_backend_timers_queued(gp_backend *self)
646{
647 return gp_timer_queue_size(self->timers);
648}
649
659
669 const char *caption)
670{
671 if (!backend->set_attr)
672 return GP_BACKEND_NOTSUPP;
673
674 return backend->set_attr(backend, GP_BACKEND_ATTR_TITLE, caption);
675}
676
691int gp_backend_resize(gp_backend *backend, uint32_t w, uint32_t h);
692
706{
707 if (!backend->set_attr)
708 return GP_BACKEND_NOTSUPP;
709
710 return backend->set_attr(backend, GP_BACKEND_ATTR_FULLSCREEN, &req);
711}
712
734
748
756
768
774static inline void gp_backend_ev_flush(gp_backend *self)
775{
776 return gp_ev_queue_flush(self->event_queue);
777}
778
786static inline unsigned int gp_backend_ev_queued(gp_backend *self)
787{
788 return gp_ev_queue_events(self->event_queue);
789}
790
802
816{
817 return gp_ev_queue_peek(self->event_queue);
818}
819
832static inline void gp_backend_ev_put_back(gp_backend *self, gp_event *ev)
833{
835}
836
837#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 int gp_backend_backlight_inc(gp_backend *self)
Increases the backlight intensity.
Definition gp_backend.h:471
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:832
void gp_backend_timer_add(gp_backend *self, gp_timer *timer)
Adds a timer to backend.
static gp_pixel_type gp_backend_pixel_type(gp_backend *self)
Returns backend pixel type.
Definition gp_backend.h:332
static void gp_backend_flip(gp_backend *self)
Copies whole backend pixmap to a display.
Definition gp_backend.h:347
int gp_backend_resize_ack(gp_backend *self)
Resize acknowledge.
gp_backend_fullscreen_req
Fullscreen request type.
Definition gp_backend.h:111
@ GP_BACKEND_FULLSCREEN_QUERY
Query fullscreen state.
Definition gp_backend.h:124
@ GP_BACKEND_FULLSCREEN_OFF
Request fullscreen to be turned off.
Definition gp_backend.h:113
@ GP_BACKEND_FULLSCREEN_ON
Request fullscreen to be turned on.
Definition gp_backend.h:115
@ GP_BACKEND_FULLSCREEN_TOGGLE
Toggle fullscreen state.
Definition gp_backend.h:117
gp_backend_cursor_req
Cursor types.
Definition gp_backend.h:130
@ GP_BACKEND_CURSOR_SHOW
Shows cursor.
Definition gp_backend.h:143
@ GP_BACKEND_CURSOR_TEXT_EDIT
Text edit cursor.
Definition gp_backend.h:134
@ GP_BACKEND_CURSOR_HIDE
Hides cursor.
Definition gp_backend.h:145
@ GP_BACKEND_CURSOR_MAX
Last cursor + 1.
Definition gp_backend.h:140
@ GP_BACKEND_CURSOR_HAND
Used typicaly while howering over links.
Definition gp_backend.h:138
@ GP_BACKEND_CURSOR_CROSSHAIR
Crosshair.
Definition gp_backend.h:136
@ GP_BACKEND_CURSOR_ARROW
Arrow default cursor type.
Definition gp_backend.h:132
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:382
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:400
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:84
@ GP_BACKEND_NOTSUPP
Unsupported attribute.
Definition gp_backend.h:96
@ GP_BACKEND_OK
Atrribute set succesfully.
Definition gp_backend.h:86
@ GP_BACKEND_CONNERR
Connection error.
Definition gp_backend.h:105
@ GP_BACKEND_ON
Attribute is enabled.
Definition gp_backend.h:90
@ GP_BACKEND_EINVAL
Invalid value.
Definition gp_backend.h:103
@ GP_BACKEND_OFF
Attribute is disabled.
Definition gp_backend.h:88
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:815
gp_backend_backlight_req
Backlight operations.
Definition gp_backend.h:151
@ GP_BACKEND_BACKLIGHT_DEC
Decreases the backlight brightness.
Definition gp_backend.h:163
@ GP_BACKEND_BACKLIGHT_GET
Returns current backlight intensity in percents.
Definition gp_backend.h:167
@ GP_BACKEND_BACKLIGHT_INC
Increases the backlight brightness.
Definition gp_backend.h:157
void gp_backend_task_queue_set(gp_backend *self, gp_task_queue *task_queue)
Sets the backend task_queue and starts task processing.
static gp_size gp_backend_h(gp_backend *self)
Returns backend height.
Definition gp_backend.h:321
void gp_backend_wait(gp_backend *self)
Waits for a backend events.
static gp_size gp_backend_w(gp_backend *self)
Returns backend width.
Definition gp_backend.h:310
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 int gp_backend_backlight_dec(gp_backend *self)
Decreases the backlight intensity.
Definition gp_backend.h:491
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:452
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:774
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:668
static unsigned int gp_backend_timers_queued(gp_backend *self)
Returns number of timers scheduled in backend.
Definition gp_backend.h:645
gp_event * gp_backend_ev_get(gp_backend *self)
Removes and returns a pointer to a first event in the queue.
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:704
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:413
gp_backend_attr
Backend attributes.
Definition gp_backend.h:43
@ GP_BACKEND_ATTR_SIZE
Window change request.
Definition gp_backend.h:49
@ GP_BACKEND_ATTR_TITLE
Window title change request.
Definition gp_backend.h:55
@ GP_BACKEND_ATTR_BACKLIGHT
Backlight support.
Definition gp_backend.h:74
@ GP_BACKEND_ATTR_CURSOR
Cursor modifications.
Definition gp_backend.h:67
@ GP_BACKEND_ATTR_FULLSCREEN
Fullscreen mode change request.
Definition gp_backend.h:61
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 int gp_backend_backlight_get(gp_backend *self)
Returns backlight intensity in percents.
Definition gp_backend.h:511
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:424
static unsigned int gp_backend_ev_queued(gp_backend *self)
Returns a number of events in the backend event queue.
Definition gp_backend.h:786
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:435
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.
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.
gp_pixel_type
List of all pixel types.
A pixel buffer.
static gp_size gp_pixmap_w(const gp_pixmap *self)
Returns pixmap width taking axes swap into account.
Definition gp_pixmap.h:533
static gp_size gp_pixmap_h(const gp_pixmap *self)
Returns pixmap height taking axes swap into account.
Definition gp_pixmap.h:547
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:175
gp_poll fds
File descriptors to poll for.
Definition gp_backend.h:266
void(* poll)(gp_backend *self)
Non-blocking event loop.
Definition gp_backend.h:246
const char * name
Backend name, e.g. "X11".
Definition gp_backend.h:187
gp_timer * timers
Priority queue for timers.
Definition gp_backend.h:272
gp_task_queue * task_queue
Task queue.
Definition gp_backend.h:275
gp_dlist input_drivers
List of input drivers feeding the ev_queue.
Definition gp_backend.h:284
void(* exit)(gp_backend *self)
Exits the backend.
Definition gp_backend.h:238
void * clipboard_data
Clipboard data.
Definition gp_backend.h:291
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:207
void(* flip)(gp_backend *self)
Updates display.
Definition gp_backend.h:197
gp_pixmap * pixmap
Pointer to pixmap app should draw to.
Definition gp_backend.h:184
gp_ev_queue * event_queue
Queue to store input events.
Definition gp_backend.h:269
unsigned int dpi
A backend DPI if unknown it's set to 0.
Definition gp_backend.h:296
void(* wait)(gp_backend *self)
Blocking event loop. Blocks until events are ready.
Definition gp_backend.h:263
enum gp_backend_ret(* set_attr)(gp_backend *self, enum gp_backend_attr attr, const void *vals)
Attribute change callback.
Definition gp_backend.h:224
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:160
An epoll file descriptor.
Definition gp_poll.h:70
A pixmap buffer.
Definition gp_pixmap.h:33
enum gp_pixel_type pixel_type
A pixel format.
Definition gp_pixmap.h:63
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