Merge commit 'origin/gallium-0.2' into gallium-xlib-rework
[mesa.git] / src / mesa / drivers / dri / intel / intel_regions.c
index 91b835d1aade5672bcdd5403d00c1558e9afa780..51ce32a96796325ae21dd25fa701f862b547fbbd 100644 (file)
@@ -46,7 +46,6 @@
 #include "intel_regions.h"
 #include "intel_blit.h"
 #include "intel_buffer_objects.h"
-#include "dri_bufmgr.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
 #include "intel_chipset.h"
@@ -80,33 +79,10 @@ intel_region_unmap(struct intel_context *intel, struct intel_region *region)
    }
 }
 
-static int
-intel_set_region_tiling_gem(struct intel_context *intel,
-                           struct intel_region *region,
-                           uint32_t bo_handle)
-{
-   struct drm_i915_gem_get_tiling get_tiling;
-   int ret;
-
-   memset(&get_tiling, 0, sizeof(get_tiling));
-
-   get_tiling.handle = bo_handle;
-   ret = ioctl(intel->driFd, DRM_IOCTL_I915_GEM_GET_TILING, &get_tiling);
-   if (ret != 0) {
-      fprintf(stderr, "Failed to get tiling state for region: %s\n",
-             strerror(errno));
-      return ret;
-   }
-
-   region->tiling = get_tiling.tiling_mode;
-   region->bit_6_swizzle = get_tiling.swizzle_mode;
-
-   return 0;
-}
-
 static struct intel_region *
 intel_region_alloc_internal(struct intel_context *intel,
-                           GLuint cpp, GLuint pitch, GLuint height,
+                           GLuint cpp,
+                           GLuint width, GLuint height, GLuint pitch,
                            dri_bo *buffer)
 {
    struct intel_region *region;
@@ -118,8 +94,9 @@ intel_region_alloc_internal(struct intel_context *intel,
 
    region = calloc(sizeof(*region), 1);
    region->cpp = cpp;
+   region->width = width;
+   region->height = height;
    region->pitch = pitch;
-   region->height = height;     /* needed? */
    region->refcount = 1;
    region->buffer = buffer;
 
@@ -132,31 +109,41 @@ intel_region_alloc_internal(struct intel_context *intel,
 
 struct intel_region *
 intel_region_alloc(struct intel_context *intel,
-                   GLuint cpp, GLuint pitch, GLuint height)
+                   GLuint cpp, GLuint width, GLuint height, GLuint pitch)
 {
    dri_bo *buffer;
 
    buffer = dri_bo_alloc(intel->bufmgr, "region",
                         pitch * cpp * height, 64);
 
-   return intel_region_alloc_internal(intel, cpp, pitch, height, buffer);
+   return intel_region_alloc_internal(intel, cpp, width, height, pitch, buffer);
 }
 
 struct intel_region *
 intel_region_alloc_for_handle(struct intel_context *intel,
-                             GLuint cpp, GLuint pitch, GLuint height,
-                             GLuint handle)
+                             GLuint cpp,
+                             GLuint width, GLuint height, GLuint pitch,
+                             GLuint handle, const char *name)
 {
    struct intel_region *region;
    dri_bo *buffer;
+   int ret;
 
-   buffer = intel_bo_gem_create_from_name(intel->bufmgr, "dri2 region", handle);
+   buffer = intel_bo_gem_create_from_name(intel->bufmgr, name, handle);
 
-   region = intel_region_alloc_internal(intel, cpp, pitch, height, buffer);
+   region = intel_region_alloc_internal(intel, cpp,
+                                       width, height, pitch, buffer);
    if (region == NULL)
       return region;
 
-   intel_set_region_tiling_gem(intel, region, handle);
+   ret = dri_bo_get_tiling(region->buffer, &region->tiling,
+                          &region->bit_6_swizzle);
+   if (ret != 0) {
+      fprintf(stderr, "Couldn't get tiling of buffer %d (%s): %s\n",
+             handle, name, strerror(-ret));
+      intel_region_release(&region);
+      return NULL;
+   }
 
    return region;
 }
@@ -164,6 +151,9 @@ intel_region_alloc_for_handle(struct intel_context *intel,
 void
 intel_region_reference(struct intel_region **dst, struct intel_region *src)
 {
+   if (src)
+      DBG("%s %d\n", __FUNCTION__, src->refcount);
+
    assert(*dst == NULL);
    if (src) {
       src->refcount++;
@@ -455,8 +445,7 @@ static struct intel_region *
 intel_recreate_static(struct intel_context *intel,
                      const char *name,
                      struct intel_region *region,
-                     intelRegion *region_desc,
-                     GLuint mem_type)
+                     intelRegion *region_desc)
 {
    intelScreenPrivate *intelScreen = intel->intelScreen;
    int ret;
@@ -473,14 +462,31 @@ intel_recreate_static(struct intel_context *intel,
    region->pitch = intelScreen->pitch;
    region->height = intelScreen->height;     /* needed? */
 
+   if (region->buffer != NULL) {
+      dri_bo_unreference(region->buffer);
+      region->buffer = NULL;
+   }
+
    if (intel->ttm) {
       assert(region_desc->bo_handle != -1);
       region->buffer = intel_bo_gem_create_from_name(intel->bufmgr,
                                                     name,
                                                     region_desc->bo_handle);
 
-      intel_set_region_tiling_gem(intel, region, region_desc->bo_handle);
+      ret = dri_bo_get_tiling(region->buffer, &region->tiling,
+                             &region->bit_6_swizzle);
+      if (ret != 0) {
+        fprintf(stderr, "Couldn't get tiling of buffer %d (%s): %s\n",
+                region_desc->bo_handle, name, strerror(-ret));
+        intel_region_release(&region);
+        return NULL;
+      }
    } else {
+      if (region->classic_map != NULL) {
+        drmUnmap(region->classic_map,
+                 region->pitch * region->cpp * region->height);
+        region->classic_map = NULL;
+      }
       ret = drmMap(intel->driFd, region_desc->handle,
                   region->pitch * region->cpp * region->height,
                   &region->classic_map);
@@ -537,24 +543,12 @@ intel_recreate_static_regions(struct intel_context *intel)
    intel->front_region =
       intel_recreate_static(intel, "front",
                            intel->front_region,
-                           &intelScreen->front,
-                           DRM_BO_FLAG_MEM_TT);
+                           &intelScreen->front);
 
    intel->back_region =
       intel_recreate_static(intel, "back",
                            intel->back_region,
-                           &intelScreen->back,
-                           DRM_BO_FLAG_MEM_TT);
-
-#ifdef I915
-   if (intelScreen->third.handle) {
-      intel->third_region =
-        intel_recreate_static(intel, "third",
-                              intel->third_region,
-                              &intelScreen->third,
-                              DRM_BO_FLAG_MEM_TT);
-   }
-#endif /* I915 */
+                           &intelScreen->back);
 
    /* Still assumes front.cpp == depth.cpp.  We can kill this when we move to
     * private buffers.
@@ -562,6 +556,5 @@ intel_recreate_static_regions(struct intel_context *intel)
    intel->depth_region =
       intel_recreate_static(intel, "depth",
                            intel->depth_region,
-                           &intelScreen->depth,
-                           DRM_BO_FLAG_MEM_TT);
+                           &intelScreen->depth);
 }