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()
16 #include "egldisplay.h"
17 #include "eglglobals.h"
19 #include "eglsurface.h"
20 #include "eglscreen.h"
24 * Return a new _EGLScreen object.
29 return (_EGLScreen
*) calloc(1, sizeof(_EGLScreen
));
34 * Given a public screen handle, return the internal _EGLScreen object.
37 _eglLookupScreen(EGLDisplay dpy
, EGLScreenMESA screen
)
40 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
45 for (i
= 0; i
< display
->NumScreens
; i
++) {
46 if (display
->Screens
[i
]->Handle
== screen
)
47 return display
->Screens
[i
];
54 * Add the given _EGLScreen to the display's list of screens.
57 _eglAddScreen(_EGLDisplay
*display
, _EGLScreen
*screen
)
64 screen
->Handle
= _eglAllocScreenHandle();
65 n
= display
->NumScreens
;
66 display
->Screens
= realloc(display
->Screens
, (n
+1) * sizeof(_EGLScreen
*));
67 display
->Screens
[n
] = screen
;
68 display
->NumScreens
++;
74 _eglGetScreensMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA
*screens
,
75 EGLint max_screens
, EGLint
*num_screens
)
77 _EGLDisplay
*display
= _eglLookupDisplay(dpy
);
81 _eglError(EGL_BAD_DISPLAY
, "eglGetScreensMESA");
85 if (display
->NumScreens
> max_screens
) {
89 n
= display
->NumScreens
;
94 for (i
= 0; i
< n
; i
++)
95 screens
[i
] = display
->Screens
[i
]->Handle
;
105 * Create a drawing surface which can be directly displayed on a screen.
108 _eglCreateScreenSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
109 const EGLint
*attrib_list
)
112 EGLint width
= 0, height
= 0;
115 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
116 switch (attrib_list
[i
]) {
118 width
= attrib_list
[++i
];
121 height
= attrib_list
[++i
];
124 _eglError(EGL_BAD_ATTRIBUTE
, "eglCreateScreenSurfaceMESA");
125 return EGL_NO_SURFACE
;
129 if (width
<= 0 || height
<= 0) {
130 _eglError(EGL_BAD_ATTRIBUTE
,
131 "eglCreateScreenSurfaceMESA(width or height)");
132 return EGL_NO_SURFACE
;
135 surf
= (_EGLSurface
*) malloc(sizeof(_EGLSurface
));
136 _eglInitSurface(surf
);
138 surf
->Height
= height
;
139 surf
->Type
= EGL_SCREEN_BIT_MESA
;
141 /* insert into hash table */
142 _eglSaveSurface(surf
);
143 assert(surf
->Handle
);
150 * Show the given surface on the named screen.
151 * If surface is EGL_NO_SURFACE, disable the screen's output.
153 * This is just a placeholder function; drivers will always override
154 * this with code that _really_ shows the surface.
157 _eglShowSurfaceMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
160 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
164 _eglError(EGL_BAD_SCREEN_MESA
, "eglShowSurfaceMESA");
169 * XXX: Check if the surface's configuration is compatible with the
170 * current screen mode.
173 mode
= scrn
->CurrentMode
;
174 if (mode
== EGL_NO_MODE_MESA
) {
175 _eglError(EGL_BAD_MODE_MESA
, "eglShowSurfaceMESA(no current mode)");
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
;
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
;
294 _eglError(EGL_BAD_ATTRIBUTE
, "eglQueryScreenMESA");
304 _eglDeleteScreen(_EGLScreen
*scrn
)