2 * Surface-related functions.
9 #include "egldisplay.h"
10 #include "eglcontext.h"
11 #include "eglconfig.h"
12 #include "eglcurrent.h"
14 #include "eglsurface.h"
18 _eglClampSwapInterval(_EGLSurface
*surf
, EGLint interval
)
20 EGLint bound
= surf
->Config
->MaxSwapInterval
;
21 if (interval
>= bound
) {
25 bound
= surf
->Config
->MinSwapInterval
;
29 surf
->SwapInterval
= interval
;
33 #ifdef EGL_MESA_screen_surface
35 _eglParseScreenSurfaceAttribList(_EGLSurface
*surf
, const EGLint
*attrib_list
)
37 EGLint i
, err
= EGL_SUCCESS
;
42 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
43 EGLint attr
= attrib_list
[i
++];
44 EGLint val
= attrib_list
[i
];
49 err
= EGL_BAD_PARAMETER
;
56 err
= EGL_BAD_PARAMETER
;
62 err
= EGL_BAD_ATTRIBUTE
;
66 if (err
!= EGL_SUCCESS
) {
67 _eglLog(_EGL_WARNING
, "bad surface attribute 0x%04x", attr
);
74 #endif /* EGL_MESA_screen_surface */
78 * Parse the list of surface attributes and return the proper error code.
81 _eglParseSurfaceAttribList(_EGLSurface
*surf
, const EGLint
*attrib_list
)
83 _EGLDisplay
*dpy
= surf
->Resource
.Display
;
84 EGLint type
= surf
->Type
;
85 EGLint texture_type
= EGL_PBUFFER_BIT
;
86 EGLint i
, err
= EGL_SUCCESS
;
91 #ifdef EGL_MESA_screen_surface
92 if (type
== EGL_SCREEN_BIT_MESA
)
93 return _eglParseScreenSurfaceAttribList(surf
, attrib_list
);
96 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
97 texture_type
|= EGL_PIXMAP_BIT
;
99 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
100 EGLint attr
= attrib_list
[i
++];
101 EGLint val
= attrib_list
[i
];
104 /* common attributes */
105 case EGL_VG_COLORSPACE
:
107 case EGL_VG_COLORSPACE_sRGB
:
108 case EGL_VG_COLORSPACE_LINEAR
:
111 err
= EGL_BAD_ATTRIBUTE
;
114 if (err
!= EGL_SUCCESS
)
116 surf
->VGColorspace
= val
;
118 case EGL_VG_ALPHA_FORMAT
:
120 case EGL_VG_ALPHA_FORMAT_NONPRE
:
121 case EGL_VG_ALPHA_FORMAT_PRE
:
124 err
= EGL_BAD_ATTRIBUTE
;
127 if (err
!= EGL_SUCCESS
)
129 surf
->VGAlphaFormat
= val
;
131 /* window surface attributes */
132 case EGL_RENDER_BUFFER
:
133 if (type
!= EGL_WINDOW_BIT
) {
134 err
= EGL_BAD_ATTRIBUTE
;
137 if (val
!= EGL_BACK_BUFFER
&& val
!= EGL_SINGLE_BUFFER
) {
138 err
= EGL_BAD_ATTRIBUTE
;
141 surf
->RenderBuffer
= val
;
143 /* pbuffer surface attributes */
145 if (type
!= EGL_PBUFFER_BIT
) {
146 err
= EGL_BAD_ATTRIBUTE
;
150 err
= EGL_BAD_PARAMETER
;
156 if (type
!= EGL_PBUFFER_BIT
) {
157 err
= EGL_BAD_ATTRIBUTE
;
161 err
= EGL_BAD_PARAMETER
;
166 case EGL_LARGEST_PBUFFER
:
167 if (type
!= EGL_PBUFFER_BIT
) {
168 err
= EGL_BAD_ATTRIBUTE
;
171 surf
->LargestPbuffer
= !!val
;
173 /* for eglBindTexImage */
174 case EGL_TEXTURE_FORMAT
:
175 if (!(type
& texture_type
)) {
176 err
= EGL_BAD_ATTRIBUTE
;
180 case EGL_TEXTURE_RGB
:
181 case EGL_TEXTURE_RGBA
:
185 err
= EGL_BAD_ATTRIBUTE
;
188 if (err
!= EGL_SUCCESS
)
190 surf
->TextureFormat
= val
;
192 case EGL_TEXTURE_TARGET
:
193 if (!(type
& texture_type
)) {
194 err
= EGL_BAD_ATTRIBUTE
;
202 err
= EGL_BAD_ATTRIBUTE
;
205 if (err
!= EGL_SUCCESS
)
207 surf
->TextureTarget
= val
;
209 case EGL_MIPMAP_TEXTURE
:
210 if (!(type
& texture_type
)) {
211 err
= EGL_BAD_ATTRIBUTE
;
214 surf
->MipmapTexture
= !!val
;
216 /* no pixmap surface specific attributes */
218 err
= EGL_BAD_ATTRIBUTE
;
222 if (err
!= EGL_SUCCESS
) {
223 _eglLog(_EGL_WARNING
, "bad surface attribute 0x%04x", attr
);
233 * Do error check on parameters and initialize the given _EGLSurface object.
234 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
237 _eglInitSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
238 _EGLConfig
*conf
, const EGLint
*attrib_list
)
241 EGLint renderBuffer
= EGL_BACK_BUFFER
;
246 func
= "eglCreateWindowSurface";
249 func
= "eglCreatePixmapSurface";
250 renderBuffer
= EGL_SINGLE_BUFFER
;
252 case EGL_PBUFFER_BIT
:
253 func
= "eglCreatePBufferSurface";
255 #ifdef EGL_MESA_screen_surface
256 case EGL_SCREEN_BIT_MESA
:
257 func
= "eglCreateScreenSurface";
258 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
262 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
266 if ((conf
->SurfaceType
& type
) == 0) {
267 /* The config can't be used to create a surface of this type */
268 _eglError(EGL_BAD_CONFIG
, func
);
272 _eglInitResource(&surf
->Resource
, sizeof(*surf
), dpy
);
278 surf
->TextureFormat
= EGL_NO_TEXTURE
;
279 surf
->TextureTarget
= EGL_NO_TEXTURE
;
280 surf
->MipmapTexture
= EGL_FALSE
;
281 surf
->LargestPbuffer
= EGL_FALSE
;
282 surf
->RenderBuffer
= renderBuffer
;
283 surf
->VGAlphaFormat
= EGL_VG_ALPHA_FORMAT_NONPRE
;
284 surf
->VGColorspace
= EGL_VG_COLORSPACE_sRGB
;
286 surf
->MipmapLevel
= 0;
287 surf
->MultisampleResolve
= EGL_MULTISAMPLE_RESOLVE_DEFAULT
;
288 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
;
290 surf
->HorizontalResolution
= EGL_UNKNOWN
;
291 surf
->VerticalResolution
= EGL_UNKNOWN
;
292 surf
->AspectRatio
= EGL_UNKNOWN
;
294 /* the default swap interval is 1 */
295 _eglClampSwapInterval(surf
, 1);
297 err
= _eglParseSurfaceAttribList(surf
, attrib_list
);
298 if (err
!= EGL_SUCCESS
)
299 return _eglError(err
, func
);
306 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
307 EGLint attribute
, EGLint
*value
)
311 *value
= surface
->Width
;
314 *value
= surface
->Height
;
317 *value
= surface
->Config
->ConfigID
;
319 case EGL_LARGEST_PBUFFER
:
320 *value
= surface
->LargestPbuffer
;
322 case EGL_TEXTURE_FORMAT
:
323 /* texture attributes: only for pbuffers, no error otherwise */
324 if (surface
->Type
== EGL_PBUFFER_BIT
)
325 *value
= surface
->TextureFormat
;
327 case EGL_TEXTURE_TARGET
:
328 if (surface
->Type
== EGL_PBUFFER_BIT
)
329 *value
= surface
->TextureTarget
;
331 case EGL_MIPMAP_TEXTURE
:
332 if (surface
->Type
== EGL_PBUFFER_BIT
)
333 *value
= surface
->MipmapTexture
;
335 case EGL_MIPMAP_LEVEL
:
336 if (surface
->Type
== EGL_PBUFFER_BIT
)
337 *value
= surface
->MipmapLevel
;
339 case EGL_SWAP_BEHAVIOR
:
340 *value
= surface
->SwapBehavior
;
342 case EGL_RENDER_BUFFER
:
343 *value
= surface
->RenderBuffer
;
345 case EGL_PIXEL_ASPECT_RATIO
:
346 *value
= surface
->AspectRatio
;
348 case EGL_HORIZONTAL_RESOLUTION
:
349 *value
= surface
->HorizontalResolution
;
351 case EGL_VERTICAL_RESOLUTION
:
352 *value
= surface
->VerticalResolution
;
354 case EGL_MULTISAMPLE_RESOLVE
:
355 *value
= surface
->MultisampleResolve
;
357 case EGL_VG_ALPHA_FORMAT
:
358 *value
= surface
->VGAlphaFormat
;
360 case EGL_VG_COLORSPACE
:
361 *value
= surface
->VGColorspace
;
364 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
373 * Default fallback routine - drivers might override this.
376 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
377 EGLint attribute
, EGLint value
)
380 EGLint err
= EGL_SUCCESS
;
383 case EGL_MIPMAP_LEVEL
:
384 confval
= surface
->Config
->RenderableType
;
385 if (!(confval
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
))) {
386 err
= EGL_BAD_PARAMETER
;
389 surface
->MipmapLevel
= value
;
391 case EGL_MULTISAMPLE_RESOLVE
:
393 case EGL_MULTISAMPLE_RESOLVE_DEFAULT
:
395 case EGL_MULTISAMPLE_RESOLVE_BOX
:
396 confval
= surface
->Config
->SurfaceType
;
397 if (!(confval
& EGL_MULTISAMPLE_RESOLVE_BOX_BIT
))
401 err
= EGL_BAD_ATTRIBUTE
;
404 if (err
!= EGL_SUCCESS
)
406 surface
->MultisampleResolve
= value
;
408 case EGL_SWAP_BEHAVIOR
:
410 case EGL_BUFFER_DESTROYED
:
412 case EGL_BUFFER_PRESERVED
:
413 confval
= surface
->Config
->SurfaceType
;
414 if (!(confval
& EGL_SWAP_BEHAVIOR_PRESERVED_BIT
))
418 err
= EGL_BAD_ATTRIBUTE
;
421 if (err
!= EGL_SUCCESS
)
423 surface
->SwapBehavior
= value
;
426 err
= EGL_BAD_ATTRIBUTE
;
430 if (err
!= EGL_SUCCESS
)
431 return _eglError(err
, "eglSurfaceAttrib");
437 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
440 EGLint texture_type
= EGL_PBUFFER_BIT
;
442 /* Just do basic error checking and return success/fail.
443 * Drivers must implement the real stuff.
446 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
447 texture_type
|= EGL_PIXMAP_BIT
;
449 if (!(surface
->Type
& texture_type
)) {
450 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
454 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
455 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
459 if (surface
->TextureTarget
== EGL_NO_TEXTURE
) {
460 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
464 if (buffer
!= EGL_BACK_BUFFER
) {
465 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
469 surface
->BoundToTexture
= EGL_TRUE
;
476 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
479 _eglClampSwapInterval(surf
, interval
);