2 * Surface-related functions.
9 #include "egldisplay.h"
10 #include "eglcontext.h"
11 #include "eglconfig.h"
12 #include "egldriver.h"
13 #include "eglglobals.h"
16 #include "eglsurface.h"
20 * Do error check on parameters and initialize the given _EGLSurface object.
21 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
24 _eglInitSurface(_EGLDriver
*drv
, _EGLSurface
*surf
, EGLint type
,
25 _EGLConfig
*conf
, const EGLint
*attrib_list
)
28 EGLint width
= 0, height
= 0, largest
= 0;
29 EGLint texFormat
= EGL_NO_TEXTURE
, texTarget
= EGL_NO_TEXTURE
;
30 EGLint mipmapTex
= EGL_FALSE
;
31 EGLint renderBuffer
= EGL_BACK_BUFFER
;
32 #ifdef EGL_VERSION_1_2
33 EGLint colorspace
= EGL_COLORSPACE_sRGB
;
34 EGLint alphaFormat
= EGL_ALPHA_FORMAT_NONPRE
;
40 func
= "eglCreateWindowSurface";
43 func
= "eglCreatePixmapSurface";
44 renderBuffer
= EGL_SINGLE_BUFFER
;
47 func
= "eglCreatePBufferSurface";
49 case EGL_SCREEN_BIT_MESA
:
50 func
= "eglCreateScreenSurface";
51 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
54 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
59 _eglError(EGL_BAD_CONFIG
, func
);
63 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
64 /* The config can't be used to create a surface of this type */
65 _eglError(EGL_BAD_CONFIG
, func
);
70 * Parse attribute list. Different kinds of surfaces support different
73 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
74 switch (attrib_list
[i
]) {
76 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
77 width
= attrib_list
[++i
];
80 _eglError(EGL_BAD_ATTRIBUTE
, func
);
85 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
86 height
= attrib_list
[++i
];
89 _eglError(EGL_BAD_ATTRIBUTE
, func
);
93 case EGL_LARGEST_PBUFFER
:
94 if (type
== EGL_PBUFFER_BIT
) {
95 largest
= attrib_list
[++i
];
98 _eglError(EGL_BAD_ATTRIBUTE
, func
);
102 case EGL_TEXTURE_FORMAT
:
103 if (type
== EGL_PBUFFER_BIT
) {
104 texFormat
= attrib_list
[++i
];
107 _eglError(EGL_BAD_ATTRIBUTE
, func
);
111 case EGL_TEXTURE_TARGET
:
112 if (type
== EGL_PBUFFER_BIT
) {
113 texTarget
= attrib_list
[++i
];
116 _eglError(EGL_BAD_ATTRIBUTE
, func
);
120 case EGL_MIPMAP_TEXTURE
:
121 if (type
== EGL_PBUFFER_BIT
) {
122 mipmapTex
= attrib_list
[++i
];
125 _eglError(EGL_BAD_ATTRIBUTE
, func
);
129 #ifdef EGL_VERSION_1_2
130 case EGL_RENDER_BUFFER
:
131 if (type
== EGL_WINDOW_BIT
) {
132 renderBuffer
= attrib_list
[++i
];
133 if (renderBuffer
!= EGL_BACK_BUFFER
&&
134 renderBuffer
!= EGL_SINGLE_BUFFER
) {
135 _eglError(EGL_BAD_ATTRIBUTE
, func
);
140 _eglError(EGL_BAD_ATTRIBUTE
, func
);
145 if (type
== EGL_WINDOW_BIT
||
146 type
== EGL_PBUFFER_BIT
||
147 type
== EGL_PIXMAP_BIT
) {
148 colorspace
= attrib_list
[++i
];
149 if (colorspace
!= EGL_COLORSPACE_sRGB
&&
150 colorspace
!= EGL_COLORSPACE_LINEAR
) {
151 _eglError(EGL_BAD_ATTRIBUTE
, func
);
156 _eglError(EGL_BAD_ATTRIBUTE
, func
);
160 case EGL_ALPHA_FORMAT
:
161 if (type
== EGL_WINDOW_BIT
||
162 type
== EGL_PBUFFER_BIT
||
163 type
== EGL_PIXMAP_BIT
) {
164 alphaFormat
= attrib_list
[++i
];
165 if (alphaFormat
!= EGL_ALPHA_FORMAT_NONPRE
&&
166 alphaFormat
!= EGL_ALPHA_FORMAT_PRE
) {
167 _eglError(EGL_BAD_ATTRIBUTE
, func
);
172 _eglError(EGL_BAD_ATTRIBUTE
, func
);
177 #endif /* EGL_VERSION_1_2 */
179 _eglError(EGL_BAD_ATTRIBUTE
, func
);
184 if (width
< 0 || height
< 0) {
185 _eglError(EGL_BAD_ATTRIBUTE
, func
);
189 memset(surf
, 0, sizeof(_EGLSurface
));
193 surf
->Height
= height
;
194 surf
->TextureFormat
= texFormat
;
195 surf
->TextureTarget
= texTarget
;
196 surf
->MipmapTexture
= mipmapTex
;
197 surf
->MipmapLevel
= 0;
198 surf
->SwapInterval
= 0;
199 #ifdef EGL_VERSION_1_2
200 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
201 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
202 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
203 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
204 surf
->RenderBuffer
= renderBuffer
;
205 surf
->AlphaFormat
= alphaFormat
;
206 surf
->Colorspace
= colorspace
;
214 _eglSwapBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
)
216 /* Basically just do error checking here. Drivers have to do the
217 * actual buffer swap.
219 _EGLSurface
*surface
= _eglLookupSurface(draw
);
220 if (surface
== NULL
) {
221 _eglError(EGL_BAD_SURFACE
, "eglSwapBuffers");
229 _eglCopyBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
,
230 NativePixmapType target
)
232 /* copy surface to native pixmap */
233 /* All implementation burdon for this is in the device driver */
239 _eglQuerySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
240 EGLint attribute
, EGLint
*value
)
242 _EGLSurface
*surface
= _eglLookupSurface(surf
);
243 if (surface
== NULL
) {
244 _eglError(EGL_BAD_SURFACE
, "eglQuerySurface");
249 *value
= surface
->Width
;
252 *value
= surface
->Height
;
255 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
257 case EGL_LARGEST_PBUFFER
:
258 *value
= drv
->LargestPbuffer
;
260 case EGL_SURFACE_TYPE
:
261 *value
= surface
->Type
;
263 #ifdef EGL_VERSION_1_1
264 case EGL_TEXTURE_FORMAT
:
265 /* texture attributes: only for pbuffers, no error otherwise */
266 if (surface
->Type
== EGL_PBUFFER_BIT
)
267 *value
= surface
->TextureFormat
;
269 case EGL_TEXTURE_TARGET
:
270 if (surface
->Type
== EGL_PBUFFER_BIT
)
271 *value
= surface
->TextureTarget
;
273 case EGL_MIPMAP_TEXTURE
:
274 if (surface
->Type
== EGL_PBUFFER_BIT
)
275 *value
= surface
->MipmapTexture
;
277 case EGL_MIPMAP_LEVEL
:
278 if (surface
->Type
== EGL_PBUFFER_BIT
)
279 *value
= surface
->MipmapLevel
;
281 #endif /* EGL_VERSION_1_1 */
282 #ifdef EGL_VERSION_1_2
283 case EGL_SWAP_BEHAVIOR
:
284 *value
= surface
->SwapBehavior
;
286 case EGL_RENDER_BUFFER
:
287 *value
= surface
->RenderBuffer
;
289 case EGL_PIXEL_ASPECT_RATIO
:
290 *value
= surface
->AspectRatio
;
292 case EGL_HORIZONTAL_RESOLUTION
:
293 *value
= surface
->HorizontalResolution
;
295 case EGL_VERTICAL_RESOLUTION
:
296 *value
= surface
->VerticalResolution
;
298 case EGL_ALPHA_FORMAT
:
299 *value
= surface
->AlphaFormat
;
302 *value
= surface
->Colorspace
;
304 #endif /* EGL_VERSION_1_2 */
306 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
313 * Example function - drivers should do a proper implementation.
316 _eglCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
317 NativeWindowType window
, const EGLint
*attrib_list
)
319 #if 0 /* THIS IS JUST EXAMPLE CODE */
323 conf
= _eglLookupConfig(drv
, dpy
, config
);
325 _eglError(EGL_BAD_CONFIG
, "eglCreateWindowSurface");
326 return EGL_NO_SURFACE
;
329 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
331 return EGL_NO_SURFACE
;
333 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
335 return EGL_NO_SURFACE
;
338 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
340 return EGL_NO_SURFACE
;
345 * Example function - drivers should do a proper implementation.
348 _eglCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
349 NativePixmapType pixmap
, const EGLint
*attrib_list
)
351 #if 0 /* THIS IS JUST EXAMPLE CODE */
355 conf
= _eglLookupConfig(drv
, dpy
, config
);
357 _eglError(EGL_BAD_CONFIG
, "eglCreatePixmapSurface");
358 return EGL_NO_SURFACE
;
361 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
363 return EGL_NO_SURFACE
;
365 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
367 return EGL_NO_SURFACE
;
370 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
372 return EGL_NO_SURFACE
;
377 * Example function - drivers should do a proper implementation.
380 _eglCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
381 const EGLint
*attrib_list
)
383 #if 0 /* THIS IS JUST EXAMPLE CODE */
387 conf
= _eglLookupConfig(drv
, dpy
, config
);
389 _eglError(EGL_BAD_CONFIG
, "eglCreatePbufferSurface");
390 return EGL_NO_SURFACE
;
393 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
395 return EGL_NO_SURFACE
;
397 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, attrib_list
)) {
399 return EGL_NO_SURFACE
;
402 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
404 return EGL_NO_SURFACE
;
409 * Default fallback routine - drivers should usually override this.
412 _eglDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
414 _EGLSurface
*surf
= _eglLookupSurface(surface
);
416 _eglUnlinkSurface(surf
);
417 if (!_eglIsSurfaceBound(surf
))
422 _eglError(EGL_BAD_SURFACE
, "eglDestroySurface");
429 * Default fallback routine - drivers might override this.
432 _eglSurfaceAttrib(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
433 EGLint attribute
, EGLint value
)
435 _EGLSurface
*surface
= _eglLookupSurface(surf
);
437 if (surface
== NULL
) {
438 _eglError(EGL_BAD_SURFACE
, "eglSurfaceAttrib");
443 case EGL_MIPMAP_LEVEL
:
444 surface
->MipmapLevel
= value
;
447 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
455 _eglBindTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
458 /* Just do basic error checking and return success/fail.
459 * Drivers must implement the real stuff.
461 _EGLSurface
*surface
= _eglLookupSurface(surf
);
463 if (!surface
|| surface
->Type
!= EGL_PBUFFER_BIT
) {
464 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
468 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
469 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
473 if (buffer
!= EGL_BACK_BUFFER
) {
474 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
478 surface
->BoundToTexture
= EGL_TRUE
;
485 _eglReleaseTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
488 /* Just do basic error checking and return success/fail.
489 * Drivers must implement the real stuff.
491 _EGLSurface
*surface
= _eglLookupSurface(surf
);
493 if (!surface
|| surface
->Type
!= EGL_PBUFFER_BIT
) {
494 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
498 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
499 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
503 if (buffer
!= EGL_BACK_BUFFER
) {
504 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
508 if (!surface
->BoundToTexture
) {
509 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
513 surface
->BoundToTexture
= EGL_FALSE
;
520 _eglSwapInterval(_EGLDriver
*drv
, EGLDisplay dpy
, EGLint interval
)
522 _EGLSurface
*surf
= _eglGetCurrentSurface(EGL_DRAW
);
524 _eglError(EGL_BAD_SURFACE
, "eglSwapInterval");
527 surf
->SwapInterval
= interval
;
532 #ifdef EGL_VERSION_1_2
535 * Example function - drivers should do a proper implementation.
538 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, EGLDisplay dpy
,
539 EGLenum buftype
, EGLClientBuffer buffer
,
540 EGLConfig config
, const EGLint
*attrib_list
)
542 if (buftype
!= EGL_OPENVG_IMAGE
) {
543 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
544 return EGL_NO_SURFACE
;
547 return EGL_NO_SURFACE
;
550 #endif /* EGL_VERSION_1_2 */