Merge commit 'origin/gallium-0.1'
[platform/upstream/mesa.git] / src / gallium / auxiliary / pipebuffer / pb_buffer.h
index 8505d33..e6b0b30 100644 (file)
@@ -37,7 +37,7 @@
  * There is no obligation of a winsys driver to use this library. And a pipe
  * driver should be completly agnostic about it.
  * 
- * \author Jos Fonseca <jrfonseca@tungstengraphics.com>
+ * \author Jose Fonseca <jrfonseca@tungstengraphics.com>
  */
 
 #ifndef PB_BUFFER_H_
@@ -45,7 +45,8 @@
 
 
 #include "pipe/p_compiler.h"
-#include "pipe/p_debug.h"
+#include "util/u_debug.h"
+#include "pipe/p_error.h"
 #include "pipe/p_state.h"
 #include "pipe/p_inlines.h"
 
@@ -56,6 +57,8 @@ extern "C" {
 
 
 struct pb_vtbl;
+struct pb_validate;
+
 
 /**
  * Buffer description.
@@ -104,6 +107,13 @@ struct pb_vtbl
    
    void (*unmap)( struct pb_buffer *buf );
 
+   enum pipe_error (*validate)( struct pb_buffer *buf, 
+                                struct pb_validate *vl,
+                                unsigned flags );
+
+   void (*fence)( struct pb_buffer *buf, 
+                  struct pipe_fence_handle *fence );
+
    /**
     * Get the base buffer and the offset.
     * 
@@ -118,6 +128,7 @@ struct pb_vtbl
    void (*get_base_buffer)( struct pb_buffer *buf,
                             struct pb_buffer **base_buf,
                             unsigned *offset );
+   
 };
 
 
@@ -148,6 +159,7 @@ pb_map(struct pb_buffer *buf,
    assert(buf);
    if(!buf)
       return NULL;
+   assert(buf->base.refcount > 0);
    return buf->vtbl->map(buf, flags);
 }
 
@@ -158,6 +170,7 @@ pb_unmap(struct pb_buffer *buf)
    assert(buf);
    if(!buf)
       return;
+   assert(buf->base.refcount > 0);
    buf->vtbl->unmap(buf);
 }
 
@@ -173,7 +186,33 @@ pb_get_base_buffer( struct pb_buffer *buf,
       offset = 0;
       return;
    }
+   assert(buf->base.refcount > 0);
+   assert(buf->vtbl->get_base_buffer);
    buf->vtbl->get_base_buffer(buf, base_buf, offset);
+   assert(*base_buf);
+   assert(*offset < (*base_buf)->base.size);
+}
+
+
+static INLINE enum pipe_error 
+pb_validate(struct pb_buffer *buf, struct pb_validate *vl, unsigned flags)
+{
+   assert(buf);
+   if(!buf)
+      return PIPE_ERROR;
+   assert(buf->vtbl->validate);
+   return buf->vtbl->validate(buf, vl, flags);
+}
+
+
+static INLINE void 
+pb_fence(struct pb_buffer *buf, struct pipe_fence_handle *fence)
+{
+   assert(buf);
+   if(!buf)
+      return;
+   assert(buf->vtbl->fence);
+   buf->vtbl->fence(buf, fence);
 }
 
 
@@ -183,6 +222,7 @@ pb_destroy(struct pb_buffer *buf)
    assert(buf);
    if(!buf)
       return;
+   assert(buf->base.refcount == 0);
    buf->vtbl->destroy(buf);
 }
 
@@ -193,11 +233,16 @@ static INLINE void
 pb_reference(struct pb_buffer **dst,
              struct pb_buffer *src)
 {
-   if (src) 
+   if (src) {
+      assert(src->base.refcount);
       src->base.refcount++;
+   }
 
-   if (*dst && --(*dst)->base.refcount == 0)
-      pb_destroy( *dst );
+   if (*dst) {
+      assert((*dst)->base.refcount);
+      if(--(*dst)->base.refcount == 0)
+         pb_destroy( *dst );
+   }
 
    *dst = src;
 }
@@ -210,7 +255,13 @@ pb_reference(struct pb_buffer **dst,
 static INLINE boolean
 pb_check_alignment(size_t requested, size_t provided)
 {
-   return requested <= provided && (provided % requested) == 0 ? TRUE : FALSE;
+   if(!requested)
+      return TRUE;
+   if(requested > provided)
+      return FALSE;
+   if(provided % requested != 0)
+      return FALSE;
+   return TRUE;
 }
 
 
@@ -234,10 +285,6 @@ pb_malloc_buffer_create(size_t size,
                         const struct pb_desc *desc);
 
 
-void 
-pb_init_winsys(struct pipe_winsys *winsys);
-
-
 #ifdef __cplusplus
 }
 #endif