eglimage.c revision cdc920a0
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 */
15static 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      case EGL_GL_TEXTURE_LEVEL_KHR:
32         img->GLTextureLevel = val;
33         break;
34      case EGL_GL_TEXTURE_ZOFFSET_KHR:
35         img->GLTextureZOffset = val;
36         break;
37      default:
38         /* unknown attrs are ignored */
39         break;
40      }
41
42      if (err != EGL_SUCCESS) {
43         _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
44         break;
45      }
46   }
47
48   return err;
49}
50
51
52EGLBoolean
53_eglInitImage(_EGLImage *img, _EGLDisplay *dpy, const EGLint *attrib_list)
54{
55   EGLint err;
56
57   memset(img, 0, sizeof(_EGLImage));
58   img->Resource.Display = dpy;
59
60   img->Preserved = EGL_FALSE;
61   img->GLTextureLevel = 0;
62   img->GLTextureZOffset = 0;
63
64   err = _eglParseImageAttribList(img, attrib_list);
65   if (err != EGL_SUCCESS)
66      return _eglError(err, "eglCreateImageKHR");
67
68   return EGL_TRUE;
69}
70
71
72_EGLImage *
73_eglCreateImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLContext *ctx,
74                   EGLenum target, EGLClientBuffer buffer,
75                   const EGLint *attr_list)
76{
77   /* driver should override this function */
78   return NULL;
79}
80
81
82EGLBoolean
83_eglDestroyImageKHR(_EGLDriver *drv, _EGLDisplay *dpy, _EGLImage *image)
84{
85   /* driver should override this function */
86   return EGL_FALSE;
87}
88
89
90#endif /* EGL_KHR_image_base */
91