egl: Remove code blocks that are commented out.
[mesa.git] / src / egl / main / eglscreen.c
1 /*
2 * Ideas for screen management extension to EGL.
3 *
4 * Each EGLDisplay has one or more screens (CRTs, Flat Panels, etc).
5 * The screens' handles can be obtained with eglGetScreensMESA().
6 *
7 * A new kind of EGLSurface is possible- one which can be directly scanned
8 * out on a screen. Such a surface is created with eglCreateScreenSurface().
9 *
10 * To actually display a screen surface on a screen, the eglShowSurface()
11 * function is called.
12 */
13
14 #include <assert.h>
15 #include <stdlib.h>
16 #include <string.h>
17
18 #include "egldisplay.h"
19 #include "eglglobals.h"
20 #include "eglcurrent.h"
21 #include "eglmode.h"
22 #include "eglconfig.h"
23 #include "eglsurface.h"
24 #include "eglscreen.h"
25
26
27 /**
28 * Return a new screen handle/ID.
29 * NOTE: we never reuse these!
30 */
31 EGLScreenMESA
32 _eglAllocScreenHandle(void)
33 {
34 EGLScreenMESA s = _eglGlobal.FreeScreenHandle;
35 _eglGlobal.FreeScreenHandle++;
36 return s;
37 }
38
39
40 /**
41 * Initialize an _EGLScreen object to default values.
42 */
43 void
44 _eglInitScreen(_EGLScreen *screen)
45 {
46 memset(screen, 0, sizeof(_EGLScreen));
47 screen->StepX = 1;
48 screen->StepY = 1;
49 }
50
51
52 /**
53 * Given a public screen handle, return the internal _EGLScreen object.
54 */
55 _EGLScreen *
56 _eglLookupScreen(EGLScreenMESA screen, _EGLDisplay *display)
57 {
58 EGLint i;
59
60 for (i = 0; i < display->NumScreens; i++) {
61 if (display->Screens[i]->Handle == screen)
62 return display->Screens[i];
63 }
64 return NULL;
65 }
66
67
68 /**
69 * Add the given _EGLScreen to the display's list of screens.
70 */
71 void
72 _eglAddScreen(_EGLDisplay *display, _EGLScreen *screen)
73 {
74 EGLint n;
75
76 assert(display);
77 assert(screen);
78
79 screen->Handle = _eglAllocScreenHandle();
80 n = display->NumScreens;
81 display->Screens = realloc(display->Screens, (n+1) * sizeof(_EGLScreen *));
82 display->Screens[n] = screen;
83 display->NumScreens++;
84 }
85
86
87
88 EGLBoolean
89 _eglGetScreensMESA(_EGLDriver *drv, _EGLDisplay *display, EGLScreenMESA *screens,
90 EGLint max_screens, EGLint *num_screens)
91 {
92 EGLint n;
93
94 if (display->NumScreens > max_screens) {
95 n = max_screens;
96 }
97 else {
98 n = display->NumScreens;
99 }
100
101 if (screens) {
102 EGLint i;
103 for (i = 0; i < n; i++)
104 screens[i] = display->Screens[i]->Handle;
105 }
106 if (num_screens)
107 *num_screens = n;
108
109 return EGL_TRUE;
110 }
111
112
113 /**
114 * Drivers should do a proper implementation.
115 */
116 _EGLSurface *
117 _eglCreateScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLConfig *conf,
118 const EGLint *attrib_list)
119 {
120 return NULL;
121 }
122
123
124 /**
125 * Show the given surface on the named screen.
126 * If surface is EGL_NO_SURFACE, disable the screen's output.
127 *
128 * This is just a placeholder function; drivers will always override
129 * this with code that _really_ shows the surface.
130 */
131 EGLBoolean
132 _eglShowScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy,
133 _EGLScreen *scrn, _EGLSurface *surf,
134 _EGLMode *mode)
135 {
136 if (!surf) {
137 scrn->CurrentSurface = NULL;
138 }
139 else {
140 if (surf->Type != EGL_SCREEN_BIT_MESA) {
141 _eglError(EGL_BAD_SURFACE, "eglShowSurfaceMESA");
142 return EGL_FALSE;
143 }
144 if (surf->Width < mode->Width || surf->Height < mode->Height) {
145 _eglError(EGL_BAD_SURFACE,
146 "eglShowSurfaceMESA(surface smaller than screen size)");
147 return EGL_FALSE;
148 }
149
150 scrn->CurrentSurface = surf;
151 scrn->CurrentMode = mode;
152 }
153 return EGL_TRUE;
154 }
155
156
157 /**
158 * Set a screen's current display mode.
159 * Note: mode = EGL_NO_MODE is valid (turns off the screen)
160 *
161 * This is just a placeholder function; drivers will always override
162 * this with code that _really_ sets the mode.
163 */
164 EGLBoolean
165 _eglScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
166 _EGLMode *m)
167 {
168 scrn->CurrentMode = m;
169 return EGL_TRUE;
170 }
171
172
173 /**
174 * Set a screen's surface origin.
175 */
176 EGLBoolean
177 _eglScreenPositionMESA(_EGLDriver *drv, _EGLDisplay *dpy,
178 _EGLScreen *scrn, EGLint x, EGLint y)
179 {
180 scrn->OriginX = x;
181 scrn->OriginY = y;
182
183 return EGL_TRUE;
184 }
185
186
187 /**
188 * Query a screen's current surface.
189 */
190 EGLBoolean
191 _eglQueryScreenSurfaceMESA(_EGLDriver *drv, _EGLDisplay *dpy,
192 _EGLScreen *scrn, _EGLSurface **surf)
193 {
194 *surf = scrn->CurrentSurface;
195 return EGL_TRUE;
196 }
197
198
199 /**
200 * Query a screen's current mode.
201 */
202 EGLBoolean
203 _eglQueryScreenModeMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
204 _EGLMode **m)
205 {
206 *m = scrn->CurrentMode;
207 return EGL_TRUE;
208 }
209
210
211 EGLBoolean
212 _eglQueryScreenMESA(_EGLDriver *drv, _EGLDisplay *dpy, _EGLScreen *scrn,
213 EGLint attribute, EGLint *value)
214 {
215 switch (attribute) {
216 case EGL_SCREEN_POSITION_MESA:
217 value[0] = scrn->OriginX;
218 value[1] = scrn->OriginY;
219 break;
220 case EGL_SCREEN_POSITION_GRANULARITY_MESA:
221 value[0] = scrn->StepX;
222 value[1] = scrn->StepY;
223 break;
224 default:
225 _eglError(EGL_BAD_ATTRIBUTE, "eglQueryScreenMESA");
226 return EGL_FALSE;
227 }
228
229 return EGL_TRUE;
230 }
231
232
233 /**
234 * Delete the modes associated with given screen.
235 */
236 void
237 _eglDestroyScreenModes(_EGLScreen *scrn)
238 {
239 EGLint i;
240 for (i = 0; i < scrn->NumModes; i++) {
241 if (scrn->Modes[i].Name)
242 free((char *) scrn->Modes[i].Name); /* cast away const */
243 }
244 if (scrn->Modes)
245 free(scrn->Modes);
246 scrn->Modes = NULL;
247 scrn->NumModes = 0;
248 }
249
250
251 /**
252 * Default fallback routine - drivers should usually override this.
253 */
254 void
255 _eglDestroyScreen(_EGLScreen *scrn)
256 {
257 _eglDestroyScreenModes(scrn);
258 free(scrn);
259 }
260