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 * Do error check on parameters and initialize the given _EGLSurface object.
35 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
38 _eglInitSurface(_EGLDriver
*drv
, _EGLSurface
*surf
, EGLint type
,
39 _EGLConfig
*conf
, const EGLint
*attrib_list
)
42 EGLint width
= 0, height
= 0, largest
= 0;
43 EGLint texFormat
= EGL_NO_TEXTURE
, texTarget
= EGL_NO_TEXTURE
;
44 EGLint mipmapTex
= EGL_FALSE
;
45 EGLint renderBuffer
= EGL_BACK_BUFFER
;
46 #ifdef EGL_VERSION_1_2
47 EGLint colorspace
= EGL_COLORSPACE_sRGB
;
48 EGLint alphaFormat
= EGL_ALPHA_FORMAT_NONPRE
;
54 func
= "eglCreateWindowSurface";
57 func
= "eglCreatePixmapSurface";
58 renderBuffer
= EGL_SINGLE_BUFFER
;
61 func
= "eglCreatePBufferSurface";
63 case EGL_SCREEN_BIT_MESA
:
64 func
= "eglCreateScreenSurface";
65 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
68 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
73 _eglError(EGL_BAD_CONFIG
, func
);
77 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
78 /* The config can't be used to create a surface of this type */
79 _eglError(EGL_BAD_CONFIG
, func
);
84 * Parse attribute list. Different kinds of surfaces support different
87 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
88 switch (attrib_list
[i
]) {
90 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
91 width
= attrib_list
[++i
];
94 _eglError(EGL_BAD_ATTRIBUTE
, func
);
99 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
100 height
= attrib_list
[++i
];
103 _eglError(EGL_BAD_ATTRIBUTE
, func
);
107 case EGL_LARGEST_PBUFFER
:
108 if (type
== EGL_PBUFFER_BIT
) {
109 largest
= attrib_list
[++i
];
112 _eglError(EGL_BAD_ATTRIBUTE
, func
);
116 case EGL_TEXTURE_FORMAT
:
117 if (type
== EGL_PBUFFER_BIT
) {
118 texFormat
= attrib_list
[++i
];
121 _eglError(EGL_BAD_ATTRIBUTE
, func
);
125 case EGL_TEXTURE_TARGET
:
126 if (type
== EGL_PBUFFER_BIT
) {
127 texTarget
= attrib_list
[++i
];
130 _eglError(EGL_BAD_ATTRIBUTE
, func
);
134 case EGL_MIPMAP_TEXTURE
:
135 if (type
== EGL_PBUFFER_BIT
) {
136 mipmapTex
= attrib_list
[++i
];
139 _eglError(EGL_BAD_ATTRIBUTE
, func
);
143 #ifdef EGL_VERSION_1_2
144 case EGL_RENDER_BUFFER
:
145 if (type
== EGL_WINDOW_BIT
) {
146 renderBuffer
= attrib_list
[++i
];
147 if (renderBuffer
!= EGL_BACK_BUFFER
&&
148 renderBuffer
!= EGL_SINGLE_BUFFER
) {
149 _eglError(EGL_BAD_ATTRIBUTE
, func
);
154 _eglError(EGL_BAD_ATTRIBUTE
, func
);
159 if (type
== EGL_WINDOW_BIT
||
160 type
== EGL_PBUFFER_BIT
||
161 type
== EGL_PIXMAP_BIT
) {
162 colorspace
= attrib_list
[++i
];
163 if (colorspace
!= EGL_COLORSPACE_sRGB
&&
164 colorspace
!= EGL_COLORSPACE_LINEAR
) {
165 _eglError(EGL_BAD_ATTRIBUTE
, func
);
170 _eglError(EGL_BAD_ATTRIBUTE
, func
);
174 case EGL_ALPHA_FORMAT
:
175 if (type
== EGL_WINDOW_BIT
||
176 type
== EGL_PBUFFER_BIT
||
177 type
== EGL_PIXMAP_BIT
) {
178 alphaFormat
= attrib_list
[++i
];
179 if (alphaFormat
!= EGL_ALPHA_FORMAT_NONPRE
&&
180 alphaFormat
!= EGL_ALPHA_FORMAT_PRE
) {
181 _eglError(EGL_BAD_ATTRIBUTE
, func
);
186 _eglError(EGL_BAD_ATTRIBUTE
, func
);
191 #endif /* EGL_VERSION_1_2 */
193 _eglError(EGL_BAD_ATTRIBUTE
, func
);
198 if (width
< 0 || height
< 0) {
199 _eglError(EGL_BAD_ATTRIBUTE
, func
);
203 memset(surf
, 0, sizeof(_EGLSurface
));
207 surf
->Height
= height
;
208 surf
->TextureFormat
= texFormat
;
209 surf
->TextureTarget
= texTarget
;
210 surf
->MipmapTexture
= mipmapTex
;
211 surf
->MipmapLevel
= 0;
212 /* the default swap interval is 1 */
213 _eglClampSwapInterval(surf
, 1);
215 #ifdef EGL_VERSION_1_2
216 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
217 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
218 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
219 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
220 surf
->RenderBuffer
= renderBuffer
;
221 surf
->AlphaFormat
= alphaFormat
;
222 surf
->Colorspace
= colorspace
;
230 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
232 /* Drivers have to do the actual buffer swap. */
238 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
239 EGLNativePixmapType target
)
241 /* copy surface to native pixmap */
242 /* All implementation burdon for this is in the device driver */
248 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
249 EGLint attribute
, EGLint
*value
)
253 *value
= surface
->Width
;
256 *value
= surface
->Height
;
259 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
261 case EGL_LARGEST_PBUFFER
:
262 *value
= dpy
->LargestPbuffer
;
264 case EGL_SURFACE_TYPE
:
265 *value
= surface
->Type
;
267 #ifdef EGL_VERSION_1_1
268 case EGL_TEXTURE_FORMAT
:
269 /* texture attributes: only for pbuffers, no error otherwise */
270 if (surface
->Type
== EGL_PBUFFER_BIT
)
271 *value
= surface
->TextureFormat
;
273 case EGL_TEXTURE_TARGET
:
274 if (surface
->Type
== EGL_PBUFFER_BIT
)
275 *value
= surface
->TextureTarget
;
277 case EGL_MIPMAP_TEXTURE
:
278 if (surface
->Type
== EGL_PBUFFER_BIT
)
279 *value
= surface
->MipmapTexture
;
281 case EGL_MIPMAP_LEVEL
:
282 if (surface
->Type
== EGL_PBUFFER_BIT
)
283 *value
= surface
->MipmapLevel
;
285 #endif /* EGL_VERSION_1_1 */
286 #ifdef EGL_VERSION_1_2
287 case EGL_SWAP_BEHAVIOR
:
288 *value
= surface
->SwapBehavior
;
290 case EGL_RENDER_BUFFER
:
291 *value
= surface
->RenderBuffer
;
293 case EGL_PIXEL_ASPECT_RATIO
:
294 *value
= surface
->AspectRatio
;
296 case EGL_HORIZONTAL_RESOLUTION
:
297 *value
= surface
->HorizontalResolution
;
299 case EGL_VERTICAL_RESOLUTION
:
300 *value
= surface
->VerticalResolution
;
302 case EGL_ALPHA_FORMAT
:
303 *value
= surface
->AlphaFormat
;
306 *value
= surface
->Colorspace
;
308 #endif /* EGL_VERSION_1_2 */
310 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
317 * Example function - drivers should do a proper implementation.
320 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
321 EGLNativeWindowType window
, const EGLint
*attrib_list
)
323 #if 0 /* THIS IS JUST EXAMPLE CODE */
326 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
330 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
342 * Example function - drivers should do a proper implementation.
345 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
346 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
348 #if 0 /* THIS IS JUST EXAMPLE CODE */
351 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
355 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
367 * Example function - drivers should do a proper implementation.
370 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
371 const EGLint
*attrib_list
)
373 #if 0 /* THIS IS JUST EXAMPLE CODE */
376 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
380 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, attrib_list
)) {
392 * Default fallback routine - drivers should usually override this.
395 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
397 if (!_eglIsSurfaceBound(surf
))
404 * Default fallback routine - drivers might override this.
407 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
408 EGLint attribute
, EGLint value
)
411 case EGL_MIPMAP_LEVEL
:
412 surface
->MipmapLevel
= value
;
415 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
423 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
426 /* Just do basic error checking and return success/fail.
427 * Drivers must implement the real stuff.
430 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
431 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
435 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
436 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
440 if (buffer
!= EGL_BACK_BUFFER
) {
441 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
445 surface
->BoundToTexture
= EGL_TRUE
;
452 _eglReleaseTexImage(_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
, "eglReleaseTexImage");
474 if (!surface
->BoundToTexture
) {
475 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
479 surface
->BoundToTexture
= EGL_FALSE
;
486 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
489 _eglClampSwapInterval(surf
, interval
);
494 #ifdef EGL_VERSION_1_2
497 * Example function - drivers should do a proper implementation.
500 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
501 EGLenum buftype
, EGLClientBuffer buffer
,
502 _EGLConfig
*conf
, const EGLint
*attrib_list
)
504 if (buftype
!= EGL_OPENVG_IMAGE
) {
505 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
512 #endif /* EGL_VERSION_1_2 */