![]() |
GFXprim
2D bitmap graphics library with emphasis on speed and correctness
|
An abstraction for display, keyboard and mouse. More...
#include <core/gp_types.h>#include <core/gp_pixmap.h>#include <utils/gp_timer.h>#include <utils/gp_list.h>#include <utils/gp_poll.h>#include <input/gp_ev_queue.h>#include <input/gp_task.h>#include <backends/gp_types.h>Go to the source code of this file.
Data Structures | |
| struct | gp_backend |
| A backend. More... | |
Functions | |
| static gp_size | gp_backend_w (gp_backend *self) |
| Returns backend width. | |
| static gp_size | gp_backend_h (gp_backend *self) |
| Returns backend height. | |
| static gp_pixel_type | gp_backend_pixel_type (gp_backend *self) |
| Returns backend pixel type. | |
| 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. | |
| 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. | |
| 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. | |
| static void | gp_backend_update (gp_backend *self) |
| Copies data from backend buffer to display. | |
| static void | gp_backend_flip (gp_backend *self) |
| Flips backend and display buffers. | |
| void | gp_backend_poll_add (gp_backend *self, gp_fd *fd) |
| Add a file descriptor to the backend poll loop. | |
| static void | gp_backend_poll_rem (gp_backend *self, gp_fd *fd) |
| Removes a file descriptor to the backend poll loop. | |
| static gp_fd * | gp_backend_poll_rem_by_fd (gp_backend *self, int fd) |
| Removes a file descriptor to the backend poll loop. | |
| static enum gp_backend_ret | gp_backend_cursor_set (gp_backend *self, enum gp_backend_cursor_req cursor) |
| Sets backend cursor type. | |
| static int | gp_backend_backlight_inc (gp_backend *self) |
| Increases the backlight intensity. | |
| static int | gp_backend_backlight_dec (gp_backend *self) |
| Decreases the backlight intensity. | |
| static int | gp_backend_backlight_get (gp_backend *self) |
| Returns backlight intensity in percents. | |
| void | gp_backend_exit (gp_backend *self) |
| Exits the backend. | |
| void | gp_backend_poll (gp_backend *self) |
| Polls a backend for events. | |
| 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. | |
| void | gp_backend_wait_timeout (gp_backend *self, int timeout_ms) |
| Waits for a backend events with a timeout. | |
| static void | gp_backend_wait (gp_backend *self) |
| Waits for a backend events. | |
| 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 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. | |
| void | gp_backend_timer_start (gp_backend *self, gp_timer *timer) |
| Adds a timer to a backend timer queue. | |
| void | gp_backend_timer_reschedule (gp_backend *self, gp_timer *timer, uint32_t expires_ms) |
| Reschedules a timer. | |
| void | gp_backend_timer_stop (gp_backend *self, gp_timer *timer) |
| Removes timer from backend timer queue. | |
| static unsigned int | gp_backend_timers_queued (gp_backend *self) |
| Returns number of timers scheduled in backend. | |
| int | gp_backend_timer_timeout (gp_backend *self) |
| Returns time to the closest timer timeout. | |
| static enum gp_backend_ret | gp_backend_set_caption (gp_backend *backend, const char *caption) |
| Sets backend caption, if supported. | |
| int | gp_backend_resize (gp_backend *backend, uint32_t w, uint32_t h) |
| Request backend resize. | |
| static enum gp_backend_ret | gp_backend_fullscreen (gp_backend *backend, enum gp_backend_fullscreen_req req) |
| Reuqests to change fullscreen mode. | |
| int | gp_backend_resize_ack (gp_backend *self) |
| Resize acknowledge. | |
| void | gp_backend_task_ins (gp_backend *self, gp_task *task) |
| Inserts a task into the task queue. | |
| void | gp_backend_task_rem (gp_backend *self, gp_task *task) |
| Removes a task from the task queue. | |
| void | gp_backend_task_queue_set (gp_backend *self, gp_task_queue *task_queue) |
| Sets the backend task_queue and starts task processing. | |
| static void | gp_backend_ev_flush (gp_backend *self) |
| Removes all events from the event queue. | |
| static unsigned int | gp_backend_ev_queued (gp_backend *self) |
| Returns a number of events in the backend event queue. | |
| gp_event * | gp_backend_ev_get (gp_backend *self) |
| Removes and returns a pointer to a first event in the queue. | |
| static gp_event * | gp_backend_ev_peek (gp_backend *self) |
| Returns a pointer to a first event in the queue. | |
| 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. | |
An abstraction for display, keyboard and mouse.
The gp_backend is unified API for managing xserver, framebuffer, waylaynd, drm, e-ink display, etc. along with support for input devices, e.g. mouse, keyboard and keymaps. It also implements timers and tasks so that work can be scheduled.
In contrast to other graphics libraries we do not try to create unified initalization interface that would match specialities for every possible backend. Rather than that we are trying to create API that is the same for all backends, once initalization is done. This is implemented by optional backend attributes that may or may not be supported by a backend.
Definition in file gp_backend.h.
| enum gp_backend_attr |
Backend attributes.
| Enumerator | |
|---|---|
| GP_BACKEND_ATTR_SIZE | Window change request. The attribute value is an array with two integers. |
| GP_BACKEND_ATTR_TITLE | Window title change request. The attribute value is an UTF8 string. |
| GP_BACKEND_ATTR_FULLSCREEN | Fullscreen mode change request. The attribute value is enum gp_backend_fullscreen_req. |
| GP_BACKEND_ATTR_CURSOR | Cursor modifications. The attribute value is enum gp_backend_cursor_req. |
| GP_BACKEND_ATTR_BACKLIGHT | Backlight support. Only a few backends need to support backlight, at the moment it's mostly Linux DRM. |
Definition at line 43 of file gp_backend.h.
Backlight operations.
Definition at line 151 of file gp_backend.h.
Cursor types.
Definition at line 130 of file gp_backend.h.
Fullscreen request type.
| Enumerator | |
|---|---|
| GP_BACKEND_FULLSCREEN_OFF | Request fullscreen to be turned off. |
| GP_BACKEND_FULLSCREEN_ON | Request fullscreen to be turned on. |
| GP_BACKEND_FULLSCREEN_TOGGLE | Toggle fullscreen state. |
| GP_BACKEND_FULLSCREEN_QUERY | Query fullscreen state. Returns the fullscreen state one of GP_BACKEND_ON, GP_BACKEND_OFF or an error e.g. GP_BACKEND_NOTSUPP if fullscreen is not supported. |
Definition at line 111 of file gp_backend.h.
| enum gp_backend_ret |
A return value from the backend set_attr callback.
All error states are negative, for fucntions that sets attribute success is 0 and for functions that query an attribute the return is either >= 0 for success, or negative for errors.
Definition at line 84 of file gp_backend.h.
|
inlinestatic |
Decreases the backlight intensity.
There are a few backends that can modify the backlight intensity, e.g. Linux DRM. For these backends the backlight can be decreased in several steps.
| self | A backend. |
Definition at line 571 of file gp_backend.h.
References GP_BACKEND_ATTR_BACKLIGHT, GP_BACKEND_BACKLIGHT_DEC, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
|
inlinestatic |
Returns backlight intensity in percents.
There are a few backends that can modify the backlight intensity, e.g. Linux DRM.
| self | A backend. |
Definition at line 591 of file gp_backend.h.
References GP_BACKEND_ATTR_BACKLIGHT, GP_BACKEND_BACKLIGHT_GET, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
|
inlinestatic |
Increases the backlight intensity.
There are a few backends that can modify the backlight intensity, e.g. Linux DRM. For these backends the backlight can be increased in several steps.
| self | A backend. |
Definition at line 551 of file gp_backend.h.
References GP_BACKEND_ATTR_BACKLIGHT, GP_BACKEND_BACKLIGHT_INC, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
|
inlinestatic |
Sets backend cursor type.
If supported changes backend cursor to the requested type, disables or enables a cursor.
| self | A backend. |
| cursor | A cursor type. |
Definition at line 532 of file gp_backend.h.
References GP_BACKEND_ATTR_CURSOR, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
|
inlinestatic |
Removes all events from the event queue.
| self | A backend. |
Definition at line 924 of file gp_backend.h.
References gp_backend::event_queue, and gp_ev_queue_flush().
| gp_event * gp_backend_ev_get | ( | gp_backend * | self | ) |
Removes and returns a pointer to a first event in the queue.
| self | A backend. |
|
inlinestatic |
Returns a pointer to a first event in the queue.
Unlike the gp_backend_ev_get() the event is not removed from the queue.
| self | A backend. |
Definition at line 965 of file gp_backend.h.
References gp_backend::event_queue, and gp_ev_queue_peek().
| 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.
This combines a gp_backend_poll() and gp_backend_ev_get() into a one function. The call to gp_backend_poll() may generate more than one event so the function tries to return events from the queue first and only if the queue is empty it reaches to the backend to try to fill the queue.
The function is supposed to be called in a loop:
| self | A backend. |
|
inlinestatic |
Puts back an event that has been just removed from the queue.
This can undo a last call to gp_backend_ev_get() by putting the event that has been just removed back into the queue.
| self | A backend. |
| ev | An event to be put back into the queue. |
Definition at line 982 of file gp_backend.h.
References gp_backend::event_queue, and gp_ev_queue_put_back().
|
inlinestatic |
Returns a number of events in the backend event queue.
| self | A backend. |
Definition at line 936 of file gp_backend.h.
References gp_backend::event_queue, and gp_ev_queue_events().
|
inlinestatic |
Returns an event from the queue, wait the backend for events if the queue is empty.
This combines a gp_backend_wait() and gp_backend_ev_get() into a one function. The call to gp_backend_wait() may generate more than one event so the function tries to return events from the queue first and only if the queue is empty it reaches to the backend to try to fill the queue.
The function is supposed to be called in a loop:
| self | A backend. |
Definition at line 754 of file gp_backend.h.
References gp_backend_ev_wait_timeout().
| 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.
This combines a gp_backend_wait_timeout() and gp_backend_ev_get() into a one function. The call to gp_backend_wait_timeout() may generate more than one event so the function tries to return events from the queue first and only if the queue is empty it reaches to the backend to try to fill the queue.
The function is supposed to be called in a loop:
| self | A backend. |
| timeout_ms | A timeout in miliseconds. Passing -1 means no timeout. |
Referenced by gp_backend_ev_wait().
| void gp_backend_exit | ( | gp_backend * | self | ) |
Exits the backend.
This functions deinitializes the backend. E.g. closes all file descriptors, frees memory, etc.
| self | A backend. |
|
inlinestatic |
Flips backend and display buffers.
In most cases this function swaps buffers between the gp_backend::pixmap and display. If flipping buffers is not supported, e.g. for displays connected over SPI the gp_backend::flip pointer is NULL and the operation falls back to gp_backend_update().
This call is no-op for backends that write directly into the display DMA buffer.
| self | A backend. |
Definition at line 479 of file gp_backend.h.
References gp_backend::flip, and gp_backend_update().
|
inlinestatic |
Reuqests to change fullscreen mode.
| backend | A backend. |
| req | A fullscreen request. |
Definition at line 854 of file gp_backend.h.
References GP_BACKEND_ATTR_FULLSCREEN, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
|
inlinestatic |
Returns backend height.
| self | A backend. |
Definition at line 360 of file gp_backend.h.
References gp_pixmap_h(), and gp_backend::pixmap.
|
inlinestatic |
Returns backend pixel type.
| self | A backend. |
Definition at line 371 of file gp_backend.h.
References gp_pixmap::pixel_type, and gp_backend::pixmap.
| void gp_backend_poll | ( | gp_backend * | self | ) |
Polls a backend for events.
This is a non-blocking function that fills the events into the backend event queue.
| self | A backend. |
| void gp_backend_poll_add | ( | gp_backend * | self, |
| gp_fd * | fd ) |
Add a file descriptor to the backend poll loop.
If fd gp_fd::event callback is NULL a gp_event with GP_EV_FD type is pushed into the backend event queue once events are returned from poll.
| self | A backend. |
| fd | A file descriptor with a callback. |
|
inlinestatic |
Removes a file descriptor to the backend poll loop.
| self | A backend. |
| fd | A file descriptor with a callback. |
Definition at line 504 of file gp_backend.h.
References gp_backend::fds, and gp_poll_rem().
|
inlinestatic |
Removes a file descriptor to the backend poll loop.
| self | A backend. |
| fd | A file descriptor used to look up the gp_fd structure. |
Definition at line 515 of file gp_backend.h.
References gp_backend::fds, and gp_poll_rem_by_fd().
| int gp_backend_resize | ( | gp_backend * | backend, |
| uint32_t | w, | ||
| uint32_t | h ) |
Request backend resize.
When the backend size matches the requested width and height no action is done.
If a resize request is granted the backend sends GP_EV_SYS event type with GP_EV_SYS_RESIZE code and the new width and height in the struct gp_ev_sys. Upon receiving this event the application must stop any access to the gp_backend::pixmap and call gp_backend_resize_ack() to signal to the backend that it's safe to resize the buffers. Once that is done the application can start drawing to the new and resized gp_backend::pixmap.
| int gp_backend_resize_ack | ( | gp_backend * | self | ) |
Resize acknowledge.
You must call this right after you application has received resize event. For a multithreaded application all threads that operate on the backend pixmap must be stopped first.
After this call returns the backend pixmap has been resized, that means that at least the width, height, and pixels of gp_backend::pixmap are different and the content of the gp_pixmap::pixels is undefined.
This call also resizes the window, display, screen size in the backend gp_ev_queue.
If the function fails the best action to take is to save application data and exit as the backend may be in undefined state.
| self | A backend. |
|
inlinestatic |
Sets backend caption, if supported.
Caption is an UTF8 string that is usually shown in the window title.
Definition at line 818 of file gp_backend.h.
References GP_BACKEND_ATTR_TITLE, GP_BACKEND_NOTSUPP, and gp_backend::set_attr.
| void gp_backend_task_ins | ( | gp_backend * | self, |
| gp_task * | task ) |
Inserts a task into the task queue.
Tasks are executed sequentionally and input processing is blocked during task execution.
| self | A backend. |
| task | A task to be inserted into the task queue. |
| void gp_backend_task_queue_set | ( | gp_backend * | self, |
| gp_task_queue * | task_queue ) |
Sets the backend task_queue and starts task processing.
By default backends does not have a task queue populated. Applications that require a task queue have to allocate and initialize the queue then pass it to the backend with this function.
| self | A backend. |
| task_queue | A pointer to initialized task_queue. |
| void gp_backend_task_rem | ( | gp_backend * | self, |
| gp_task * | task ) |
Removes a task from the task queue.
| self | A backend. |
| task | A task to be removed from the task queue. |
| void gp_backend_timer_reschedule | ( | gp_backend * | self, |
| gp_timer * | timer, | ||
| uint32_t | expires_ms ) |
Reschedules a timer.
If a timer is running (inserted into the timer queue) it's stopped before it's started again.
| self | A backend. |
| timer | A timer. |
| expires_ms | A new timeout for the timer in miliseconds. |
| void gp_backend_timer_start | ( | gp_backend * | self, |
| gp_timer * | timer ) |
| void gp_backend_timer_stop | ( | gp_backend * | self, |
| gp_timer * | timer ) |
Removes timer from backend timer queue.
| self | A backend. |
| timer | A timer. |
| int gp_backend_timer_timeout | ( | gp_backend * | self | ) |
Returns time to the closest timer timeout.
| self | A backend. |
|
inlinestatic |
Returns number of timers scheduled in backend.
| self | A backend. |
Definition at line 795 of file gp_backend.h.
References gp_timer_queue_size(), and gp_backend::timers.
|
inlinestatic |
Copies data from backend buffer to display.
This function copies the data from the backend pixmap to the displayed buffer. Unlike the gp_backend_flip() the pixmap data are kept after the operation. For some backends, e.g. Linux DRM this means that this function does memcpy() of the buffer we are about to display. For SPI display backends this sends the whole gp_backend::pixmap pixels buffer to the display over SPI.
This call is no-op for backends that write directly into the display DMA buffer.
| self | A backend. |
Definition at line 454 of file gp_backend.h.
References gp_backend::update.
Referenced by gp_backend_flip().
|
inlinestatic |
Copies a rectangle from backend pixmap to a display.
This is an alias for gp_backend_update_rect_xyxy().
| self | A backend. |
| x0 | First x coordinate of the rectangle. |
| y0 | First y coordinate of the rectangle. |
| x1 | Last x coordinate of the rectangle. |
| y1 | Last y coordinate of the rectangle. |
Definition at line 414 of file gp_backend.h.
References gp_backend_update_rect_xyxy().
|
inlinestatic |
Copies a rectangle from backend pixmap to a display.
This is a version of gp_backend_update_rect_xyxy() with width and height.
| self | A backend. |
| x | Left x coordinate of the rectangle. |
| y | Top y coordinate of the rectangle. |
| w | Rectangle width. |
| h | Rectangle height. |
Definition at line 432 of file gp_backend.h.
References gp_backend_update_rect_xyxy().
| 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.
Updates a rectangle from a gp_pixmap::pixels buffer on the display.
This call is no-op for backends that write directly into the display DMA buffer.
| self | A backend. |
| x0 | First x coordinate of the rectangle. |
| y0 | First y coordinate of the rectangle. |
| x1 | Last x coordinate of the rectangle. |
| y1 | Last y coordinate of the rectangle. |
Referenced by gp_backend_update_rect(), and gp_backend_update_rect_xywh().
|
inlinestatic |
Returns backend width.
| self | A backend. |
Definition at line 349 of file gp_backend.h.
References gp_pixmap_w(), and gp_backend::pixmap.
|
inlinestatic |
Waits for a backend events.
This is a blocking call that fills the events into the backend event queue.
Once this call returns the events from the event queue must be processed.
The event processing may look like:
| self | A backend. |
Definition at line 702 of file gp_backend.h.
References gp_backend_wait_timeout().
| void gp_backend_wait_timeout | ( | gp_backend * | self, |
| int | timeout_ms ) |
Waits for a backend events with a timeout.
This is a blocking call that fills the events into the backend event queue until timeout.
Once this call returns the events from the event queue must be processed.
The event processing may look like:
| self | A backend. |
| timeout_ms | A timeout in miliseconds. Passing -1 means no timeout. |
Referenced by gp_backend_wait().