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 * Parse the list of surface attributes and return the proper error code.
37 _eglParseSurfaceAttribList(_EGLSurface
*surf
, const EGLint
*attrib_list
)
39 EGLint type
= surf
->Type
;
40 EGLint i
, err
= EGL_SUCCESS
;
45 for (i
= 0; attrib_list
[i
] != EGL_NONE
; i
++) {
46 EGLint attr
= attrib_list
[i
++];
47 EGLint val
= attrib_list
[i
];
50 #ifdef EGL_VERSION_1_3
51 /* common (except for screen surfaces) attributes */
52 case EGL_VG_COLORSPACE
:
53 if (type
== EGL_SCREEN_BIT_MESA
) {
54 err
= EGL_BAD_ATTRIBUTE
;
58 case EGL_VG_COLORSPACE_sRGB
:
59 case EGL_VG_COLORSPACE_LINEAR
:
62 err
= EGL_BAD_ATTRIBUTE
;
65 if (err
!= EGL_SUCCESS
)
67 surf
->Colorspace
= val
;
69 case EGL_VG_ALPHA_FORMAT
:
70 if (type
== EGL_SCREEN_BIT_MESA
) {
71 err
= EGL_BAD_ATTRIBUTE
;
75 case EGL_VG_ALPHA_FORMAT_NONPRE
:
76 case EGL_VG_ALPHA_FORMAT_PRE
:
79 err
= EGL_BAD_ATTRIBUTE
;
82 if (err
!= EGL_SUCCESS
)
84 surf
->AlphaFormat
= val
;
86 /* window surface attributes */
87 case EGL_RENDER_BUFFER
:
88 if (type
!= EGL_WINDOW_BIT
) {
89 err
= EGL_BAD_ATTRIBUTE
;
92 if (val
!= EGL_BACK_BUFFER
&& val
!= EGL_SINGLE_BUFFER
) {
93 err
= EGL_BAD_ATTRIBUTE
;
96 surf
->RenderBuffer
= val
;
98 #endif /* EGL_VERSION_1_3 */
99 /* pbuffer surface attributes */
101 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
102 err
= EGL_BAD_ATTRIBUTE
;
106 err
= EGL_BAD_PARAMETER
;
112 if (type
!= EGL_PBUFFER_BIT
&& type
!= EGL_SCREEN_BIT_MESA
) {
113 err
= EGL_BAD_ATTRIBUTE
;
117 err
= EGL_BAD_PARAMETER
;
122 case EGL_LARGEST_PBUFFER
:
123 if (type
!= EGL_PBUFFER_BIT
) {
124 err
= EGL_BAD_ATTRIBUTE
;
128 case EGL_TEXTURE_FORMAT
:
129 if (type
!= EGL_PBUFFER_BIT
) {
130 err
= EGL_BAD_ATTRIBUTE
;
133 surf
->TextureFormat
= val
;
135 case EGL_TEXTURE_TARGET
:
136 if (type
!= EGL_PBUFFER_BIT
) {
137 err
= EGL_BAD_ATTRIBUTE
;
140 surf
->TextureTarget
= val
;
142 case EGL_MIPMAP_TEXTURE
:
143 if (type
!= EGL_PBUFFER_BIT
) {
144 err
= EGL_BAD_ATTRIBUTE
;
147 surf
->MipmapTexture
= val
;
149 /* no pixmap surface specific attributes */
151 err
= EGL_BAD_ATTRIBUTE
;
155 if (err
!= EGL_SUCCESS
) {
156 _eglLog(_EGL_WARNING
, "bad surface attribute 0x%04x", attr
);
166 * Do error check on parameters and initialize the given _EGLSurface object.
167 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
170 _eglInitSurface(_EGLSurface
*surf
, _EGLDisplay
*dpy
, EGLint type
,
171 _EGLConfig
*conf
, const EGLint
*attrib_list
)
174 EGLint renderBuffer
= EGL_BACK_BUFFER
;
179 func
= "eglCreateWindowSurface";
182 func
= "eglCreatePixmapSurface";
183 renderBuffer
= EGL_SINGLE_BUFFER
;
185 case EGL_PBUFFER_BIT
:
186 func
= "eglCreatePBufferSurface";
188 case EGL_SCREEN_BIT_MESA
:
189 func
= "eglCreateScreenSurface";
190 renderBuffer
= EGL_SINGLE_BUFFER
; /* XXX correct? */
193 _eglLog(_EGL_WARNING
, "Bad type in _eglInitSurface");
197 if ((GET_CONFIG_ATTRIB(conf
, EGL_SURFACE_TYPE
) & type
) == 0) {
198 /* The config can't be used to create a surface of this type */
199 _eglError(EGL_BAD_CONFIG
, func
);
203 memset(surf
, 0, sizeof(_EGLSurface
));
204 surf
->Resource
.Display
= dpy
;
210 surf
->TextureFormat
= EGL_NO_TEXTURE
;
211 surf
->TextureTarget
= EGL_NO_TEXTURE
;
212 surf
->MipmapTexture
= EGL_FALSE
;
213 surf
->MipmapLevel
= 0;
214 /* the default swap interval is 1 */
215 _eglClampSwapInterval(surf
, 1);
217 #ifdef EGL_VERSION_1_2
218 surf
->SwapBehavior
= EGL_BUFFER_DESTROYED
; /* XXX ok? */
219 surf
->HorizontalResolution
= EGL_UNKNOWN
; /* set by caller */
220 surf
->VerticalResolution
= EGL_UNKNOWN
; /* set by caller */
221 surf
->AspectRatio
= EGL_UNKNOWN
; /* set by caller */
222 surf
->RenderBuffer
= renderBuffer
;
223 surf
->AlphaFormat
= EGL_ALPHA_FORMAT_NONPRE
;
224 surf
->Colorspace
= EGL_COLORSPACE_sRGB
;
227 err
= _eglParseSurfaceAttribList(surf
, attrib_list
);
228 if (err
!= EGL_SUCCESS
)
229 return _eglError(err
, func
);
236 _eglSwapBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
238 /* Drivers have to do the actual buffer swap. */
244 _eglCopyBuffers(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
245 EGLNativePixmapType target
)
247 /* copy surface to native pixmap */
248 /* All implementation burdon for this is in the device driver */
254 _eglQuerySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
255 EGLint attribute
, EGLint
*value
)
259 *value
= surface
->Width
;
262 *value
= surface
->Height
;
265 *value
= GET_CONFIG_ATTRIB(surface
->Config
, EGL_CONFIG_ID
);
267 case EGL_LARGEST_PBUFFER
:
268 *value
= dpy
->LargestPbuffer
;
270 case EGL_SURFACE_TYPE
:
271 *value
= surface
->Type
;
273 #ifdef EGL_VERSION_1_1
274 case EGL_TEXTURE_FORMAT
:
275 /* texture attributes: only for pbuffers, no error otherwise */
276 if (surface
->Type
== EGL_PBUFFER_BIT
)
277 *value
= surface
->TextureFormat
;
279 case EGL_TEXTURE_TARGET
:
280 if (surface
->Type
== EGL_PBUFFER_BIT
)
281 *value
= surface
->TextureTarget
;
283 case EGL_MIPMAP_TEXTURE
:
284 if (surface
->Type
== EGL_PBUFFER_BIT
)
285 *value
= surface
->MipmapTexture
;
287 case EGL_MIPMAP_LEVEL
:
288 if (surface
->Type
== EGL_PBUFFER_BIT
)
289 *value
= surface
->MipmapLevel
;
291 #endif /* EGL_VERSION_1_1 */
292 #ifdef EGL_VERSION_1_2
293 case EGL_SWAP_BEHAVIOR
:
294 *value
= surface
->SwapBehavior
;
296 case EGL_RENDER_BUFFER
:
297 *value
= surface
->RenderBuffer
;
299 case EGL_PIXEL_ASPECT_RATIO
:
300 *value
= surface
->AspectRatio
;
302 case EGL_HORIZONTAL_RESOLUTION
:
303 *value
= surface
->HorizontalResolution
;
305 case EGL_VERTICAL_RESOLUTION
:
306 *value
= surface
->VerticalResolution
;
308 case EGL_ALPHA_FORMAT
:
309 *value
= surface
->AlphaFormat
;
312 *value
= surface
->Colorspace
;
314 #endif /* EGL_VERSION_1_2 */
316 _eglError(EGL_BAD_ATTRIBUTE
, "eglQuerySurface");
323 * Drivers should do a proper implementation.
326 _eglCreateWindowSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
327 EGLNativeWindowType window
, const EGLint
*attrib_list
)
334 * Drivers should do a proper implementation.
337 _eglCreatePixmapSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
338 EGLNativePixmapType pixmap
, const EGLint
*attrib_list
)
345 * Drivers should do a proper implementation.
348 _eglCreatePbufferSurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLConfig
*conf
,
349 const EGLint
*attrib_list
)
356 * Default fallback routine - drivers should usually override this.
359 _eglDestroySurface(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
)
361 if (!_eglIsSurfaceBound(surf
))
368 * Default fallback routine - drivers might override this.
371 _eglSurfaceAttrib(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
372 EGLint attribute
, EGLint value
)
375 case EGL_MIPMAP_LEVEL
:
376 surface
->MipmapLevel
= value
;
379 _eglError(EGL_BAD_ATTRIBUTE
, "eglSurfaceAttrib");
387 _eglBindTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
390 /* Just do basic error checking and return success/fail.
391 * Drivers must implement the real stuff.
394 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
395 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
399 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
400 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
404 if (buffer
!= EGL_BACK_BUFFER
) {
405 _eglError(EGL_BAD_PARAMETER
, "eglBindTexImage");
409 surface
->BoundToTexture
= EGL_TRUE
;
416 _eglReleaseTexImage(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surface
,
419 /* Just do basic error checking and return success/fail.
420 * Drivers must implement the real stuff.
423 if (surface
->Type
!= EGL_PBUFFER_BIT
) {
424 _eglError(EGL_BAD_SURFACE
, "eglBindTexImage");
428 if (surface
->TextureFormat
== EGL_NO_TEXTURE
) {
429 _eglError(EGL_BAD_MATCH
, "eglBindTexImage");
433 if (buffer
!= EGL_BACK_BUFFER
) {
434 _eglError(EGL_BAD_PARAMETER
, "eglReleaseTexImage");
438 if (!surface
->BoundToTexture
) {
439 _eglError(EGL_BAD_SURFACE
, "eglReleaseTexImage");
443 surface
->BoundToTexture
= EGL_FALSE
;
450 _eglSwapInterval(_EGLDriver
*drv
, _EGLDisplay
*dpy
, _EGLSurface
*surf
,
453 _eglClampSwapInterval(surf
, interval
);
458 #ifdef EGL_VERSION_1_2
461 * Example function - drivers should do a proper implementation.
464 _eglCreatePbufferFromClientBuffer(_EGLDriver
*drv
, _EGLDisplay
*dpy
,
465 EGLenum buftype
, EGLClientBuffer buffer
,
466 _EGLConfig
*conf
, const EGLint
*attrib_list
)
468 if (buftype
!= EGL_OPENVG_IMAGE
) {
469 _eglError(EGL_BAD_PARAMETER
, "eglCreatePbufferFromClientBuffer");
476 #endif /* EGL_VERSION_1_2 */