egl: Refactor _eglInitImage.
[mesa.git] / src / egl / main / eglimage.c
1 #include <assert.h>
2 #include <string.h>
3
4 #include "eglimage.h"
5 #include "eglcurrent.h"
6 #include "egllog.h"
7
8
9 #ifdef EGL_KHR_image_base
10
11
12 /**
13 * Parse the list of image attributes and return the proper error code.
14 */
15 static EGLint
16 _eglParseImageAttribList(_EGLImage *img, const EGLint *attrib_list)
17 {
18 EGLint i, err = EGL_SUCCESS;
19
20 if (!attrib_list)
21 return EGL_SUCCESS;
22
23 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
24 EGLint attr = attrib_list[i++];
25 EGLint val = attrib_list[i];
26
27 switch (attr) {
28 case EGL_IMAGE_PRESERVED_KHR:
29 img->Preserved = val;
30 break;
31 default:
32 err = EGL_BAD_ATTRIBUTE;
33 break;
34 }
35
36 if (err != EGL_SUCCESS) {
37 _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
38 break;
39 }
40 }
41
42 return err;
43 }
44
45
46 EGLBoolean
47 _eglInitImage(_EGLDriver *drv, _EGLImage *img, const EGLint *attrib_list)
48 {
49 EGLint err;
50
51 memset(img, 0, sizeof(_EGLImage));
52
53 img->Preserved = EGL_FALSE;
54
55 err = _eglParseImageAttribList(img, attrib_list);
56 if (err != EGL_SUCCESS)
57 return _eglError(err, "eglCreateImageKHR");
58
59 return EGL_TRUE;
60 }
61
62
63 _EGLImage *
64 _eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
65 EGLenum target, EGLClientBuffer buffer,
66 const EGLint *attr_list)
67 {
68 /* driver should override this function */
69 return NULL;
70 }
71
72
73 EGLBoolean
74 _eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image)
75 {
76 /* driver should override this function */
77 return EGL_FALSE;
78 }
79
80
81 #endif /* EGL_KHR_image_base */