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 _eglClampSwapInterval(_EGLSurface
*surf
, EGLint interval
)
21 EGLint bound
= GET_CONFIG_ATTRIB(surf
->Config
, EGL_MAX_SWAP_INTERVAL
);
22 if (interval
>= bound
) {
26 bound
= GET_CONFIG_ATTRIB(surf
->Config
, EGL_MIN_SWAP_INTERVAL
);
30 surf
->SwapInterval
= interval
;
35 * Do error check on parameters and initialize the given _EGLSurface object.
36 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
39 _eglInitSurface(_EGLDriver
*drv
, _EGLSurface
*surf
, EGLint type
,
40 _EGLConfig
*conf
, const EGLint
*attrib_list
)
43 EGLint width
= 0, height
= 0, largest
= 0;
44 EGLint texFormat
= EGL_NO_TEXTURE
, texTarget
= EGL_NO_TEXTURE
;
45 EGLint mipmapTex
= EGL_FALSE
;
46 EGLint renderBuffer
= EGL_BACK_BUFFER
;
47 #ifdef EGL_VERSION_1_2
48 EGLint colorspace
= EGL_COLORSPACE_sRGB
;
49 EGLint alphaFormat
= EGL_ALPHA_FORMAT_NONPRE
;
55 func
= "eglCreateWindowSurface";
58 func
= "eglCreatePixmapSurface";
59 renderBuffer
= EGL_SINGLE_BUFFER
;
62 func
= "eglCreatePBufferSurface";
64 case EGL_SCREEN_BIT_MESA
:
65 func
= "eglCreateScreenSurface";
66 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
69 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
74 _eglError(EGL_BAD_CONFIG
, func
);
78 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
79 /* The config can't be used to create a surface of this type */
80 _eglError(EGL_BAD_CONFIG
, func
);
85 * Parse attribute list. Different kinds of surfaces support different
88 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
89 switch (attrib_list
[i
]) {
91 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
92 width
= attrib_list
[++i
];
95 _eglError(EGL_BAD_ATTRIBUTE
, func
);
100 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
101 height
= attrib_list
[++i
];
104 _eglError(EGL_BAD_ATTRIBUTE
, func
);
108 case EGL_LARGEST_PBUFFER
:
109 if (type
== EGL_PBUFFER_BIT
) {
110 largest
= attrib_list
[++i
];
113 _eglError(EGL_BAD_ATTRIBUTE
, func
);
117 case EGL_TEXTURE_FORMAT
:
118 if (type
== EGL_PBUFFER_BIT
) {
119 texFormat
= attrib_list
[++i
];
122 _eglError(EGL_BAD_ATTRIBUTE
, func
);
126 case EGL_TEXTURE_TARGET
:
127 if (type
== EGL_PBUFFER_BIT
) {
128 texTarget
= attrib_list
[++i
];
131 _eglError(EGL_BAD_ATTRIBUTE
, func
);
135 case EGL_MIPMAP_TEXTURE
:
136 if (type
== EGL_PBUFFER_BIT
) {
137 mipmapTex
= attrib_list
[++i
];
140 _eglError(EGL_BAD_ATTRIBUTE
, func
);
144 #ifdef EGL_VERSION_1_2
145 case EGL_RENDER_BUFFER
:
146 if (type
== EGL_WINDOW_BIT
) {
147 renderBuffer
= attrib_list
[++i
];
148 if (renderBuffer
!= EGL_BACK_BUFFER
&&
149 renderBuffer
!= EGL_SINGLE_BUFFER
) {
150 _eglError(EGL_BAD_ATTRIBUTE
, func
);
155 _eglError(EGL_BAD_ATTRIBUTE
, func
);
160 if (type
== EGL_WINDOW_BIT
||
161 type
== EGL_PBUFFER_BIT
||
162 type
== EGL_PIXMAP_BIT
) {
163 colorspace
= attrib_list
[++i
];
164 if (colorspace
!= EGL_COLORSPACE_sRGB
&&
165 colorspace
!= EGL_COLORSPACE_LINEAR
) {
166 _eglError(EGL_BAD_ATTRIBUTE
, func
);
171 _eglError(EGL_BAD_ATTRIBUTE
, func
);
175 case EGL_ALPHA_FORMAT
:
176 if (type
== EGL_WINDOW_BIT
||
177 type
== EGL_PBUFFER_BIT
||
178 type
== EGL_PIXMAP_BIT
) {
179 alphaFormat
= attrib_list
[++i
];
180 if (alphaFormat
!= EGL_ALPHA_FORMAT_NONPRE
&&
181 alphaFormat
!= EGL_ALPHA_FORMAT_PRE
) {
182 _eglError(EGL_BAD_ATTRIBUTE
, func
);
187 _eglError(EGL_BAD_ATTRIBUTE
, func
);
192 #endif /* EGL_VERSION_1_2 */
194 _eglError(EGL_BAD_ATTRIBUTE
, func
);
199 if (width
< 0 || height
< 0) {
200 _eglError(EGL_BAD_ATTRIBUTE
, func
);
204 memset(surf
, 0, sizeof(_EGLSurface
));
208 surf
->Height
= height
;
209 surf
->TextureFormat
= texFormat
;
210 surf
->TextureTarget
= texTarget
;
211 surf
->MipmapTexture
= mipmapTex
;
212 surf
->MipmapLevel
= 0;
213 /* the default swap interval is 1 */
214 _eglClampSwapInterval(surf
, 1);
216 #ifdef EGL_VERSION_1_2
217 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
218 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
219 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
220 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
221 surf
->RenderBuffer
= renderBuffer
;
222 surf
->AlphaFormat
= alphaFormat
;
223 surf
->Colorspace
= colorspace
;
231 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
233 /* Drivers have to do the actual buffer swap. */
239 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
240 EGLNativePixmapType target
)
242 /* copy surface to native pixmap */
243 /* All implementation burdon for this is in the device driver */
249 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
250 EGLint attribute
, EGLint
*value
)
254 *value
= surface
->Width
;
257 *value
= surface
->Height
;
260 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
262 case EGL_LARGEST_PBUFFER
:
263 *value
= dpy
->LargestPbuffer
;
265 case EGL_SURFACE_TYPE
:
266 *value
= surface
->Type
;
268 #ifdef EGL_VERSION_1_1
269 case EGL_TEXTURE_FORMAT
:
270 /* texture attributes: only for pbuffers, no error otherwise */
271 if (surface
->Type
== EGL_PBUFFER_BIT
)
272 *value
= surface
->TextureFormat
;
274 case EGL_TEXTURE_TARGET
:
275 if (surface
->Type
== EGL_PBUFFER_BIT
)
276 *value
= surface
->TextureTarget
;
278 case EGL_MIPMAP_TEXTURE
:
279 if (surface
->Type
== EGL_PBUFFER_BIT
)
280 *value
= surface
->MipmapTexture
;
282 case EGL_MIPMAP_LEVEL
:
283 if (surface
->Type
== EGL_PBUFFER_BIT
)
284 *value
= surface
->MipmapLevel
;
286 #endif /* EGL_VERSION_1_1 */
287 #ifdef EGL_VERSION_1_2
288 case EGL_SWAP_BEHAVIOR
:
289 *value
= surface
->SwapBehavior
;
291 case EGL_RENDER_BUFFER
:
292 *value
= surface
->RenderBuffer
;
294 case EGL_PIXEL_ASPECT_RATIO
:
295 *value
= surface
->AspectRatio
;
297 case EGL_HORIZONTAL_RESOLUTION
:
298 *value
= surface
->HorizontalResolution
;
300 case EGL_VERTICAL_RESOLUTION
:
301 *value
= surface
->VerticalResolution
;
303 case EGL_ALPHA_FORMAT
:
304 *value
= surface
->AlphaFormat
;
307 *value
= surface
->Colorspace
;
309 #endif /* EGL_VERSION_1_2 */
311 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
318 * Example function - drivers should do a proper implementation.
321 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
322 EGLNativeWindowType window
, const EGLint
*attrib_list
)
324 #if 0 /* THIS IS JUST EXAMPLE CODE */
327 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
331 if (!_eglInitSurface(drv
, surf
, EGL_WINDOW_BIT
, conf
, attrib_list
)) {
343 * Example function - drivers should do a proper implementation.
346 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
347 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
349 #if 0 /* THIS IS JUST EXAMPLE CODE */
352 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
356 if (!_eglInitSurface(drv
, surf
, EGL_PIXMAP_BIT
, conf
, attrib_list
)) {
368 * Example function - drivers should do a proper implementation.
371 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
372 const EGLint
*attrib_list
)
374 #if 0 /* THIS IS JUST EXAMPLE CODE */
377 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
381 if (!_eglInitSurface(drv
, surf
, EGL_PBUFFER_BIT
, conf
, attrib_list
)) {
393 * Default fallback routine - drivers should usually override this.
396 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
398 if (!_eglIsSurfaceBound(surf
))
405 * Default fallback routine - drivers might override this.
408 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
409 EGLint attribute
, EGLint value
)
412 case EGL_MIPMAP_LEVEL
:
413 surface
->MipmapLevel
= value
;
416 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
424 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
427 /* Just do basic error checking and return success/fail.
428 * Drivers must implement the real stuff.
431 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
432 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
436 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
437 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
441 if (buffer
!= EGL_BACK_BUFFER
) {
442 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
446 surface
->BoundToTexture
= EGL_TRUE
;
453 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
456 /* Just do basic error checking and return success/fail.
457 * Drivers must implement the real stuff.
460 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
461 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
465 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
466 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
470 if (buffer
!= EGL_BACK_BUFFER
) {
471 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
475 if (!surface
->BoundToTexture
) {
476 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
480 surface
->BoundToTexture
= EGL_FALSE
;
487 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
490 _eglClampSwapInterval(surf
, interval
);
495 #ifdef EGL_VERSION_1_2
498 * Example function - drivers should do a proper implementation.
501 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
502 EGLenum buftype
, EGLClientBuffer buffer
,
503 _EGLConfig
*conf
, const EGLint
*attrib_list
)
505 if (buftype
!= EGL_OPENVG_IMAGE
) {
506 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
513 #endif /* EGL_VERSION_1_2 */