summaryrefslogtreecommitdiff
path: root/egl_1_4/34ChooseConfig.c
blob: 8b145e2d5c9e4b4d11d3dda31f6545a762a0df19 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/* 
 * 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"


struct ConfigExtra configExtraDefault = {
	EGL_DONT_CARE, (GLXFBConfig)EGL_DONT_CARE,	
	0, 0, 0, 0,	0, 0, 0, 
	EGL_DONT_CARE, EGL_DONT_CARE, EGL_RGB_BUFFER, EGL_DONT_CARE,
	EGL_DONT_CARE, 0, 0,	
	0, 0, 0,	
	EGL_DONT_CARE, EGL_DONT_CARE,	
	EGL_DONT_CARE, EGL_DONT_CARE, EGL_DONT_CARE,	
	EGL_DONT_CARE,	
	0, 0, 0, EGL_WINDOW_BIT, 
	EGL_NONE, EGL_DONT_CARE, EGL_DONT_CARE, EGL_DONT_CARE, 
};

EGLBoolean EGLAPIENTRY eglChooseConfig(EGLDisplay dpy, const EGLint* attrib_list,
        EGLConfig* configs, EGLint config_size, EGLint* num_config) {
	struct DisplayExtra* pDisplay;
	struct ConfigExtra configValue;
	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;
	}
	if (num_config == NULL) {
		EGLINTER(SetError)(EGL_BAD_PARAMETER);
		return EGL_FALSE;
	}
	memcpy(&configValue, &configExtraDefault, sizeof(struct ConfigExtra));
	while (attrib_list && *attrib_list != EGL_NONE) {
		switch (*attrib_list++) {
		case EGL_CONFIG_ID:		configValue.unique = *attrib_list++; break;
		case EGL_BUFFER_SIZE:	configValue.bufferSize = *attrib_list++; break;
		case EGL_RED_SIZE:		configValue.redSize = *attrib_list++; break;
		case EGL_GREEN_SIZE:	configValue.greenSize = *attrib_list++; break;
		case EGL_BLUE_SIZE:		configValue.blueSize = *attrib_list++; break;
		case EGL_LUMINANCE_SIZE:	configValue.luminanceSize = *attrib_list++; break;
		case EGL_ALPHA_SIZE:		configValue.alphaSize = *attrib_list++; break;
		case EGL_ALPHA_MASK_SIZE:		configValue.alphaMaskSize = *attrib_list++; break;
		case EGL_BIND_TO_TEXTURE_RGB:	configValue.bindToTexRGB = *attrib_list++; break;
		case EGL_BIND_TO_TEXTURE_RGBA:	configValue.bindToTexRGBA = *attrib_list++; break;
		case EGL_COLOR_BUFFER_TYPE:		configValue.colorBufferType = *attrib_list++; break;
		case EGL_CONFIG_CAVEAT:		configValue.configCaveat = *attrib_list++; break;
		case EGL_CONFORMANT:		configValue.conformant = *attrib_list++; break;
		case EGL_DEPTH_SIZE:		configValue.depthSize = *attrib_list++; break;
		case EGL_LEVEL:				configValue.level = *attrib_list++; break;
		case EGL_MAX_PBUFFER_WIDTH:		attrib_list++; break; 
		case EGL_MAX_PBUFFER_HEIGHT:	attrib_list++; break; 
		case EGL_MAX_PBUFFER_PIXELS:	attrib_list++; break; 
		case EGL_MAX_SWAP_INTERVAL:		configValue.maxSwapInterval = *attrib_list++; break;
		case EGL_MIN_SWAP_INTERVAL:		configValue.minSwapInterval = *attrib_list++; break;
		case EGL_NATIVE_RENDERABLE:		configValue.nativeRenderable = *attrib_list++; break;
		case EGL_NATIVE_VISUAL_ID:		attrib_list++; break; 
		case EGL_NATIVE_VISUAL_TYPE:	configValue.nativeVisualType = *attrib_list++; break;
		case EGL_RENDERABLE_TYPE:	configValue.renderableType = *attrib_list++; break;
		case EGL_SAMPLE_BUFFERS: configValue.sampleBuffers = *attrib_list++; break;
		case EGL_SAMPLES: configValue.samples = *attrib_list++; break;
		case EGL_STENCIL_SIZE: configValue.stencilSize = *attrib_list++; break;
		case EGL_SURFACE_TYPE: configValue.surfaceType = *attrib_list++; break;
		case EGL_TRANSPARENT_TYPE: configValue.transparentType = *attrib_list++; break;
		case EGL_TRANSPARENT_RED_VALUE: configValue.transparentRedValue = *attrib_list++; break;
		case EGL_TRANSPARENT_GREEN_VALUE: configValue.transparentGreenValue = *attrib_list++; break;
		case EGL_TRANSPARENT_BLUE_VALUE: configValue.transparentBlueValue = *attrib_list++; break;
		case EGL_MATCH_NATIVE_PIXMAP:	assert(0); break; 
		default:
			EGLINTER(SetError)(EGL_BAD_ATTRIBUTE);
			return EGL_FALSE;
		}
	}
	struct ConfigExtra* pUnit = pDisplay->pConfigExtra;
	int nCount = pDisplay->nConfigExtra;
	int i;
	if (configValue.unique != EGL_DONT_CARE) {
		while (nCount--) {
			if (pUnit->unique == configValue.unique) {
				*num_config = 1;
				if (configs != NULL && config_size > 0) {
					configs[0] = (EGLConfig)pUnit;
				}
				goto SETSUCCESS;
			}
			pUnit++;
		}
		*num_config = 0;
		goto SETSUCCESS;
	}
	int nAnswer = 0;
	EGLConfig* pAnswer = pDisplay->pConfigAnswer;
	for (; nCount--; pUnit++) {
		if (pUnit->bufferSize < configValue.bufferSize) continue;
		if (pUnit->redSize < configValue.redSize) continue;
		if (pUnit->greenSize < configValue.greenSize) continue;
		if (pUnit->blueSize < configValue.blueSize) continue;
		if (pUnit->luminanceSize < configValue.luminanceSize) continue;
		if (pUnit->alphaSize < configValue.alphaSize) continue;
		if (pUnit->alphaMaskSize < configValue.alphaMaskSize) continue;
		if (configValue.bindToTexRGB != EGL_DONT_CARE
		        && pUnit->bindToTexRGB != configValue.bindToTexRGB) continue;
		if (configValue.bindToTexRGBA != EGL_DONT_CARE
		        && pUnit->bindToTexRGBA != configValue.bindToTexRGBA) continue;
		if (pUnit->colorBufferType != configValue.colorBufferType) continue;
		if (configValue.configCaveat != EGL_DONT_CARE
		        && pUnit->configCaveat != configValue.configCaveat) continue;
		if (configValue.conformant != EGL_DONT_CARE
				&& (pUnit->conformant & configValue.conformant) == 0) continue;
		if (pUnit->depthSize < configValue.depthSize) continue;
		if (pUnit->level != configValue.level) continue;
		if (configValue.maxSwapInterval != EGL_DONT_CARE
		        && pUnit->maxSwapInterval != configValue.maxSwapInterval) continue;
		if (configValue.minSwapInterval != EGL_DONT_CARE
		        && pUnit->minSwapInterval != configValue.minSwapInterval) continue;
		if (configValue.nativeRenderable != EGL_DONT_CARE
		        && pUnit->nativeRenderable != configValue.nativeRenderable) continue;
		if (configValue.renderableType != EGL_DONT_CARE
				&& (pUnit->renderableType & configValue.renderableType) == 0) continue;
		if (pUnit->sampleBuffers < configValue.sampleBuffers) continue;
		if (pUnit->samples < configValue.samples) continue;
		if (pUnit->stencilSize < configValue.stencilSize) continue;
		if (pUnit->surfaceType & configValue.surfaceType == 0) continue;
		if (pUnit->transparentType != configValue.transparentType) continue;
		if (pUnit->transparentType != EGL_NONE
		        && pUnit->transparentRedValue != configValue.transparentRedValue) continue;
		if (pUnit->transparentType != EGL_NONE
		        && pUnit->transparentGreenValue != configValue.transparentGreenValue) continue;
		if (pUnit->transparentType != EGL_NONE
		        && pUnit->transparentBlueValue != configValue.transparentBlueValue) continue;
		*pAnswer++ = pUnit;
		nAnswer++;
	}
	int num = nAnswer;
	if (configs == NULL) {
		*num_config = num;
	} else {
		if (config_size < num) num = config_size;
		if (num < 0) num = 0;
		*num_config = num;
		memcpy(configs, pDisplay->pConfigAnswer, num * sizeof(EGLConfig));
	}
SETSUCCESS:
        EGLINTER(SetError)(EGL_SUCCESS);
	return EGL_TRUE;
}