2 * Surface-related functions.
9 #include "egldisplay.h"
10 #include "eglcontext.h"
11 #include "eglconfig.h"
12 #include "egldriver.h"
13 #include "eglglobals.h"
15 #include "eglsurface.h"
19 * Do error check on parameters and initialize the given _EGLSurface object.
20 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
23 _eglInitSurface(_EGLDriver
*drv
, _EGLSurface
*surf
, EGLint type
,
24 _EGLConfig
*conf
, const EGLint
*attrib_list
)
27 EGLint width
= 0, height
= 0, largest
= 0;
28 EGLint texFormat
= EGL_NO_TEXTURE
, texTarget
= EGL_NO_TEXTURE
;
29 EGLint mipmapTex
= EGL_FALSE
;
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
*surf
)
215 /* Drivers have to do the actual buffer swap. */
221 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
222 NativePixmapType target
)
224 /* copy surface to native pixmap */
225 /* All implementation burdon for this is in the device driver */
231 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
232 EGLint attribute
, EGLint
*value
)
236 *value
= surface
->Width
;
239 *value
= surface
->Height
;
242 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
244 case EGL_LARGEST_PBUFFER
:
245 *value
= dpy
->LargestPbuffer
;
247 case EGL_SURFACE_TYPE
:
248 *value
= surface
->Type
;
250 #ifdef EGL_VERSION_1_1
251 case EGL_TEXTURE_FORMAT
:
252 /* texture attributes: only for pbuffers, no error otherwise */
253 if (surface
->Type
== EGL_PBUFFER_BIT
)
254 *value
= surface
->TextureFormat
;
256 case EGL_TEXTURE_TARGET
:
257 if (surface
->Type
== EGL_PBUFFER_BIT
)
258 *value
= surface
->TextureTarget
;
260 case EGL_MIPMAP_TEXTURE
:
261 if (surface
->Type
== EGL_PBUFFER_BIT
)
262 *value
= surface
->MipmapTexture
;
264 case EGL_MIPMAP_LEVEL
:
265 if (surface
->Type
== EGL_PBUFFER_BIT
)
266 *value
= surface
->MipmapLevel
;
268 #endif /* EGL_VERSION_1_1 */
269 #ifdef EGL_VERSION_1_2
270 case EGL_SWAP_BEHAVIOR
:
271 *value
= surface
->SwapBehavior
;
273 case EGL_RENDER_BUFFER
:
274 *value
= surface
->RenderBuffer
;
276 case EGL_PIXEL_ASPECT_RATIO
:
277 *value
= surface
->AspectRatio
;
279 case EGL_HORIZONTAL_RESOLUTION
:
280 *value
= surface
->HorizontalResolution
;
282 case EGL_VERTICAL_RESOLUTION
:
283 *value
= surface
->VerticalResolution
;
285 case EGL_ALPHA_FORMAT
:
286 *value
= surface
->AlphaFormat
;
289 *value
= surface
->Colorspace
;
291 #endif /* EGL_VERSION_1_2 */
293 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
300 * Example function - drivers should do a proper implementation.
303 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
304 NativeWindowType window
, const EGLint
*attrib_list
)
306 #if 0 /* THIS IS JUST EXAMPLE CODE */
309 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
313 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
325 * Example function - drivers should do a proper implementation.
328 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
329 NativePixmapType pixmap
, const EGLint
*attrib_list
)
331 #if 0 /* THIS IS JUST EXAMPLE CODE */
334 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
338 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
350 * Example function - drivers should do a proper implementation.
353 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
354 const EGLint
*attrib_list
)
356 #if 0 /* THIS IS JUST EXAMPLE CODE */
359 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
363 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, attrib_list
)) {
375 * Default fallback routine - drivers should usually override this.
378 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
380 if (!_eglIsSurfaceBound(surf
))
387 * Default fallback routine - drivers might override this.
390 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
391 EGLint attribute
, EGLint value
)
394 case EGL_MIPMAP_LEVEL
:
395 surface
->MipmapLevel
= value
;
398 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
406 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
409 /* Just do basic error checking and return success/fail.
410 * Drivers must implement the real stuff.
413 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
414 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
418 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
419 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
423 if (buffer
!= EGL_BACK_BUFFER
) {
424 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
428 surface
->BoundToTexture
= EGL_TRUE
;
435 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
438 /* Just do basic error checking and return success/fail.
439 * Drivers must implement the real stuff.
442 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
443 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
447 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
448 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
452 if (buffer
!= EGL_BACK_BUFFER
) {
453 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
457 if (!surface
->BoundToTexture
) {
458 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
462 surface
->BoundToTexture
= EGL_FALSE
;
469 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint interval
)
471 _EGLSurface
*surf
= _eglGetCurrentSurface(EGL_DRAW
);
473 surf
->SwapInterval
= interval
;
478 #ifdef EGL_VERSION_1_2
481 * Example function - drivers should do a proper implementation.
484 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
485 EGLenum buftype
, EGLClientBuffer buffer
,
486 _EGLConfig
*conf
, const EGLint
*attrib_list
)
488 if (buftype
!= EGL_OPENVG_IMAGE
) {
489 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
496 #endif /* EGL_VERSION_1_2 */