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 * Initialize an _EGLScreen object to default values.
30 _eglInitScreen(_EGLScreen
*screen
)
32 memset(screen
, 0, sizeof(_EGLScreen
));
39 * Given a public screen handle, return the internal _EGLScreen object.
42 _eglLookupScreen(EGLDisplay dpy
, EGLScreenMESA screen
)
45 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
50 for (i
= 0; i
< display
->NumScreens
; i
++) {
51 if (display
->Screens
[i
]->Handle
== screen
)
52 return display
->Screens
[i
];
59 * Add the given _EGLScreen to the display's list of screens.
62 _eglAddScreen(_EGLDisplay
*display
, _EGLScreen
*screen
)
69 screen
->Handle
= _eglAllocScreenHandle();
70 n
= display
->NumScreens
;
71 display
->Screens
= realloc(display
->Screens
, (n
+1) * sizeof(_EGLScreen
*));
72 display
->Screens
[n
] = screen
;
73 display
->NumScreens
++;
79 _eglGetScreensMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA
*screens
,
80 EGLint max_screens
, EGLint
*num_screens
)
82 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
86 _eglError(EGL_BAD_DISPLAY
, "eglGetScreensMESA");
90 if (display
->NumScreens
> max_screens
) {
94 n
= display
->NumScreens
;
99 for (i
= 0; i
< n
; i
++)
100 screens
[i
] = display
->Screens
[i
]->Handle
;
110 * Example function - drivers should do a proper implementation.
113 _eglCreateScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
114 const EGLint
*attrib_list
)
116 #if 0 /* THIS IS JUST EXAMPLE CODE */
119 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
121 return EGL_NO_SURFACE
;
123 if (!_eglInitSurface(drv
, dpy
, surf
, EGL_SCREEN_BIT_MESA
,
124 config
, attrib_list
)) {
126 return EGL_NO_SURFACE
;
129 _eglSaveSurface(surf
);
133 return EGL_NO_SURFACE
;
138 * Show the given surface on the named screen.
139 * If surface is EGL_NO_SURFACE, disable the screen's output.
141 * This is just a placeholder function; drivers will always override
142 * this with code that _really_ shows the surface.
145 _eglShowScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
146 EGLScreenMESA screen
, EGLSurface surface
,
149 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
150 _EGLMode
*mode
= _eglLookupMode(dpy
, m
);
153 _eglError(EGL_BAD_SCREEN_MESA
, "eglShowSurfaceMESA");
156 if (!mode
&& (m
!= EGL_NO_MODE_MESA
)) {
157 _eglError(EGL_BAD_MODE_MESA
, "eglShowSurfaceMESA");
161 if (surface
== EGL_NO_SURFACE
) {
162 scrn
->CurrentSurface
= NULL
;
165 _EGLSurface
*surf
= _eglLookupSurface(surface
);
166 if (!surf
|| surf
->Type
!= EGL_SCREEN_BIT_MESA
) {
167 _eglError(EGL_BAD_SURFACE
, "eglShowSurfaceMESA");
170 if (surf
->Width
< mode
->Width
|| surf
->Height
< mode
->Height
) {
171 _eglError(EGL_BAD_SURFACE
,
172 "eglShowSurfaceMESA(surface smaller than screen size)");
176 scrn
->CurrentSurface
= surf
;
177 scrn
->CurrentMode
= mode
;
184 * Set a screen's current display mode.
185 * Note: mode = EGL_NO_MODE is valid (turns off the screen)
187 * This is just a placeholder function; drivers will always override
188 * this with code that _really_ sets the mode.
191 _eglScreenModeMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
194 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
197 _eglError(EGL_BAD_SCREEN_MESA
, "eglScreenModeMESA");
201 scrn
->CurrentMode
= _eglLookupMode(dpy
, mode
);
208 * Set a screen's surface origin.
211 _eglScreenPositionMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
212 EGLScreenMESA screen
, EGLint x
, EGLint y
)
214 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
216 _eglError(EGL_BAD_SCREEN_MESA
, "eglScreenPositionMESA");
228 * Query a screen's current surface.
231 _eglQueryScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
232 EGLScreenMESA screen
, EGLSurface
*surface
)
234 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
235 if (scrn
->CurrentSurface
)
236 *surface
= scrn
->CurrentSurface
->Handle
;
238 *surface
= EGL_NO_SURFACE
;
244 * Query a screen's current mode.
247 _eglQueryScreenModeMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
250 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
251 if (scrn
->CurrentMode
)
252 *mode
= scrn
->CurrentMode
->Handle
;
254 *mode
= EGL_NO_MODE_MESA
;
260 _eglQueryScreenMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
261 EGLint attribute
, EGLint
*value
)
263 const _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
266 _eglError(EGL_BAD_SCREEN_MESA
, "eglQueryScreenMESA");
271 case EGL_SCREEN_POSITION_MESA
:
272 value
[0] = scrn
->OriginX
;
273 value
[1] = scrn
->OriginY
;
275 case EGL_SCREEN_POSITION_GRANULARITY_MESA
:
276 value
[0] = scrn
->StepX
;
277 value
[1] = scrn
->StepY
;
280 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryScreenMESA");
289 * Delete the modes associated with given screen.
292 _eglDestroyScreenModes(_EGLScreen
*scrn
)
295 for (i
= 0; i
< scrn
->NumModes
; i
++) {
296 if (scrn
->Modes
[i
].Name
)
297 free((char *) scrn
->Modes
[i
].Name
); /* cast away const */
307 * Default fallback routine - drivers should usually override this.
310 _eglDestroyScreen(_EGLScreen
*scrn
)
312 _eglDestroyScreenModes(scrn
);