summaryrefslogtreecommitdiffstats
path: root/src/vivante_utils.h
blob: e7bd2d4bd35ab710fe99e1cdeca705a2634fffd3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*
 * Vivante GPU Acceleration Xorg driver
 *
 * Written by Russell King, 2012, derived in part from the
 * Intel xorg X server driver.
 */
#ifndef VIVANTE_UTILS_H
#define VIVANTE_UTILS_H

/* Needed for gcsRECT */
#include <gc_hal_base.h>

struct vivante;
struct vivante_pixmap;

const char *vivante_strerror(int err);
#define vivante_error(v,w,e) __vivante_error(v,__func__,w,e)
void __vivante_error(struct vivante *, const char *, const char *, int);

static inline PixmapPtr vivante_drawable_pixmap(DrawablePtr pDrawable)
{
	if (OnScreenDrawable(pDrawable->type)) {
		WindowPtr pWin = container_of(pDrawable, struct _Window, drawable);

		return pDrawable->pScreen->GetWindowPixmap(pWin);
	} else {
		return container_of(pDrawable, struct _Pixmap, drawable);
	}
}

PixmapPtr vivante_drawable_pixmap_deltas(DrawablePtr pDrawable, int *x, int *y);

Bool vivante_map_bo_to_gpu(struct vivante *vivante, struct drm_armada_bo *bo,
	void **info, uint32_t *handle);
void vivante_unmap_from_gpu(struct vivante *vivante, void *info,
	uint32_t handle);

void vivante_unmap_gpu(struct vivante *vivante, struct vivante_pixmap *vPix);
Bool vivante_map_gpu(struct vivante *vivante, struct vivante_pixmap *vPix);

enum {
	ACCESS_RO,
	ACCESS_RW,
};

void vivante_finish_drawable(DrawablePtr pDrawable, int access);
void vivante_prepare_drawable(DrawablePtr pDrawable, int access);

gceSURF_FORMAT vivante_pict_format(PictFormatShort format, Bool force);

/*
 * The following functions are here to allow the compiler to inline them
 * if it so wishes; otherwise it will include a copy of these functions
 * in each object including this file.
 */

/*
 * Calculate the intersection of two boxes.  Returns TRUE if
 * they do not overlap.
 */
static inline Bool BoxClip(BoxPtr out, const BoxRec *in, const BoxRec *clip)
{
   out->x1 = max(in->x1, clip->x1);
   out->y1 = max(in->y1, clip->y1);
   out->x2 = min(in->x2, clip->x2);
   out->y2 = min(in->y2, clip->y2);
   return out->x1 >= out->x2 || out->y1 >= out->y2;
}

/* Translate the box by off_x, off_y, and convert to a vivante rectangle */
static inline void RectBox(gcsRECT_PTR rect, const BoxRec *box, int off_x, int off_y)
{
	rect->left   = box->x1 + off_x;
	rect->top    = box->y1 + off_y;
	rect->right  = box->x2 + off_x;
	rect->bottom = box->y2 + off_y;
}

void dump_Drawable(DrawablePtr pDraw, const char *, ...);
void dump_Picture(PicturePtr pDst, const char *, ...);
void dump_vPix(struct vivante *vivante, struct vivante_pixmap *vPix,
	int alpha, const char *fmt, ...);

#endif