Initial commit
[profile/ivi/simulator-opengl.git] / egl_1_4 / 35CreatePbufferSurface.c
1 /* 
2  * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
3  * 
4  * Contact:
5  * DongKyun Yun <dk77.yun@samsung.com>
6  * SangJin Kim <sangjin3.kim@samsung.com>
7  * HyunGoo Kang <hyungoo1.kang@samsung.com>
8  *
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:
15  * 
16  * The above copyright notice and this permission notice shall be included in all
17  * copies or substantial portions 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 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
25  * SOFTWARE.
26  * 
27  * Contributors:
28  * - S-Core Co., Ltd
29  *
30  */
31
32 #include "implement.h"
33
34
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;
41         }
42         if (pDisplay->bInitialized == EGL_FALSE) {
43                 EGLINTER(SetError)(EGL_NOT_INITIALIZED);
44                 return EGL_NO_SURFACE;
45         }
46         struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config);
47         if (pConfig == NULL) {
48                 EGLINTER(SetError)(EGL_BAD_CONFIG);
49                 return EGL_NO_SURFACE;
50         }
51         if (pConfig->surfaceType & EGL_PBUFFER_BIT == 0) {
52                 EGLINTER(SetError)(EGL_BAD_MATCH);
53                 return EGL_NO_SURFACE;
54         }
55         struct SurfaceExtra surfaceValue;
56         memcpy(&surfaceValue, &surfaceExtraDefault, sizeof(struct SurfaceExtra));
57         surfaceValue.renderBuffer = EGL_BACK_BUFFER; 
58         int buf[32];
59         int* ptr = &buf[0];
60         while (attrib_list && *attrib_list != EGL_NONE) {
61                 switch (*attrib_list++) {
62                 case EGL_WIDTH: 
63                         *ptr++ = GLX_WIDTH;
64                         *ptr++ = *attrib_list++;
65                         break;
66                 case EGL_HEIGHT: 
67                         *ptr++ = GLX_HEIGHT;
68                         *ptr++ = *attrib_list++;
69                         break;
70                 case EGL_LARGEST_PBUFFER: 
71                         *ptr++ = GLX_LARGEST_PBUFFER;
72                         *ptr++ = (*attrib_list++ == EGL_FALSE) ? False : True;
73                         break;
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++;
78                         } else {
79                                 EGLINTER(SetError)(EGL_BAD_PARAMETER);
80                                 return EGL_NO_SURFACE;
81                         }
82                         break;
83                 case EGL_TEXTURE_TARGET:
84                         if (*attrib_list == EGL_NO_TEXTURE || *attrib_list == EGL_TEXTURE_2D) {
85                                 surfaceValue.textureFormat = *attrib_list++;
86                         } else {
87                                 EGLINTER(SetError)(EGL_BAD_PARAMETER);
88                                 return EGL_NO_SURFACE;
89                         }
90                         break;
91                 case EGL_MIPMAP_TEXTURE:
92                         surfaceValue.mipmapTexture = (*attrib_list++ == EGL_FALSE) ? EGL_FALSE : EGL_TRUE;
93                         break;
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++;
98                         } else {
99                                 EGLINTER(SetError)(EGL_BAD_PARAMETER);
100                                 return EGL_NO_SURFACE;
101                         }
102                         break;
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++;
107                         } else {
108                                 EGLINTER(SetError)(EGL_BAD_PARAMETER);
109                                 return EGL_NO_SURFACE;
110                         }
111                         break;
112                 default:
113                         EGLINTER(SetError)(EGL_BAD_ATTRIBUTE);
114                         return EGL_NO_SURFACE;
115                 }
116         }
117         *ptr = None;
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;
126                 }
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;
133         } else {
134                 
135                 EGLINTER(SetError)(EGL_BAD_MATCH);
136                 return EGL_NO_SURFACE;
137         }
138         return (EGLSurface)(pSurface->native);
139 }