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
*surf
)
216 /* Drivers have to do the actual buffer swap. */
222 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
223 NativePixmapType target
)
225 /* copy surface to native pixmap */
226 /* All implementation burdon for this is in the device driver */
232 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
233 EGLint attribute
, EGLint
*value
)
237 *value
= surface
->Width
;
240 *value
= surface
->Height
;
243 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
245 case EGL_LARGEST_PBUFFER
:
246 *value
= dpy
->LargestPbuffer
;
248 case EGL_SURFACE_TYPE
:
249 *value
= surface
->Type
;
251 #ifdef EGL_VERSION_1_1
252 case EGL_TEXTURE_FORMAT
:
253 /* texture attributes: only for pbuffers, no error otherwise */
254 if (surface
->Type
== EGL_PBUFFER_BIT
)
255 *value
= surface
->TextureFormat
;
257 case EGL_TEXTURE_TARGET
:
258 if (surface
->Type
== EGL_PBUFFER_BIT
)
259 *value
= surface
->TextureTarget
;
261 case EGL_MIPMAP_TEXTURE
:
262 if (surface
->Type
== EGL_PBUFFER_BIT
)
263 *value
= surface
->MipmapTexture
;
265 case EGL_MIPMAP_LEVEL
:
266 if (surface
->Type
== EGL_PBUFFER_BIT
)
267 *value
= surface
->MipmapLevel
;
269 #endif /* EGL_VERSION_1_1 */
270 #ifdef EGL_VERSION_1_2
271 case EGL_SWAP_BEHAVIOR
:
272 *value
= surface
->SwapBehavior
;
274 case EGL_RENDER_BUFFER
:
275 *value
= surface
->RenderBuffer
;
277 case EGL_PIXEL_ASPECT_RATIO
:
278 *value
= surface
->AspectRatio
;
280 case EGL_HORIZONTAL_RESOLUTION
:
281 *value
= surface
->HorizontalResolution
;
283 case EGL_VERTICAL_RESOLUTION
:
284 *value
= surface
->VerticalResolution
;
286 case EGL_ALPHA_FORMAT
:
287 *value
= surface
->AlphaFormat
;
290 *value
= surface
->Colorspace
;
292 #endif /* EGL_VERSION_1_2 */
294 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
301 * Example function - drivers should do a proper implementation.
304 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
305 NativeWindowType window
, const EGLint
*attrib_list
)
307 #if 0 /* THIS IS JUST EXAMPLE CODE */
310 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
314 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
326 * Example function - drivers should do a proper implementation.
329 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
330 NativePixmapType pixmap
, const EGLint
*attrib_list
)
332 #if 0 /* THIS IS JUST EXAMPLE CODE */
335 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
339 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
351 * Example function - drivers should do a proper implementation.
354 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
355 const EGLint
*attrib_list
)
357 #if 0 /* THIS IS JUST EXAMPLE CODE */
360 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
364 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, 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 case EGL_MIPMAP_LEVEL
:
396 surface
->MipmapLevel
= value
;
399 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
407 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
410 /* Just do basic error checking and return success/fail.
411 * Drivers must implement the real stuff.
414 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
415 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
419 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
420 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
424 if (buffer
!= EGL_BACK_BUFFER
) {
425 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
429 surface
->BoundToTexture
= EGL_TRUE
;
436 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
439 /* Just do basic error checking and return success/fail.
440 * Drivers must implement the real stuff.
443 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
444 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
448 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
449 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
453 if (buffer
!= EGL_BACK_BUFFER
) {
454 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
458 if (!surface
->BoundToTexture
) {
459 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
463 surface
->BoundToTexture
= EGL_FALSE
;
470 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, EGLint interval
)
472 _EGLSurface
*surf
= _eglGetCurrentSurface(EGL_DRAW
);
474 surf
->SwapInterval
= interval
;
479 #ifdef EGL_VERSION_1_2
482 * Example function - drivers should do a proper implementation.
485 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
486 EGLenum buftype
, EGLClientBuffer buffer
,
487 _EGLConfig
*conf
, const EGLint
*attrib_list
)
489 if (buftype
!= EGL_OPENVG_IMAGE
) {
490 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
497 #endif /* EGL_VERSION_1_2 */