st/xorg: bind rasterizer state
[mesa.git] / src / gallium / state_trackers / g3dvl / vl_surface.c
index ffc81221728271b2f041ea105f92b8ba27ea109e..7f60852cae8c7a52f9d49aaeb20a6041c76f334b 100644 (file)
@@ -1,11 +1,11 @@
 #define VL_INTERNAL
 #include "vl_surface.h"
 #include <assert.h>
-#include <stdlib.h>
 #include <string.h>
 #include <pipe/p_screen.h>
 #include <pipe/p_state.h>
 #include <pipe/p_inlines.h>
+#include <util/u_memory.h>
 #include <vl_winsys.h>
 #include "vl_screen.h"
 #include "vl_context.h"
@@ -28,7 +28,7 @@ int vlCreateSurface
        assert(screen);
        assert(surface);
 
-       sfc = calloc(1, sizeof(struct vlSurface));
+       sfc = CALLOC_STRUCT(vlSurface);
 
        if (!sfc)
                return 1;
@@ -45,12 +45,17 @@ int vlCreateSurface
        template.width[0] = vlRoundUpPOT(sfc->width);
        template.height[0] = vlRoundUpPOT(sfc->height);
        template.depth[0] = 1;
-       template.compressed = 0;
        pf_get_block(template.format, &template.block);
        template.tex_usage = PIPE_TEXTURE_USAGE_SAMPLER | PIPE_TEXTURE_USAGE_RENDER_TARGET;
 
        sfc->texture = vlGetPipeScreen(screen)->texture_create(vlGetPipeScreen(screen), &template);
 
+       if (!sfc->texture)
+       {
+               FREE(sfc);
+               return 1;
+       }
+
        *surface = sfc;
 
        return 0;
@@ -63,8 +68,8 @@ int vlDestroySurface
 {
        assert(surface);
 
-       pipe_texture_release(&surface->texture);
-       free(surface);
+       pipe_texture_reference(&surface->texture, NULL);
+       FREE(surface);
 
        return 0;
 }
@@ -77,6 +82,7 @@ int vlRenderMacroBlocksMpeg2
 {
        assert(batch);
        assert(surface);
+       assert(surface->context);
 
        surface->context->render->vlBegin(surface->context->render);
 
@@ -104,6 +110,8 @@ int vlPutPicture
        int desty,
        int destw,
        int desth,
+       int drawable_w,
+       int drawable_h,
        enum vlPictureType picture_type
 )
 {
@@ -113,10 +121,12 @@ int vlPutPicture
        assert(surface);
        assert(surface->context);
 
+       surface->context->render->vlFlush(surface->context->render);
+
        csc = surface->context->csc;
        pipe = surface->context->pipe;
 
-       csc->vlResizeFrameBuffer(csc, destw, desth);
+       csc->vlResizeFrameBuffer(csc, drawable_w, drawable_h);
 
        csc->vlBegin(csc);
 
@@ -137,12 +147,13 @@ int vlPutPicture
 
        csc->vlEnd(csc);
 
-       pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, NULL);
+       pipe->flush(pipe, PIPE_FLUSH_RENDER_CACHE, &surface->disp_fence);
+
        bind_pipe_drawable(pipe, drawable);
-       /* TODO: Need to take destx, desty into consideration */
-       pipe->winsys->flush_frontbuffer
+
+       pipe->screen->flush_frontbuffer
        (
-               pipe->winsys,
+               pipe->screen,
                csc->vlGetFrameBuffer(csc),
                pipe->priv
        );
@@ -150,6 +161,60 @@ int vlPutPicture
        return 0;
 }
 
+int vlSurfaceGetStatus
+(
+       struct vlSurface *surface,
+       enum vlResourceStatus *status
+)
+{
+       assert(surface);
+       assert(surface->context);
+       assert(status);
+
+       if (surface->render_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->render_fence, 0))
+       {
+               *status = vlResourceStatusRendering;
+               return 0;
+       }
+
+       if (surface->disp_fence && !surface->context->pipe->screen->fence_signalled(surface->context->pipe->screen, surface->disp_fence, 0))
+       {
+               *status = vlResourceStatusDisplaying;
+               return 0;
+       }
+
+       *status = vlResourceStatusFree;
+
+       return 0;
+}
+
+int vlSurfaceFlush
+(
+       struct vlSurface *surface
+)
+{
+       assert(surface);
+       assert(surface->context);
+
+       surface->context->render->vlFlush(surface->context->render);
+
+       return 0;
+}
+
+int vlSurfaceSync
+(
+       struct vlSurface *surface
+)
+{
+       assert(surface);
+       assert(surface->context);
+       assert(surface->render_fence);
+
+       surface->context->pipe->screen->fence_finish(surface->context->pipe->screen, surface->render_fence, 0);
+
+       return 0;
+}
+
 struct vlScreen* vlSurfaceGetScreen
 (
        struct vlSurface *surface