XenevaOS
Loading...
Searching...
No Matches
gpudamage.h
Go to the documentation of this file.
1/* Pure bounded damage-state helpers, also compiled by the host regression test.
2 * Callers serialize access (AArch64 device ioctls run with IRQs masked).
3 */
4#ifndef __GPU_DAMAGE_H__
5#define __GPU_DAMAGE_H__
6#include <stdint.h>
7#include <gpusrv.h>
8
9typedef struct {
11 uint32_t left, top, right, bottom, dirty, busy;
12 uint64_t next, pending;
13} GpuDamage;
14
15static inline int GpuDamageAdd(GpuDamage* d, uint64_t x, uint64_t y,
16 uint64_t w, uint64_t h) {
17 if (!w || !h || x >= d->width || y >= d->height ||
18 w > d->width - x || h > d->height - y)
19 return GPUSRV_E_INVAL;
20 uint32_t r = (uint32_t)(x + w), b = (uint32_t)(y + h);
21 if (!d->dirty) {
22 d->left = (uint32_t)x; d->top = (uint32_t)y;
23 d->right = r; d->bottom = b; d->dirty = 1;
24 } else {
25 if (x < d->left) d->left = (uint32_t)x;
26 if (y < d->top) d->top = (uint32_t)y;
27 if (r > d->right) d->right = r;
28 if (b > d->bottom) d->bottom = b;
29 }
30 return GPUSRV_OK;
31}
32
33static inline int GpuDamageTake(GpuDamage* d, GpuSrvFrame* f) {
34 if (d->busy) return GPUSRV_E_BUSY;
35 if (!d->dirty) return GPUSRV_E_EMPTY;
36 if (++d->next == 0) ++d->next;
37 d->pending = d->next; d->busy = 1; d->dirty = 0;
38 f->sequence = d->pending;
39 f->x = d->left; f->y = d->top;
40 f->width = d->right - d->left; f->height = d->bottom - d->top;
41 return GPUSRV_OK;
42}
43
44static inline int GpuDamageAck(GpuDamage* d, uint64_t sequence) {
45 if (!d->busy || sequence != d->pending) return GPUSRV_E_INVAL;
46 d->busy = 0;
47 return GPUSRV_OK;
48}
49
50static inline void GpuDamageReset(GpuDamage* d) {
51 /* Do not reset next: an old generation's ACK must never match a new frame. */
52 d->busy = 0;
53 (void)GpuDamageAdd(d, 0, 0, d->width, d->height);
54}
55#endif
size_t b
Definition main.cpp:156
unsigned int uint32_t
Definition acefiex.h:163
COMPILER_DEPENDENT_UINT64 uint64_t
Definition acefiex.h:165
const char * f
Definition drm_print.h:205
#define GPUSRV_E_EMPTY
Definition gpusrv.h:42
#define GPUSRV_E_BUSY
Definition gpusrv.h:41
#define GPUSRV_OK
Definition gpusrv.h:38
#define GPUSRV_E_INVAL
Definition gpusrv.h:40
int y
Definition layout.c:118
int h
Definition layout.c:118
int x
Definition layout.c:118
int w
Definition layout.c:118
#define d
Definition libunicode.c:1833
@ top
Definition p_spec.h:217
Definition gpudamage.h:9
uint32_t bottom
Definition gpudamage.h:11
uint64_t next
Definition gpudamage.h:12
uint32_t height
Definition gpudamage.h:10
Definition gpusrv.h:64
bool dirty
Definition term.cpp:55