PebbleOS v4.47.0-327-g7753e801d
Loading...
Searching...
No Matches

2D graphics accelerator class. More...

Modules

 SF32LB57 ePIC
 GPU driver for the ePIC graphics accelerator of the SF32LB57.
 

Data Structures

struct  pbl_gpu_caps
 What a GPU can do. More...
 
struct  pbl_gpu_buffer
 A pixel buffer. More...
 
struct  pbl_gpu_rect
 A rectangle of a buffer. More...
 
struct  pbl_gpu_transform
 Rotation and scaling of a blit around a pivot, which stays where it is. More...
 
struct  pbl_gpu_blit
 A blit: a source drawn over what the target holds. More...
 
struct  pbl_gpu_ops
 GPU driver operations. More...
 
struct  pbl_gpu
 A GPU. More...
 

Macros

#define PBL_GPU_ALPHA_OPAQUE   255U
 Opaque alpha.
 
#define PBL_GPU_SCALE_NONE   256U
 Scale of 1:1.
 
#define PBL_GPU_STATE_DEFINE(sym)
 Define the class state of GPU sym, for the PBL_*_DEFINE() macro of a driver.
 
#define PBL_GPU_INIT(sym, _name, _ops, _deps, ...)
 Initializer for the struct pbl_gpu of GPU sym.
 

Enumerations

enum  pbl_gpu_format : uint8_t {
  PBL_GPU_FORMAT_RGB565 , PBL_GPU_FORMAT_RGB888 , PBL_GPU_FORMAT_ARGB8888 , PBL_GPU_FORMAT_A8 ,
  PBL_GPU_FORMAT_COUNT
}
 Pixel formats. More...
 
enum  : uint32_t { PBL_GPU_CAP_ROTATE = PBL_BIT(0) , PBL_GPU_CAP_SCALE = PBL_BIT(1) }
 Capability flags. More...
 

Functions

int pbl_gpu_init (const struct pbl_device *dev)
 Device init of every GPU: calls the driver's init.
 
static const struct pbl_gpu_caps * pbl_gpu_get_caps (const struct pbl_gpu *gpu)
 Get what a GPU can do.
 
int pbl_gpu_fill (const struct pbl_gpu *gpu, const struct pbl_gpu_buffer *dst, const struct pbl_gpu_rect *rect, uint32_t argb)
 Fill a rectangle with a color.
 
int pbl_gpu_blit (const struct pbl_gpu *gpu, const struct pbl_gpu_buffer *dst, const struct pbl_gpu_rect *clip, const struct pbl_gpu_blit *blit)
 Draw a buffer over another.
 

Variables

const struct pbl_device_class pbl_gpu_class
 Class of the GPUs.
 
const struct pbl_gpu *const GPU
 The GPU, defined by the board.
 

Detailed Description

2D graphics accelerator class.

A GPU is a struct pbl_gpu device that draws into pixel buffers owned by the caller: it fills rectangles and blits one buffer onto another, converting between formats, blending and, where the hardware can, rotating and scaling. What a GPU can do is in its pbl_gpu_caps. A job it cannot take is refused with -ENOTSUP before anything is drawn, for the caller to draw it in software, so the class can be used without knowing the hardware behind it.

struct pbl_gpu_buffer fb = {
.data = pixels, .pitch = 390 * 2, .width = 390, .height = 450,
};
struct pbl_gpu_rect bar = {.x = 0, .y = 400, .width = 390, .height = 50};
// Half-transparent red over what the bar holds
ret = pbl_gpu_fill(GPU, &fb, &bar, 0x80FF0000);
struct pbl_gpu_blit blit = {.src = &icon, .x = 20, .y = 20, .alpha = 255};
ret = pbl_gpu_blit(GPU, &fb, nullptr, &blit);
void * data
First pixel.
Definition gpu.h:86
int16_t x
Left column.
Definition gpu.h:100
const struct pbl_gpu_buffer * src
Source.
Definition gpu.h:126
A blit: a source drawn over what the target holds.
Definition gpu.h:124
A rectangle of a buffer.
Definition gpu.h:98
A pixel buffer.
Definition gpu.h:84
const struct pbl_gpu *const GPU
The GPU, defined by the board.
int pbl_gpu_fill(const struct pbl_gpu *gpu, const struct pbl_gpu_buffer *dst, const struct pbl_gpu_rect *rect, uint32_t argb)
Fill a rectangle with a color.
@ PBL_GPU_FORMAT_RGB565
16 bits per pixel: 5 of red, 6 of green and 5 of blue, from the most significant bit.
Definition gpu.h:48

