62f2aa869d2f191bc88e08e4a680ea710449c3b1
[mesa.git] / src / egl / main / eglsurface.c
1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * Copyright 2009-2010 Chia-I Wu <olvaffe@gmail.com>
5 * Copyright 2010 LunarG, Inc.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the
10 * "Software"), to deal in the Software without restriction, including
11 * without limitation the rights to use, copy, modify, merge, publish,
12 * distribute, sub license, and/or sell copies of the Software, and to
13 * permit persons to whom the Software is furnished to do so, subject to
14 * the following conditions:
15 *
16 * The above copyright notice and this permission notice (including the
17 * next paragraph) shall be included in all copies or substantial portions
18 * of the Software.
19 *
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26 * DEALINGS IN THE SOFTWARE.
27 *
28 **************************************************************************/
29
30
31 /**
32 * Surface-related functions.
33 */
34
35
36 #include <assert.h>
37 #include <stdlib.h>
38 #include <string.h>
39 #include "egldefines.h"
40 #include "egldisplay.h"
41 #include "egldriver.h"
42 #include "eglcontext.h"
43 #include "eglconfig.h"
44 #include "eglcurrent.h"
45 #include "egllog.h"
46 #include "eglsurface.h"
47
48 #include "util/macros.h"
49
50 /**
51 * Parse the list of surface attributes and return the proper error code.
52 */
53 static EGLint
54 _eglParseSurfaceAttribList(_EGLSurface *surf, const EGLint *attrib_list)
55 {
56 _EGLDisplay *disp = surf->Resource.Display;
57 EGLint type = surf->Type;
58 EGLint texture_type = EGL_PBUFFER_BIT;
59 EGLint i, err = EGL_SUCCESS;
60 EGLint attr = EGL_NONE;
61 EGLint val = EGL_NONE;
62
63 if (!attrib_list)
64 return EGL_SUCCESS;
65
66 if (disp->Extensions.NOK_texture_from_pixmap)
67 texture_type |= EGL_PIXMAP_BIT;
68
69 for (i = 0; attrib_list[i] != EGL_NONE; i++) {
70 attr = attrib_list[i++];
71 val = attrib_list[i];
72
73 switch (attr) {
74 /* common attributes */
75 case EGL_GL_COLORSPACE_KHR:
76 if (!disp->Extensions.KHR_gl_colorspace) {
77 err = EGL_BAD_ATTRIBUTE;
78 break;
79 }
80 switch (val) {
81 case EGL_GL_COLORSPACE_SRGB_KHR:
82 case EGL_GL_COLORSPACE_LINEAR_KHR:
83 break;
84 default:
85 err = EGL_BAD_ATTRIBUTE;
86 }
87 if (err != EGL_SUCCESS)
88 break;
89 surf->GLColorspace = val;
90 break;
91 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
92 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
93 err = EGL_BAD_ATTRIBUTE;
94 break;
95 }
96 surf->HdrMetadata.display_primary_r.x = val;
97 break;
98 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
99 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
100 err = EGL_BAD_ATTRIBUTE;
101 break;
102 }
103 surf->HdrMetadata.display_primary_r.y = val;
104 break;
105 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
106 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
107 err = EGL_BAD_ATTRIBUTE;
108 break;
109 }
110 surf->HdrMetadata.display_primary_g.x = val;
111 break;
112 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
113 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
114 err = EGL_BAD_ATTRIBUTE;
115 break;
116 }
117 surf->HdrMetadata.display_primary_g.y = val;
118 break;
119 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
120 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
121 err = EGL_BAD_ATTRIBUTE;
122 break;
123 }
124 surf->HdrMetadata.display_primary_b.x = val;
125 break;
126 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
127 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
128 err = EGL_BAD_ATTRIBUTE;
129 break;
130 }
131 surf->HdrMetadata.display_primary_b.y = val;
132 break;
133 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
134 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
135 err = EGL_BAD_ATTRIBUTE;
136 break;
137 }
138 surf->HdrMetadata.white_point.x = val;
139 break;
140 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
141 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
142 err = EGL_BAD_ATTRIBUTE;
143 break;
144 }
145 surf->HdrMetadata.white_point.y = val;
146 break;
147 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
148 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
149 err = EGL_BAD_ATTRIBUTE;
150 break;
151 }
152 surf->HdrMetadata.max_luminance = val;
153 break;
154 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
155 if (!disp->Extensions.EXT_surface_SMPTE2086_metadata) {
156 err = EGL_BAD_ATTRIBUTE;
157 break;
158 }
159 surf->HdrMetadata.min_luminance = val;
160 break;
161 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
162 if (!disp->Extensions.EXT_surface_CTA861_3_metadata) {
163 err = EGL_BAD_ATTRIBUTE;
164 break;
165 }
166 surf->HdrMetadata.max_cll = val;
167 break;
168 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
169 if (!disp->Extensions.EXT_surface_CTA861_3_metadata) {
170 err = EGL_BAD_ATTRIBUTE;
171 break;
172 }
173 surf->HdrMetadata.max_fall = val;
174 break;
175 case EGL_VG_COLORSPACE:
176 switch (val) {
177 case EGL_VG_COLORSPACE_sRGB:
178 case EGL_VG_COLORSPACE_LINEAR:
179 break;
180 default:
181 err = EGL_BAD_ATTRIBUTE;
182 break;
183 }
184 if (err != EGL_SUCCESS)
185 break;
186 surf->VGColorspace = val;
187 break;
188 case EGL_VG_ALPHA_FORMAT:
189 switch (val) {
190 case EGL_VG_ALPHA_FORMAT_NONPRE:
191 case EGL_VG_ALPHA_FORMAT_PRE:
192 break;
193 default:
194 err = EGL_BAD_ATTRIBUTE;
195 break;
196 }
197 if (err != EGL_SUCCESS)
198 break;
199 surf->VGAlphaFormat = val;
200 break;
201 /* window surface attributes */
202 case EGL_RENDER_BUFFER:
203 if (type != EGL_WINDOW_BIT) {
204 err = EGL_BAD_ATTRIBUTE;
205 break;
206 }
207 if (val != EGL_BACK_BUFFER && val != EGL_SINGLE_BUFFER) {
208 err = EGL_BAD_ATTRIBUTE;
209 break;
210 }
211 surf->RequestedRenderBuffer = val;
212 if (surf->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR) {
213 /* Unlike normal EGLSurfaces, one with a mutable render buffer
214 * uses the application-chosen render buffer.
215 */
216 surf->ActiveRenderBuffer = val;
217 }
218 break;
219 case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
220 if (!disp->Extensions.NV_post_sub_buffer ||
221 type != EGL_WINDOW_BIT) {
222 err = EGL_BAD_ATTRIBUTE;
223 break;
224 }
225 if (val != EGL_TRUE && val != EGL_FALSE) {
226 err = EGL_BAD_PARAMETER;
227 break;
228 }
229 surf->PostSubBufferSupportedNV = val;
230 break;
231 /* pbuffer surface attributes */
232 case EGL_WIDTH:
233 if (type != EGL_PBUFFER_BIT) {
234 err = EGL_BAD_ATTRIBUTE;
235 break;
236 }
237 if (val < 0) {
238 err = EGL_BAD_PARAMETER;
239 break;
240 }
241 surf->Width = val;
242 break;
243 case EGL_HEIGHT:
244 if (type != EGL_PBUFFER_BIT) {
245 err = EGL_BAD_ATTRIBUTE;
246 break;
247 }
248 if (val < 0) {
249 err = EGL_BAD_PARAMETER;
250 break;
251 }
252 surf->Height = val;
253 break;
254 case EGL_LARGEST_PBUFFER:
255 if (type != EGL_PBUFFER_BIT) {
256 err = EGL_BAD_ATTRIBUTE;
257 break;
258 }
259 surf->LargestPbuffer = !!val;
260 break;
261 /* for eglBindTexImage */
262 case EGL_TEXTURE_FORMAT:
263 if (!(type & texture_type)) {
264 err = EGL_BAD_ATTRIBUTE;
265 break;
266 }
267
268 switch (val) {
269 case EGL_TEXTURE_RGB:
270 case EGL_TEXTURE_RGBA:
271 case EGL_NO_TEXTURE:
272 break;
273 default:
274 err = EGL_BAD_ATTRIBUTE;
275 break;
276 }
277 if (err != EGL_SUCCESS)
278 break;
279 surf->TextureFormat = val;
280 break;
281 case EGL_TEXTURE_TARGET:
282 if (!(type & texture_type)) {
283 err = EGL_BAD_ATTRIBUTE;
284 break;
285 }
286
287 switch (val) {
288 case EGL_TEXTURE_2D:
289 case EGL_NO_TEXTURE:
290 break;
291 default:
292 err = EGL_BAD_ATTRIBUTE;
293 break;
294 }
295 if (err != EGL_SUCCESS)
296 break;
297 surf->TextureTarget = val;
298 break;
299 case EGL_MIPMAP_TEXTURE:
300 if (!(type & texture_type)) {
301 err = EGL_BAD_ATTRIBUTE;
302 break;
303 }
304 surf->MipmapTexture = !!val;
305 break;
306 /* no pixmap surface specific attributes */
307 default:
308 err = EGL_BAD_ATTRIBUTE;
309 break;
310 }
311
312 if (err != EGL_SUCCESS)
313 break;
314 }
315
316 if (err == EGL_SUCCESS && type == EGL_PBUFFER_BIT) {
317 if ((surf->TextureTarget == EGL_NO_TEXTURE && surf->TextureFormat != EGL_NO_TEXTURE) ||
318 (surf->TextureFormat == EGL_NO_TEXTURE && surf->TextureTarget != EGL_NO_TEXTURE)) {
319 attr = surf->TextureTarget == EGL_NO_TEXTURE ? EGL_TEXTURE_TARGET : EGL_TEXTURE_FORMAT;
320 err = EGL_BAD_MATCH;
321 }
322 }
323
324 if (err != EGL_SUCCESS)
325 _eglLog(_EGL_WARNING, "bad surface attribute 0x%04x", attr);
326
327 return err;
328 }
329
330
331 /**
332 * Do error check on parameters and initialize the given _EGLSurface object.
333 * \return EGL_TRUE if no errors, EGL_FALSE otherwise.
334 */
335 EGLBoolean
336 _eglInitSurface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
337 _EGLConfig *conf, const EGLint *attrib_list,
338 void *native_surface)
339 {
340 const char *func;
341 EGLint renderBuffer = EGL_BACK_BUFFER;
342 EGLint swapBehavior = EGL_BUFFER_DESTROYED;
343 EGLint err;
344
345 /* Swap behavior can be preserved only if config supports this. */
346 if (conf->SurfaceType & EGL_SWAP_BEHAVIOR_PRESERVED_BIT)
347 swapBehavior = EGL_BUFFER_PRESERVED;
348
349 switch (type) {
350 case EGL_WINDOW_BIT:
351 func = "eglCreateWindowSurface";
352 swapBehavior = EGL_BUFFER_DESTROYED;
353 break;
354 case EGL_PIXMAP_BIT:
355 func = "eglCreatePixmapSurface";
356 renderBuffer = EGL_SINGLE_BUFFER;
357 break;
358 case EGL_PBUFFER_BIT:
359 func = "eglCreatePBufferSurface";
360 break;
361 default:
362 _eglLog(_EGL_WARNING, "Bad type in _eglInitSurface");
363 return EGL_FALSE;
364 }
365
366 if ((conf->SurfaceType & type) == 0)
367 /* The config can't be used to create a surface of this type */
368 return _eglError(EGL_BAD_MATCH, func);
369
370 _eglInitResource(&surf->Resource, sizeof(*surf), disp);
371 surf->Type = type;
372 surf->Config = conf;
373 surf->Lost = EGL_FALSE;
374
375 surf->Width = 0;
376 surf->Height = 0;
377 surf->TextureFormat = EGL_NO_TEXTURE;
378 surf->TextureTarget = EGL_NO_TEXTURE;
379 surf->MipmapTexture = EGL_FALSE;
380 surf->LargestPbuffer = EGL_FALSE;
381 surf->RequestedRenderBuffer = renderBuffer;
382 surf->ActiveRenderBuffer = renderBuffer;
383 surf->VGAlphaFormat = EGL_VG_ALPHA_FORMAT_NONPRE;
384 surf->VGColorspace = EGL_VG_COLORSPACE_sRGB;
385 surf->GLColorspace = EGL_GL_COLORSPACE_LINEAR_KHR;
386
387 surf->MipmapLevel = 0;
388 surf->MultisampleResolve = EGL_MULTISAMPLE_RESOLVE_DEFAULT;
389 surf->SwapBehavior = swapBehavior;
390
391 surf->HorizontalResolution = EGL_UNKNOWN;
392 surf->VerticalResolution = EGL_UNKNOWN;
393 surf->AspectRatio = EGL_UNKNOWN;
394
395 surf->PostSubBufferSupportedNV = EGL_FALSE;
396 surf->SetDamageRegionCalled = EGL_FALSE;
397 surf->BufferAgeRead = EGL_FALSE;
398
399 /* the default swap interval is 1 */
400 surf->SwapInterval = 1;
401
402 surf->HdrMetadata.display_primary_r.x = EGL_DONT_CARE;
403 surf->HdrMetadata.display_primary_r.y = EGL_DONT_CARE;
404 surf->HdrMetadata.display_primary_g.x = EGL_DONT_CARE;
405 surf->HdrMetadata.display_primary_g.y = EGL_DONT_CARE;
406 surf->HdrMetadata.display_primary_b.x = EGL_DONT_CARE;
407 surf->HdrMetadata.display_primary_b.y = EGL_DONT_CARE;
408 surf->HdrMetadata.white_point.x = EGL_DONT_CARE;
409 surf->HdrMetadata.white_point.y = EGL_DONT_CARE;
410 surf->HdrMetadata.max_luminance = EGL_DONT_CARE;
411 surf->HdrMetadata.min_luminance = EGL_DONT_CARE;
412 surf->HdrMetadata.max_cll = EGL_DONT_CARE;
413 surf->HdrMetadata.max_fall = EGL_DONT_CARE;
414
415 err = _eglParseSurfaceAttribList(surf, attrib_list);
416 if (err != EGL_SUCCESS)
417 return _eglError(err, func);
418
419 /* if EGL_LARGEST_PBUFFER in use, clamp width and height */
420 if (surf->LargestPbuffer) {
421 surf->Width = MIN2(surf->Width, _EGL_MAX_PBUFFER_WIDTH);
422 surf->Height = MIN2(surf->Height, _EGL_MAX_PBUFFER_HEIGHT);
423 }
424
425 surf->NativeSurface = native_surface;
426
427 return EGL_TRUE;
428 }
429
430
431 EGLBoolean
432 _eglQuerySurface(_EGLDisplay *disp, _EGLSurface *surface,
433 EGLint attribute, EGLint *value)
434 {
435 switch (attribute) {
436 case EGL_WIDTH:
437 *value = surface->Width;
438 break;
439 case EGL_HEIGHT:
440 *value = surface->Height;
441 break;
442 case EGL_CONFIG_ID:
443 *value = surface->Config->ConfigID;
444 break;
445 case EGL_LARGEST_PBUFFER:
446 if (surface->Type == EGL_PBUFFER_BIT)
447 *value = surface->LargestPbuffer;
448 break;
449 case EGL_TEXTURE_FORMAT:
450 /* texture attributes: only for pbuffers, no error otherwise */
451 if (surface->Type == EGL_PBUFFER_BIT)
452 *value = surface->TextureFormat;
453 break;
454 case EGL_TEXTURE_TARGET:
455 if (surface->Type == EGL_PBUFFER_BIT)
456 *value = surface->TextureTarget;
457 break;
458 case EGL_MIPMAP_TEXTURE:
459 if (surface->Type == EGL_PBUFFER_BIT)
460 *value = surface->MipmapTexture;
461 break;
462 case EGL_MIPMAP_LEVEL:
463 if (surface->Type == EGL_PBUFFER_BIT)
464 *value = surface->MipmapLevel;
465 break;
466 case EGL_SWAP_BEHAVIOR:
467 *value = surface->SwapBehavior;
468 break;
469 case EGL_RENDER_BUFFER:
470 /* From the EGL_KHR_mutable_render_buffer spec (v12):
471 *
472 * Querying EGL_RENDER_BUFFER returns the buffer which client API
473 * rendering is requested to use. For a window surface, this is the
474 * attribute value specified when the surface was created or last set
475 * via eglSurfaceAttrib.
476 *
477 * In other words, querying a window surface returns the value most
478 * recently *requested* by the user.
479 *
480 * The paragraph continues in the EGL 1.5 spec (2014.08.27):
481 *
482 * For a pbuffer surface, it is always EGL_BACK_BUFFER . For a pixmap
483 * surface, it is always EGL_SINGLE_BUFFER . To determine the actual
484 * buffer being rendered to by a context, call eglQueryContext.
485 */
486 switch (surface->Type) {
487 default:
488 unreachable("bad EGLSurface type");
489 case EGL_WINDOW_BIT:
490 *value = surface->RequestedRenderBuffer;
491 break;
492 case EGL_PBUFFER_BIT:
493 *value = EGL_BACK_BUFFER;
494 break;
495 case EGL_PIXMAP_BIT:
496 *value = EGL_SINGLE_BUFFER;
497 break;
498 }
499 break;
500 case EGL_PIXEL_ASPECT_RATIO:
501 *value = surface->AspectRatio;
502 break;
503 case EGL_HORIZONTAL_RESOLUTION:
504 *value = surface->HorizontalResolution;
505 break;
506 case EGL_VERTICAL_RESOLUTION:
507 *value = surface->VerticalResolution;
508 break;
509 case EGL_MULTISAMPLE_RESOLVE:
510 *value = surface->MultisampleResolve;
511 break;
512 case EGL_VG_ALPHA_FORMAT:
513 *value = surface->VGAlphaFormat;
514 break;
515 case EGL_VG_COLORSPACE:
516 *value = surface->VGColorspace;
517 break;
518 case EGL_GL_COLORSPACE_KHR:
519 if (!disp->Extensions.KHR_gl_colorspace)
520 return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
521
522 *value = surface->GLColorspace;
523 break;
524 case EGL_POST_SUB_BUFFER_SUPPORTED_NV:
525 *value = surface->PostSubBufferSupportedNV;
526 break;
527 case EGL_BUFFER_AGE_EXT:
528 /* Both EXT_buffer_age and KHR_partial_update accept EGL_BUFFER_AGE_EXT.
529 * To be precise, the KHR one accepts EGL_BUFFER_AGE_KHR which is an
530 * alias with the same numeric value.
531 */
532 if (!disp->Extensions.EXT_buffer_age &&
533 !disp->Extensions.KHR_partial_update)
534 return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
535
536 _EGLContext *ctx = _eglGetCurrentContext();
537 EGLint result = disp->Driver->QueryBufferAge(disp, surface);
538 /* error happened */
539 if (result < 0)
540 return EGL_FALSE;
541 if (_eglGetContextHandle(ctx) == EGL_NO_CONTEXT ||
542 ctx->DrawSurface != surface)
543 return _eglError(EGL_BAD_SURFACE, "eglQuerySurface");
544
545 *value = result;
546 surface->BufferAgeRead = EGL_TRUE;
547 break;
548 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
549 *value = surface->HdrMetadata.display_primary_r.x;
550 break;
551 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
552 *value = surface->HdrMetadata.display_primary_r.y;
553 break;
554 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
555 *value = surface->HdrMetadata.display_primary_g.x;
556 break;
557 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
558 *value = surface->HdrMetadata.display_primary_g.y;
559 break;
560 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
561 *value = surface->HdrMetadata.display_primary_b.x;
562 break;
563 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
564 *value = surface->HdrMetadata.display_primary_b.y;
565 break;
566 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
567 *value = surface->HdrMetadata.white_point.x;
568 break;
569 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
570 *value = surface->HdrMetadata.white_point.y;
571 break;
572 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
573 *value = surface->HdrMetadata.max_luminance;
574 break;
575 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
576 *value = surface->HdrMetadata.min_luminance;
577 break;
578 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
579 *value = surface->HdrMetadata.max_cll;
580 break;
581 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
582 *value = surface->HdrMetadata.max_fall;
583 break;
584 default:
585 return _eglError(EGL_BAD_ATTRIBUTE, "eglQuerySurface");
586 }
587
588 return EGL_TRUE;
589 }
590
591
592 /**
593 * Default fallback routine - drivers might override this.
594 */
595 EGLBoolean
596 _eglSurfaceAttrib(const _EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surface,
597 EGLint attribute, EGLint value)
598 {
599 EGLint confval;
600 EGLint err = EGL_SUCCESS;
601 EGLint all_es_bits = EGL_OPENGL_ES_BIT |
602 EGL_OPENGL_ES2_BIT |
603 EGL_OPENGL_ES3_BIT_KHR;
604
605 switch (attribute) {
606 case EGL_MIPMAP_LEVEL:
607 confval = surface->Config->RenderableType;
608 if (!(confval & all_es_bits)) {
609 err = EGL_BAD_PARAMETER;
610 break;
611 }
612 surface->MipmapLevel = value;
613 break;
614 case EGL_MULTISAMPLE_RESOLVE:
615 switch (value) {
616 case EGL_MULTISAMPLE_RESOLVE_DEFAULT:
617 break;
618 case EGL_MULTISAMPLE_RESOLVE_BOX:
619 confval = surface->Config->SurfaceType;
620 if (!(confval & EGL_MULTISAMPLE_RESOLVE_BOX_BIT))
621 err = EGL_BAD_MATCH;
622 break;
623 default:
624 err = EGL_BAD_ATTRIBUTE;
625 break;
626 }
627 if (err != EGL_SUCCESS)
628 break;
629 surface->MultisampleResolve = value;
630 break;
631 case EGL_RENDER_BUFFER:
632 if (!disp->Extensions.KHR_mutable_render_buffer) {
633 err = EGL_BAD_ATTRIBUTE;
634 break;
635 }
636
637 if (value != EGL_BACK_BUFFER && value != EGL_SINGLE_BUFFER) {
638 err = EGL_BAD_PARAMETER;
639 break;
640 }
641
642 /* From the EGL_KHR_mutable_render_buffer spec (v12):
643 *
644 * If attribute is EGL_RENDER_BUFFER, and the EGL_SURFACE_TYPE
645 * attribute of the EGLConfig used to create surface does not contain
646 * EGL_MUTABLE_RENDER_BUFFER_BIT_KHR, [...] an EGL_BAD_MATCH error is
647 * generated [...].
648 */
649 if (!(surface->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR)) {
650 err = EGL_BAD_MATCH;
651 break;
652 }
653
654 surface->RequestedRenderBuffer = value;
655 break;
656 case EGL_SWAP_BEHAVIOR:
657 switch (value) {
658 case EGL_BUFFER_DESTROYED:
659 break;
660 case EGL_BUFFER_PRESERVED:
661 confval = surface->Config->SurfaceType;
662 if (!(confval & EGL_SWAP_BEHAVIOR_PRESERVED_BIT))
663 err = EGL_BAD_MATCH;
664 break;
665 default:
666 err = EGL_BAD_ATTRIBUTE;
667 break;
668 }
669 if (err != EGL_SUCCESS)
670 break;
671 surface->SwapBehavior = value;
672 break;
673 case EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT:
674 surface->HdrMetadata.display_primary_r.x = value;
675 break;
676 case EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT:
677 surface->HdrMetadata.display_primary_r.y = value;
678 break;
679 case EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT:
680 surface->HdrMetadata.display_primary_g.x = value;
681 break;
682 case EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT:
683 surface->HdrMetadata.display_primary_g.y = value;
684 break;
685 case EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT:
686 surface->HdrMetadata.display_primary_b.x = value;
687 break;
688 case EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT:
689 surface->HdrMetadata.display_primary_b.y = value;
690 break;
691 case EGL_SMPTE2086_WHITE_POINT_X_EXT:
692 surface->HdrMetadata.white_point.x = value;
693 break;
694 case EGL_SMPTE2086_WHITE_POINT_Y_EXT:
695 surface->HdrMetadata.white_point.y = value;
696 break;
697 case EGL_SMPTE2086_MAX_LUMINANCE_EXT:
698 surface->HdrMetadata.max_luminance = value;
699 break;
700 case EGL_SMPTE2086_MIN_LUMINANCE_EXT:
701 surface->HdrMetadata.min_luminance = value;
702 break;
703 case EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT:
704 surface->HdrMetadata.max_cll = value;
705 break;
706 case EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT:
707 surface->HdrMetadata.max_fall = value;
708 break;
709 default:
710 err = EGL_BAD_ATTRIBUTE;
711 break;
712 }
713
714 if (err != EGL_SUCCESS)
715 return _eglError(err, "eglSurfaceAttrib");
716 return EGL_TRUE;
717 }
718
719
720 EGLBoolean
721 _eglBindTexImage(_EGLDisplay *disp, _EGLSurface *surface, EGLint buffer)
722 {
723 EGLint texture_type = EGL_PBUFFER_BIT;
724
725 /* Just do basic error checking and return success/fail.
726 * Drivers must implement the real stuff.
727 */
728
729 if (disp->Extensions.NOK_texture_from_pixmap)
730 texture_type |= EGL_PIXMAP_BIT;
731
732 if (!(surface->Type & texture_type))
733 return _eglError(EGL_BAD_SURFACE, "eglBindTexImage");
734
735 if (surface->TextureFormat == EGL_NO_TEXTURE)
736 return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
737
738 if (surface->TextureTarget == EGL_NO_TEXTURE)
739 return _eglError(EGL_BAD_MATCH, "eglBindTexImage");
740
741 if (buffer != EGL_BACK_BUFFER)
742 return _eglError(EGL_BAD_PARAMETER, "eglBindTexImage");
743
744 surface->BoundToTexture = EGL_TRUE;
745
746 return EGL_TRUE;
747 }
748
749 EGLBoolean
750 _eglReleaseTexImage(_EGLDisplay *disp, _EGLSurface *surf, EGLint buffer)
751 {
752 /* Just do basic error checking and return success/fail.
753 * Drivers must implement the real stuff.
754 */
755
756 EGLint texture_type = EGL_PBUFFER_BIT;
757
758 if (surf == EGL_NO_SURFACE)
759 return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
760
761 if (!surf->BoundToTexture)
762 {
763 /* Not an error, simply nothing to do */
764 return EGL_TRUE;
765 }
766
767 if (surf->TextureFormat == EGL_NO_TEXTURE)
768 return _eglError(EGL_BAD_MATCH, "eglReleaseTexImage");
769
770 if (buffer != EGL_BACK_BUFFER)
771 return _eglError(EGL_BAD_PARAMETER, "eglReleaseTexImage");
772
773 if (disp->Extensions.NOK_texture_from_pixmap)
774 texture_type |= EGL_PIXMAP_BIT;
775
776 if (!(surf->Type & texture_type))
777 return _eglError(EGL_BAD_SURFACE, "eglReleaseTexImage");
778
779 surf->BoundToTexture = EGL_FALSE;
780
781 return EGL_TRUE;
782 }
783
784
785 EGLBoolean
786 _eglSwapInterval(_EGLDisplay *disp, _EGLSurface *surf, EGLint interval)
787 {
788 return EGL_TRUE;
789 }
790
791 EGLBoolean
792 _eglSurfaceHasMutableRenderBuffer(_EGLSurface *surf)
793 {
794 return surf->Type == EGL_WINDOW_BIT &&
795 surf->Config &&
796 (surf->Config->SurfaceType & EGL_MUTABLE_RENDER_BUFFER_BIT_KHR);
797 }
798
799 EGLBoolean
800 _eglSurfaceInSharedBufferMode(_EGLSurface *surf)
801 {
802 return _eglSurfaceHasMutableRenderBuffer(surf) &&
803 surf->ActiveRenderBuffer == EGL_SINGLE_BUFFER;
804 }