2 * Surface-related functions.
9 #include "eglcontext.h"
10 #include "eglconfig.h"
11 #include "eglglobals.h"
14 #include "eglsurface.h"
18 * Do error check on parameters and initialize the given _EGLSurface object.
19 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
22 _eglInitSurface(_EGLDriver
*drv
, EGLDisplay dpy
,
23 _EGLSurface
*surf
, EGLint type
, EGLConfig config
,
24 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");
57 conf
= _eglLookupConfig(drv
, dpy
, config
);
59 _eglError(EGL_BAD_CONFIG
, func
);
64 * Parse attribute list. Different kinds of surfaces support different
67 for (i
= 0; attrib_list
&& attrib_list
[i
] != EGL_NONE
; i
++) {
68 switch (attrib_list
[i
]) {
70 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
71 width
= attrib_list
[++i
];
74 _eglError(EGL_BAD_ATTRIBUTE
, func
);
79 if (type
== EGL_PBUFFER_BIT
|| type
== EGL_SCREEN_BIT_MESA
) {
80 height
= attrib_list
[++i
];
83 _eglError(EGL_BAD_ATTRIBUTE
, func
);
87 case EGL_LARGEST_PBUFFER
:
88 if (type
== EGL_PBUFFER_BIT
) {
89 largest
= attrib_list
[++i
];
92 _eglError(EGL_BAD_ATTRIBUTE
, func
);
96 case EGL_TEXTURE_FORMAT
:
97 if (type
== EGL_PBUFFER_BIT
) {
98 texFormat
= attrib_list
[++i
];
101 _eglError(EGL_BAD_ATTRIBUTE
, func
);
105 case EGL_TEXTURE_TARGET
:
106 if (type
== EGL_PBUFFER_BIT
) {
107 texTarget
= attrib_list
[++i
];
110 _eglError(EGL_BAD_ATTRIBUTE
, func
);
114 case EGL_MIPMAP_TEXTURE
:
115 if (type
== EGL_PBUFFER_BIT
) {
116 mipmapTex
= attrib_list
[++i
];
119 _eglError(EGL_BAD_ATTRIBUTE
, func
);
123 #ifdef EGL_VERSION_1_2
124 case EGL_RENDER_BUFFER
:
125 if (type
== EGL_WINDOW_BIT
) {
126 renderBuffer
= attrib_list
[++i
];
127 if (renderBuffer
!= EGL_BACK_BUFFER
&&
128 renderBuffer
!= EGL_SINGLE_BUFFER
) {
129 _eglError(EGL_BAD_ATTRIBUTE
, func
);
134 _eglError(EGL_BAD_ATTRIBUTE
, func
);
139 if (type
== EGL_WINDOW_BIT
||
140 type
== EGL_PBUFFER_BIT
||
141 type
== EGL_PIXMAP_BIT
) {
142 colorspace
= attrib_list
[++i
];
143 if (colorspace
!= EGL_COLORSPACE_sRGB
&&
144 colorspace
!= EGL_COLORSPACE_LINEAR
) {
145 _eglError(EGL_BAD_ATTRIBUTE
, func
);
150 _eglError(EGL_BAD_ATTRIBUTE
, func
);
154 case EGL_ALPHA_FORMAT
:
155 if (type
== EGL_WINDOW_BIT
||
156 type
== EGL_PBUFFER_BIT
||
157 type
== EGL_PIXMAP_BIT
) {
158 alphaFormat
= attrib_list
[++i
];
159 if (alphaFormat
!= EGL_ALPHA_FORMAT_NONPRE
&&
160 alphaFormat
!= EGL_ALPHA_FORMAT_PRE
) {
161 _eglError(EGL_BAD_ATTRIBUTE
, func
);
166 _eglError(EGL_BAD_ATTRIBUTE
, func
);
171 #endif /* EGL_VERSION_1_2 */
173 _eglError(EGL_BAD_ATTRIBUTE
, func
);
178 if (width
<= 0 || height
<= 0) {
179 _eglError(EGL_BAD_ATTRIBUTE
, func
);
183 memset(surf
, 0, sizeof(_EGLSurface
));
187 surf
->Height
= height
;
188 surf
->TextureFormat
= texFormat
;
189 surf
->TextureTarget
= texTarget
;
190 surf
->MipmapTexture
= mipmapTex
;
191 surf
->MipmapLevel
= 0;
192 surf
->SwapInterval
= 0;
193 #ifdef EGL_VERSION_1_2
194 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
195 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
196 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
197 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
198 surf
->RenderBuffer
= renderBuffer
;
199 surf
->AlphaFormat
= alphaFormat
;
200 surf
->Colorspace
= colorspace
;
208 _eglSaveSurface(_EGLSurface
*surf
)
211 assert(!surf
->Handle
);
212 surf
->Handle
= _eglHashGenKey(_eglGlobal
.Contexts
);
213 assert(surf
->Handle
);
214 _eglHashInsert(_eglGlobal
.Surfaces
, surf
->Handle
, surf
);
219 _eglRemoveSurface(_EGLSurface
*surf
)
221 _eglHashRemove(_eglGlobal
.Surfaces
, surf
->Handle
);
226 _eglLookupSurface(EGLSurface surf
)
228 _EGLSurface
*c
= (_EGLSurface
*) _eglHashLookup(_eglGlobal
.Surfaces
, surf
);
234 _eglGetCurrentSurface(EGLint readdraw
)
236 _EGLContext
*ctx
= _eglGetCurrentContext();
240 return ctx
->DrawSurface
;
242 return ctx
->ReadSurface
;
252 _eglSwapBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface draw
)
254 /* Basically just do error checking here. Drivers have to do the
255 * actual buffer swap.
257 _EGLContext
*context
= _eglGetCurrentContext();
258 _EGLSurface
*surface
= _eglLookupSurface(draw
);
259 if (context
&& context
->DrawSurface
!= surface
) {
260 _eglError(EGL_BAD_SURFACE
, "eglSwapBuffers");
263 if (surface
== NULL
) {
264 _eglError(EGL_BAD_SURFACE
, "eglSwapBuffers");
272 _eglCopyBuffers(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
,
273 NativePixmapType target
)
275 /* copy surface to native pixmap */
276 /* All implementation burdon for this is in the device driver */
282 _eglQuerySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
,
283 EGLint attribute
, EGLint
*value
)
285 _EGLSurface
*surface
= _eglLookupSurface(surf
);
286 if (surface
== NULL
) {
287 _eglError(EGL_BAD_SURFACE
, "eglQuerySurface");
292 *value
= surface
->Width
;
295 *value
= surface
->Height
;
298 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
300 /*XXX case EGL_LARGEST_PBUFFER:*/
301 case EGL_SURFACE_TYPE
:
302 *value
= surface
->Type
;
304 #ifdef EGL_VERSION_1_1
305 case EGL_TEXTURE_FORMAT
:
306 /* texture attributes: only for pbuffers, no error otherwise */
307 if (surface
->Type
== EGL_PBUFFER_BIT
)
308 *value
= surface
->TextureFormat
;
310 case EGL_TEXTURE_TARGET
:
311 if (surface
->Type
== EGL_PBUFFER_BIT
)
312 *value
= surface
->TextureTarget
;
314 case EGL_MIPMAP_TEXTURE
:
315 if (surface
->Type
== EGL_PBUFFER_BIT
)
316 *value
= surface
->MipmapTexture
;
318 case EGL_MIPMAP_LEVEL
:
319 if (surface
->Type
== EGL_PBUFFER_BIT
)
320 *value
= surface
->MipmapLevel
;
322 #endif /* EGL_VERSION_1_1 */
323 #ifdef EGL_VERSION_1_2
324 case EGL_SWAP_BEHAVIOR
:
325 *value
= surface
->SwapBehavior
;
327 case EGL_RENDER_BUFFER
:
328 *value
= surface
->RenderBuffer
;
330 case EGL_PIXEL_ASPECT_RATIO
:
331 *value
= surface
->AspectRatio
;
333 case EGL_HORIZONTAL_RESOLUTION
:
334 *value
= surface
->HorizontalResolution
;
336 case EGL_VERTICAL_RESOLUTION
:
337 *value
= surface
->VerticalResolution
;
339 case EGL_ALPHA_FORMAT
:
340 *value
= surface
->AlphaFormat
;
343 *value
= surface
->Colorspace
;
345 #endif /* EGL_VERSION_1_2 */
347 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
354 * Example function - drivers should do a proper implementation.
357 _eglCreateWindowSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
358 NativeWindowType window
, const EGLint
*attrib_list
)
360 #if 0 /* THIS IS JUST EXAMPLE CODE */
363 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
365 return EGL_NO_SURFACE
;
367 if (!_eglInitSurface(drv
, dpy
, surf
, EGL_WINDOW_BIT
, config
, attrib_list
)) {
369 return EGL_NO_SURFACE
;
372 _eglSaveSurface(surf
);
376 return EGL_NO_SURFACE
;
381 * Example function - drivers should do a proper implementation.
384 _eglCreatePixmapSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
385 NativePixmapType pixmap
, const EGLint
*attrib_list
)
387 #if 0 /* THIS IS JUST EXAMPLE CODE */
390 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
392 return EGL_NO_SURFACE
;
394 if (!_eglInitSurface(drv
, dpy
, surf
, EGL_PIXMAP_BIT
, config
, attrib_list
)) {
396 return EGL_NO_SURFACE
;
399 _eglSaveSurface(surf
);
403 return EGL_NO_SURFACE
;
408 * Example function - drivers should do a proper implementation.
411 _eglCreatePbufferSurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLConfig config
,
412 const EGLint
*attrib_list
)
414 #if 0 /* THIS IS JUST EXAMPLE CODE */
417 surf
= (_EGLSurface
*) calloc(1, sizeof(_EGLSurface
));
419 return EGL_NO_SURFACE
;
421 if (!_eglInitSurface(drv
, dpy
, surf
, EGL_PBUFFER_BIT
, config
, attrib_list
)) {
423 return EGL_NO_SURFACE
;
426 _eglSaveSurface(surf
);
430 return EGL_NO_SURFACE
;
435 * Default fallback routine - drivers should usually override this.
438 _eglDestroySurface(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
)
440 _EGLSurface
*surf
= _eglLookupSurface(surface
);
442 _eglHashRemove(_eglGlobal
.Surfaces
, surface
);
444 surf
->DeletePending
= EGL_TRUE
;
452 _eglError(EGL_BAD_SURFACE
, "eglDestroySurface");
459 * Default fallback routine - drivers might override this.
462 _eglSurfaceAttrib(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surf
, EGLint attribute
, EGLint value
)
464 _EGLSurface
*surface
= _eglLookupSurface(surf
);
466 if (surface
== NULL
) {
467 _eglError(EGL_BAD_SURFACE
, "eglSurfaceAttrib");
472 case EGL_MIPMAP_LEVEL
:
473 surface
->MipmapLevel
= value
;
476 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
484 _eglBindTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
492 _eglReleaseTexImage(_EGLDriver
*drv
, EGLDisplay dpy
, EGLSurface surface
, EGLint buffer
)
500 _eglSwapInterval(_EGLDriver
*drv
, EGLDisplay dpy
, EGLint interval
)
502 _EGLSurface
*surf
= _eglGetCurrentSurface(EGL_DRAW
);
504 _eglError(EGL_BAD_SURFACE
, "eglSwapInterval");
507 surf
->SwapInterval
= interval
;
512 #ifdef EGL_VERSION_1_2
515 * Example function - drivers should do a proper implementation.
518 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, EGLDisplay dpy
,
519 EGLenum buftype
, EGLClientBuffer buffer
,
520 EGLConfig config
, const EGLint
*attrib_list
)
522 if (buftype
!= EGL_OPENVG_IMAGE
) {
523 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
524 return ELG_NO_SURFACE
;
527 return EGL_NO_SURFACE
;
530 #endif /* EGL_VERSION_1_2 */