egl: Updated EGL samples to use new i915 EGL winsys
[mesa.git] / progs / egl / demo1.c
1 /*
2 * Exercise EGL API functions
3 */
4
5 #include <GLES/egl.h>
6 #include <assert.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <string.h>
10
11
12 /**
13 * Test EGL_MESA_screen_surface functions
14 */
15 static void
16 TestScreens(EGLDisplay dpy)
17 {
18 #define MAX 8
19 EGLScreenMESA screens[MAX];
20 EGLint numScreens;
21 EGLint i;
22
23 eglGetScreensMESA(dpy, screens, MAX, &numScreens);
24 printf("Found %d screens\n", numScreens);
25 for (i = 0; i < numScreens; i++) {
26 printf(" Screen %d handle: %d\n", i, (int) screens[i]);
27 }
28 }
29
30 /**
31 * Print table of all available configurations.
32 */
33 static void
34 PrintConfigs(EGLDisplay d)
35 {
36 EGLConfig *configs;
37 EGLint numConfigs, i;
38
39 eglGetConfigs(d, NULL, 0, &numConfigs);
40 configs = malloc(sizeof(*configs) *numConfigs);
41 eglGetConfigs(d, configs, numConfigs, &numConfigs);
42
43 printf("Configurations:\n");
44 printf(" bf lv d st colorbuffer dp st supported \n");
45 printf(" id sz l b ro r g b a th cl surfaces \n");
46 printf("----------------------------------------------\n");
47 for (i = 0; i < numConfigs; i++) {
48 EGLint id, size, level;
49 EGLint red, green, blue, alpha;
50 EGLint depth, stencil;
51 EGLint surfaces;
52 EGLint doubleBuf = 1, stereo = 0;
53 char surfString[100] = "";
54
55 eglGetConfigAttrib(d, configs[i], EGL_CONFIG_ID, &id);
56 eglGetConfigAttrib(d, configs[i], EGL_BUFFER_SIZE, &size);
57 eglGetConfigAttrib(d, configs[i], EGL_LEVEL, &level);
58
59 eglGetConfigAttrib(d, configs[i], EGL_RED_SIZE, &red);
60 eglGetConfigAttrib(d, configs[i], EGL_GREEN_SIZE, &green);
61 eglGetConfigAttrib(d, configs[i], EGL_BLUE_SIZE, &blue);
62 eglGetConfigAttrib(d, configs[i], EGL_ALPHA_SIZE, &alpha);
63 eglGetConfigAttrib(d, configs[i], EGL_DEPTH_SIZE, &depth);
64 eglGetConfigAttrib(d, configs[i], EGL_STENCIL_SIZE, &stencil);
65 eglGetConfigAttrib(d, configs[i], EGL_SURFACE_TYPE, &surfaces);
66
67 if (surfaces & EGL_WINDOW_BIT)
68 strcat(surfString, "win,");
69 if (surfaces & EGL_PBUFFER_BIT)
70 strcat(surfString, "pb,");
71 if (surfaces & EGL_PIXMAP_BIT)
72 strcat(surfString, "pix,");
73 if (strlen(surfString) > 0)
74 surfString[strlen(surfString) - 1] = 0;
75
76 printf("0x%02x %2d %2d %c %c %2d %2d %2d %2d %2d %2d %-12s\n",
77 id, size, level,
78 doubleBuf ? 'y' : '.',
79 stereo ? 'y' : '.',
80 red, green, blue, alpha,
81 depth, stencil, surfString);
82 }
83 free(configs);
84 }
85
86
87
88 int
89 main(int argc, char *argv[])
90 {
91 int maj, min;
92 EGLContext ctx;
93 EGLSurface pbuffer;
94 EGLConfig configs[10];
95 EGLBoolean b;
96 const EGLint pbufAttribs[] = {
97 EGL_WIDTH, 500,
98 EGL_HEIGHT, 500,
99 EGL_NONE
100 };
101
102 /*
103 EGLDisplay d = eglGetDisplay(EGL_DEFAULT_DISPLAY);
104 */
105 EGLDisplay d = eglGetDisplay("!EGL_i915");
106 assert(d);
107
108 if (!eglInitialize(d, &maj, &min)) {
109 printf("demo: eglInitialize failed\n");
110 exit(1);
111 }
112
113 printf("EGL version = %d.%d\n", maj, min);
114 printf("EGL_VENDOR = %s\n", eglQueryString(d, EGL_VENDOR));
115
116 PrintConfigs(d);
117
118 ctx = eglCreateContext(d, configs[0], EGL_NO_CONTEXT, NULL);
119 if (ctx == EGL_NO_CONTEXT) {
120 printf("failed to create context\n");
121 return 0;
122 }
123
124 pbuffer = eglCreatePbufferSurface(d, configs[0], pbufAttribs);
125 if (pbuffer == EGL_NO_SURFACE) {
126 printf("failed to create pbuffer\n");
127 return 0;
128 }
129
130 b = eglMakeCurrent(d, pbuffer, pbuffer, ctx);
131 if (!b) {
132 printf("make current failed\n");
133 return 0;
134 }
135
136 b = eglMakeCurrent(d, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
137
138 TestScreens(d);
139
140 eglDestroySurface(d, pbuffer);
141 eglDestroyContext(d, ctx);
142 eglTerminate(d);
143
144 return 0;
145 }