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
= GET_CONFIG_ATTRIB(surf
->Config
, EGL_MAX_SWAP_INTERVAL
);
21 if (interval
>= bound
) {
25 bound
= GET_CONFIG_ATTRIB(surf
->Config
, EGL_MIN_SWAP_INTERVAL
);
29 surf
->SwapInterval
= interval
;
34 * Parse the list of surface attributes and return the proper error code.
37 _eglParseSurfaceAttribList(_EGLSurface
*surf
, const EGLint
*attrib_list
)
39 _EGLDisplay
*dpy
= surf
->Resource
.Display
;
40 EGLint type
= surf
->Type
;
41 EGLint texture_type
= EGL_PBUFFER_BIT
;
42 EGLint i
, err
= EGL_SUCCESS
;
47 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
48 texture_type
|= EGL_PIXMAP_BIT
;
50 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
51 EGLint attr
= attrib_list
[i
++];
52 EGLint val
= attrib_list
[i
];
55 /* common (except for screen surfaces) attributes */
56 case EGL_VG_COLORSPACE
:
57 if (type
== EGL_SCREEN_BIT_MESA
) {
58 err
= EGL_BAD_ATTRIBUTE
;
62 case EGL_VG_COLORSPACE_sRGB
:
63 case EGL_VG_COLORSPACE_LINEAR
:
66 err
= EGL_BAD_ATTRIBUTE
;
69 if (err
!= EGL_SUCCESS
)
71 surf
->VGColorspace
= val
;
73 case EGL_VG_ALPHA_FORMAT
:
74 if (type
== EGL_SCREEN_BIT_MESA
) {
75 err
= EGL_BAD_ATTRIBUTE
;
79 case EGL_VG_ALPHA_FORMAT_NONPRE
:
80 case EGL_VG_ALPHA_FORMAT_PRE
:
83 err
= EGL_BAD_ATTRIBUTE
;
86 if (err
!= EGL_SUCCESS
)
88 surf
->VGAlphaFormat
= val
;
90 /* window surface attributes */
91 case EGL_RENDER_BUFFER
:
92 if (type
!= EGL_WINDOW_BIT
) {
93 err
= EGL_BAD_ATTRIBUTE
;
96 if (val
!= EGL_BACK_BUFFER
&& val
!= EGL_SINGLE_BUFFER
) {
97 err
= EGL_BAD_ATTRIBUTE
;
100 surf
->RenderBuffer
= val
;
102 /* pbuffer surface attributes */
104 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
105 err
= EGL_BAD_ATTRIBUTE
;
109 err
= EGL_BAD_PARAMETER
;
115 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
116 err
= EGL_BAD_ATTRIBUTE
;
120 err
= EGL_BAD_PARAMETER
;
125 case EGL_LARGEST_PBUFFER
:
126 if (type
!= EGL_PBUFFER_BIT
) {
127 err
= EGL_BAD_ATTRIBUTE
;
130 surf
->LargestPbuffer
= !!val
;
132 case EGL_TEXTURE_FORMAT
:
133 if (!(type
& texture_type
)) {
134 err
= EGL_BAD_ATTRIBUTE
;
138 case EGL_TEXTURE_RGB
:
139 case EGL_TEXTURE_RGBA
:
143 err
= EGL_BAD_ATTRIBUTE
;
146 if (err
!= EGL_SUCCESS
)
148 surf
->TextureFormat
= val
;
150 case EGL_TEXTURE_TARGET
:
151 if (!(type
& texture_type
)) {
152 err
= EGL_BAD_ATTRIBUTE
;
160 err
= EGL_BAD_ATTRIBUTE
;
163 if (err
!= EGL_SUCCESS
)
165 surf
->TextureTarget
= val
;
167 case EGL_MIPMAP_TEXTURE
:
168 if (!(type
& texture_type
)) {
169 err
= EGL_BAD_ATTRIBUTE
;
172 surf
->MipmapTexture
= !!val
;
174 /* no pixmap surface specific attributes */
176 err
= EGL_BAD_ATTRIBUTE
;
180 if (err
!= EGL_SUCCESS
) {
181 _eglLog(_EGL_WARNING
, "bad surface attribute 0x%04x", attr
);
191 * Do error check on parameters and initialize the given _EGLSurface object.
192 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
195 _eglInitSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
196 _EGLConfig
*conf
, const EGLint
*attrib_list
)
199 EGLint renderBuffer
= EGL_BACK_BUFFER
;
204 func
= "eglCreateWindowSurface";
207 func
= "eglCreatePixmapSurface";
208 renderBuffer
= EGL_SINGLE_BUFFER
;
210 case EGL_PBUFFER_BIT
:
211 func
= "eglCreatePBufferSurface";
213 case EGL_SCREEN_BIT_MESA
:
214 func
= "eglCreateScreenSurface";
215 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
218 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
222 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
223 /* The config can't be used to create a surface of this type */
224 _eglError(EGL_BAD_CONFIG
, func
);
228 memset(surf
, 0, sizeof(_EGLSurface
));
229 surf
->Resource
.Display
= dpy
;
235 surf
->TextureFormat
= EGL_NO_TEXTURE
;
236 surf
->TextureTarget
= EGL_NO_TEXTURE
;
237 surf
->MipmapTexture
= EGL_FALSE
;
238 surf
->LargestPbuffer
= EGL_FALSE
;
239 surf
->RenderBuffer
= renderBuffer
;
240 surf
->VGAlphaFormat
= EGL_VG_ALPHA_FORMAT_NONPRE
;
241 surf
->VGColorspace
= EGL_VG_COLORSPACE_sRGB
;
243 surf
->MipmapLevel
= 0;
244 surf
->MultisampleResolve
= EGL_MULTISAMPLE_RESOLVE_DEFAULT
;
245 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
;
247 surf
->HorizontalResolution
= EGL_UNKNOWN
;
248 surf
->VerticalResolution
= EGL_UNKNOWN
;
249 surf
->AspectRatio
= EGL_UNKNOWN
;
251 /* the default swap interval is 1 */
252 _eglClampSwapInterval(surf
, 1);
254 err
= _eglParseSurfaceAttribList(surf
, attrib_list
);
255 if (err
!= EGL_SUCCESS
)
256 return _eglError(err
, func
);
263 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
265 /* Drivers have to do the actual buffer swap. */
271 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
272 EGLNativePixmapType target
)
274 /* copy surface to native pixmap */
275 /* All implementation burdon for this is in the device driver */
281 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
282 EGLint attribute
, EGLint
*value
)
286 *value
= surface
->Width
;
289 *value
= surface
->Height
;
292 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
294 case EGL_LARGEST_PBUFFER
:
295 *value
= surface
->LargestPbuffer
;
297 case EGL_TEXTURE_FORMAT
:
298 /* texture attributes: only for pbuffers, no error otherwise */
299 if (surface
->Type
== EGL_PBUFFER_BIT
)
300 *value
= surface
->TextureFormat
;
302 case EGL_TEXTURE_TARGET
:
303 if (surface
->Type
== EGL_PBUFFER_BIT
)
304 *value
= surface
->TextureTarget
;
306 case EGL_MIPMAP_TEXTURE
:
307 if (surface
->Type
== EGL_PBUFFER_BIT
)
308 *value
= surface
->MipmapTexture
;
310 case EGL_MIPMAP_LEVEL
:
311 if (surface
->Type
== EGL_PBUFFER_BIT
)
312 *value
= surface
->MipmapLevel
;
314 case EGL_SWAP_BEHAVIOR
:
315 *value
= surface
->SwapBehavior
;
317 case EGL_RENDER_BUFFER
:
318 *value
= surface
->RenderBuffer
;
320 case EGL_PIXEL_ASPECT_RATIO
:
321 *value
= surface
->AspectRatio
;
323 case EGL_HORIZONTAL_RESOLUTION
:
324 *value
= surface
->HorizontalResolution
;
326 case EGL_VERTICAL_RESOLUTION
:
327 *value
= surface
->VerticalResolution
;
329 case EGL_MULTISAMPLE_RESOLVE
:
330 *value
= surface
->MultisampleResolve
;
332 case EGL_VG_ALPHA_FORMAT
:
333 *value
= surface
->VGAlphaFormat
;
335 case EGL_VG_COLORSPACE
:
336 *value
= surface
->VGColorspace
;
339 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
348 * Drivers should do a proper implementation.
351 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
352 EGLNativeWindowType window
, const EGLint
*attrib_list
)
359 * Drivers should do a proper implementation.
362 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
363 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
370 * Drivers should do a proper implementation.
373 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
374 const EGLint
*attrib_list
)
381 * Default fallback routine - drivers should usually override this.
384 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
386 if (!_eglIsSurfaceBound(surf
))
393 * Default fallback routine - drivers might override this.
396 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
397 EGLint attribute
, EGLint value
)
400 EGLint err
= EGL_SUCCESS
;
403 case EGL_MIPMAP_LEVEL
:
404 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_RENDERABLE_TYPE
);
405 if (!(confval
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
))) {
406 err
= EGL_BAD_PARAMETER
;
409 surface
->MipmapLevel
= value
;
411 case EGL_MULTISAMPLE_RESOLVE
:
413 case EGL_MULTISAMPLE_RESOLVE_DEFAULT
:
415 case EGL_MULTISAMPLE_RESOLVE_BOX
:
416 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_SURFACE_TYPE
);
417 if (!(confval
& EGL_MULTISAMPLE_RESOLVE_BOX_BIT
))
421 err
= EGL_BAD_ATTRIBUTE
;
424 if (err
!= EGL_SUCCESS
)
426 surface
->MultisampleResolve
= value
;
428 case EGL_SWAP_BEHAVIOR
:
430 case EGL_BUFFER_DESTROYED
:
432 case EGL_BUFFER_PRESERVED
:
433 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_SURFACE_TYPE
);
434 if (!(confval
& EGL_SWAP_BEHAVIOR_PRESERVED_BIT
))
438 err
= EGL_BAD_ATTRIBUTE
;
441 if (err
!= EGL_SUCCESS
)
443 surface
->SwapBehavior
= value
;
446 err
= EGL_BAD_ATTRIBUTE
;
450 if (err
!= EGL_SUCCESS
)
451 return _eglError(err
, "eglSurfaceAttrib");
457 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
460 EGLint texture_type
= EGL_PBUFFER_BIT
;
462 /* Just do basic error checking and return success/fail.
463 * Drivers must implement the real stuff.
466 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
467 texture_type
|= EGL_PIXMAP_BIT
;
469 if (!(surface
->Type
& texture_type
)) {
470 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
474 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
475 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
479 if (surface
->TextureTarget
== EGL_NO_TEXTURE
) {
480 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
484 if (buffer
!= EGL_BACK_BUFFER
) {
485 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
489 surface
->BoundToTexture
= EGL_TRUE
;
496 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
499 /* Just do basic error checking and return success/fail.
500 * Drivers must implement the real stuff.
503 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
504 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
508 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
509 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
513 if (buffer
!= EGL_BACK_BUFFER
) {
514 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
518 if (!surface
->BoundToTexture
) {
519 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
523 surface
->BoundToTexture
= EGL_FALSE
;
530 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
533 _eglClampSwapInterval(surf
, interval
);
538 #ifdef EGL_VERSION_1_2
541 * Example function - drivers should do a proper implementation.
544 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
545 EGLenum buftype
, EGLClientBuffer buffer
,
546 _EGLConfig
*conf
, const EGLint
*attrib_list
)
548 if (buftype
!= EGL_OPENVG_IMAGE
) {
549 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
556 #endif /* EGL_VERSION_1_2 */