dri_is_thread_safe(void *loaderPrivate)
{
struct dri2_egl_surface *dri2_surf = loaderPrivate;
- MAYBE_UNUSED _EGLDisplay *display = dri2_surf->base.Resource.Display;
+ UNUSED _EGLDisplay *display = dri2_surf->base.Resource.Display;
#ifdef HAVE_X11_PLATFORM
Display *xdpy = (Display*)display->PlatformDisplay;
.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;
{ __DRI2_NO_ERROR, 1, offsetof(struct dri2_egl_display, no_error) },
{ __DRI2_CONFIG_QUERY, 1, offsetof(struct dri2_egl_display, config) },
{ __DRI2_FENCE, 1, offsetof(struct dri2_egl_display, fence) },
+ { __DRI2_BUFFER_DAMAGE, 1, offsetof(struct dri2_egl_display, buffer_damage) },
{ __DRI2_RENDERER_QUERY, 1, offsetof(struct dri2_egl_display, rendererQuery) },
{ __DRI2_INTEROP, 1, offsetof(struct dri2_egl_display, interop) },
{ __DRI_IMAGE, 1, offsetof(struct dri2_egl_display, image) },
if (dri2_dpy->flush_control)
disp->Extensions.KHR_context_flush_control = EGL_TRUE;
+
+ if (dri2_dpy->buffer_damage && dri2_dpy->buffer_damage->set_damage_region)
+ disp->Extensions.KHR_partial_update = EGL_TRUE;
}
void
case _EGL_PLATFORM_SURFACELESS:
ret = dri2_initialize_surfaceless(drv, disp);
break;
+ case _EGL_PLATFORM_DEVICE:
+ ret = dri2_initialize_device(drv, disp);
+ break;
case _EGL_PLATFORM_X11:
ret = dri2_initialize_x11(drv, disp);
break;
&& dri2_ctx->base.ClientMinorVersion >= 2))
&& dri2_ctx->base.Profile == EGL_CONTEXT_OPENGL_CORE_PROFILE_BIT_KHR)
api = __DRI_API_OPENGL_CORE;
+ else if (dri2_ctx->base.ClientMajorVersion == 3 &&
+ dri2_ctx->base.ClientMinorVersion == 1)
+ api = __DRI_API_OPENGL_CORE;
else
api = __DRI_API_OPENGL;
break;
EGLBoolean
dri2_init_surface(_EGLSurface *surf, _EGLDisplay *disp, EGLint type,
- _EGLConfig *conf, const EGLint *attrib_list, EGLBoolean enable_out_fence)
+ _EGLConfig *conf, const EGLint *attrib_list,
+ EGLBoolean enable_out_fence, void *native_surface)
{
struct dri2_egl_surface *dri2_surf = dri2_egl_surface(surf);
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
dri2_surf->enable_out_fence = enable_out_fence;
}
- return _eglInitSurface(surf, disp, type, conf, attrib_list);
+ return _eglInitSurface(surf, disp, type, conf, attrib_list, native_surface);
}
static void
dri2_surface_set_out_fence_fd(surf, fence_fd);
}
+EGLBoolean
+dri2_create_drawable(struct dri2_egl_display *dri2_dpy,
+ const __DRIconfig *config,
+ struct dri2_egl_surface *dri2_surf,
+ void *loaderPrivate)
+{
+ __DRIcreateNewDrawableFunc createNewDrawable;
+
+ if (dri2_dpy->image_driver)
+ createNewDrawable = dri2_dpy->image_driver->createNewDrawable;
+ else if (dri2_dpy->dri2)
+ createNewDrawable = dri2_dpy->dri2->createNewDrawable;
+ else if (dri2_dpy->swrast)
+ createNewDrawable = dri2_dpy->swrast->createNewDrawable;
+ else
+ return _eglError(EGL_BAD_ALLOC, "no createNewDrawable");
+
+ dri2_surf->dri_drawable = createNewDrawable(dri2_dpy->dri_screen,
+ config, loaderPrivate);
+ if (dri2_surf->dri_drawable == NULL)
+ return _eglError(EGL_BAD_ALLOC, "createNewDrawable");
+
+ return EGL_TRUE;
+}
+
/**
* Called via eglMakeCurrent(), drv->API.MakeCurrent().
*/
dri2_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *surf)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
_EGLContext *ctx = _eglGetCurrentContext();
+ EGLBoolean ret;
if (ctx && surf)
dri2_surf_update_fence_fd(ctx, disp, surf);
- return dri2_dpy->vtbl->swap_buffers(drv, disp, surf);
+ ret = dri2_dpy->vtbl->swap_buffers(drv, disp, surf);
+
+ /* SwapBuffers marks the end of the frame; reset the damage region for
+ * use again next time.
+ */
+ if (ret && dri2_dpy->buffer_damage &&
+ dri2_dpy->buffer_damage->set_damage_region)
+ dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL);
+
+ return ret;
}
static EGLBoolean
const EGLint *rects, EGLint n_rects)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
_EGLContext *ctx = _eglGetCurrentContext();
+ EGLBoolean ret;
if (ctx && surf)
dri2_surf_update_fence_fd(ctx, disp, surf);
- return dri2_dpy->vtbl->swap_buffers_with_damage(drv, disp, surf,
- rects, n_rects);
+ ret = dri2_dpy->vtbl->swap_buffers_with_damage(drv, disp, surf,
+ rects, n_rects);
+
+ /* SwapBuffers marks the end of the frame; reset the damage region for
+ * use again next time.
+ */
+ if (ret && dri2_dpy->buffer_damage &&
+ dri2_dpy->buffer_damage->set_damage_region)
+ dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL);
+
+ return ret;
}
static EGLBoolean
EGLint numRects, const EGLint *rects)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- return dri2_dpy->vtbl->swap_buffers_region(drv, disp, surf, numRects, rects);
+ __DRIdrawable *dri_drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
+ EGLBoolean ret;
+
+ ret = dri2_dpy->vtbl->swap_buffers_region(drv, disp, surf, numRects, rects);
+
+ /* SwapBuffers marks the end of the frame; reset the damage region for
+ * use again next time.
+ */
+ if (ret && dri2_dpy->buffer_damage &&
+ dri2_dpy->buffer_damage->set_damage_region)
+ dri2_dpy->buffer_damage->set_damage_region(dri_drawable, 0, NULL);
+
+ return ret;
}
static EGLBoolean
EGLint *rects, EGLint n_rects)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
- return dri2_dpy->vtbl->set_damage_region(drv, disp, surf, rects, n_rects);
+ __DRIdrawable *drawable = dri2_dpy->vtbl->get_dri_drawable(surf);
+
+ if (!dri2_dpy->buffer_damage || !dri2_dpy->buffer_damage->set_damage_region)
+ return EGL_FALSE;
+
+ dri2_dpy->buffer_damage->set_damage_region(drawable, n_rects, rects);
+ return EGL_TRUE;
}
static EGLBoolean
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:
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_image *dri2_img = dri2_egl_image(img);
+ int num_planes;
(void) drv;
if (!dri2_can_export_dma_buf_image(disp, img))
return EGL_FALSE;
+ dri2_dpy->image->queryImage(dri2_img->dri_image,
+ __DRI_IMAGE_ATTRIB_NUM_PLANES, &num_planes);
if (nplanes)
- dri2_dpy->image->queryImage(dri2_img->dri_image,
- __DRI_IMAGE_ATTRIB_NUM_PLANES, nplanes);
+ *nplanes = num_planes;
+
if (fourcc)
dri2_dpy->image->queryImage(dri2_img->dri_image,
__DRI_IMAGE_ATTRIB_FOURCC, fourcc);
- if (modifiers)
- *modifiers = 0;
+ if (modifiers) {
+ int mod_hi, mod_lo;
+ uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+ bool query;
+
+ query = dri2_dpy->image->queryImage(dri2_img->dri_image,
+ __DRI_IMAGE_ATTRIB_MODIFIER_UPPER,
+ &mod_hi);
+ query &= dri2_dpy->image->queryImage(dri2_img->dri_image,
+ __DRI_IMAGE_ATTRIB_MODIFIER_LOWER,
+ &mod_lo);
+ if (query)
+ modifier = combine_u32_into_u64 (mod_hi, mod_lo);
+
+ for (int i = 0; i < num_planes; i++)
+ modifiers[i] = modifier;
+ }
return EGL_TRUE;
}