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