eglimage.c revision f2001df508fda599a18b3586d2775e970a3db13a
1/**************************************************************************
2 *
3 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
4 * Copyright 2010-2011 LunarG, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30#include <assert.h>
31#include <string.h>
32
33#include "eglimage.h"
34#include "egllog.h"
35
36
37#ifdef EGL_KHR_image_base
38
39
40/**
41 * Parse the list of image attributes and return the proper error code.
42 */
43EGLint
44_eglParseImageAttribList(_EGLImageAttribs *attrs, _EGLDisplay *dpy,
45                         const EGLint *attrib_list)
46{
47   EGLint i, err = EGL_SUCCESS;
48
49   (void) dpy;
50
51   memset(attrs, 0, sizeof(attrs));
52   attrs->ImagePreserved = EGL_FALSE;
53   attrs->GLTextureLevel = 0;
54   attrs->GLTextureZOffset = 0;
55
56   if (!attrib_list)
57      return err;
58
59   for (i = 0; attrib_list[i] != EGL_NONE; i++) {
60      EGLint attr = attrib_list[i++];
61      EGLint val = attrib_list[i];
62
63      switch (attr) {
64      /* EGL_KHR_image_base */
65      case EGL_IMAGE_PRESERVED_KHR:
66         attrs->ImagePreserved = val;
67         break;
68
69      /* EGL_KHR_gl_image */
70      case EGL_GL_TEXTURE_LEVEL_KHR:
71         attrs->GLTextureLevel = val;
72         break;
73      case EGL_GL_TEXTURE_ZOFFSET_KHR:
74         attrs->GLTextureZOffset = val;
75         break;
76
77      /* EGL_MESA_drm_image */
78      case EGL_WIDTH:
79         attrs->Width = val;
80         break;
81      case EGL_HEIGHT:
82         attrs->Height = val;
83         break;
84      case EGL_DRM_BUFFER_FORMAT_MESA:
85         attrs->DRMBufferFormatMESA = val;
86         break;
87      case EGL_DRM_BUFFER_USE_MESA:
88         attrs->DRMBufferUseMESA = val;
89         break;
90      case EGL_DRM_BUFFER_STRIDE_MESA:
91         attrs->DRMBufferStrideMESA = val;
92         break;
93
94      default:
95         /* unknown attrs are ignored */
96         break;
97      }
98
99      if (err != EGL_SUCCESS) {
100         _eglLog(_EGL_DEBUG, "bad image attribute 0x%04x", attr);
101         break;
102      }
103   }
104
105   return err;
106}
107
108
109EGLBoolean
110_eglInitImage(_EGLImage *img, _EGLDisplay *dpy)
111{
112   _eglInitResource(&img->Resource, sizeof(*img), dpy);
113
114   return EGL_TRUE;
115}
116
117
118#endif /* EGL_KHR_image_base */
119