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