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
24
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
205
207 const char *name;
208
217 void (*flip)(gp_backend *self);
218
233 void (*update)(gp_backend *self);
234
246 void (*update_rect)(gp_backend *self,
247 gp_coord x0, gp_coord y0,
248 gp_coord x1, gp_coord y1);
249
263 enum gp_backend_ret (*set_attr)(gp_backend *self,
264 enum gp_backend_attr attr,
265 const void *vals);
266
267 /*
268 * Resize acknowledge callback. This must be called
269 * after you got resize event in order to resize
270 * backend buffers.
271 */
272 int (*resize_ack)(gp_backend *self);
273
277 void (*exit)(gp_backend *self);
278
285 void (*poll)(gp_backend *self);
286
287 /*
288 * Clipboard handler.
289 */
290 int (*clipboard)(gp_backend *self, gp_clipboard *op);
291
302 void (*wait)(gp_backend *self, int timeout_ms);
303
306
309
312
315
324
331
335 unsigned int dpi;
336
337 /* Backed private data */
338 char priv[];
339};
340
341#define GP_BACKEND_PRIV(backend) ((void*)(backend)->priv)
342
349static inline gp_size gp_backend_w(gp_backend *self)
350{
351 return gp_pixmap_w(self->pixmap);
352}
353
360static inline gp_size gp_backend_h(gp_backend *self)
361{
362 return gp_pixmap_h(self->pixmap);
363}
364
372{
373 return self->pixmap->pixel_type;
374}
375
400 gp_coord x0, gp_coord y0,
401 gp_coord x1, gp_coord y1);
402
414static inline void gp_backend_update_rect(gp_backend *self,
415 gp_coord x0, gp_coord y0,
416 gp_coord x1, gp_coord y1)
417{
418 return gp_backend_update_rect_xyxy(self, x0, y0, x1, y1);
419}
420
433 gp_coord x, gp_coord y,
434 gp_size w, gp_size h)
435{
436 gp_backend_update_rect_xyxy(self, x, y, x + w - 1, y + h - 1);
437}
438
454static inline void gp_backend_update(gp_backend *self)
455{
456 if (self->update)
457 self->update(self);
458}
459
479static inline void gp_backend_flip(gp_backend *self)
480{
481 if (self->flip)
482 self->flip(self);
483 else
484 gp_backend_update(self);
485}
486
497
504static inline void gp_backend_poll_rem(gp_backend *self, gp_fd *fd)
505{
506 gp_poll_rem(&self->fds, fd);
507}
508
515static inline gp_fd *gp_backend_poll_rem_by_fd(gp_backend *self, int fd)
516{
517 return gp_poll_rem_by_fd(&self->fds, fd);
518}
519
533 enum gp_backend_cursor_req cursor)
534{
535 if (self->set_attr)
536 return self->set_attr(self, GP_BACKEND_ATTR_CURSOR, &cursor);
537
538 return GP_BACKEND_NOTSUPP;
539}
540
551static inline int gp_backend_backlight_inc(gp_backend *self)
552{
554
555 if (self->set_attr)
556 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
557
558 return GP_BACKEND_NOTSUPP;
559}
560
571static inline int gp_backend_backlight_dec(gp_backend *self)
572{
574
575 if (self->set_attr)
576 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
577
578 return GP_BACKEND_NOTSUPP;
579}
580
591static inline int gp_backend_backlight_get(gp_backend *self)
592{
594
595 if (self->set_attr)
596 return self->set_attr(self, GP_BACKEND_ATTR_BACKLIGHT, &req);
597
598 return GP_BACKEND_NOTSUPP;
599}
600
614
624
651
677void gp_backend_wait_timeout(gp_backend *self, int timeout_ms);
678
702static inline void gp_backend_wait(gp_backend *self)
703{
704 gp_backend_wait_timeout(self, -1);
705}
706
731
755{
756 return gp_backend_ev_wait_timeout(self, -1);
757}
758
769
780void gp_backend_timer_reschedule(gp_backend *self, gp_timer *timer, uint32_t expires_ms);
781
789
795static inline unsigned int gp_backend_timers_queued(gp_backend *self)
796{
797 return gp_timer_queue_size(self->timers);
798}
799
809
819 const char *caption)
820{
821 if (!backend->set_attr)
822 return GP_BACKEND_NOTSUPP;
823
824 return backend->set_attr(backend, GP_BACKEND_ATTR_TITLE, caption);
825}
826
841int gp_backend_resize(gp_backend *backend, uint32_t w, uint32_t h);
842
853
856{
857 if (!backend->set_attr)
858 return GP_BACKEND_NOTSUPP;
859
860 return backend->set_attr(backend, GP_BACKEND_ATTR_FULLSCREEN, &req);
861}
862
884
898
906
918
924static inline void gp_backend_ev_flush(gp_backend *self)
925{
926 return gp_ev_queue_flush(self->event_queue);
927}
928
936static inline unsigned int gp_backend_ev_queued(gp_backend *self)
937{
938 return gp_ev_queue_events(self->event_queue);
939}
940
952
966{
967 return gp_ev_queue_peek(self->event_queue);
968}
969
982static inline void gp_backend_ev_put_back(gp_backend *self, gp_event *ev)
983{
985}
986
987#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:551
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:982
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:371
static void gp_backend_flip(gp_backend *self)
Flips backend and display buffers.
Definition gp_backend.h:479
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:414
static void gp_backend_wait(gp_backend *self)
Waits for a backend events.
Definition gp_backend.h:702
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:432
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: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
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:754
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:965
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:360
static gp_size gp_backend_w(gp_backend *self)
Returns backend width.
Definition gp_backend.h:349
static int gp_backend_backlight_dec(gp_backend *self)
Decreases the backlight intensity.
Definition gp_backend.h:571
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:532
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:924
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:818
static unsigned int gp_backend_timers_queued(gp_backend *self)
Returns number of timers scheduled in backend.
Definition gp_backend.h:795
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:854
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:591
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:504
static void gp_backend_update(gp_backend *self)
Copies data from backend buffer to display.
Definition gp_backend.h:454
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:936
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:515
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.
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:554
static gp_size gp_pixmap_h(const gp_pixmap *self)
Returns pixmap height taking axes swap into account.
Definition gp_pixmap.h:568
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:139
A backend.
Definition gp_backend.h:175
void(* wait)(gp_backend *self, int timeout_ms)
Blocking event loop. Blocks until events are ready.
Definition gp_backend.h:302
gp_poll fds
File descriptors to poll for.
Definition gp_backend.h:305
void(* poll)(gp_backend *self)
Non-blocking event loop.
Definition gp_backend.h:285
const char * name
Backend name, e.g. "X11".
Definition gp_backend.h:207
gp_timer * timers
Priority queue for timers.
Definition gp_backend.h:311
gp_task_queue * task_queue
Task queue.
Definition gp_backend.h:314
gp_dlist input_drivers
List of input drivers feeding the ev_queue.
Definition gp_backend.h:323
void(* exit)(gp_backend *self)
Exits the backend.
Definition gp_backend.h:277
void * clipboard_data
Clipboard data.
Definition gp_backend.h:330
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:246
void(* update)(gp_backend *self)
Updates whole display buffer.
Definition gp_backend.h:233
void(* flip)(gp_backend *self)
Flips backend and display buffers.
Definition gp_backend.h:217
gp_pixmap * pixmap
Pointer to a pixmap an app should draw to.
Definition gp_backend.h:204
gp_ev_queue * event_queue
Queue to store input events.
Definition gp_backend.h:308
unsigned int dpi
A backend DPI if unknown it's set to 0.
Definition gp_backend.h:335
enum gp_backend_ret(* set_attr)(gp_backend *self, enum gp_backend_attr attr, const void *vals)
Attribute change callback.
Definition gp_backend.h:263
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:213
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