Merge branch 'mesa_7_6_branch' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / gallium / winsys / drm / radeon / core / radeon_buffer.c
index 0d0fdc5bd86e17db44d4b6446ac2070e4cb2f007..7bf23cba236520c0749b511e487de47b72ce86d1 100644 (file)
@@ -1,8 +1,8 @@
-/* 
+/*
  * Copyright © 2008 Jérôme Glisse
  *             2009 Corbin Simpson
  * All Rights Reserved.
- * 
+ *
  * 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
  * 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 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 COPYRIGHT HOLDERS, AUTHORS
  * AND/OR ITS 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 
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  *
  * The above copyright notice and this permission notice (including the
@@ -32,6 +32,8 @@
 
 #include "radeon_buffer.h"
 
+#include "radeon_bo_gem.h"
+
 static const char *radeon_get_name(struct pipe_winsys *ws)
 {
     return "Radeon/GEM+KMS";
@@ -72,6 +74,7 @@ static struct pipe_buffer *radeon_buffer_create(struct pipe_winsys *ws,
             alignment, domain, 0);
     if (radeon_buffer->bo == NULL) {
         FREE(radeon_buffer);
+        return NULL;
     }
     return &radeon_buffer->base;
 }
@@ -98,6 +101,7 @@ static struct pipe_buffer *radeon_surface_buffer_create(struct pipe_winsys *ws,
                                                         unsigned height,
                                                         enum pipe_format format,
                                                         unsigned usage,
+                                                        unsigned tex_usage,
                                                         unsigned *stride)
 {
     struct pipe_format_block block;
@@ -134,15 +138,19 @@ static void *radeon_buffer_map(struct pipe_winsys *ws,
     int write = 0;
 
     if (flags & PIPE_BUFFER_USAGE_DONTBLOCK) {
-       /* XXX Remove this when radeon_bo_map supports DONTBLOCK */
-       return NULL;
+        uint32_t domain;
+
+        if (radeon_bo_is_busy(radeon_buffer->bo, &domain))
+            return NULL;
     }
     if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) {
         write = 1;
     }
 
-    if (radeon_bo_map(radeon_buffer->bo, write))
+    if (radeon_bo_map(radeon_buffer->bo, write)) {
         return NULL;
+    }
+
     return radeon_buffer->bo->ptr;
 }
 
@@ -185,7 +193,6 @@ static void radeon_flush_frontbuffer(struct pipe_winsys *pipe_winsys,
 struct radeon_winsys* radeon_pipe_winsys(int fd)
 {
     struct radeon_winsys* radeon_ws;
-    struct radeon_bo_manager* bom;
 
     radeon_ws = CALLOC_STRUCT(radeon_winsys);
     if (radeon_ws == NULL) {
@@ -198,6 +205,7 @@ struct radeon_winsys* radeon_pipe_winsys(int fd)
         return NULL;
     }
 
+    radeon_ws->priv->fd = fd;
     radeon_ws->priv->bom = radeon_bo_manager_gem_ctor(fd);
 
     radeon_ws->base.flush_frontbuffer = radeon_flush_frontbuffer;