#include "util/u_atomic.h"
#include "util/u_vector.h"
#include "mapi/glapi/glapi.h"
+#include "util/bitscan.h"
/* Additional definitions not yet in the drm_fourcc.h.
*/
.base = { __DRI_USE_INVALIDATE, 1 }
};
+static void
+dri2_get_pbuffer_drawable_info(__DRIdrawable * draw,
+ int *x, int *y, int *w, int *h,
+ void *loaderPrivate)
+{
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+
+ *x = *y = 0;
+ *w = dri2_surf->base.Width;
+ *h = dri2_surf->base.Height;
+}
+
+/* HACK: technically we should have swrast_null, instead of these. We
+ * get away since only pbuffers are supported, thus the callbacks are
+ * unused.
+ */
+const __DRIswrastLoaderExtension swrast_pbuffer_loader_extension = {
+ .base = { __DRI_SWRAST_LOADER, 1 },
+ .getDrawableInfo = dri2_get_pbuffer_drawable_info,
+ .putImage = NULL,
+ .getImage = NULL,
+};
+
static const EGLint dri2_to_egl_attribute_map[__DRI_ATTRIB_MAX] = {
[__DRI_ATTRIB_BUFFER_SIZE ] = EGL_BUFFER_SIZE,
[__DRI_ATTRIB_LEVEL] = EGL_LEVEL,
- [__DRI_ATTRIB_RED_SIZE] = EGL_RED_SIZE,
- [__DRI_ATTRIB_GREEN_SIZE] = EGL_GREEN_SIZE,
- [__DRI_ATTRIB_BLUE_SIZE] = EGL_BLUE_SIZE,
[__DRI_ATTRIB_LUMINANCE_SIZE] = EGL_LUMINANCE_SIZE,
- [__DRI_ATTRIB_ALPHA_SIZE] = EGL_ALPHA_SIZE,
[__DRI_ATTRIB_DEPTH_SIZE] = EGL_DEPTH_SIZE,
[__DRI_ATTRIB_STENCIL_SIZE] = EGL_STENCIL_SIZE,
[__DRI_ATTRIB_SAMPLE_BUFFERS] = EGL_SAMPLE_BUFFERS,
return EGL_TRUE;
}
+void
+dri2_get_shifts_and_sizes(const __DRIcoreExtension *core,
+ const __DRIconfig *config, int *shifts,
+ unsigned int *sizes)
+{
+ unsigned int mask;
+
+ if (core->getConfigAttrib(config, __DRI_ATTRIB_RED_SHIFT, (unsigned int *)&shifts[0])) {
+ core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SHIFT, (unsigned int *)&shifts[1]);
+ core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SHIFT, (unsigned int *)&shifts[2]);
+ core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SHIFT, (unsigned int *)&shifts[3]);
+ } else {
+ /* Driver isn't exposing shifts, so convert masks to shifts */
+ core->getConfigAttrib(config, __DRI_ATTRIB_RED_MASK, &mask);
+ shifts[0] = ffs(mask) - 1;
+ core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_MASK, &mask);
+ shifts[1] = ffs(mask) - 1;
+ core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_MASK, &mask);
+ shifts[2] = ffs(mask) - 1;
+ core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_MASK, &mask);
+ shifts[3] = ffs(mask) - 1;
+ }
+
+ core->getConfigAttrib(config, __DRI_ATTRIB_RED_SIZE, &sizes[0]);
+ core->getConfigAttrib(config, __DRI_ATTRIB_GREEN_SIZE, &sizes[1]);
+ core->getConfigAttrib(config, __DRI_ATTRIB_BLUE_SIZE, &sizes[2]);
+ core->getConfigAttrib(config, __DRI_ATTRIB_ALPHA_SIZE, &sizes[3]);
+}
+
+void
+dri2_get_render_type_float(const __DRIcoreExtension *core,
+ const __DRIconfig *config,
+ bool *is_float)
+{
+ unsigned int render_type;
+
+ core->getConfigAttrib(config, __DRI_ATTRIB_RENDER_TYPE, &render_type);
+ *is_float = (render_type & __DRI_ATTRIB_FLOAT_BIT) ? true : false;
+}
+
struct dri2_egl_config *
dri2_add_config(_EGLDisplay *disp, const __DRIconfig *dri_config, int id,
EGLint surface_type, const EGLint *attr_list,
- const unsigned int *rgba_masks)
+ const int *rgba_shifts, const unsigned int *rgba_sizes)
{
struct dri2_egl_config *conf;
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
unsigned int attrib, value, double_buffer;
bool srgb = false;
EGLint key, bind_to_texture_rgb, bind_to_texture_rgba;
- unsigned int dri_masks[4] = { 0, 0, 0, 0 };
+ int dri_shifts[4] = { -1, -1, -1, -1 };
+ unsigned int dri_sizes[4] = { 0, 0, 0, 0 };
_EGLConfig *matching_config;
EGLint num_configs = 0;
EGLint config_id;
switch (attrib) {
case __DRI_ATTRIB_RENDER_TYPE:
+ if (value & __DRI_ATTRIB_FLOAT_BIT)
+ _eglSetConfigKey(&base, EGL_COLOR_COMPONENT_TYPE_EXT,
+ EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT);
if (value & __DRI_ATTRIB_RGBA_BIT)
value = EGL_RGB_BUFFER;
else if (value & __DRI_ATTRIB_LUMINANCE_BIT)
double_buffer = value;
break;
+ case __DRI_ATTRIB_RED_SIZE:
+ dri_sizes[0] = value;
+ _eglSetConfigKey(&base, EGL_RED_SIZE, value);
+ break;
+
case __DRI_ATTRIB_RED_MASK:
- dri_masks[0] = value;
+ dri_shifts[0] = ffs(value) - 1;
+ break;
+
+ case __DRI_ATTRIB_RED_SHIFT:
+ dri_shifts[0] = value;
+ break;
+
+ case __DRI_ATTRIB_GREEN_SIZE:
+ dri_sizes[1] = value;
+ _eglSetConfigKey(&base, EGL_GREEN_SIZE, value);
break;
case __DRI_ATTRIB_GREEN_MASK:
- dri_masks[1] = value;
+ dri_shifts[1] = ffs(value) - 1;
+ break;
+
+ case __DRI_ATTRIB_GREEN_SHIFT:
+ dri_shifts[1] = value;
+ break;
+
+ case __DRI_ATTRIB_BLUE_SIZE:
+ dri_sizes[2] = value;
+ _eglSetConfigKey(&base, EGL_BLUE_SIZE, value);
break;
case __DRI_ATTRIB_BLUE_MASK:
- dri_masks[2] = value;
+ dri_shifts[2] = ffs(value) - 1;
+ break;
+
+ case __DRI_ATTRIB_BLUE_SHIFT:
+ dri_shifts[2] = value;
+ break;
+
+ case __DRI_ATTRIB_ALPHA_SIZE:
+ dri_sizes[3] = value;
+ _eglSetConfigKey(&base, EGL_ALPHA_SIZE, value);
break;
case __DRI_ATTRIB_ALPHA_MASK:
- dri_masks[3] = value;
+ dri_shifts[3] = ffs(value) - 1;
+ break;
+
+ case __DRI_ATTRIB_ALPHA_SHIFT:
+ dri_shifts[3] = value;
break;
case __DRI_ATTRIB_ACCUM_RED_SIZE:
for (int i = 0; attr_list[i] != EGL_NONE; i += 2)
_eglSetConfigKey(&base, attr_list[i], attr_list[i+1]);
- if (rgba_masks && memcmp(rgba_masks, dri_masks, sizeof(dri_masks)))
+ if (rgba_shifts && memcmp(rgba_shifts, dri_shifts, sizeof(dri_shifts)))
+ return NULL;
+
+ if (rgba_sizes && memcmp(rgba_sizes, dri_sizes, sizeof(dri_sizes)))
return NULL;
base.NativeRenderable = EGL_TRUE;
base.BindToTextureRGBA = bind_to_texture_rgba;
}
+ if (double_buffer) {
+ surface_type &= ~EGL_PIXMAP_BIT;
+ }
+
+ /* No support for pbuffer + MSAA for now.
+ *
+ * XXX TODO: pbuffer + MSAA does not work and causes crashes.
+ * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
+ */
+ if (base.Samples) {
+ surface_type &= ~EGL_PBUFFER_BIT;
+ }
+
+ if (!surface_type)
+ return NULL;
+
base.RenderableType = disp->ClientAPIs;
base.Conformant = disp->ClientAPIs;
return NULL;
}
- if (double_buffer) {
- surface_type &= ~EGL_PIXMAP_BIT;
- }
-
- /* No support for pbuffer + MSAA for now.
- *
- * XXX TODO: pbuffer + MSAA does not work and causes crashes.
- * See QT bugreport: https://bugreports.qt.io/browse/QTBUG-47509
- */
- if (base.Samples) {
- surface_type &= ~EGL_PBUFFER_BIT;
- }
-
conf->base.SurfaceType |= surface_type;
return conf;
if (!extensions)
return EGL_FALSE;
- if (!dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false)) {
- dlclose(dri2_dpy->driver);
+ if (!dri2_bind_extensions(dri2_dpy, driver_extensions, extensions, false))
return EGL_FALSE;
- }
+
dri2_dpy->driver_extensions = extensions;
dri2_bind_extensions(dri2_dpy, optional_driver_extensions, extensions, true);
case DRM_FORMAT_ABGR2101010:
case DRM_FORMAT_RGBA1010102:
case DRM_FORMAT_BGRA1010102:
+ case DRM_FORMAT_XBGR16161616F:
+ case DRM_FORMAT_ABGR16161616F:
case DRM_FORMAT_YUYV:
case DRM_FORMAT_YVYU:
case DRM_FORMAT_UYVY: