+static void
+swrast_put_image2(__DRIdrawable *driDrawable,
+ int op,
+ int x,
+ int y,
+ int width,
+ int height,
+ int stride,
+ char *data,
+ void *loaderPrivate)
+{
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+ int internal_stride, i;
+ struct gbm_dri_bo *bo;
+
+ if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&
+ op != __DRI_SWRAST_IMAGE_OP_SWAP)
+ return;
+
+ if (get_swrast_front_bo(dri2_surf) < 0)
+ return;
+
+ bo = gbm_dri_bo(dri2_surf->current->bo);
+ if (gbm_dri_bo_map_dumb(bo) == NULL)
+ return;
+
+ internal_stride = bo->base.stride;
+
+ for (i = 0; i < height; i++) {
+ memcpy(bo->map + (x + i) * internal_stride + y,
+ data + i * stride, stride);
+ }
+
+ gbm_dri_bo_unmap_dumb(bo);
+}
+
+static void
+swrast_get_image(__DRIdrawable *driDrawable,
+ int x,
+ int y,
+ int width,
+ int height,
+ char *data,
+ void *loaderPrivate)
+{
+ struct dri2_egl_surface *dri2_surf = loaderPrivate;
+ int internal_stride, stride, i;
+ struct gbm_dri_bo *bo;
+
+ if (get_swrast_front_bo(dri2_surf) < 0)
+ return;
+
+ bo = gbm_dri_bo(dri2_surf->current->bo);
+ if (gbm_dri_bo_map_dumb(bo) == NULL)
+ return;
+
+ internal_stride = bo->base.stride;
+ stride = width * 4;
+
+ for (i = 0; i < height; i++) {
+ memcpy(data + i * stride,
+ bo->map + (x + i) * internal_stride + y, stride);
+ }
+
+ gbm_dri_bo_unmap_dumb(bo);
+}
+
+static EGLBoolean
+drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
+{
+ struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
+ static const struct {
+ int format;
+ unsigned int red_mask;
+ unsigned int alpha_mask;
+ } visuals[] = {
+ { GBM_FORMAT_XRGB2101010, 0x3ff00000, 0x00000000 },
+ { GBM_FORMAT_ARGB2101010, 0x3ff00000, 0xc0000000 },
+ { GBM_FORMAT_XRGB8888, 0x00ff0000, 0x00000000 },
+ { GBM_FORMAT_ARGB8888, 0x00ff0000, 0xff000000 },
+ { GBM_FORMAT_RGB565, 0x0000f800, 0x00000000 },
+ };
+ EGLint attr_list[] = {
+ EGL_NATIVE_VISUAL_ID, 0,
+ EGL_NONE,
+ };
+ unsigned int format_count[ARRAY_SIZE(visuals)] = { 0 };
+ unsigned int count, i, j;
+
+ count = 0;
+ for (i = 0; dri2_dpy->driver_configs[i]; i++) {
+ unsigned int red, alpha;
+
+ dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+ __DRI_ATTRIB_RED_MASK, &red);
+ dri2_dpy->core->getConfigAttrib(dri2_dpy->driver_configs[i],
+ __DRI_ATTRIB_ALPHA_MASK, &alpha);
+
+ for (j = 0; j < ARRAY_SIZE(visuals); j++) {
+ struct dri2_egl_config *dri2_conf;
+
+ if (visuals[j].red_mask != red || visuals[j].alpha_mask != alpha)
+ continue;
+
+ attr_list[1] = visuals[j].format;
+
+ dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
+ count + 1, EGL_WINDOW_BIT, attr_list, NULL);
+ if (dri2_conf) {
+ count++;
+ format_count[j]++;
+ }
+ }
+ }
+
+ for (i = 0; i < ARRAY_SIZE(format_count); i++) {
+ if (!format_count[i]) {
+ _eglLog(_EGL_DEBUG, "No DRI config supports native format 0x%x",
+ visuals[i].format);
+ }
+ }
+
+ return (count != 0);
+}
+
+static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl = {