Initial commit
[profile/ivi/simulator-opengl.git] / egl_1_4 / 34GetConfigAttrib.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 #include <dlfcn.h>
34
35 struct ConfigExtra* EGLINTER(LookUpConfig)(struct DisplayExtra* pDisplay, EGLConfig config) {
36         
37         struct ConfigExtra* pConfig = (struct ConfigExtra*)config;
38         struct ConfigExtra* pUnit = pDisplay->pConfigExtra;
39         int nCount = pDisplay->nConfigExtra;
40         while (nCount--) {
41                 if (pConfig == pUnit) {
42                         return pConfig;
43                 }
44                 pUnit++;
45         }
46         return NULL;
47 }
48
49 EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
50         EGLint attribute, EGLint *value) {
51         struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy);
52         if (pDisplay == NULL) {
53                 EGLINTER(SetError)(EGL_BAD_DISPLAY);
54                 return EGL_FALSE;
55         }
56         if (pDisplay->bInitialized == EGL_FALSE) {
57                 EGLINTER(SetError)(EGL_NOT_INITIALIZED);
58                 return EGL_FALSE;
59         }
60         struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config);
61         if (pConfig == NULL) {
62                 EGLINTER(SetError)(EGL_BAD_CONFIG);
63                 return EGL_FALSE;
64         }
65         EGLint answer;
66         switch (attribute) {
67         case EGL_CONFIG_ID:             answer = pConfig->unique; break;
68         case EGL_BUFFER_SIZE:   answer = pConfig->bufferSize; break;
69         case EGL_RED_SIZE:              answer = pConfig->redSize; break;
70         case EGL_GREEN_SIZE:    answer = pConfig->greenSize; break;
71         case EGL_BLUE_SIZE:             answer = pConfig->blueSize; break;
72         case EGL_LUMINANCE_SIZE:        answer = pConfig->luminanceSize; break;
73         case EGL_ALPHA_SIZE:            answer = pConfig->alphaSize; break;
74         case EGL_ALPHA_MASK_SIZE:               answer = pConfig->alphaMaskSize; break;
75         case EGL_BIND_TO_TEXTURE_RGB:   answer = pConfig->bindToTexRGB; break;
76         case EGL_BIND_TO_TEXTURE_RGBA:  answer = pConfig->bindToTexRGBA; break;
77         case EGL_COLOR_BUFFER_TYPE:             answer = pConfig->colorBufferType; break;
78         case EGL_CONFIG_CAVEAT:         answer = pConfig->configCaveat; break;
79         case EGL_CONFORMANT:            answer = pConfig->conformant; break;
80         case EGL_DEPTH_SIZE:            answer = pConfig->depthSize; break;
81         case EGL_LEVEL:                         answer = pConfig->level; break;
82         case EGL_MAX_PBUFFER_WIDTH:             answer = pConfig->maxPbufferWidth; break;
83         case EGL_MAX_PBUFFER_HEIGHT:            answer = pConfig->maxPbufferHeight; break;
84         case EGL_MAX_PBUFFER_PIXELS:            answer = pConfig->maxPbufferPixels; break;
85         case EGL_MAX_SWAP_INTERVAL:             answer = pConfig->maxSwapInterval; break;
86         case EGL_MIN_SWAP_INTERVAL:             answer = pConfig->minSwapInterval; break;
87         case EGL_NATIVE_RENDERABLE:             answer = pConfig->nativeRenderable; break;
88         case EGL_NATIVE_VISUAL_ID:
89                 {
90                         XVisualInfo *vi;
91                         XVisualInfo* (*fpGetVisualFromFBConfig)(Display*, GLXFBConfig) = NULL;
92                         void* dl = dlopen("libGL.so", RTLD_NOW);
93                         assert(dl != 0);
94                         *(void**)(&fpGetVisualFromFBConfig) = dlsym(dl, "glXGetVisualFromFBConfig");
95                         assert(fpGetVisualFromFBConfig != NULL);
96
97                         vi = (*fpGetVisualFromFBConfig) (pDisplay->native, pConfig->native);
98                         answer = vi->visualid;
99                         break;
100                 }
101         case EGL_NATIVE_VISUAL_TYPE:    answer = pConfig->nativeVisualType; break;
102         case EGL_RENDERABLE_TYPE:       answer = pConfig->renderableType; break;
103         case EGL_SAMPLE_BUFFERS: answer = pConfig->sampleBuffers; break;
104         case EGL_SAMPLES: answer = pConfig->samples; break;
105         case EGL_STENCIL_SIZE: answer = pConfig->stencilSize; break;
106         case EGL_SURFACE_TYPE: answer = pConfig->surfaceType; break;
107         case EGL_TRANSPARENT_TYPE: answer = pConfig->transparentType; break;
108         case EGL_TRANSPARENT_RED_VALUE: answer = pConfig->transparentRedValue; break;
109         case EGL_TRANSPARENT_GREEN_VALUE: answer = pConfig->transparentGreenValue; break;
110         case EGL_TRANSPARENT_BLUE_VALUE: answer = pConfig->transparentBlueValue; break;
111         default:
112                 EGLINTER(SetError)(EGL_BAD_ATTRIBUTE);
113                 return EGL_FALSE;
114         }
115         if (value != NULL) *value = answer;
116         return EGL_TRUE;
117 }