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
= 0, texTarget
= 0, mipmapTex
= 0;
30 EGLint renderBuffer
= EGL_BACK_BUFFER
;
31 #ifdef EGL_VERSION_1_2
32 EGLint colorspace
= EGL_COLORSPACE_sRGB
;
33 EGLint alphaFormat
= EGL_ALPHA_FORMAT_NONPRE
;
39 func
= "eglCreateWindowSurface";
42 func
= "eglCreatePixmapSurface";
43 renderBuffer
= EGL_SINGLE_BUFFER
;
46 func
= "eglCreatePBufferSurface";
48 case EGL_SCREEN_BIT_MESA
:
49 func
= "eglCreateScreenSurface";
50 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
53 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
58 _eglError(EGL_BAD_CONFIG
, func
);
62 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
63 /* The config can't be used to create a surface of this type */
64 _eglError(EGL_BAD_CONFIG
, func
);
69 * Parse attribute list. Different kinds of surfaces support different
72 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
73 switch (attrib_list
[i
]) {
75 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
76 width
= attrib_list
[++i
];
79 _eglError(EGL_BAD_ATTRIBUTE
, func
);
84 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
85 height
= attrib_list
[++i
];
88 _eglError(EGL_BAD_ATTRIBUTE
, func
);
92 case EGL_LARGEST_PBUFFER
:
93 if (type
== EGL_PBUFFER_BIT
) {
94 largest
= attrib_list
[++i
];
97 _eglError(EGL_BAD_ATTRIBUTE
, func
);
101 case EGL_TEXTURE_FORMAT
:
102 if (type
== EGL_PBUFFER_BIT
) {
103 texFormat
= attrib_list
[++i
];
106 _eglError(EGL_BAD_ATTRIBUTE
, func
);
110 case EGL_TEXTURE_TARGET
:
111 if (type
== EGL_PBUFFER_BIT
) {
112 texTarget
= attrib_list
[++i
];
115 _eglError(EGL_BAD_ATTRIBUTE
, func
);
119 case EGL_MIPMAP_TEXTURE
:
120 if (type
== EGL_PBUFFER_BIT
) {
121 mipmapTex
= attrib_list
[++i
];
124 _eglError(EGL_BAD_ATTRIBUTE
, func
);
128 #ifdef EGL_VERSION_1_2
129 case EGL_RENDER_BUFFER
:
130 if (type
== EGL_WINDOW_BIT
) {
131 renderBuffer
= attrib_list
[++i
];
132 if (renderBuffer
!= EGL_BACK_BUFFER
&&
133 renderBuffer
!= EGL_SINGLE_BUFFER
) {
134 _eglError(EGL_BAD_ATTRIBUTE
, func
);
139 _eglError(EGL_BAD_ATTRIBUTE
, func
);
144 if (type
== EGL_WINDOW_BIT
||
145 type
== EGL_PBUFFER_BIT
||
146 type
== EGL_PIXMAP_BIT
) {
147 colorspace
= attrib_list
[++i
];
148 if (colorspace
!= EGL_COLORSPACE_sRGB
&&
149 colorspace
!= EGL_COLORSPACE_LINEAR
) {
150 _eglError(EGL_BAD_ATTRIBUTE
, func
);
155 _eglError(EGL_BAD_ATTRIBUTE
, func
);
159 case EGL_ALPHA_FORMAT
:
160 if (type
== EGL_WINDOW_BIT
||
161 type
== EGL_PBUFFER_BIT
||
162 type
== EGL_PIXMAP_BIT
) {
163 alphaFormat
= attrib_list
[++i
];
164 if (alphaFormat
!= EGL_ALPHA_FORMAT_NONPRE
&&
165 alphaFormat
!= EGL_ALPHA_FORMAT_PRE
) {
166 _eglError(EGL_BAD_ATTRIBUTE
, func
);
171 _eglError(EGL_BAD_ATTRIBUTE
, func
);
176 #endif /* EGL_VERSION_1_2 */
178 _eglError(EGL_BAD_ATTRIBUTE
, func
);
183 if (width
< 0 || height
< 0) {
184 _eglError(EGL_BAD_ATTRIBUTE
, func
);
188 memset(surf
, 0, sizeof(_EGLSurface
));
192 surf
->Height
= height
;
193 surf
->TextureFormat
= texFormat
;
194 surf
->TextureTarget
= texTarget
;
195 surf
->MipmapTexture
= mipmapTex
;
196 surf
->MipmapLevel
= 0;
197 surf
->SwapInterval
= 0;
198 #ifdef EGL_VERSION_1_2
199 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
200 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
201 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
202 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
203 surf
->RenderBuffer
= renderBuffer
;
204 surf
->AlphaFormat
= alphaFormat
;
205 surf
->Colorspace
= colorspace
;
213 _eglSwapBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
)
215 /* Basically just do error checking here. Drivers have to do the
216 * actual buffer swap.
218 _EGLSurface
*surface
= _eglLookupSurface(draw
);
219 if (surface
== NULL
) {
220 _eglError(EGL_BAD_SURFACE
, "eglSwapBuffers");
228 _eglCopyBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
,
229 NativePixmapType target
)
231 /* copy surface to native pixmap */
232 /* All implementation burdon for this is in the device driver */
238 _eglQuerySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
239 EGLint attribute
, EGLint
*value
)
241 _EGLSurface
*surface
= _eglLookupSurface(surf
);
242 if (surface
== NULL
) {
243 _eglError(EGL_BAD_SURFACE
, "eglQuerySurface");
248 *value
= surface
->Width
;
251 *value
= surface
->Height
;
254 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
256 case EGL_LARGEST_PBUFFER
:
257 *value
= drv
->LargestPbuffer
;
259 case EGL_SURFACE_TYPE
:
260 *value
= surface
->Type
;
262 #ifdef EGL_VERSION_1_1
263 case EGL_TEXTURE_FORMAT
:
264 /* texture attributes: only for pbuffers, no error otherwise */
265 if (surface
->Type
== EGL_PBUFFER_BIT
)
266 *value
= surface
->TextureFormat
;
268 case EGL_TEXTURE_TARGET
:
269 if (surface
->Type
== EGL_PBUFFER_BIT
)
270 *value
= surface
->TextureTarget
;
272 case EGL_MIPMAP_TEXTURE
:
273 if (surface
->Type
== EGL_PBUFFER_BIT
)
274 *value
= surface
->MipmapTexture
;
276 case EGL_MIPMAP_LEVEL
:
277 if (surface
->Type
== EGL_PBUFFER_BIT
)
278 *value
= surface
->MipmapLevel
;
280 #endif /* EGL_VERSION_1_1 */
281 #ifdef EGL_VERSION_1_2
282 case EGL_SWAP_BEHAVIOR
:
283 *value
= surface
->SwapBehavior
;
285 case EGL_RENDER_BUFFER
:
286 *value
= surface
->RenderBuffer
;
288 case EGL_PIXEL_ASPECT_RATIO
:
289 *value
= surface
->AspectRatio
;
291 case EGL_HORIZONTAL_RESOLUTION
:
292 *value
= surface
->HorizontalResolution
;
294 case EGL_VERTICAL_RESOLUTION
:
295 *value
= surface
->VerticalResolution
;
297 case EGL_ALPHA_FORMAT
:
298 *value
= surface
->AlphaFormat
;
301 *value
= surface
->Colorspace
;
303 #endif /* EGL_VERSION_1_2 */
305 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
312 * Example function - drivers should do a proper implementation.
315 _eglCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
316 NativeWindowType window
, const EGLint
*attrib_list
)
318 #if 0 /* THIS IS JUST EXAMPLE CODE */
322 conf
= _eglLookupConfig(drv
, dpy
, config
);
324 _eglError(EGL_BAD_CONFIG
, "eglCreateWindowSurface");
325 return EGL_NO_SURFACE
;
328 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
330 return EGL_NO_SURFACE
;
332 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
334 return EGL_NO_SURFACE
;
337 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
339 return EGL_NO_SURFACE
;
344 * Example function - drivers should do a proper implementation.
347 _eglCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
348 NativePixmapType pixmap
, const EGLint
*attrib_list
)
350 #if 0 /* THIS IS JUST EXAMPLE CODE */
354 conf
= _eglLookupConfig(drv
, dpy
, config
);
356 _eglError(EGL_BAD_CONFIG
, "eglCreatePixmapSurface");
357 return EGL_NO_SURFACE
;
360 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
362 return EGL_NO_SURFACE
;
364 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
366 return EGL_NO_SURFACE
;
369 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
371 return EGL_NO_SURFACE
;
376 * Example function - drivers should do a proper implementation.
379 _eglCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
380 const EGLint
*attrib_list
)
382 #if 0 /* THIS IS JUST EXAMPLE CODE */
386 conf
= _eglLookupConfig(drv
, dpy
, config
);
388 _eglError(EGL_BAD_CONFIG
, "eglCreatePbufferSurface");
389 return EGL_NO_SURFACE
;
392 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
394 return EGL_NO_SURFACE
;
396 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, attrib_list
)) {
398 return EGL_NO_SURFACE
;
401 return _eglLinkSurface(surf
, _eglLookupDisplay(dpy
));
403 return EGL_NO_SURFACE
;
408 * Default fallback routine - drivers should usually override this.
411 _eglDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
413 _EGLSurface
*surf
= _eglLookupSurface(surface
);
415 _eglUnlinkSurface(surf
);
421 _eglError(EGL_BAD_SURFACE
, "eglDestroySurface");
428 * Default fallback routine - drivers might override this.
431 _eglSurfaceAttrib(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
432 EGLint attribute
, EGLint value
)
434 _EGLSurface
*surface
= _eglLookupSurface(surf
);
436 if (surface
== NULL
) {
437 _eglError(EGL_BAD_SURFACE
, "eglSurfaceAttrib");
442 case EGL_MIPMAP_LEVEL
:
443 surface
->MipmapLevel
= value
;
446 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
454 _eglBindTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
457 /* Just do basic error checking and return success/fail.
458 * Drivers must implement the real stuff.
460 _EGLSurface
*surface
= _eglLookupSurface(surf
);
462 if (!surface
|| surface
->Type
!= EGL_PBUFFER_BIT
) {
463 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
467 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
468 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
472 if (buffer
!= EGL_BACK_BUFFER
) {
473 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
477 surface
->BoundToTexture
= EGL_TRUE
;
484 _eglReleaseTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
487 /* Just do basic error checking and return success/fail.
488 * Drivers must implement the real stuff.
490 _EGLSurface
*surface
= _eglLookupSurface(surf
);
492 if (!surface
|| surface
->Type
!= EGL_PBUFFER_BIT
) {
493 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
497 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
498 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
502 if (buffer
!= EGL_BACK_BUFFER
) {
503 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
507 if (!surface
->BoundToTexture
) {
508 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
512 surface
->BoundToTexture
= EGL_FALSE
;
519 _eglSwapInterval(_EGLDriver
*drv
, EGLDisplay dpy
, EGLint interval
)
521 _EGLSurface
*surf
= _eglGetCurrentSurface(EGL_DRAW
);
523 _eglError(EGL_BAD_SURFACE
, "eglSwapInterval");
526 surf
->SwapInterval
= interval
;
531 #ifdef EGL_VERSION_1_2
534 * Example function - drivers should do a proper implementation.
537 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, EGLDisplay dpy
,
538 EGLenum buftype
, EGLClientBuffer buffer
,
539 EGLConfig config
, const EGLint
*attrib_list
)
541 if (buftype
!= EGL_OPENVG_IMAGE
) {
542 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
543 return EGL_NO_SURFACE
;
546 return EGL_NO_SURFACE
;
549 #endif /* EGL_VERSION_1_2 */