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 EGLint type
= surf
->Type
;
40 EGLint i
, err
= EGL_SUCCESS
;
45 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
46 EGLint attr
= attrib_list
[i
++];
47 EGLint val
= attrib_list
[i
];
50 /* common (except for screen surfaces) attributes */
51 case EGL_VG_COLORSPACE
:
52 if (type
== EGL_SCREEN_BIT_MESA
) {
53 err
= EGL_BAD_ATTRIBUTE
;
57 case EGL_VG_COLORSPACE_sRGB
:
58 case EGL_VG_COLORSPACE_LINEAR
:
61 err
= EGL_BAD_ATTRIBUTE
;
64 if (err
!= EGL_SUCCESS
)
66 surf
->VGColorspace
= val
;
68 case EGL_VG_ALPHA_FORMAT
:
69 if (type
== EGL_SCREEN_BIT_MESA
) {
70 err
= EGL_BAD_ATTRIBUTE
;
74 case EGL_VG_ALPHA_FORMAT_NONPRE
:
75 case EGL_VG_ALPHA_FORMAT_PRE
:
78 err
= EGL_BAD_ATTRIBUTE
;
81 if (err
!= EGL_SUCCESS
)
83 surf
->VGAlphaFormat
= val
;
85 /* window surface attributes */
86 case EGL_RENDER_BUFFER
:
87 if (type
!= EGL_WINDOW_BIT
) {
88 err
= EGL_BAD_ATTRIBUTE
;
91 if (val
!= EGL_BACK_BUFFER
&& val
!= EGL_SINGLE_BUFFER
) {
92 err
= EGL_BAD_ATTRIBUTE
;
95 surf
->RenderBuffer
= val
;
97 /* pbuffer surface attributes */
99 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
100 err
= EGL_BAD_ATTRIBUTE
;
104 err
= EGL_BAD_PARAMETER
;
110 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
111 err
= EGL_BAD_ATTRIBUTE
;
115 err
= EGL_BAD_PARAMETER
;
120 case EGL_LARGEST_PBUFFER
:
121 if (type
!= EGL_PBUFFER_BIT
) {
122 err
= EGL_BAD_ATTRIBUTE
;
125 surf
->LargestPbuffer
= !!val
;
127 case EGL_TEXTURE_FORMAT
:
128 if (type
!= EGL_PBUFFER_BIT
) {
129 err
= EGL_BAD_ATTRIBUTE
;
133 case EGL_TEXTURE_RGB
:
134 case EGL_TEXTURE_RGBA
:
138 err
= EGL_BAD_ATTRIBUTE
;
141 if (err
!= EGL_SUCCESS
)
143 surf
->TextureFormat
= val
;
145 case EGL_TEXTURE_TARGET
:
146 if (type
!= EGL_PBUFFER_BIT
) {
147 err
= EGL_BAD_ATTRIBUTE
;
155 err
= EGL_BAD_ATTRIBUTE
;
158 if (err
!= EGL_SUCCESS
)
160 surf
->TextureTarget
= val
;
162 case EGL_MIPMAP_TEXTURE
:
163 if (type
!= EGL_PBUFFER_BIT
) {
164 err
= EGL_BAD_ATTRIBUTE
;
167 surf
->MipmapTexture
= !!val
;
169 /* no pixmap surface specific attributes */
171 err
= EGL_BAD_ATTRIBUTE
;
175 if (err
!= EGL_SUCCESS
) {
176 _eglLog(_EGL_WARNING
, "bad surface attribute 0x%04x", attr
);
186 * Do error check on parameters and initialize the given _EGLSurface object.
187 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
190 _eglInitSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
191 _EGLConfig
*conf
, const EGLint
*attrib_list
)
194 EGLint renderBuffer
= EGL_BACK_BUFFER
;
199 func
= "eglCreateWindowSurface";
202 func
= "eglCreatePixmapSurface";
203 renderBuffer
= EGL_SINGLE_BUFFER
;
205 case EGL_PBUFFER_BIT
:
206 func
= "eglCreatePBufferSurface";
208 case EGL_SCREEN_BIT_MESA
:
209 func
= "eglCreateScreenSurface";
210 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
213 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
217 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
218 /* The config can't be used to create a surface of this type */
219 _eglError(EGL_BAD_CONFIG
, func
);
223 memset(surf
, 0, sizeof(_EGLSurface
));
224 surf
->Resource
.Display
= dpy
;
230 surf
->TextureFormat
= EGL_NO_TEXTURE
;
231 surf
->TextureTarget
= EGL_NO_TEXTURE
;
232 surf
->MipmapTexture
= EGL_FALSE
;
233 surf
->LargestPbuffer
= EGL_FALSE
;
234 surf
->RenderBuffer
= renderBuffer
;
235 surf
->VGAlphaFormat
= EGL_VG_ALPHA_FORMAT_NONPRE
;
236 surf
->VGColorspace
= EGL_VG_COLORSPACE_sRGB
;
238 surf
->MipmapLevel
= 0;
239 surf
->MultisampleResolve
= EGL_MULTISAMPLE_RESOLVE_DEFAULT
;
240 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
;
242 surf
->HorizontalResolution
= EGL_UNKNOWN
;
243 surf
->VerticalResolution
= EGL_UNKNOWN
;
244 surf
->AspectRatio
= EGL_UNKNOWN
;
246 /* the default swap interval is 1 */
247 _eglClampSwapInterval(surf
, 1);
249 err
= _eglParseSurfaceAttribList(surf
, attrib_list
);
250 if (err
!= EGL_SUCCESS
)
251 return _eglError(err
, func
);
258 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
260 /* Drivers have to do the actual buffer swap. */
266 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
267 EGLNativePixmapType target
)
269 /* copy surface to native pixmap */
270 /* All implementation burdon for this is in the device driver */
276 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
277 EGLint attribute
, EGLint
*value
)
281 *value
= surface
->Width
;
284 *value
= surface
->Height
;
287 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
289 case EGL_LARGEST_PBUFFER
:
290 *value
= surface
->LargestPbuffer
;
292 case EGL_TEXTURE_FORMAT
:
293 /* texture attributes: only for pbuffers, no error otherwise */
294 if (surface
->Type
== EGL_PBUFFER_BIT
)
295 *value
= surface
->TextureFormat
;
297 case EGL_TEXTURE_TARGET
:
298 if (surface
->Type
== EGL_PBUFFER_BIT
)
299 *value
= surface
->TextureTarget
;
301 case EGL_MIPMAP_TEXTURE
:
302 if (surface
->Type
== EGL_PBUFFER_BIT
)
303 *value
= surface
->MipmapTexture
;
305 case EGL_MIPMAP_LEVEL
:
306 if (surface
->Type
== EGL_PBUFFER_BIT
)
307 *value
= surface
->MipmapLevel
;
309 case EGL_SWAP_BEHAVIOR
:
310 *value
= surface
->SwapBehavior
;
312 case EGL_RENDER_BUFFER
:
313 *value
= surface
->RenderBuffer
;
315 case EGL_PIXEL_ASPECT_RATIO
:
316 *value
= surface
->AspectRatio
;
318 case EGL_HORIZONTAL_RESOLUTION
:
319 *value
= surface
->HorizontalResolution
;
321 case EGL_VERTICAL_RESOLUTION
:
322 *value
= surface
->VerticalResolution
;
324 case EGL_MULTISAMPLE_RESOLVE
:
325 *value
= surface
->MultisampleResolve
;
327 case EGL_VG_ALPHA_FORMAT
:
328 *value
= surface
->VGAlphaFormat
;
330 case EGL_VG_COLORSPACE
:
331 *value
= surface
->VGColorspace
;
334 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
343 * Drivers should do a proper implementation.
346 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
347 EGLNativeWindowType window
, const EGLint
*attrib_list
)
354 * Drivers should do a proper implementation.
357 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
358 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
365 * Drivers should do a proper implementation.
368 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
369 const EGLint
*attrib_list
)
376 * Default fallback routine - drivers should usually override this.
379 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
381 if (!_eglIsSurfaceBound(surf
))
388 * Default fallback routine - drivers might override this.
391 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
392 EGLint attribute
, EGLint value
)
395 EGLint err
= EGL_SUCCESS
;
398 case EGL_MIPMAP_LEVEL
:
399 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_RENDERABLE_TYPE
);
400 if (!(confval
& (EGL_OPENGL_ES_BIT
| EGL_OPENGL_ES2_BIT
))) {
401 err
= EGL_BAD_PARAMETER
;
404 surface
->MipmapLevel
= value
;
406 case EGL_MULTISAMPLE_RESOLVE
:
408 case EGL_MULTISAMPLE_RESOLVE_DEFAULT
:
410 case EGL_MULTISAMPLE_RESOLVE_BOX
:
411 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_SURFACE_TYPE
);
412 if (!(confval
& EGL_MULTISAMPLE_RESOLVE_BOX_BIT
))
416 err
= EGL_BAD_ATTRIBUTE
;
419 if (err
!= EGL_SUCCESS
)
421 surface
->MultisampleResolve
= value
;
423 case EGL_SWAP_BEHAVIOR
:
425 case EGL_BUFFER_DESTROYED
:
427 case EGL_BUFFER_PRESERVED
:
428 confval
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_SURFACE_TYPE
);
429 if (!(confval
& EGL_SWAP_BEHAVIOR_PRESERVED_BIT
))
433 err
= EGL_BAD_ATTRIBUTE
;
436 if (err
!= EGL_SUCCESS
)
438 surface
->SwapBehavior
= value
;
441 err
= EGL_BAD_ATTRIBUTE
;
445 if (err
!= EGL_SUCCESS
)
446 return _eglError(err
, "eglSurfaceAttrib");
452 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
455 /* Just do basic error checking and return success/fail.
456 * Drivers must implement the real stuff.
459 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
460 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
464 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
465 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
469 if (buffer
!= EGL_BACK_BUFFER
) {
470 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
474 surface
->BoundToTexture
= EGL_TRUE
;
481 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
484 /* Just do basic error checking and return success/fail.
485 * Drivers must implement the real stuff.
488 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
489 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
493 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
494 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
498 if (buffer
!= EGL_BACK_BUFFER
) {
499 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
503 if (!surface
->BoundToTexture
) {
504 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
508 surface
->BoundToTexture
= EGL_FALSE
;
515 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
518 _eglClampSwapInterval(surf
, interval
);
523 #ifdef EGL_VERSION_1_2
526 * Example function - drivers should do a proper implementation.
529 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
530 EGLenum buftype
, EGLClientBuffer buffer
,
531 _EGLConfig
*conf
, const EGLint
*attrib_list
)
533 if (buftype
!= EGL_OPENVG_IMAGE
) {
534 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
541 #endif /* EGL_VERSION_1_2 */