summaryrefslogtreecommitdiff
path: root/egl_1_4/34GetConfigAttrib.c
blob: 37269e82820b8671c6c7f9dc2f828d4fcd28abd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/* 
 * Copyright (C) 2010 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
 * 
 * Contact:
 * DongKyun Yun <dk77.yun@samsung.com>
 * SangJin Kim <sangjin3.kim@samsung.com>
 * HyunGoo Kang <hyungoo1.kang@samsung.com>
 *
 * 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"
#include <dlfcn.h>

struct ConfigExtra* EGLINTER(LookUpConfig)(struct DisplayExtra* pDisplay, EGLConfig config) {
	
	struct ConfigExtra* pConfig = (struct ConfigExtra*)config;
	struct ConfigExtra* pUnit = pDisplay->pConfigExtra;
	int nCount = pDisplay->nConfigExtra;
	while (nCount--) {
		if (pConfig == pUnit) {
			return pConfig;
		}
		pUnit++;
	}
	return NULL;
}

EGLBoolean EGLAPIENTRY eglGetConfigAttrib(EGLDisplay dpy, EGLConfig config,
        EGLint attribute, EGLint *value) {
	struct DisplayExtra* pDisplay = EGLINTER(LookUpDisplay)(dpy);
	if (pDisplay == NULL) {
		EGLINTER(SetError)(EGL_BAD_DISPLAY);
		return EGL_FALSE;
	}
	if (pDisplay->bInitialized == EGL_FALSE) {
		EGLINTER(SetError)(EGL_NOT_INITIALIZED);
		return EGL_FALSE;
	}
	struct ConfigExtra* pConfig = EGLINTER(LookUpConfig)(pDisplay, config);
	if (pConfig == NULL) {
		EGLINTER(SetError)(EGL_BAD_CONFIG);
		return EGL_FALSE;
	}
	EGLint answer;
	switch (attribute) {
	case EGL_CONFIG_ID:		answer = pConfig->unique; break;
	case EGL_BUFFER_SIZE:	answer = pConfig->bufferSize; break;
	case EGL_RED_SIZE:		answer = pConfig->redSize; break;
	case EGL_GREEN_SIZE:	answer = pConfig->greenSize; break;
	case EGL_BLUE_SIZE:		answer = pConfig->blueSize; break;
	case EGL_LUMINANCE_SIZE:	answer = pConfig->luminanceSize; break;
	case EGL_ALPHA_SIZE:		answer = pConfig->alphaSize; break;
	case EGL_ALPHA_MASK_SIZE:		answer = pConfig->alphaMaskSize; break;
	case EGL_BIND_TO_TEXTURE_RGB:	answer = pConfig->bindToTexRGB; break;
	case EGL_BIND_TO_TEXTURE_RGBA:	answer = pConfig->bindToTexRGBA; break;
	case EGL_COLOR_BUFFER_TYPE:		answer = pConfig->colorBufferType; break;
	case EGL_CONFIG_CAVEAT:		answer = pConfig->configCaveat; break;
	case EGL_CONFORMANT:		answer = pConfig->conformant; break;
	case EGL_DEPTH_SIZE:		answer = pConfig->depthSize; break;
	case EGL_LEVEL:				answer = pConfig->level; break;
	case EGL_MAX_PBUFFER_WIDTH:		answer = pConfig->maxPbufferWidth; break;
	case EGL_MAX_PBUFFER_HEIGHT:		answer = pConfig->maxPbufferHeight; break;
	case EGL_MAX_PBUFFER_PIXELS:		answer = pConfig->maxPbufferPixels; break;
	case EGL_MAX_SWAP_INTERVAL:		answer = pConfig->maxSwapInterval; break;
	case EGL_MIN_SWAP_INTERVAL:		answer = pConfig->minSwapInterval; break;
	case EGL_NATIVE_RENDERABLE:		answer = pConfig->nativeRenderable; break;
	case EGL_NATIVE_VISUAL_ID:
		{
			XVisualInfo *vi;
			XVisualInfo* (*fpGetVisualFromFBConfig)(Display*, GLXFBConfig) = NULL;
			void* dl = dlopen("libGL.so", RTLD_NOW);
			assert(dl != 0);
			*(void**)(&fpGetVisualFromFBConfig) = dlsym(dl, "glXGetVisualFromFBConfig");
			assert(fpGetVisualFromFBConfig != NULL);

			vi = (*fpGetVisualFromFBConfig) (pDisplay->native, pConfig->native);
			answer = vi->visualid;
			break;
		}
	case EGL_NATIVE_VISUAL_TYPE:	answer = pConfig->nativeVisualType; break;
	case EGL_RENDERABLE_TYPE:	answer = pConfig->renderableType; break;
	case EGL_SAMPLE_BUFFERS: answer = pConfig->sampleBuffers; break;
	case EGL_SAMPLES: answer = pConfig->samples; break;
	case EGL_STENCIL_SIZE: answer = pConfig->stencilSize; break;
	case EGL_SURFACE_TYPE: answer = pConfig->surfaceType; break;
	case EGL_TRANSPARENT_TYPE: answer = pConfig->transparentType; break;
	case EGL_TRANSPARENT_RED_VALUE: answer = pConfig->transparentRedValue; break;
	case EGL_TRANSPARENT_GREEN_VALUE: answer = pConfig->transparentGreenValue; break;
	case EGL_TRANSPARENT_BLUE_VALUE: answer = pConfig->transparentBlueValue; break;
	default:
		EGLINTER(SetError)(EGL_BAD_ATTRIBUTE);
		return EGL_FALSE;
	}
	if (value != NULL) *value = answer;
	return EGL_TRUE;
}