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 memset(surf
, 0, sizeof(_EGLSurface
));
273 surf
->Resource
.Display
= dpy
;
279 surf
->TextureFormat
= EGL_NO_TEXTURE
;
280 surf
->TextureTarget
= EGL_NO_TEXTURE
;
281 surf
->MipmapTexture
= EGL_FALSE
;
282 surf
->LargestPbuffer
= EGL_FALSE
;
283 surf
->RenderBuffer
= renderBuffer
;
284 surf
->VGAlphaFormat
= EGL_VG_ALPHA_FORMAT_NONPRE
;
285 surf
->VGColorspace
= EGL_VG_COLORSPACE_sRGB
;
287 surf
->MipmapLevel
= 0;
288 surf
->MultisampleResolve
= EGL_MULTISAMPLE_RESOLVE_DEFAULT
;
289 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
;
291 surf
->HorizontalResolution
= EGL_UNKNOWN
;
292 surf
->VerticalResolution
= EGL_UNKNOWN
;
293 surf
->AspectRatio
= EGL_UNKNOWN
;
295 /* the default swap interval is 1 */
296 _eglClampSwapInterval(surf
, 1);
298 err
= _eglParseSurfaceAttribList(surf
, attrib_list
);
299 if (err
!= EGL_SUCCESS
)
300 return _eglError(err
, func
);
307 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
309 /* Drivers have to do the actual buffer swap. */
315 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
316 EGLNativePixmapType target
)
318 /* copy surface to native pixmap */
319 /* All implementation burdon for this is in the device driver */
325 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
326 EGLint attribute
, EGLint
*value
)
330 *value
= surface
->Width
;
333 *value
= surface
->Height
;
336 *value
= surface
->Config
->ConfigID
;
338 case EGL_LARGEST_PBUFFER
:
339 *value
= surface
->LargestPbuffer
;
341 case EGL_TEXTURE_FORMAT
:
342 /* texture attributes: only for pbuffers, no error otherwise */
343 if (surface
->Type
== EGL_PBUFFER_BIT
)
344 *value
= surface
->TextureFormat
;
346 case EGL_TEXTURE_TARGET
:
347 if (surface
->Type
== EGL_PBUFFER_BIT
)
348 *value
= surface
->TextureTarget
;
350 case EGL_MIPMAP_TEXTURE
:
351 if (surface
->Type
== EGL_PBUFFER_BIT
)
352 *value
= surface
->MipmapTexture
;
354 case EGL_MIPMAP_LEVEL
:
355 if (surface
->Type
== EGL_PBUFFER_BIT
)
356 *value
= surface
->MipmapLevel
;
358 case EGL_SWAP_BEHAVIOR
:
359 *value
= surface
->SwapBehavior
;
361 case EGL_RENDER_BUFFER
:
362 *value
= surface
->RenderBuffer
;
364 case EGL_PIXEL_ASPECT_RATIO
:
365 *value
= surface
->AspectRatio
;
367 case EGL_HORIZONTAL_RESOLUTION
:
368 *value
= surface
->HorizontalResolution
;
370 case EGL_VERTICAL_RESOLUTION
:
371 *value
= surface
->VerticalResolution
;
373 case EGL_MULTISAMPLE_RESOLVE
:
374 *value
= surface
->MultisampleResolve
;
376 case EGL_VG_ALPHA_FORMAT
:
377 *value
= surface
->VGAlphaFormat
;
379 case EGL_VG_COLORSPACE
:
380 *value
= surface
->VGColorspace
;
383 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
392 * Drivers should do a proper implementation.
395 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
396 EGLNativeWindowType window
, const EGLint
*attrib_list
)
403 * Drivers should do a proper implementation.
406 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
407 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
414 * Drivers should do a proper implementation.
417 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
418 const EGLint
*attrib_list
)
425 * Default fallback routine - drivers should usually override this.
428 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
430 if (!_eglIsSurfaceBound(surf
))
437 * Default fallback routine - drivers might override this.
440 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
441 EGLint attribute
, EGLint value
)
444 EGLint err
= EGL_SUCCESS
;
447 case EGL_MIPMAP_LEVEL
:
448 confval
= surface
->Config
->RenderableType
;
449 if (!(confval
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
))) {
450 err
= EGL_BAD_PARAMETER
;
453 surface
->MipmapLevel
= value
;
455 case EGL_MULTISAMPLE_RESOLVE
:
457 case EGL_MULTISAMPLE_RESOLVE_DEFAULT
:
459 case EGL_MULTISAMPLE_RESOLVE_BOX
:
460 confval
= surface
->Config
->SurfaceType
;
461 if (!(confval
& EGL_MULTISAMPLE_RESOLVE_BOX_BIT
))
465 err
= EGL_BAD_ATTRIBUTE
;
468 if (err
!= EGL_SUCCESS
)
470 surface
->MultisampleResolve
= value
;
472 case EGL_SWAP_BEHAVIOR
:
474 case EGL_BUFFER_DESTROYED
:
476 case EGL_BUFFER_PRESERVED
:
477 confval
= surface
->Config
->SurfaceType
;
478 if (!(confval
& EGL_SWAP_BEHAVIOR_PRESERVED_BIT
))
482 err
= EGL_BAD_ATTRIBUTE
;
485 if (err
!= EGL_SUCCESS
)
487 surface
->SwapBehavior
= value
;
490 err
= EGL_BAD_ATTRIBUTE
;
494 if (err
!= EGL_SUCCESS
)
495 return _eglError(err
, "eglSurfaceAttrib");
501 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
504 EGLint texture_type
= EGL_PBUFFER_BIT
;
506 /* Just do basic error checking and return success/fail.
507 * Drivers must implement the real stuff.
510 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
511 texture_type
|= EGL_PIXMAP_BIT
;
513 if (!(surface
->Type
& texture_type
)) {
514 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
518 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
519 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
523 if (surface
->TextureTarget
== EGL_NO_TEXTURE
) {
524 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
528 if (buffer
!= EGL_BACK_BUFFER
) {
529 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
533 surface
->BoundToTexture
= EGL_TRUE
;
540 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
543 /* Just do basic error checking and return success/fail.
544 * Drivers must implement the real stuff.
547 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
548 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
552 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
553 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
557 if (buffer
!= EGL_BACK_BUFFER
) {
558 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
562 if (!surface
->BoundToTexture
) {
563 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
567 surface
->BoundToTexture
= EGL_FALSE
;
574 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
577 _eglClampSwapInterval(surf
, interval
);
582 #ifdef EGL_VERSION_1_2
585 * Example function - drivers should do a proper implementation.
588 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
589 EGLenum buftype
, EGLClientBuffer buffer
,
590 _EGLConfig
*conf
, const EGLint
*attrib_list
)
592 if (buftype
!= EGL_OPENVG_IMAGE
) {
593 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
600 #endif /* EGL_VERSION_1_2 */