2 * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5 * DongKyun Yun <dk77.yun@samsung.com>
6 * SangJin Kim <sangjin3.kim@samsung.com>
7 * HyunGoo Kang <hyungoo1.kang@samsung.com>
9 * Permission is hereby granted, free of charge, to any person obtaining a copy of
10 * this software and associated documentation files (the "Software"), to deal in
11 * the Software without restriction, including without limitation the rights to
12 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
13 * of the Software, and to permit persons to whom the Software is furnished to do
14 * so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included in all
17 * copies or substantial portions of the Software.
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 THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
32 #include "implement.h"
35 EGLSurface EGLAPIENTRY eglCreatePbufferSurface(EGLDisplay dpy, EGLConfig config,
36 const EGLint *attrib_list) {
37 struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy);
38 if (pDisplay == NULL) {
39 EGLINTER(SetError)(EGL_BAD_DISPLAY);
40 return EGL_NO_SURFACE;
42 if (pDisplay->bInitialized == EGL_FALSE) {
43 EGLINTER(SetError)(EGL_NOT_INITIALIZED);
44 return EGL_NO_SURFACE;
46 struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config);
47 if (pConfig == NULL) {
48 EGLINTER(SetError)(EGL_BAD_CONFIG);
49 return EGL_NO_SURFACE;
51 if (pConfig->surfaceType & EGL_PBUFFER_BIT == 0) {
52 EGLINTER(SetError)(EGL_BAD_MATCH);
53 return EGL_NO_SURFACE;
55 struct SurfaceExtra surfaceValue;
56 memcpy(&surfaceValue, &surfaceExtraDefault, sizeof(struct SurfaceExtra));
57 surfaceValue.renderBuffer = EGL_BACK_BUFFER;
60 while (attrib_list && *attrib_list != EGL_NONE) {
61 switch (*attrib_list++) {
64 *ptr++ = *attrib_list++;
68 *ptr++ = *attrib_list++;
70 case EGL_LARGEST_PBUFFER:
71 *ptr++ = GLX_LARGEST_PBUFFER;
72 *ptr++ = (*attrib_list++ == EGL_FALSE) ? False : True;
74 case EGL_TEXTURE_FORMAT:
75 if (*attrib_list == EGL_NO_TEXTURE || *attrib_list == EGL_TEXTURE_RGB
76 || *attrib_list == EGL_TEXTURE_RGBA) {
77 surfaceValue.textureFormat = *attrib_list++;
79 EGLINTER(SetError)(EGL_BAD_PARAMETER);
80 return EGL_NO_SURFACE;
83 case EGL_TEXTURE_TARGET:
84 if (*attrib_list == EGL_NO_TEXTURE || *attrib_list == EGL_TEXTURE_2D) {
85 surfaceValue.textureFormat = *attrib_list++;
87 EGLINTER(SetError)(EGL_BAD_PARAMETER);
88 return EGL_NO_SURFACE;
91 case EGL_MIPMAP_TEXTURE:
92 surfaceValue.mipmapTexture = (*attrib_list++ == EGL_FALSE) ? EGL_FALSE : EGL_TRUE;
94 case EGL_VG_ALPHA_FORMAT:
95 if (*attrib_list == EGL_VG_ALPHA_FORMAT_NONPRE
96 || *attrib_list == EGL_VG_ALPHA_FORMAT_PRE) {
97 surfaceValue.vgAlphaFormat = *attrib_list++;
99 EGLINTER(SetError)(EGL_BAD_PARAMETER);
100 return EGL_NO_SURFACE;
103 case EGL_VG_COLORSPACE:
104 if (*attrib_list == EGL_VG_COLORSPACE_sRGB
105 || *attrib_list == EGL_VG_COLORSPACE_LINEAR) {
106 surfaceValue.vgColorSpace = *attrib_list++;
108 EGLINTER(SetError)(EGL_BAD_PARAMETER);
109 return EGL_NO_SURFACE;
113 EGLINTER(SetError)(EGL_BAD_ATTRIBUTE);
114 return EGL_NO_SURFACE;
118 GLXPbuffer native = FNPTR(CreatePbuffer)(pDisplay->native, pConfig->native, buf);
119 EGLSurface unique = (EGLSurface)(native);
120 struct SurfaceExtra* pSurface = EGLINTER(LookUpSurface)(unique);
121 if (pSurface == NULL) {
122 pSurface = EGLINTER(InsertSurface)(unique);
123 if (pSurface == NULL) {
124 EGLINTER(SetError)(EGL_BAD_ALLOC);
125 return EGL_NO_SURFACE;
127 memcpy(pSurface, &surfaceValue, sizeof(struct SurfaceExtra));
128 pSurface->unique = unique;
129 pSurface->native = native;
130 pSurface->display = dpy;
131 pSurface->config = config;
132 pSurface->type = EGL_PBUFFER_BIT;
135 EGLINTER(SetError)(EGL_BAD_MATCH);
136 return EGL_NO_SURFACE;
138 return (EGLSurface)(pSurface->native);