Calls are made from task context, one job at a time, and return once the job is done, with the target ready to be read by the CPU: buffers may be cached. They return 0 or a negative errno: -ENOTSUP for a job the GPU cannot take, -EINVAL for an invalid one, -ENODEV if the GPU is not ready and -EIO or -ETIMEDOUT if the hardware failed.


Data Structure Documentation

◆ pbl_gpu_caps

struct pbl_gpu_caps

What a GPU can do.

Data Fields
uint32_t dst_formats Formats it draws into, a bit per pbl_gpu_format.
uint32_t flags Capability flags.
uint32_t src_formats Formats it blits from, a bit per pbl_gpu_format.

◆ pbl_gpu_buffer

struct pbl_gpu_buffer

A pixel buffer.

Data Fields
void * data First pixel.
enum pbl_gpu_format format Format.
uint16_t height Height, in pixels.
uint32_t pitch Bytes from one row to the next.
uint16_t width Width, in pixels.

◆ pbl_gpu_rect

struct pbl_gpu_rect

A rectangle of a buffer.

Data Fields
uint16_t height Height, in pixels.
uint16_t width Width, in pixels.
int16_t x Left column.
int16_t y Top row.

◆ pbl_gpu_transform

struct pbl_gpu_transform

Rotation and scaling of a blit around a pivot, which stays where it is.

Data Fields
int16_t angle Clockwise rotation, in tenths of a degree.
int16_t pivot_x Pivot column, from the first pixel of the source.
int16_t pivot_y Pivot row, from the first pixel of the source.
uint16_t scale_x Horizontal scale, PBL_GPU_SCALE_NONE for 1:1.
uint16_t scale_y Vertical scale, PBL_GPU_SCALE_NONE for 1:1.

◆ pbl_gpu_blit

struct pbl_gpu_blit

A blit: a source drawn over what the target holds.

Data Fields
uint8_t alpha Alpha of the whole source, on top of its own: PBL_GPU_ALPHA_OPAQUE to leave it.
uint32_t color Color of a PBL_GPU_FORMAT_A8 source, as 0x00RRGGBB.
const struct pbl_gpu_buffer * src Source.
const struct pbl_gpu_transform * transform Transform, or NULL.
int16_t x Column of the target the first pixel of the source goes to, before any transform.
int16_t y Row of the target the first pixel of the source goes to, before any transform.

◆ pbl_gpu

struct pbl_gpu

A GPU.

Data Fields
struct pbl_gpu_caps caps Capabilities.
struct pbl_device dev Device.
const struct pbl_gpu_ops * ops Driver operations.
struct pbl_gpu_state * state Runtime state.

Macro Definition Documentation

◆ PBL_GPU_ALPHA_OPAQUE

#define PBL_GPU_ALPHA_OPAQUE   255U

Opaque alpha.

◆ PBL_GPU_INIT

#define PBL_GPU_INIT (   sym,
  _name,
  _ops,
  _deps,
  ... 
)
Value:
{ \
.dev = PBL_DEVICE_INIT_CLASS(sym, _name, pbl_gpu_init, nullptr, _deps, &pbl_gpu_class), \
.ops = (_ops), .state = &sym##_gpu_state, .caps = { \
__VA_ARGS__ \
} \
}
#define PBL_DEVICE_INIT_CLASS(sym, _name, _init, _parent, _deps, _cls)
Initializer for the struct pbl_device of device instance sym, in class _cls.
Definition device.h:145
const struct pbl_device_class pbl_gpu_class
Class of the GPUs.
int pbl_gpu_init(const struct pbl_device *dev)
Device init of every GPU: calls the driver's init.

