Merge branch 'mesa_7_6_branch'
[mesa.git] / src / gallium / drivers / softpipe / sp_context.c
index d8a5631488f9029254ba5933ab5a74552c487149..c699c433e9c2fb7ded72111baeeeb53aed85480d 100644 (file)
@@ -32,7 +32,6 @@
 
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
-#include "pipe/p_inlines.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
 #include "sp_clear.h"
  * Map any drawing surfaces which aren't already mapped
  */
 void
-softpipe_map_surfaces(struct softpipe_context *sp)
+softpipe_map_transfers(struct softpipe_context *sp)
 {
    unsigned i;
 
    for (i = 0; i < sp->framebuffer.nr_cbufs; i++) {
-      sp_tile_cache_map_surfaces(sp->cbuf_cache[i]);
+      sp_tile_cache_map_transfers(sp->cbuf_cache[i]);
    }
 
-   sp_tile_cache_map_surfaces(sp->zsbuf_cache);
+   sp_tile_cache_map_transfers(sp->zsbuf_cache);
 }
 
 
@@ -69,7 +68,7 @@ softpipe_map_surfaces(struct softpipe_context *sp)
  * Unmap any mapped drawing surfaces
  */
 void
-softpipe_unmap_surfaces(struct softpipe_context *sp)
+softpipe_unmap_transfers(struct softpipe_context *sp)
 {
    uint i;
 
@@ -78,16 +77,16 @@ softpipe_unmap_surfaces(struct softpipe_context *sp)
    sp_flush_tile_cache(sp, sp->zsbuf_cache);
 
    for (i = 0; i < sp->framebuffer.nr_cbufs; i++) {
-      sp_tile_cache_unmap_surfaces(sp->cbuf_cache[i]);
+      sp_tile_cache_unmap_transfers(sp->cbuf_cache[i]);
    }
-   sp_tile_cache_unmap_surfaces(sp->zsbuf_cache);
+   sp_tile_cache_unmap_transfers(sp->zsbuf_cache);
 }
 
 
-static void softpipe_destroy( struct pipe_context *pipe )
+static void
+softpipe_destroy( struct pipe_context *pipe )
 {
    struct softpipe_context *softpipe = softpipe_context( pipe );
-   struct pipe_winsys *ws = pipe->winsys;
    uint i;
 
    if (softpipe->draw)
@@ -116,7 +115,7 @@ static void softpipe_destroy( struct pipe_context *pipe )
 
    for (i = 0; i < Elements(softpipe->constants); i++) {
       if (softpipe->constants[i].buffer) {
-         winsys_buffer_reference(ws, &softpipe->constants[i].buffer, NULL);
+         pipe_buffer_reference(&softpipe->constants[i].buffer, NULL);
       }
    }
 
@@ -124,10 +123,51 @@ static void softpipe_destroy( struct pipe_context *pipe )
 }
 
 
+/**
+ * if (the texture is being used as a framebuffer surface)
+ *    return PIPE_REFERENCED_FOR_WRITE
+ * else if (the texture is a bound texture source)
+ *    return PIPE_REFERENCED_FOR_READ  XXX not done yet
+ * else
+ *    return PIPE_UNREFERENCED
+ */
+static unsigned int
+softpipe_is_texture_referenced( struct pipe_context *pipe,
+                               struct pipe_texture *texture,
+                               unsigned face, unsigned level)
+{
+   struct softpipe_context *softpipe = softpipe_context( pipe );
+   unsigned i;
+
+   if (softpipe->dirty_render_cache) {
+      for (i = 0; i < softpipe->framebuffer.nr_cbufs; i++) {
+         if (softpipe->framebuffer.cbufs[i] && 
+             softpipe->framebuffer.cbufs[i]->texture == texture) {
+            return PIPE_REFERENCED_FOR_WRITE;
+         }
+      }
+      if (softpipe->framebuffer.zsbuf && 
+          softpipe->framebuffer.zsbuf->texture == texture) {
+         return PIPE_REFERENCED_FOR_WRITE;
+      }
+   }
+   
+   /* FIXME: we also need to do the same for the texture cache */
+   
+   return PIPE_UNREFERENCED;
+}
+
+
+static unsigned int
+softpipe_is_buffer_referenced( struct pipe_context *pipe,
+                              struct pipe_buffer *buf)
+{
+   return PIPE_UNREFERENCED;
+}
+
+
 struct pipe_context *
-softpipe_create( struct pipe_screen *screen,
-                 struct pipe_winsys *pipe_winsys,
-                 void *unused )
+softpipe_create( struct pipe_screen *screen )
 {
    struct softpipe_context *softpipe = CALLOC_STRUCT(softpipe_context);
    uint i;
@@ -142,7 +182,7 @@ softpipe_create( struct pipe_screen *screen,
 
    softpipe->dump_fs = debug_get_bool_option( "GALLIUM_DUMP_FS", FALSE );
 
-   softpipe->pipe.winsys = pipe_winsys;
+   softpipe->pipe.winsys = screen->winsys;
    softpipe->pipe.screen = screen;
    softpipe->pipe.destroy = softpipe_destroy;
 
@@ -192,8 +232,10 @@ softpipe_create( struct pipe_screen *screen,
    softpipe->pipe.clear = softpipe_clear;
    softpipe->pipe.flush = softpipe_flush;
 
+   softpipe->pipe.is_texture_referenced = softpipe_is_texture_referenced;
+   softpipe->pipe.is_buffer_referenced = softpipe_is_buffer_referenced;
+
    softpipe_init_query_funcs( softpipe );
-   softpipe_init_texture_funcs( softpipe );
 
    /*
     * Alloc caches for accessing drawing surfaces and textures.