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(EGLScreenMESA screen
, _EGLDisplay
*display
)
59 for (i
= 0; i
< display
->NumScreens
; i
++) {
60 if (display
->Screens
[i
]->Handle
== screen
)
61 return display
->Screens
[i
];
68 * Add the given _EGLScreen to the display's list of screens.
71 _eglAddScreen(_EGLDisplay
*display
, _EGLScreen
*screen
)
78 screen
->Handle
= _eglAllocScreenHandle();
79 n
= display
->NumScreens
;
80 display
->Screens
= realloc(display
->Screens
, (n
+1) * sizeof(_EGLScreen
*));
81 display
->Screens
[n
] = screen
;
82 display
->NumScreens
++;
88 _eglGetScreensMESA(_EGLDriver
*drv
, _EGLDisplay
*display
, EGLScreenMESA
*screens
,
89 EGLint max_screens
, EGLint
*num_screens
)
93 if (display
->NumScreens
> max_screens
) {
97 n
= display
->NumScreens
;
102 for (i
= 0; i
< n
; i
++)
103 screens
[i
] = display
->Screens
[i
]->Handle
;
113 * Example function - drivers should do a proper implementation.
116 _eglCreateScreenSurfaceMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
117 const EGLint
*attrib_list
)
119 #if 0 /* THIS IS JUST EXAMPLE CODE */
122 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
126 if (!_eglInitSurface(drv
, surf
, EGL_SCREEN_BIT_MESA
,
127 conf
, attrib_list
)) {
139 * Show the given surface on the named screen.
140 * If surface is EGL_NO_SURFACE, disable the screen's output.
142 * This is just a placeholder function; drivers will always override
143 * this with code that _really_ shows the surface.
146 _eglShowScreenSurfaceMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
147 _EGLScreen
*scrn
, _EGLSurface
*surf
,
151 scrn
->CurrentSurface
= NULL
;
154 if (surf
->Type
!= EGL_SCREEN_BIT_MESA
) {
155 _eglError(EGL_BAD_SURFACE
, "eglShowSurfaceMESA");
158 if (surf
->Width
< mode
->Width
|| surf
->Height
< mode
->Height
) {
159 _eglError(EGL_BAD_SURFACE
,
160 "eglShowSurfaceMESA(surface smaller than screen size)");
164 scrn
->CurrentSurface
= surf
;
165 scrn
->CurrentMode
= mode
;
172 * Set a screen's current display mode.
173 * Note: mode = EGL_NO_MODE is valid (turns off the screen)
175 * This is just a placeholder function; drivers will always override
176 * this with code that _really_ sets the mode.
179 _eglScreenModeMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLScreen
*scrn
,
182 scrn
->CurrentMode
= m
;
188 * Set a screen's surface origin.
191 _eglScreenPositionMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
192 _EGLScreen
*scrn
, EGLint x
, EGLint y
)
202 * Query a screen's current surface.
205 _eglQueryScreenSurfaceMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
206 _EGLScreen
*scrn
, _EGLSurface
**surf
)
208 *surf
= scrn
->CurrentSurface
;
214 * Query a screen's current mode.
217 _eglQueryScreenModeMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLScreen
*scrn
,
220 *m
= scrn
->CurrentMode
;
226 _eglQueryScreenMESA(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLScreen
*scrn
,
227 EGLint attribute
, EGLint
*value
)
230 case EGL_SCREEN_POSITION_MESA
:
231 value
[0] = scrn
->OriginX
;
232 value
[1] = scrn
->OriginY
;
234 case EGL_SCREEN_POSITION_GRANULARITY_MESA
:
235 value
[0] = scrn
->StepX
;
236 value
[1] = scrn
->StepY
;
239 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryScreenMESA");
248 * Delete the modes associated with given screen.
251 _eglDestroyScreenModes(_EGLScreen
*scrn
)
254 for (i
= 0; i
< scrn
->NumModes
; i
++) {
255 if (scrn
->Modes
[i
].Name
)
256 free((char *) scrn
->Modes
[i
].Name
); /* cast away const */
266 * Default fallback routine - drivers should usually override this.
269 _eglDestroyScreen(_EGLScreen
*scrn
)
271 _eglDestroyScreenModes(scrn
);