026b10307dedc4b498539d177a045c6f5ea9f183
[mesa.git] / src / egl / main / eglimage.h
1 #ifndef EGLIMAGE_INCLUDED
2 #define EGLIMAGE_INCLUDED
3
4
5 #include "egltypedefs.h"
6 #include "egldisplay.h"
7
8
9 /**
10 * "Base" class for device driver images.
11 */
12 struct _egl_image
13 {
14 /* An image is a display resource */
15 _EGLResource Resource;
16
17 EGLBoolean Preserved;
18 };
19
20
21 PUBLIC EGLBoolean
22 _eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list);
23
24
25 extern _EGLImage *
26 _eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
27 EGLenum target, EGLClientBuffer buffer, const EGLint *attr_list);
28
29
30 extern EGLBoolean
31 _eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image);
32
33
34 /**
35 * Link an image to a display and return the handle of the link.
36 * The handle can be passed to client directly.
37 */
38 static INLINE EGLImageKHR
39 _eglLinkImage(_EGLImage *img, _EGLDisplay *dpy)
40 {
41 _eglLinkResource(&img->Resource, _EGL_RESOURCE_IMAGE, dpy);
42 return (EGLImageKHR) img;
43 }
44
45
46 /**
47 * Unlink a linked image from its display.
48 * Accessing an unlinked image should generate EGL_BAD_PARAMETER error.
49 */
50 static INLINE void
51 _eglUnlinkImage(_EGLImage *img)
52 {
53 _eglUnlinkResource(&img->Resource, _EGL_RESOURCE_IMAGE);
54 }
55
56
57 /**
58 * Lookup a handle to find the linked image.
59 * Return NULL if the handle has no corresponding linked image.
60 */
61 static INLINE _EGLImage *
62 _eglLookupImage(EGLImageKHR image, _EGLDisplay *dpy)
63 {
64 _EGLResource *res = (_EGLResource *) image;
65 _EGLImage *img = (_EGLImage *) image;
66 if (!res || !dpy || !_eglCheckResource(res, _EGL_RESOURCE_IMAGE, dpy))
67 img = NULL;
68 return img;
69 }
70
71
72 /**
73 * Return the handle of a linked image, or EGL_NO_IMAGE_KHR.
74 */
75 static INLINE EGLImageKHR
76 _eglGetImageHandle(_EGLImage *img)
77 {
78 _EGLResource *res = (_EGLResource *) img;
79 return (res && _eglIsResourceLinked(res)) ?
80 (EGLImageKHR) img : EGL_NO_IMAGE_KHR;
81 }
82
83
84 /**
85 * Return true if the image is linked to a display.
86 */
87 static INLINE EGLBoolean
88 _eglIsImageLinked(_EGLImage *img)
89 {
90 _EGLResource *res = (_EGLResource *) img;
91 return (res && _eglIsResourceLinked(res));
92 }
93
94
95 #endif /* EGLIMAGE_INCLUDED */