vl: move dirty area handling into winsys abstraction
authorChristian König <deathsimple@vodafone.de>
Sat, 25 Feb 2012 11:26:37 +0000 (12:26 +0100)
committerChristian König <deathsimple@vodafone.de>
Thu, 1 Mar 2012 14:06:55 +0000 (15:06 +0100)
Fixing uninitialized areas in SwapBuffers mode.

Signed-off-by: Christian König <deathsimple@vodafone.de>
src/gallium/state_trackers/vdpau/presentation.c
src/gallium/state_trackers/vdpau/vdpau_private.h
src/gallium/state_trackers/xvmc/surface.c
src/gallium/state_trackers/xvmc/xvmc_private.h
src/gallium/winsys/g3dvl/dri/dri_winsys.c
src/gallium/winsys/g3dvl/vl_winsys.h
src/gallium/winsys/g3dvl/xlib/xsp_winsys.c

index e3ad03a2a51f0282b1a76b18bb482f6f518f87b1..37c5c695e4d0c94c118f97c5067c53ed15829660 100644 (file)
@@ -73,8 +73,6 @@ vlVdpPresentationQueueCreate(VdpDevice device,
       goto no_compositor;
    }
 
-   vl_compositor_reset_dirty_area(&pq->dirty_area);
-
    *presentation_queue = vlAddDataHTAB(pq);
    if (*presentation_queue == 0) {
       ret = VDP_STATUS_ERROR;
@@ -205,6 +203,7 @@ vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
    struct pipe_resource *tex;
    struct pipe_surface surf_templ, *surf_draw;
    struct pipe_video_rect src_rect, dst_clip;
+   struct u_rect *dirty_area;
 
    pq = vlGetDataHTAB(presentation_queue);
    if (!pq)
@@ -216,6 +215,8 @@ vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
    if (!tex)
       return VDP_STATUS_INVALID_HANDLE;
 
+   dirty_area = vl_screen_get_dirty_area(pq->device->vscreen);
+
    memset(&surf_templ, 0, sizeof(surf_templ));
    surf_templ.format = tex->format;
    surf_templ.usage = PIPE_BIND_RENDER_TARGET;
@@ -239,7 +240,7 @@ vlVdpPresentationQueueDisplay(VdpPresentationQueue presentation_queue,
 
    vl_compositor_clear_layers(&pq->compositor);
    vl_compositor_set_rgba_layer(&pq->compositor, 0, surf->sampler_view, &src_rect, NULL);
-   vl_compositor_render(&pq->compositor, surf_draw, NULL, &dst_clip, &pq->dirty_area);
+   vl_compositor_render(&pq->compositor, surf_draw, NULL, &dst_clip, dirty_area);
 
    pipe->screen->flush_frontbuffer
    (
index e02744ffd41394b1404b73bcfe3b43f5de9c0629..1645362444e278390491d33283abbfda0b30d655 100644 (file)
@@ -301,7 +301,6 @@ typedef struct
    vlVdpDevice *device;
    Drawable drawable;
    struct vl_compositor compositor;
-   struct u_rect dirty_area;
 } vlVdpPresentationQueue;
 
 typedef struct
index 8fc960723443ad192119065c619b02b077247a87..c6f6ef593b4956c2dd790b92536dc20ed3f30e69 100644 (file)
@@ -359,6 +359,7 @@ Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
 
    struct pipe_resource *tex;
    struct pipe_surface surf_templ, *surf;
+   struct u_rect *dirty_area;
 
    XVMC_MSG(XVMC_TRACE, "[XvMC] Displaying surface %p.\n", surface);
 
@@ -380,6 +381,8 @@ Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
    compositor = &context_priv->compositor;
 
    tex = vl_screen_texture_from_drawable(context_priv->vscreen, drawable);
+   dirty_area = vl_screen_get_dirty_area(context_priv->vscreen);
+
    memset(&surf_templ, 0, sizeof(surf_templ));
    surf_templ.format = tex->format;
    surf_templ.usage = PIPE_BIND_RENDER_TARGET;
@@ -427,7 +430,7 @@ Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
    // Workaround for r600g, there seems to be a bug in the fence refcounting code
    pipe->screen->fence_reference(pipe->screen, &surface_priv->fence, NULL);
 
-   vl_compositor_render(compositor, surf, &dst_rect, NULL, &context_priv->dirty_area);
+   vl_compositor_render(compositor, surf, &dst_rect, NULL, dirty_area);
 
    pipe->flush(pipe, &surface_priv->fence);
 
index 8242be9aea82f4bbb77dab700f7e360cfacf568b..4117f5bf68965649e2e0b176712bfc9ba39a6fa7 100644 (file)
@@ -35,7 +35,6 @@
 
 #include "util/u_debug.h"
 #include "util/u_math.h"
-#include "util/u_rect.h"
 
 #include "vl/vl_csc.h"
 #include "vl/vl_compositor.h"
@@ -62,8 +61,6 @@ typedef struct
    unsigned short subpicture_max_width;
    unsigned short subpicture_max_height;
 
-   struct u_rect dirty_area;
-
 } XvMCContextPrivate;
 
 typedef struct
index 096f068dbb497ba2caed76db153a4e695a7f5f98..c1e4a54bc49773f1c68d5742e8e516664a6e847a 100644 (file)
@@ -43,6 +43,7 @@
 #include "util/u_hash_table.h"
 #include "util/u_inlines.h"
 
+#include "vl/vl_compositor.h"
 #include "vl_winsys.h"
 
 struct vl_dri_screen
@@ -51,6 +52,12 @@ struct vl_dri_screen
    xcb_connection_t *conn;
    xcb_drawable_t drawable;
 
+   unsigned width, height;
+
+   bool current_buffer;
+   uint32_t buffer_names[2];
+   struct u_rect dirty_areas[2];
+
    bool flushed;
    xcb_dri2_swap_buffers_cookie_t swap_cookie;
    xcb_dri2_wait_sbc_cookie_t wait_cookie;
@@ -79,6 +86,8 @@ vl_dri2_flush_frontbuffer(struct pipe_screen *screen,
    scrn->swap_cookie = xcb_dri2_swap_buffers_unchecked(scrn->conn, scrn->drawable, 0, 0, 0, 0, 0, 0);
    scrn->wait_cookie = xcb_dri2_wait_sbc_unchecked(scrn->conn, scrn->drawable, 0, 0);
    scrn->buffers_cookie = xcb_dri2_get_buffers_unchecked(scrn->conn, scrn->drawable, 1, 1, attachments);
+
+   scrn->current_buffer = !scrn->current_buffer;
 }
 
 static void
@@ -113,6 +122,9 @@ vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable)
    if (scrn->drawable != drawable) {
       vl_dri2_destroy_drawable(scrn);
       xcb_dri2_create_drawable(scrn->conn, drawable);
+      scrn->current_buffer = false;
+      vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
+      vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);
       scrn->drawable = drawable;
 
       if (scrn->flushed) {
@@ -138,6 +150,17 @@ vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable)
 
    assert(reply->count == 1);
 
