Merge branch 'lp-offset-twoside'
[mesa.git] / src / gallium / winsys / r600 / drm / radeon_bo_pb.c
index 897938c2cafd4dba08f758d870633df1f286cd25..312552f07589717dedda92406043fe1dc14edef3 100644 (file)
@@ -1,10 +1,34 @@
-#include "radeon_priv.h"
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-#include "util/u_double_list.h"
-#include "pipebuffer/pb_buffer.h"
-#include "pipebuffer/pb_bufmgr.h"
+/*
+ * Copyright 2010 Dave Airlie
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Authors:
+ *      Dave Airlie
+ */
+#include <util/u_inlines.h>
+#include <util/u_memory.h>
+#include <util/u_double_list.h>
+#include <pipebuffer/pb_buffer.h>
+#include <pipebuffer/pb_bufmgr.h>
+#include "r600_priv.h"
 
 struct radeon_bo_pb {
        struct pb_buffer b;
@@ -39,11 +63,13 @@ static void radeon_bo_pb_destroy(struct pb_buffer *_buf)
 {
        struct radeon_bo_pb *buf = radeon_bo_pb(_buf);
 
-       LIST_DEL(&buf->maplist);
-
-       if (buf->bo->data != NULL) {
+       /* If this buffer is on the list of buffers to unmap,
+        * do the unmapping now.
+        */
+       if (!LIST_IS_EMPTY(&buf->maplist))
                radeon_bo_unmap(buf->mgr->radeon, buf->bo);
-       }
+
+       LIST_DEL(&buf->maplist);
        radeon_bo_reference(buf->mgr->radeon, &buf->bo, NULL);
        FREE(buf);
 }
@@ -56,7 +82,7 @@ radeon_bo_pb_map_internal(struct pb_buffer *_buf,
        struct pipe_context *pctx = ctx;
 
        if (flags & PB_USAGE_UNSYNCHRONIZED) {
-               if (!buf->bo->data && radeon_bo_map(buf->mgr->radeon, buf->bo)) {
+               if (radeon_bo_map(buf->mgr->radeon, buf->bo)) {
                        return NULL;
                }
                LIST_DELINIT(&buf->maplist);
@@ -76,22 +102,20 @@ radeon_bo_pb_map_internal(struct pb_buffer *_buf,
                uint32_t domain;
                if (radeon_bo_busy(buf->mgr->radeon, buf->bo, &domain))
                        return NULL;
-       }
-
-       if (buf->bo->data != NULL) {
-               if (radeon_bo_wait(buf->mgr->radeon, buf->bo)) {
-                       return NULL;
-               }
-       } else {
                if (radeon_bo_map(buf->mgr->radeon, buf->bo)) {
                        return NULL;
                }
-               if (radeon_bo_wait(buf->mgr->radeon, buf->bo)) {
-                       radeon_bo_unmap(buf->mgr->radeon, buf->bo);
-                       return NULL;
-               }
+               goto out;
        }
 
+       if (radeon_bo_map(buf->mgr->radeon, buf->bo)) {
+               return NULL;
+       }
+       if (radeon_bo_wait(buf->mgr->radeon, buf->bo)) {
+               radeon_bo_unmap(buf->mgr->radeon, buf->bo);
+               return NULL;
+       }
+out:
        LIST_DELINIT(&buf->maplist);
        return buf->bo->data;
 }
@@ -144,7 +168,7 @@ radeon_bo_pb_create_buffer_from_handle(struct pb_manager *_mgr,
        struct radeon_bo_pb *bo;
        struct radeon_bo *hw_bo;
 
-       hw_bo = radeon_bo(radeon, handle, 0, 0, NULL);
+       hw_bo = radeon_bo(radeon, handle, 0, 0);
        if (hw_bo == NULL)
                return NULL;
 
@@ -175,7 +199,6 @@ radeon_bo_pb_create_buffer(struct pb_manager *_mgr,
        struct radeon_bo_pbmgr *mgr = radeon_bo_pbmgr(_mgr);
        struct radeon *radeon = mgr->radeon;
        struct radeon_bo_pb *bo;
-       uint32_t domain;
 
        bo = CALLOC_STRUCT(radeon_bo_pb);
        if (!bo)
@@ -190,8 +213,7 @@ radeon_bo_pb_create_buffer(struct pb_manager *_mgr,
 
        LIST_INITHEAD(&bo->maplist);
 
-       bo->bo = radeon_bo(radeon, 0, size,
-                          desc->alignment, NULL);
+       bo->bo = radeon_bo(radeon, 0, size, desc->alignment);
        if (bo->bo == NULL)
                goto error2;
        return &bo->b;