/* * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved. * * Contact: * DongKyun Yun * SangJin Kim * HyunGoo Kang * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies * of the Software, and to permit persons to whom the Software is furnished to do * so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * Contributors: * - S-Core Co., Ltd * */ #include "implement.h" EGLSurface EGLAPIENTRY eglCreatePixmapSurface(EGLDisplay dpy, EGLConfig config, EGLNativePixmapType pixmap, const EGLint *attrib_list) { struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy); if (pDisplay == NULL) { EGLINTER(SetError)(EGL_BAD_DISPLAY); return EGL_NO_SURFACE; } if (pDisplay->bInitialized == EGL_FALSE) { EGLINTER(SetError)(EGL_NOT_INITIALIZED); return EGL_NO_SURFACE; } struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config); if (pConfig == NULL) { EGLINTER(SetError)(EGL_BAD_CONFIG); return EGL_NO_SURFACE; } if (pConfig->surfaceType & EGL_PIXMAP_BIT == 0) { EGLINTER(SetError)(EGL_BAD_MATCH); return EGL_NO_SURFACE; } struct SurfaceExtra surfaceValue; memcpy(&surfaceValue, &surfaceExtraDefault, sizeof(struct SurfaceExtra)); surfaceValue.renderBuffer = EGL_SINGLE_BUFFER; while (attrib_list && *attrib_list != EGL_NONE) { switch (*attrib_list++) { case EGL_VG_COLORSPACE: if (*attrib_list == EGL_VG_COLORSPACE_sRGB || *attrib_list == EGL_VG_COLORSPACE_LINEAR) { surfaceValue.vgColorSpace = *attrib_list++; } else { EGLINTER(SetError)(EGL_BAD_PARAMETER); return EGL_NO_SURFACE; } break; case EGL_VG_ALPHA_FORMAT: if (*attrib_list == EGL_VG_ALPHA_FORMAT_NONPRE || *attrib_list == EGL_VG_ALPHA_FORMAT_PRE) { surfaceValue.vgAlphaFormat = *attrib_list++; } else { EGLINTER(SetError)(EGL_BAD_PARAMETER); return EGL_NO_SURFACE; } break; default: EGLINTER(SetError)(EGL_BAD_ATTRIBUTE); return EGL_NO_SURFACE; } } Window root; unsigned dummy, width, height; if (XGetGeometry(pDisplay->native, (Pixmap)pixmap, &root, &dummy, &dummy, &width, &height, &dummy, &dummy) == 0) { fprintf (stderr, "XGetGeometry failed.\n"); EGLINTER(SetError)(EGL_BAD_NATIVE_PIXMAP); return EGL_FALSE; } /* Need pass the width & height, so put them in attrib_list although it * should be NULL in normal */ int buf[8]; int* ptr = &buf[0]; *ptr++ = GLX_WIDTH; *ptr++ = width; *ptr++ = GLX_HEIGHT; *ptr++ = height; *ptr++ = None; GLXPixmap native = FNPTR(CreatePixmap)(pDisplay->native, pConfig->native, pixmap, buf); EGLSurface unique = (EGLSurface)(native); struct SurfaceExtra* pSurface = EGLINTER(LookUpSurface)(unique); if (pSurface == NULL) { pSurface = EGLINTER(InsertSurface)(unique); if (pSurface == NULL) { EGLINTER(SetError)(EGL_BAD_ALLOC); return EGL_NO_SURFACE; } memcpy(pSurface, &surfaceValue, sizeof(struct SurfaceExtra)); pSurface->unique = unique; pSurface->native = native; pSurface->lowWinPix = pixmap; pSurface->display = dpy; pSurface->config = config; pSurface->type = EGL_PIXMAP_BIT; } else { EGLINTER(SetError)(EGL_BAD_MATCH); return EGL_NO_SURFACE; } return (EGLSurface)(pSurface->native); }