5 #include "egldisplay.h"
8 #include "eglglobals.h"
12 #define MIN2(A, B) (((A) < (B)) ? (A) : (B))
16 my_strdup(const char *s
)
19 char *s2
= malloc(l
+ 1);
26 * Given an EGLModeMESA handle, return the corresponding _EGLMode object
27 * or null if non-existant.
30 _eglLookupMode(EGLDisplay dpy
, EGLModeMESA mode
)
32 const _EGLDisplay
*disp
= _eglLookupDisplay(dpy
);
35 /* loop over all screens on the display */
36 for (scrnum
= 0; scrnum
< disp
->NumScreens
; scrnum
++) {
37 const _EGLScreen
*scrn
= disp
->Screens
[scrnum
];
39 /* search list of modes for handle */
40 for (i
= 0; i
< scrn
->NumModes
; i
++) {
41 if (scrn
->Modes
[i
].Handle
== mode
) {
42 return scrn
->Modes
+ i
;
52 * Add a new mode with the given attributes (width, height, depth, refreshRate)
53 * to the given screen.
54 * Assign a new mode ID/handle to the mode as well.
55 * \return pointer to the new _EGLMode
58 _eglAddMode(_EGLScreen
*screen
, EGLint width
, EGLint height
,
59 EGLint refreshRate
, char *name
)
67 assert(refreshRate
> 0);
70 newModes
= (_EGLMode
*) realloc(screen
->Modes
, (n
+1) * sizeof(_EGLMode
));
72 screen
->Modes
= newModes
;
73 screen
->Modes
[n
].Handle
= n
+ 1;
74 screen
->Modes
[n
].Width
= width
;
75 screen
->Modes
[n
].Height
= height
;
76 screen
->Modes
[n
].RefreshRate
= refreshRate
;
77 screen
->Modes
[n
].Stereo
= EGL_FALSE
;
78 screen
->Modes
[n
].Name
= my_strdup(name
);
80 return screen
->Modes
+ n
;
90 * Search for the EGLMode that best matches the given attribute list.
93 _eglChooseModeMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
94 const EGLint
*attrib_list
, EGLModeMESA
*modes
,
95 EGLint modes_size
, EGLint
*num_modes
)
101 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
102 switch (attrib_list
[i
]) {
109 case EGL_REFRESH_RATE_MESA
:
113 case EGL_STEREO_MESA
:
118 _eglError(EGL_BAD_ATTRIBUTE
, "eglChooseMode");
129 * Return all possible modes for the given screen
132 _eglGetModesMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLScreenMESA screen
,
133 EGLModeMESA
*modes
, EGLint modes_size
, EGLint
*num_modes
)
135 _EGLScreen
*scrn
= _eglLookupScreen(dpy
, screen
);
139 _eglError(EGL_BAD_SCREEN_MESA
, "eglGetModes");
143 *num_modes
= MIN2(modes_size
, scrn
->NumModes
);
144 for (i
= 0; i
< *num_modes
; i
++) {
145 modes
[i
] = scrn
->Modes
[i
].Handle
;
153 * Query an attribute of a mode.
156 _eglGetModeAttribMESA(_EGLDriver
*drv
, EGLDisplay dpy
,
157 EGLModeMESA mode
, EGLint attribute
, EGLint
*value
)
159 _EGLMode
*m
= _eglLookupMode(dpy
, mode
);
162 case EGL_MODE_ID_MESA
:
176 case EGL_REFRESH_RATE_MESA
:
177 *value
= m
->RefreshRate
;
180 case EGL_STEREO_MESA
:
185 _eglError(EGL_BAD_ATTRIBUTE
, "eglGetModeAttrib");
193 _eglQueryModeStringMESA(_EGLDriver
*drv
, EGLDisplay dpy
, EGLModeMESA mode
)
195 _EGLMode
*m
= _eglLookupMode(dpy
, mode
);