Initializer for the struct pbl_gpu of GPU sym.

Parameters
symSymbol of the GPU instance, with its state defined by PBL_GPU_STATE_DEFINE().
_nameName.
_opsDriver operations.
_depsDependencies from PBL_DEVICE_DEPS(), or NULL.
...Capabilities, designated initializers of struct pbl_gpu_caps.

◆ PBL_GPU_SCALE_NONE

#define PBL_GPU_SCALE_NONE   256U

Scale of 1:1.

◆ PBL_GPU_STATE_DEFINE

#define PBL_GPU_STATE_DEFINE (   sym)
Value:
static struct pbl_gpu_state sym##_gpu_state = {.lock = PBL_MUTEX_INITIALIZER}
#define PBL_DEVICE_STATE_DEFINE(sym)
Define the runtime state of device instance sym.
Definition device.h:131
#define PBL_MUTEX_INITIALIZER
Static initializer for an unlocked mutex.
Definition mutex.h:50

Define the class state of GPU sym, for the PBL_*_DEFINE() macro of a driver.

Parameters
symSymbol of the GPU instance.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum : uint32_t

Capability flags.

Enumerator
PBL_GPU_CAP_ROTATE 

Blits rotate by any angle.

PBL_GPU_CAP_SCALE 

Blits scale.

◆ pbl_gpu_format

enum pbl_gpu_format : uint8_t

Pixel formats.

Pixels wider than a byte are little-endian.

Enumerator
PBL_GPU_FORMAT_RGB565 

16 bits per pixel: 5 of red, 6 of green and 5 of blue, from the most significant bit.

PBL_GPU_FORMAT_RGB888 

24 bits per pixel: 8 of red, green and blue, from the most significant bit.

PBL_GPU_FORMAT_ARGB8888 

32 bits per pixel: 8 of alpha, red, green and blue, from the most significant bit.

PBL_GPU_FORMAT_A8 

8 bits per pixel, alpha only: the color comes from the blit.

PBL_GPU_FORMAT_COUNT 

Number of formats.

Function Documentation

◆ pbl_gpu_blit()

int pbl_gpu_blit ( const struct pbl_gpu *  gpu,
const struct pbl_gpu_buffer *  dst,
const struct pbl_gpu_rect *  clip,
const struct pbl_gpu_blit *  blit 
)

Draw a buffer over another.

Parameters
gpuGPU.
dstTarget.
clipRectangle of the target that may change, clipped to it, or NULL for all of it.
blitSource, where it goes and how.
Returns
0 or a negative errno.

◆ pbl_gpu_fill()

int pbl_gpu_fill ( const struct pbl_gpu *  gpu,
const struct pbl_gpu_buffer *  dst,
const struct pbl_gpu_rect *  rect,
uint32_t  argb 
)

Fill a rectangle with a color.

Parameters
gpuGPU.
dstTarget.
rectRectangle, clipped to the target, or NULL for all of it.
argbColor, as 0xAARRGGBB: blended over what the rectangle holds unless its alpha is PBL_GPU_ALPHA_OPAQUE.
Returns
0 or a negative errno.

◆ pbl_gpu_get_caps()

static const struct pbl_gpu_caps * pbl_gpu_get_caps ( const struct pbl_gpu *  gpu)
inlinestatic

Get what a GPU can do.

Parameters
gpuGPU.
Returns
Capabilities.

References pbl_gpu::caps.

◆ pbl_gpu_init()

int pbl_gpu_init ( const struct pbl_device *  dev)

Device init of every GPU: calls the driver's init.

Parameters
devGPU device.
Returns
0 or a negative errno.

Variable Documentation

◆ GPU

const struct pbl_gpu* const GPU
extern

The GPU, defined by the board.

◆ pbl_gpu_class

const struct pbl_device_class pbl_gpu_class
extern

Class of the GPUs.