gallium: Fix the ->set_damage_region() implementation
[mesa.git] / src / gallium / state_trackers / dri / drisw.c
index e24fcba3869a455d59c018f19c903acf00ceba33..bf7ee6f9471354c0fd6e4299299ffb31ecb1d6e5 100644 (file)
@@ -26,7 +26,7 @@
  *
  **************************************************************************/
 
-#include "util/u_format.h"
+#include "util/format/u_format.h"
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 #include "util/u_box.h"
@@ -42,7 +42,6 @@
 #include "dri_query_renderer.h"
 
 DEBUG_GET_ONCE_BOOL_OPTION(swrast_no_present, "SWRAST_NO_PRESENT", FALSE);
-static boolean swrast_no_present = FALSE;
 
 static inline void
 get_drawable_info(__DRIdrawable *dPriv, int *x, int *y, int *w, int *h)
@@ -80,15 +79,21 @@ put_image2(__DRIdrawable *dPriv, void *data, int x, int y,
 
 static inline void
 put_image_shm(__DRIdrawable *dPriv, int shmid, char *shmaddr,
-              unsigned offset, int x, int y,
+              unsigned offset, unsigned offset_x, int x, int y,
               unsigned width, unsigned height, unsigned stride)
 {
    __DRIscreen *sPriv = dPriv->driScreenPriv;
    const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
 
-   loader->putImageShm(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
-                       x, y, width, height, stride,
-                       shmid, shmaddr, offset, dPriv->loaderPrivate);
+   /* if we have the newer interface, don't have to add the offset_x here. */
+   if (loader->base.version > 4 && loader->putImageShm2)
+     loader->putImageShm2(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
+                          x, y, width, height, stride,
+                          shmid, shmaddr, offset, dPriv->loaderPrivate);
+   else
+     loader->putImageShm(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
+                         x, y, width, height, stride,
+                         shmid, shmaddr, offset + offset_x, dPriv->loaderPrivate);
 }
 
 static inline void
@@ -130,7 +135,7 @@ get_image_shm(__DRIdrawable *dPriv, int x, int y, int width, int height,
    if (loader->base.version < 4 || !loader->getImageShm)
       return FALSE;
 
-   if (!res->screen->resource_get_handle(res->screen, NULL, res, &whandle, PIPE_HANDLE_USAGE_WRITE))
+   if (!res->screen->resource_get_handle(res->screen, NULL, res, &whandle, PIPE_HANDLE_USAGE_FRAMEBUFFER_WRITE))
       return FALSE;
 
    loader->getImageShm(dPriv, x, y, width, height, whandle.handle, dPriv->loaderPrivate);
@@ -180,12 +185,13 @@ drisw_put_image2(struct dri_drawable *drawable,
 static inline void
 drisw_put_image_shm(struct dri_drawable *drawable,
                     int shmid, char *shmaddr, unsigned offset,
+                    unsigned offset_x,
                     int x, int y, unsigned width, unsigned height,
                     unsigned stride)
 {
    __DRIdrawable *dPriv = drawable->dPriv;
 
-   put_image_shm(dPriv, shmid, shmaddr, offset, x, y, width, height, stride);
+   put_image_shm(dPriv, shmid, shmaddr, offset, offset_x, x, y, width, height, stride);
 }
 
 static inline void
@@ -195,7 +201,7 @@ drisw_present_texture(__DRIdrawable *dPriv,
    struct dri_drawable *drawable = dri_drawable(dPriv);
    struct dri_screen *screen = dri_screen(drawable->sPriv);
 
-   if (swrast_no_present)
+   if (screen->swrast_no_present)
       return;
 
    screen->base.screen->flush_frontbuffer(screen->base.screen, ptex, 0, 0, drawable, sub_box);
@@ -240,6 +246,9 @@ drisw_swap_buffers(__DRIdrawable *dPriv)
       if (ctx->pp)
          pp_run(ctx->pp, ptex, ptex, drawable->textures[ST_ATTACHMENT_DEPTH_STENCIL]);
 
+      if (ctx->hud)
+         hud_run(ctx->hud, ctx->st->cso_context, ptex);
+
       ctx->st->flush(ctx->st, ST_FLUSH_FRONT, NULL);
 
       drisw_copy_to_front(dPriv, ptex);
@@ -338,7 +347,7 @@ drisw_allocate_textures(struct dri_context *stctx,
       dri_drawable_get_format(drawable, statts[i], &format, &bind);
 
       /* if we don't do any present, no need for display targets */
-      if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !swrast_no_present)
+      if (statts[i] != ST_ATTACHMENT_DEPTH_STENCIL && !screen->swrast_no_present)
          bind |= PIPE_BIND_DISPLAY_TARGET;
 
       if (format == PIPE_FORMAT_NONE)
@@ -422,12 +431,19 @@ static const __DRIextension *drisw_screen_extensions[] = {
    NULL
 };
 
-static struct drisw_loader_funcs drisw_lf = {
+static const struct drisw_loader_funcs drisw_lf = {
    .get_image = drisw_get_image,
    .put_image = drisw_put_image,
    .put_image2 = drisw_put_image2
 };
 
+static const struct drisw_loader_funcs drisw_shm_lf = {
+   .get_image = drisw_get_image,
+   .put_image = drisw_put_image,
+   .put_image2 = drisw_put_image2,
+   .put_image_shm = drisw_put_image_shm
+};
+
 static const __DRIconfig **
 drisw_init_screen(__DRIscreen * sPriv)
 {
@@ -435,6 +451,7 @@ drisw_init_screen(__DRIscreen * sPriv)
    const __DRIconfig **configs;
    struct dri_screen *screen;
    struct pipe_screen *pscreen = NULL;
+   const struct drisw_loader_funcs *lf = &drisw_lf;
 
    screen = CALLOC_STRUCT(dri_screen);
    if (!screen)
@@ -443,16 +460,16 @@ drisw_init_screen(__DRIscreen * sPriv)
    screen->sPriv = sPriv;
    screen->fd = -1;
 
-   swrast_no_present = debug_get_option_swrast_no_present();
+   screen->swrast_no_present = debug_get_option_swrast_no_present();
 
    sPriv->driverPrivate = (void *)screen;
    sPriv->extensions = drisw_screen_extensions;
    if (loader->base.version >= 4) {
       if (loader->putImageShm)
-         drisw_lf.put_image_shm = drisw_put_image_shm;
+         lf = &drisw_shm_lf;
    }
 
-   if (pipe_loader_sw_probe_dri(&screen->dev, &drisw_lf)) {
+   if (pipe_loader_sw_probe_dri(&screen->dev, lf)) {
       dri_init_options(screen);
 
       pscreen = pipe_loader_create_screen(screen->dev);