loader: drop the [gs]et_swap_interval callbacks
[mesa.git] / src / egl / drivers / dri2 / platform_drm.c
index 7f907aff6c91a71c9839cd6dd8306dc4c1b52b9d..a952aa545607811153e8175580813826b1acf883 100644 (file)
@@ -72,6 +72,7 @@ release_buffer(struct gbm_surface *_surf, struct gbm_bo *bo)
    for (unsigned i = 0; i < ARRAY_SIZE(dri2_surf->color_buffers); i++) {
       if (dri2_surf->color_buffers[i].bo == bo) {
         dri2_surf->color_buffers[i].locked = false;
+        break;
       }
    }
 }
@@ -229,7 +230,8 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)
    if (dri2_surf->back->bo == NULL) {
       if (surf->base.modifiers)
          dri2_surf->back->bo = gbm_bo_create_with_modifiers(&dri2_dpy->gbm_dri->base,
-                                                            surf->base.width, surf->base.height,
+                                                            surf->base.width,
+                                                            surf->base.height,
                                                             surf->base.format,
                                                             surf->base.modifiers,
                                                             surf->base.count);
@@ -321,10 +323,9 @@ dri2_drm_get_buffers_with_format(__DRIdrawable *driDrawable,
    struct dri2_egl_surface *dri2_surf = loaderPrivate;
    int i, j;
 
-   dri2_surf->buffer_count = 0;
    for (i = 0, j = 0; i < 2 * count; i += 2, j++) {
       assert(attachments[i] < __DRI_BUFFER_COUNT);
-      assert(dri2_surf->buffer_count < 5);
+      assert(j < ARRAY_SIZE(dri2_surf->buffers));
 
       switch (attachments[i]) {
       case __DRI_BUFFER_BACK_LEFT:
@@ -434,10 +435,8 @@ dri2_drm_swap_buffers(_EGLDriver *drv, _EGLDisplay *disp, _EGLSurface *draw)
 
       /* Make sure we have a back buffer in case we're swapping without
        * ever rendering. */
-      if (get_back_bo(dri2_surf) < 0) {
-         _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");
-         return EGL_FALSE;
-      }
+      if (get_back_bo(dri2_surf) < 0)
+         return _eglError(EGL_BAD_ALLOC, "dri2_swap_buffers");
 
       dri2_surf->current = dri2_surf->back;
       dri2_surf->current->age = 1;
@@ -478,10 +477,7 @@ dri2_drm_create_image_khr_pixmap(_EGLDisplay *disp, _EGLContext *ctx,
       return NULL;
    }
 
-   if (!_eglInitImage(&dri2_img->base, disp)) {
-      free(dri2_img);
-      return NULL;
-   }
+   _eglInitImage(&dri2_img->base, disp);
 
    dri2_img->dri_image = dri2_dpy->image->dupImage(dri_bo->image, dri2_img);
    if (dri2_img->dri_image == NULL) {
@@ -530,6 +526,9 @@ swrast_put_image2(__DRIdrawable *driDrawable,
    struct dri2_egl_surface *dri2_surf = loaderPrivate;
    int internal_stride;
    struct gbm_dri_bo *bo;
+   uint32_t bpp;
+   int x_bytes, width_bytes;
+   char *src, *dst;
 
    if (op != __DRI_SWRAST_IMAGE_OP_DRAW &&
        op != __DRI_SWRAST_IMAGE_OP_SWAP)
@@ -539,14 +538,26 @@ swrast_put_image2(__DRIdrawable *driDrawable,
       return;
 
    bo = gbm_dri_bo(dri2_surf->current->bo);
+
+   bpp = gbm_bo_get_bpp(&bo->base);
+   if (bpp == 0)
+      return;
+
+   x_bytes = x * (bpp >> 3);
+   width_bytes = width * (bpp >> 3);
+
    if (gbm_dri_bo_map_dumb(bo) == NULL)
       return;
 
    internal_stride = bo->base.stride;
 
+   dst = bo->map + x_bytes + (y * internal_stride);
+   src = data;
+
    for (int i = 0; i < height; i++) {
-      memcpy(bo->map + (x + i) * internal_stride + y,
-             data + i * stride, stride);
+      memcpy(dst, src, width_bytes);
+      dst += internal_stride;
+      src += stride;
    }
 
    gbm_dri_bo_unmap_dumb(bo);
@@ -564,20 +575,35 @@ swrast_get_image(__DRIdrawable *driDrawable,
    struct dri2_egl_surface *dri2_surf = loaderPrivate;
    int internal_stride, stride;
    struct gbm_dri_bo *bo;
+   uint32_t bpp;
+   int x_bytes, width_bytes;
+   char *src, *dst;
 
    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)
+
+   bpp = gbm_bo_get_bpp(&bo->base);
+   if (bpp == 0)
       return;
 
+   x_bytes = x * (bpp >> 3);
+   width_bytes = width * (bpp >> 3);
+
    internal_stride = bo->base.stride;
-   stride = width * 4;
+   stride = width_bytes;
+
+   if (gbm_dri_bo_map_dumb(bo) == NULL)
+      return;
+
+   dst = data;
+   src = bo->map + x_bytes + (y * internal_stride);
 
    for (int i = 0; i < height; i++) {
-      memcpy(data + i * stride,
-             bo->map + (x + i) * internal_stride + y, stride);
+      memcpy(dst, src, width_bytes);
+      dst += stride;
+      src += internal_stride;
    }
 
    gbm_dri_bo_unmap_dumb(bo);
@@ -598,12 +624,9 @@ drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
       { 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 = 0;
+   unsigned int config_count = 0;
 
    for (unsigned i = 0; dri2_dpy->driver_configs[i]; i++) {
       unsigned int red, alpha;
@@ -619,13 +642,16 @@ drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
          if (visuals[j].red_mask != red || visuals[j].alpha_mask != alpha)
             continue;
 
-         attr_list[1] = visuals[j].format;
+         const EGLint attr_list[] = {
+            EGL_NATIVE_VISUAL_ID,  visuals[j].format,
+            EGL_NONE,
+         };
 
          dri2_conf = dri2_add_config(disp, dri2_dpy->driver_configs[i],
-               count + 1, EGL_WINDOW_BIT, attr_list, NULL);
+               config_count + 1, EGL_WINDOW_BIT, attr_list, NULL);
          if (dri2_conf) {
-            if (dri2_conf->base.ConfigID == count + 1)
-               count++;
+            if (dri2_conf->base.ConfigID == config_count + 1)
+               config_count++;
             format_count[j]++;
          }
       }
@@ -638,7 +664,7 @@ drm_add_configs_for_visuals(_EGLDriver *drv, _EGLDisplay *disp)
       }
    }
 
-   return (count != 0);
+   return (config_count != 0);
 }
 
 static const struct dri2_egl_display_vtbl dri2_drm_display_vtbl = {