i965: Untested Sandybridge SF setup.
[mesa.git] / src / mesa / drivers / dri / intel / intel_regions.c
index 61aefa01b8a184b38e76c6536096e72ee469de37..f63d3a40825db9e76089f0a254ccd587488e6f64 100644 (file)
 #include <sys/ioctl.h>
 #include <errno.h>
 
+#include "main/hash.h"
 #include "intel_context.h"
 #include "intel_regions.h"
 #include "intel_blit.h"
 #include "intel_buffer_objects.h"
 #include "intel_bufmgr.h"
 #include "intel_batchbuffer.h"
-#include "intel_chipset.h"
 
 #define FILE_DEBUG_FLAG DEBUG_REGION
 
@@ -229,10 +229,24 @@ intel_region_alloc_for_handle(struct intel_context *intel,
                              GLuint width, GLuint height, GLuint pitch,
                              GLuint handle, const char *name)
 {
-   struct intel_region *region;
+   struct intel_region *region, *dummy;
    dri_bo *buffer;
    int ret;
 
+   region = _mesa_HashLookup(intel->intelScreen->named_regions, handle);
+   if (region != NULL) {
+      dummy = NULL;
+      if (region->width != width || region->height != height ||
+         region->cpp != cpp || region->pitch != pitch) {
+        fprintf(stderr,
+                "Region for name %d already exists but is not compatible\n",
+                handle);
+        return NULL;
+      }
+      intel_region_reference(&dummy, region);
+      return dummy;
+   }
+
    buffer = intel_bo_gem_create_from_name(intel->bufmgr, name, handle);
 
    region = intel_region_alloc_internal(intel, cpp,
@@ -249,6 +263,10 @@ intel_region_alloc_for_handle(struct intel_context *intel,
       return NULL;
    }
 
+   region->name = handle;
+   region->screen = intel->intelScreen;
+   _mesa_HashInsert(intel->intelScreen->named_regions, handle, region);
+
    return region;
 }
 
@@ -288,10 +306,8 @@ intel_region_release(struct intel_region **region_handle)
       region->pbo = NULL;
       dri_bo_unreference(region->buffer);
 
-      if (region->classic_map != NULL) {
-        drmUnmap(region->classic_map,
-                       region->pitch * region->cpp * region->height);
-      }
+      if (region->name > 0)
+        _mesa_HashRemove(region->screen->named_regions, region->name);
 
       free(region);
    }
@@ -362,6 +378,8 @@ intel_region_data(struct intel_context *intel,
          intel_region_cow(intel, dst);
    }
 
+   intel_prepare_render(intel);
+
    _mesa_copy_rect(intel_region_map(intel, dst) + dst_offset,
                    dst->cpp,
                    dst->pitch,
@@ -443,6 +461,7 @@ intel_region_attach_pbo(struct intel_context *intel,
    region->pbo->region = region;
    dri_bo_reference(buffer);
    region->buffer = buffer;
+   region->tiling = I915_TILING_NONE;
 }
 
 
@@ -483,6 +502,7 @@ intel_region_cow(struct intel_context *intel, struct intel_region *region)
    /* Now blit from the texture buffer to the new buffer: 
     */
 
+   intel_prepare_render(intel);
    ok = intelEmitCopyBlit(intel,
                           region->cpp,
                           region->pitch, pbo->buffer, 0, region->tiling,