2 * Ideas for screen management extension to EGL.
4 * Each EGLDisplay has one or more screens (CRTs, Flat Panels, etc).
5 * The screens' handles can be obtained with eglGetScreensMESA().
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().
10 * To actually display a screen surface on a screen, the eglShowSurface()
18 #include "egldisplay.h"
19 #include "eglglobals.h"
21 #include "eglconfig.h"
22 #include "eglsurface.h"
23 #include "eglscreen.h"
27 * Return a new screen handle/ID.
28 * NOTE: we never reuse these!
31 _eglAllocScreenHandle(void)
33 EGLScreenMESA s
= _eglGlobal
.FreeScreenHandle
;
34 _eglGlobal
.FreeScreenHandle
++;
40 * Initialize an _EGLScreen object to default values.
43 _eglInitScreen(_EGLScreen
*screen
)
45 memset(screen
, 0, sizeof(_EGLScreen
));
52 * Given a public screen handle, return the internal _EGLScreen object.
55 _eglLookupScreen(EGLDisplay dpy
, EGLScreenMESA screen
)
58 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
63 for (i
= 0; i
< display
->NumScreens
; i
++) {
64 if (display
->Screens
[i
]->Handle
== screen
)
65 return display
->Screens
[i
];
72 * Add the given _EGLScreen to the display's list of screens.
75 _eglAddScreen(_EGLDisplay
*display
, _EGLScreen
*screen
)
82 screen
->Handle
= _eglAllocScreenHandle();
83 n
= display
->NumScreens
;
84 display
->Screens
= realloc(display
->Screens
, (n
+1) * sizeof(_EGLScreen
*));
85 display
->Screens
[n
] = screen
;
86 display
->NumScreens
++;
92 _eglGetScreensMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA
*screens
,
93 EGLint max_screens
, EGLint
*num_screens
)
95 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
99 _eglError(EGL_BAD_DISPLAY
, "eglGetScreensMESA");
103 if (display
->NumScreens
> max_screens
) {
107 n
= display
->NumScreens
;
112 for (i
= 0; i
< n
; i
++)
113 screens
[i
] = display
->Screens
[i
]->Handle
;
123 * Example function - drivers should do a proper implementation.
126 _eglCreateScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
127 const EGLint
*attrib_list
)
129 #if 0 /* THIS IS JUST EXAMPLE CODE */
133 conf
= _eglLookupConfig(drv
, dpy
, config
);
135 _eglError(EGL_BAD_CONFIG
, "eglCreateScreenSurfaceMESA");
136 return EGL_NO_SURFACE
;
139 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
141 return EGL_NO_SURFACE
;
143 if (!_eglInitSurface(drv
, surf
, EGL_SCREEN_BIT_MESA
,
144 conf
, attrib_list
)) {
146 return EGL_NO_SURFACE
;
149 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
151 return EGL_NO_SURFACE
;
156 * Show the given surface on the named screen.
157 * If surface is EGL_NO_SURFACE, disable the screen's output.
159 * This is just a placeholder function; drivers will always override
160 * this with code that _really_ shows the surface.
163 _eglShowScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
164 EGLScreenMESA screen
, EGLSurface surface
,
167 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
168 _EGLMode
*mode
= _eglLookupMode(dpy
, m
);
171 _eglError(EGL_BAD_SCREEN_MESA
, "eglShowSurfaceMESA");
174 if (!mode
&& (m
!= EGL_NO_MODE_MESA
)) {
175 _eglError(EGL_BAD_MODE_MESA
, "eglShowSurfaceMESA");
179 if (surface
== EGL_NO_SURFACE
) {
180 scrn
->CurrentSurface
= NULL
;
183 _EGLSurface
*surf
= _eglLookupSurface(surface
);
184 if (!surf
|| surf
->Type
!= EGL_SCREEN_BIT_MESA
) {
185 _eglError(EGL_BAD_SURFACE
, "eglShowSurfaceMESA");
188 if (surf
->Width
< mode
->Width
|| surf
->Height
< mode
->Height
) {
189 _eglError(EGL_BAD_SURFACE
,
190 "eglShowSurfaceMESA(surface smaller than screen size)");
194 scrn
->CurrentSurface
= surf
;
195 scrn
->CurrentMode
= mode
;
202 * Set a screen's current display mode.
203 * Note: mode = EGL_NO_MODE is valid (turns off the screen)
205 * This is just a placeholder function; drivers will always override
206 * this with code that _really_ sets the mode.
209 _eglScreenModeMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
212 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
215 _eglError(EGL_BAD_SCREEN_MESA
, "eglScreenModeMESA");
219 scrn
->CurrentMode
= _eglLookupMode(dpy
, mode
);
226 * Set a screen's surface origin.
229 _eglScreenPositionMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
230 EGLScreenMESA screen
, EGLint x
, EGLint y
)
232 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
234 _eglError(EGL_BAD_SCREEN_MESA
, "eglScreenPositionMESA");
246 * Query a screen's current surface.
249 _eglQueryScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
250 EGLScreenMESA screen
, EGLSurface
*surface
)
252 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
253 if (scrn
->CurrentSurface
)
254 *surface
= scrn
->CurrentSurface
->Handle
;
256 *surface
= EGL_NO_SURFACE
;
262 * Query a screen's current mode.
265 _eglQueryScreenModeMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
268 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
269 if (scrn
->CurrentMode
)
270 *mode
= scrn
->CurrentMode
->Handle
;
272 *mode
= EGL_NO_MODE_MESA
;
278 _eglQueryScreenMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
279 EGLint attribute
, EGLint
*value
)
281 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
284 _eglError(EGL_BAD_SCREEN_MESA
, "eglQueryScreenMESA");
289 case EGL_SCREEN_POSITION_MESA
:
290 value
[0] = scrn
->OriginX
;
291 value
[1] = scrn
->OriginY
;
293 case EGL_SCREEN_POSITION_GRANULARITY_MESA
:
294 value
[0] = scrn
->StepX
;
295 value
[1] = scrn
->StepY
;
298 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryScreenMESA");
307 * Delete the modes associated with given screen.
310 _eglDestroyScreenModes(_EGLScreen
*scrn
)
313 for (i
= 0; i
< scrn
->NumModes
; i
++) {
314 if (scrn
->Modes
[i
].Name
)
315 free((char *) scrn
->Modes
[i
].Name
); /* cast away const */
325 * Default fallback routine - drivers should usually override this.
328 _eglDestroyScreen(_EGLScreen
*scrn
)
330 _eglDestroyScreenModes(scrn
);