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
|
/*
* Exercise EGL API functions
*/
#define EGL_EGLEXT_PROTOTYPES
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wayland-client.h>
/**
* Test EGL_MESA_screen_surface functions
*/
static void
TestScreens(EGLDisplay dpy)
{
#ifdef EGL_MESA_screen_surface
#define MAX 8
EGLScreenMESA screens[MAX];
EGLint numScreens;
EGLint i;
eglGetScreensMESA(dpy, screens, MAX, &numScreens);
printf("Found %d screens\n", numScreens);
for (i = 0; i < numScreens; i++) {
printf(" Screen %d handle: %d\n", i, (int) screens[i]);
}
#endif
}
/**
* Print table of all available configurations.
*/
static void
PrintConfigs(EGLDisplay d, EGLConfig *configs, EGLint numConfigs)
{
EGLint i;
printf("Configurations:\n");
printf(" bf lv d st colorbuffer dp st tr supported \n");
printf(" id sz l b ro r g b a th cl an surfaces \n");
printf("----------------------------------------------\n");
for (i = 0; i < numConfigs; i++) {
EGLint id, size, level;
EGLint red, green, blue, alpha;
EGLint depth, stencil;
EGLint surfaces;
EGLint doubleBuf = 1, stereo = 0;
EGLint trans;
char surfString[100] = "";
char *transString = "( - )";
eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
eglGetConfigAttrib(d, configs[i], EGL_TRANSPARENT_TYPE, &trans);
if (surfaces & EGL_WINDOW_BIT)
strcat(surfString, "win,");
if (surfaces & EGL_PBUFFER_BIT)
strcat(surfString, "pb,");
if (surfaces & EGL_PIXMAP_BIT)
strcat(surfString, "pix,");
if (strlen(surfString) > 0)
surfString[strlen(surfString) - 1] = 0;
if (trans == EGL_NONE)
transString = "none ";
else if (trans == EGL_TRANSPARENT_RGB)
transString = "rgb ";
else if (trans == EGL_TRANSPARENT_ALPHA_MESA)
transString = "alpha";
printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %s %-12s\n",
id, size, level,
doubleBuf ? 'y' : '.',
stereo ? 'y' : '.',
red, green, blue, alpha,
depth, stencil, transString, surfString);
}
}
int
main(int argc, char *argv[])
{
int maj, min;
EGLContext ctx;
EGLSurface pbuffer;
EGLConfig *configs;
EGLint numConfigs;
EGLBoolean b;
const EGLint pbufAttribs[] = {
EGL_WIDTH, 500,
EGL_HEIGHT, 500,
EGL_NONE
};
struct wl_display *display = wl_display_connect(NULL);
EGLDisplay d = eglGetPlatformDisplayEXT(EGL_PLATFORM_WAYLAND_EXT,
display, NULL);
assert(d);
if (!eglInitialize(d, &maj, &min)) {
printf("demo: eglInitialize failed\n");
exit(1);
}
printf("EGL version = %d.%d\n", maj, min);
printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
eglGetConfigs(d, NULL, 0, &numConfigs);
configs = malloc(sizeof(*configs) *numConfigs);
eglGetConfigs(d, configs, numConfigs, &numConfigs);
PrintConfigs(d, configs, numConfigs);
eglBindAPI(EGL_OPENGL_API);
ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
if (ctx == EGL_NO_CONTEXT) {
printf("failed to create context\n");
return 0;
}
pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
if (pbuffer == EGL_NO_SURFACE) {
printf("failed to create pbuffer\n");
return 0;
}
free(configs);
b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
if (!b) {
printf("make current failed\n");
return 0;
}
b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
TestScreens(d);
eglDestroySurface(d, pbuffer);
eglDestroyContext(d, ctx);
eglTerminate(d);
return 0;
}
|