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 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
308 EGLint attribute
, EGLint
*value
)
312 *value
= surface
->Width
;
315 *value
= surface
->Height
;
318 *value
= surface
->Config
->ConfigID
;
320 case EGL_LARGEST_PBUFFER
:
321 *value
= surface
->LargestPbuffer
;
323 case EGL_TEXTURE_FORMAT
:
324 /* texture attributes: only for pbuffers, no error otherwise */
325 if (surface
->Type
== EGL_PBUFFER_BIT
)
326 *value
= surface
->TextureFormat
;
328 case EGL_TEXTURE_TARGET
:
329 if (surface
->Type
== EGL_PBUFFER_BIT
)
330 *value
= surface
->TextureTarget
;
332 case EGL_MIPMAP_TEXTURE
:
333 if (surface
->Type
== EGL_PBUFFER_BIT
)
334 *value
= surface
->MipmapTexture
;
336 case EGL_MIPMAP_LEVEL
:
337 if (surface
->Type
== EGL_PBUFFER_BIT
)
338 *value
= surface
->MipmapLevel
;
340 case EGL_SWAP_BEHAVIOR
:
341 *value
= surface
->SwapBehavior
;
343 case EGL_RENDER_BUFFER
:
344 *value
= surface
->RenderBuffer
;
346 case EGL_PIXEL_ASPECT_RATIO
:
347 *value
= surface
->AspectRatio
;
349 case EGL_HORIZONTAL_RESOLUTION
:
350 *value
= surface
->HorizontalResolution
;
352 case EGL_VERTICAL_RESOLUTION
:
353 *value
= surface
->VerticalResolution
;
355 case EGL_MULTISAMPLE_RESOLVE
:
356 *value
= surface
->MultisampleResolve
;
358 case EGL_VG_ALPHA_FORMAT
:
359 *value
= surface
->VGAlphaFormat
;
361 case EGL_VG_COLORSPACE
:
362 *value
= surface
->VGColorspace
;
365 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
374 * Default fallback routine - drivers might override this.
377 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
378 EGLint attribute
, EGLint value
)
381 EGLint err
= EGL_SUCCESS
;
384 case EGL_MIPMAP_LEVEL
:
385 confval
= surface
->Config
->RenderableType
;
386 if (!(confval
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
))) {
387 err
= EGL_BAD_PARAMETER
;
390 surface
->MipmapLevel
= value
;
392 case EGL_MULTISAMPLE_RESOLVE
:
394 case EGL_MULTISAMPLE_RESOLVE_DEFAULT
:
396 case EGL_MULTISAMPLE_RESOLVE_BOX
:
397 confval
= surface
->Config
->SurfaceType
;
398 if (!(confval
& EGL_MULTISAMPLE_RESOLVE_BOX_BIT
))
402 err
= EGL_BAD_ATTRIBUTE
;
405 if (err
!= EGL_SUCCESS
)
407 surface
->MultisampleResolve
= value
;
409 case EGL_SWAP_BEHAVIOR
:
411 case EGL_BUFFER_DESTROYED
:
413 case EGL_BUFFER_PRESERVED
:
414 confval
= surface
->Config
->SurfaceType
;
415 if (!(confval
& EGL_SWAP_BEHAVIOR_PRESERVED_BIT
))
419 err
= EGL_BAD_ATTRIBUTE
;
422 if (err
!= EGL_SUCCESS
)
424 surface
->SwapBehavior
= value
;
427 err
= EGL_BAD_ATTRIBUTE
;
431 if (err
!= EGL_SUCCESS
)
432 return _eglError(err
, "eglSurfaceAttrib");
438 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
441 EGLint texture_type
= EGL_PBUFFER_BIT
;
443 /* Just do basic error checking and return success/fail.
444 * Drivers must implement the real stuff.
447 if (dpy
->Extensions
.NOK_texture_from_pixmap
)
448 texture_type
|= EGL_PIXMAP_BIT
;
450 if (!(surface
->Type
& texture_type
)) {
451 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
455 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
456 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
460 if (surface
->TextureTarget
== EGL_NO_TEXTURE
) {
461 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
465 if (buffer
!= EGL_BACK_BUFFER
) {
466 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
470 surface
->BoundToTexture
= EGL_TRUE
;
477 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
480 _eglClampSwapInterval(surf
, interval
);