+   if (reply->width != scrn->width || reply->height != scrn->height) {
+      vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
+      vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);
+      scrn->width = reply->width;
+      scrn->height = reply->height;
+
+   } else if (buffers[0].name != scrn->buffer_names[scrn->current_buffer]) {
+      vl_compositor_reset_dirty_area(&scrn->dirty_areas[scrn->current_buffer]);
+      scrn->buffer_names[scrn->current_buffer] = buffers[0].name;
+   }
+
    memset(&dri2_front_handle, 0, sizeof(dri2_front_handle));
    dri2_front_handle.type = DRM_API_HANDLE_TYPE_SHARED;
    dri2_front_handle.handle = buffers[0].name;
@@ -161,6 +184,14 @@ vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable)
    return tex;
 }
 
+struct u_rect *
+vl_screen_get_dirty_area(struct vl_screen *vscreen)
+{
+   struct vl_dri_screen *scrn = (struct vl_dri_screen*)vscreen;
+   assert(scrn);
+   return &scrn->dirty_areas[scrn->current_buffer];
+}
+
 void*
 vl_screen_get_private(struct vl_screen *vscreen)
 {
@@ -234,6 +265,8 @@ vl_screen_create(Display *display, int screen)
       goto free_screen;
 
    scrn->base.pscreen->flush_frontbuffer = vl_dri2_flush_frontbuffer;
+   vl_compositor_reset_dirty_area(&scrn->dirty_areas[0]);
+   vl_compositor_reset_dirty_area(&scrn->dirty_areas[1]);
 
    free(dri2_query);
    free(connect);
index 3e7d771db2ff330242a129229ee4259adbd97eaf..281a391266d19efc10dc29ddfbf4991413469e33 100644 (file)
@@ -48,6 +48,9 @@ void vl_screen_destroy(struct vl_screen *vscreen);
 struct pipe_resource*
 vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable);
 
+struct u_rect *
+vl_screen_get_dirty_area(struct vl_screen *vscreen);
+
 void*
 vl_screen_get_private(struct vl_screen *vscreen);
 
index 6cd16bf46478661a7d318ad83faa7084caec0d93..a4f5326d8c0e4cd90fccac893633ba94e4ccf43a 100644 (file)
@@ -34,6 +34,7 @@
 #include "state_tracker/xlib_sw_winsys.h"
 #include "softpipe/sp_public.h"
 
+#include "vl/vl_compositor.h"
 #include "vl_winsys.h"
 
 struct vl_xsp_screen
@@ -44,6 +45,7 @@ struct vl_xsp_screen
    Visual visual;
    struct xlib_drawable xdraw;
    struct pipe_resource *tex;
+   struct u_rect dirty_area;
 };
 
 struct pipe_resource*
@@ -68,8 +70,8 @@ vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable)
    if (xsp_screen->tex) {
       if (xsp_screen->tex->width0 == width && xsp_screen->tex->height0 == height)
          return xsp_screen->tex;
-      else
-         pipe_resource_reference(&xsp_screen->tex, NULL);
+      pipe_resource_reference(&xsp_screen->tex, NULL);
+      vl_compositor_reset_dirty_area(&xsp_screen->dirty_area);
    }
 
    memset(&templat, 0, sizeof(struct pipe_resource));
@@ -91,6 +93,13 @@ vl_screen_texture_from_drawable(struct vl_screen *vscreen, Drawable drawable)
    return xsp_screen->tex;
 }
 
+struct u_rect *
+vl_screen_get_dirty_area(struct vl_screen *vscreen)
+{
+   struct vl_xsp_screen *xsp_screen = (struct vl_xsp_screen*)vscreen;
+   return &xsp_screen->dirty_area;
+}
+
 void*
 vl_screen_get_private(struct vl_screen *vscreen)
 {
@@ -126,6 +135,7 @@ vl_screen_create(Display *display, int screen)
    xsp_screen->display = display;
    xsp_screen->screen = screen;
    xsp_screen->xdraw.visual = XDefaultVisual(display, screen);
+   vl_compositor_reset_dirty_area(&xsp_screen->dirty_area);
 
    return &xsp_screen->base;
 }