_eglLinkConfig(&conf->base);
}
else {
- assert(0);
+ unreachable("duplicates should not be possible");
return NULL;
}
break;
default:
- assert(0);
+ assert(!"unknown dri_error code");
egl_error = EGL_BAD_MATCH;
break;
}
target = GL_TEXTURE_2D;
break;
default:
- assert(0);
+ assert(!"missing texture target");
}
if (dri2_dpy->tex_buffer->base.version >= 3 &&
case __DRI_IMAGE_ERROR_BAD_ACCESS:
return EGL_BAD_ACCESS;
default:
- assert(0);
+ assert(!"unknown dri_error code");
return EGL_BAD_ALLOC;
}
}
return EGL_TRUE;
}
-/* Returns the total number of file descriptors. Zero indicates an error. */
+/* Returns the total number of planes for the format or zero if it isn't a
+ * valid fourcc format.
+ */
static unsigned
-dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
+dri2_num_fourcc_format_planes(EGLint format)
{
- unsigned plane_n;
-
- switch (attrs->DMABufFourCC.Value) {
+ switch (format) {
case DRM_FORMAT_R8:
case DRM_FORMAT_RG88:
case DRM_FORMAT_GR88:
case DRM_FORMAT_YVYU:
case DRM_FORMAT_UYVY:
case DRM_FORMAT_VYUY:
- plane_n = 1;
- break;
+ return 1;
+
case DRM_FORMAT_NV12:
case DRM_FORMAT_NV21:
case DRM_FORMAT_NV16:
case DRM_FORMAT_NV61:
- plane_n = 2;
- break;
+ return 2;
+
case DRM_FORMAT_YUV410:
case DRM_FORMAT_YVU410:
case DRM_FORMAT_YUV411:
case DRM_FORMAT_YVU422:
case DRM_FORMAT_YUV444:
case DRM_FORMAT_YVU444:
- plane_n = 3;
- break;
+ return 3;
+
default:
+ return 0;
+ }
+}
+
+/* Returns the total number of file descriptors. Zero indicates an error. */
+static unsigned
+dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
+{
+ unsigned plane_n = dri2_num_fourcc_format_planes(attrs->DMABufFourCC.Value);
+ if (plane_n == 0) {
_eglError(EGL_BAD_ATTRIBUTE, "invalid format");
return 0;
}
formats, count))
return EGL_FALSE;
+ if (max > 0) {
+ /* Assert that all of the formats returned are actually fourcc formats.
+ * Some day, if we want the internal interface function to be able to
+ * return the fake fourcc formats defined in dri_interface.h, we'll have
+ * to do something more clever here to pair the list down to just real
+ * fourcc formats so that we don't leak the fake internal ones.
+ */
+ for (int i = 0; i < *count; i++) {
+ assert(dri2_num_fourcc_format_planes(formats[i]) > 0);
+ }
+ }
+
return EGL_TRUE;
}
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ if (dri2_num_fourcc_format_planes(format) == 0)
+ return _eglError(EGL_BAD_PARAMETER, "invalid fourcc format");
+
if (max < 0)
return _eglError(EGL_BAD_PARAMETER, "invalid value for max count of formats");
/**
* This is the main entrypoint into the driver, called by libEGL.
- * Create a new _EGLDriver object and init its dispatch table.
+ * Gets an _EGLDriver object and init its dispatch table.
*/
-_EGLDriver *
-_eglBuiltInDriver(void)
+void
+_eglInitDriver(_EGLDriver *dri2_drv)
{
- _EGLDriver *dri2_drv = calloc(1, sizeof *dri2_drv);
- if (!dri2_drv)
- return NULL;
-
- _eglInitDriverFallbacks(dri2_drv);
dri2_drv->API.Initialize = dri2_initialize;
dri2_drv->API.Terminate = dri2_terminate;
dri2_drv->API.CreateContext = dri2_create_context;
dri2_drv->API.GLInteropExportObject = dri2_interop_export_object;
dri2_drv->API.DupNativeFenceFDANDROID = dri2_dup_native_fence_fd;
dri2_drv->API.SetBlobCacheFuncsANDROID = dri2_set_blob_cache_funcs;
-
- dri2_drv->Name = "DRI2";
-
- return dri2_drv;
}