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_compiler.h>
30#include <core/gp_pixmap.h>
31
32#include <utils/gp_timer.h>
33#include <utils/gp_list.h>
34#include <utils/gp_poll.h>
35
36#include <input/gp_ev_queue.h>
37#include <input/gp_task.h>
38
39#include <backends/gp_types.h>
40
77
108
127
148
170
206
208 const char *name;
209
218 void (*flip)(gp_backend *self);
219
234 void (*update)(gp_backend *self);
235
247 void (*update_rect)(gp_backend *self,
248 gp_coord x0, gp_coord y0,
249 gp_coord x1, gp_coord y1);
250
264 enum gp_backend_ret (*set_attr)(gp_backend *self,
265 enum gp_backend_attr attr,
266 const void *vals);
267
278
282 void (*exit)(gp_backend *self);
283
290 void (*poll)(gp_backend *self);
291
292 /*
293 * Clipboard handler.
294 */
295 int (*clipboard)(gp_backend *self, gp_clipboard *op);
296
307 void (*wait)(gp_backend *self, int timeout_ms);
308
311
314
317
320
329
336
340 unsigned int dpi;
341
342 /* Backed private data */
343 char priv[] GP_ALIGNED;
344};
345
346#define GP_BACKEND_PRIV(backend) ((void*)(backend)->priv)
347
354static inline gp_size gp_backend_w(gp_backend *self)
355{
356 return gp_pixmap_w(self->pixmap);
357}
358
365static inline gp_size gp_backend_h(gp_backend *self)
366{
367 return gp_pixmap_h(self->pixmap);
368}
369
377{
378 return self->pixmap->pixel_type;
379}
380
405 gp_coord x0, gp_coord y0,
406 gp_coord x1, gp_coord y1);
407
419static inline void gp_backend_update_rect(gp_backend *self,
420 gp_coord x0, gp_coord y0,
421 gp_coord x1, gp_coord y1)
422{
423 return gp_backend_update_rect_xyxy(self, x0, y0, x1, y1);
424}
425
438 gp_coord x, gp_coord y,
439 gp_size w, gp_size h)
440{
441 gp_backend_update_rect_xyxy(self, x, y, x + w - 1, y + h - 1);
442}
443
459static inline void gp_backend_update(gp_backend *self)
460{
461 if (self->update)
462 self->update(self);
463}
464
484static inline void gp_backend_flip(gp_backend *self)
485{
486 if (self->flip)
487 self->flip(self);
488 else
489 gp_backend_update(self);
490}
491
502
509static inline void gp_backend_poll_rem(gp_backend *self, gp_fd *fd)
510{
511 gp_poll_rem(&self->fds, fd);
512}
513
520static inline gp_fd *gp_backend_poll_rem_by_fd(gp_backend *self, int fd)
521{
522 return gp_poll_rem_by_fd(&self->fds, fd);
523}
524
538 enum gp_backend_cursor_req cursor)
539{
540 if (self->set_attr)
541 return self->set_attr(self, GP_BACKEND_ATTR_CURSOR, &cursor);
542
543 return GP_BACKEND_NOTSUPP;
544}
545
556static inline int gp_backend_backlight_inc(gp_backend *self)
557{
559
560 if (self->set_attr)
561 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
562
563 return GP_BACKEND_NOTSUPP;
564}
565
576static inline int gp_backend_backlight_dec(gp_backend *self)
577{
579
580 if (self->set_attr)
581 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
582
583 return GP_BACKEND_NOTSUPP;
584}
585
596static inline int gp_backend_backlight_get(gp_backend *self)
597{
599
600 if (self->set_attr)
601 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
602
603 return GP_BACKEND_NOTSUPP;
604}
605
619
629
656
682void gp_backend_wait_timeout(gp_backend *self, int timeout_ms);
683
707static inline void gp_backend_wait(gp_backend *self)
708{
709 gp_backend_wait_timeout(self, -1);
710}
711
736
760{
761 return gp_backend_ev_wait_timeout(self, -1);
762}
763
774
785void gp_backend_timer_reschedule(gp_backend *self, gp_timer *timer, uint32_t expires_ms);
786
794
800static inline unsigned int gp_backend_timers_queued(gp_backend *self)
801{
802 return gp_timer_queue_size(self->timers);
803}
804
814
824 const char *caption)
825{
826 if (!backend->set_attr)
827 return GP_BACKEND_NOTSUPP;
828
829 return backend->set_attr(backend, GP_BACKEND_ATTR_TITLE, caption);
830}
831
846int gp_backend_resize(gp_backend *backend, uint32_t w, uint32_t h);
847
861{
862 if (!backend->set_attr)
863 return GP_BACKEND_NOTSUPP;
864
865 return backend->set_attr(backend, GP_BACKEND_ATTR_FULLSCREEN, &req);
866}
867
894
908
916
928
934static inline void gp_backend_ev_flush(gp_backend *self)
935{
936 return gp_ev_queue_flush(self->event_queue);
937}
938
946static inline unsigned int gp_backend_ev_queued(gp_backend *self)
947{
948 return gp_ev_queue_events(self->event_queue);
949}
950
962
976{
977 return gp_ev_queue_peek(self->event_queue);
978}
979
992static inline void gp_backend_ev_put_back(gp_backend *self, gp_event *ev)
993{
995}
996
997#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:556
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:992
void gp_backend_poll_add(gp_backend *self, gp_fd *fd)
Add a file descriptor to the backend poll loop.
static gp_pixel_type gp_backend_pixel_type(gp_backend *self)
Returns backend pixel type.
Definition gp_backend.h:376
static void gp_backend_flip(gp_backend *self)
Flips backend and display buffers.
Definition gp_backend.h:484
gp_backend_fullscreen_req
Fullscreen request type.
Definition gp_backend.h:112
@ GP_BACKEND_FULLSCREEN_QUERY
Query fullscreen state.
Definition gp_backend.h:125
@ GP_BACKEND_FULLSCREEN_OFF
Request fullscreen to be turned off.
Definition gp_backend.h:114
@ GP_BACKEND_FULLSCREEN_ON
Request fullscreen to be turned on.
Definition gp_backend.h:116
@ GP_BACKEND_FULLSCREEN_TOGGLE
Toggle fullscreen state.
Definition gp_backend.h:118
gp_backend_cursor_req
Cursor types.
Definition gp_backend.h:131
@ GP_BACKEND_CURSOR_SHOW
Shows cursor.
Definition gp_backend.h:144
@ GP_BACKEND_CURSOR_TEXT_EDIT
Text edit cursor.
Definition gp_backend.h:135
@ GP_BACKEND_CURSOR_HIDE
Hides cursor.
Definition gp_backend.h:146
@ GP_BACKEND_CURSOR_MAX
Last cursor + 1.
Definition gp_backend.h:141
@ GP_BACKEND_CURSOR_HAND
Used typicaly while howering over links.
Definition gp_backend.h:139
@ GP_BACKEND_CURSOR_CROSSHAIR
Crosshair.
Definition gp_backend.h:137
@ GP_BACKEND_CURSOR_ARROW
Arrow default cursor type.
Definition gp_backend.h:133
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:419
static void gp_backend_wait(gp_backend *self)
Waits for a backend events.
Definition gp_backend.h:707
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:437
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_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:85
@ GP_BACKEND_NOTSUPP
Unsupported attribute.
Definition gp_backend.h:97
@ GP_BACKEND_OK
Atrribute set succesfully.
Definition gp_backend.h:87
@ GP_BACKEND_CONNERR
Connection error.
Definition gp_backend.h:106
@ GP_BACKEND_ON
Attribute is enabled.
Definition gp_backend.h:91
@ GP_BACKEND_EINVAL
Invalid value.
Definition gp_backend.h:104
@ GP_BACKEND_OFF
Attribute is disabled.
Definition gp_backend.h:89
static 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.
Definition gp_backend.h:759
void gp_backend_timer_reschedule(gp_backend *self, gp_timer *timer, uint32_t expires_ms)
Reschedules a timer.
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:975
gp_backend_backlight_req
Backlight operations.
Definition gp_backend.h:152
@ GP_BACKEND_BACKLIGHT_DEC
Decreases the backlight brightness.
Definition gp_backend.h:164
@ GP_BACKEND_BACKLIGHT_GET
Returns current backlight intensity in percents.
Definition gp_backend.h:168
@ GP_BACKEND_BACKLIGHT_INC
Increases the backlight brightness.
Definition gp_backend.h:158
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:365
static gp_size gp_backend_w(gp_backend *self)
Returns backend width.
Definition gp_backend.h:354
static int gp_backend_backlight_dec(gp_backend *self)
Decreases the backlight intensity.
Definition gp_backend.h:576
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:537
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:934
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:823
static unsigned int gp_backend_timers_queued(gp_backend *self)
Returns number of timers scheduled in backend.
Definition gp_backend.h:800
gp_event * gp_backend_ev_get(gp_backend *self)
Removes and returns a pointer to a first event in the queue.
gp_event * gp_backend_ev_wait_timeout(gp_backend *self, int timeout_ms)
Returns an event from the queue, wait for the backend events until a timeout if the queue is empty.
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:859
gp_backend_attr
Backend attributes.
Definition gp_backend.h:44
@ GP_BACKEND_ATTR_SIZE
Window change request.
Definition gp_backend.h:50
@ GP_BACKEND_ATTR_TITLE
Window title change request.
Definition gp_backend.h:56
@ GP_BACKEND_ATTR_BACKLIGHT
Backlight support.
Definition gp_backend.h:75
@ GP_BACKEND_ATTR_CURSOR
Cursor modifications.
Definition gp_backend.h:68
@ GP_BACKEND_ATTR_FULLSCREEN
Fullscreen mode change request.
Definition gp_backend.h:62
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:596
int gp_backend_render_stopped(gp_backend *self)
Rendering stopped acknowledge.
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:509
static void gp_backend_update(gp_backend *self)
Copies data from backend buffer to display.
Definition gp_backend.h:459
void gp_backend_timer_stop(gp_backend *self, gp_timer *timer)
Removes timer from backend timer queue.
static unsigned int gp_backend_ev_queued(gp_backend *self)
Returns a number of events in the backend event queue.
Definition gp_backend.h:946
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:520
void gp_backend_timer_start(gp_backend *self, gp_timer *timer)
Adds a timer to a backend timer queue.
void gp_backend_wait_timeout(gp_backend *self, int timeout_ms)
Waits for a backend events with a timeout.
A compiler dependent macros.
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:571
static gp_size gp_pixmap_h(const gp_pixmap *self)
Returns pixmap height taking axes swap into account.
Definition gp_pixmap.h:585
A simple epoll wrapper.
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:151
A backend.
Definition gp_backend.h:176
void(* wait)(gp_backend *self, int timeout_ms)
Blocking event loop. Blocks until events are ready.
Definition gp_backend.h:307
gp_poll fds
File descriptors to poll for.
Definition gp_backend.h:310
void(* poll)(gp_backend *self)
Non-blocking event loop.
Definition gp_backend.h:290
const char * name
Backend name, e.g. "X11".
Definition gp_backend.h:208
gp_timer * timers
Priority queue for timers.
Definition gp_backend.h:316
gp_task_queue * task_queue
Task queue.
Definition gp_backend.h:319
gp_dlist input_drivers
List of input drivers feeding the ev_queue.
Definition gp_backend.h:328
void(* exit)(gp_backend *self)
Exits the backend.
Definition gp_backend.h:282
void * clipboard_data
Clipboard data.
Definition gp_backend.h:335
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:247
int(* render_stopped)(gp_backend *self)
Rendering stopped callback.
Definition gp_backend.h:277
void(* update)(gp_backend *self)
Updates whole display buffer.
Definition gp_backend.h:234
void(* flip)(gp_backend *self)
Flips backend and display buffers.
Definition gp_backend.h:218
gp_pixmap * pixmap
Pointer to a pixmap an app should draw to.
Definition gp_backend.h:205
gp_ev_queue * event_queue
Queue to store input events.
Definition gp_backend.h:313
unsigned int dpi
A backend DPI if unknown it's set to 0.
Definition gp_backend.h:340
enum gp_backend_ret(* set_attr)(gp_backend *self, enum gp_backend_attr attr, const void *vals)
Attribute change callback.
Definition gp_backend.h:264
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:225
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