intel: Check for region allocation failure.
[mesa.git] / src / mesa / drivers / dri / intel / intel_regions.c
index 193bbf6038b983d733f6192741439d8e7f3fde1d..680d18ba2999eac1f6c5c379a36091f6838f1b3a 100644 (file)
@@ -111,7 +111,7 @@ debug_backtrace(void)
 GLubyte *
 intel_region_map(struct intel_context *intel, struct intel_region *region)
 {
-   intelFlush(&intel->ctx);
+   intel_flush(&intel->ctx);
 
    _DBG("%s %p\n", __FUNCTION__, region);
    if (!region->map_refcount++) {
@@ -121,7 +121,7 @@ intel_region_map(struct intel_context *intel, struct intel_region *region)
       if (region->tiling != I915_TILING_NONE)
         drm_intel_gem_bo_map_gtt(region->buffer);
       else
-        dri_bo_map(region->buffer, GL_TRUE);
+        drm_intel_bo_map(region->buffer, GL_TRUE);
       region->map = region->buffer->virtual;
    }
 
@@ -136,7 +136,7 @@ intel_region_unmap(struct intel_context *intel, struct intel_region *region)
       if (region->tiling != I915_TILING_NONE)
         drm_intel_gem_bo_unmap_gtt(region->buffer);
       else
-        dri_bo_unmap(region->buffer);
+        drm_intel_bo_unmap(region->buffer);
       region->map = NULL;
    }
 }
@@ -145,7 +145,7 @@ static struct intel_region *
 intel_region_alloc_internal(struct intel_context *intel,
                            GLuint cpp,
                            GLuint width, GLuint height, GLuint pitch,
-                           dri_bo *buffer)
+                           drm_intel_bo *buffer)
 {
    struct intel_region *region;
 
@@ -155,6 +155,9 @@ intel_region_alloc_internal(struct intel_context *intel,
    }
 
    region = calloc(sizeof(*region), 1);
+   if (region == NULL)
+      return region;
+
    region->cpp = cpp;
    region->width = width;
    region->height = height;
@@ -175,7 +178,7 @@ intel_region_alloc(struct intel_context *intel,
                    GLuint cpp, GLuint width, GLuint height,
                   GLboolean expect_accelerated_upload)
 {
-   dri_bo *buffer;
+   drm_intel_bo *buffer;
    struct intel_region *region;
    unsigned long flags = 0;
    unsigned long aligned_pitch;
@@ -189,6 +192,9 @@ intel_region_alloc(struct intel_context *intel,
 
    region = intel_region_alloc_internal(intel, cpp, width, height,
                                        aligned_pitch / cpp, buffer);
+   if (region == NULL)
+      return region;
+
    region->tiling = tiling;
 
    return region;
@@ -201,7 +207,7 @@ intel_region_alloc_for_handle(struct intel_context *intel,
                              GLuint handle, const char *name)
 {
    struct intel_region *region, *dummy;
-   dri_bo *buffer;
+   drm_intel_bo *buffer;
    int ret;
    uint32_t bit_6_swizzle;
 
@@ -226,8 +232,8 @@ intel_region_alloc_for_handle(struct intel_context *intel,
    if (region == NULL)
       return region;
 
-   ret = dri_bo_get_tiling(region->buffer, &region->tiling,
-                          &bit_6_swizzle);
+   ret = drm_intel_bo_get_tiling(region->buffer, &region->tiling,
+                                &bit_6_swizzle);
    if (ret != 0) {
       fprintf(stderr, "Couldn't get tiling of buffer %d (%s): %s\n",
              handle, name, strerror(-ret));
@@ -276,7 +282,7 @@ intel_region_release(struct intel_region **region_handle)
       if (region->pbo)
         region->pbo->region = NULL;
       region->pbo = NULL;
-      dri_bo_unreference(region->buffer);
+      drm_intel_bo_unreference(region->buffer);
 
       if (region->name > 0)
         _mesa_HashRemove(region->screen->named_regions, region->name);
@@ -371,8 +377,11 @@ intel_region_copy(struct intel_context *intel,
                   struct intel_region *src,
                   GLuint src_offset,
                   GLuint srcx, GLuint srcy, GLuint width, GLuint height,
+                 GLboolean flip,
                  GLenum logicop)
 {
+   uint32_t src_pitch = src->pitch;
+
    _DBG("%s\n", __FUNCTION__);
 
    if (intel == NULL)
@@ -388,9 +397,12 @@ intel_region_copy(struct intel_context *intel,
 
    assert(src->cpp == dst->cpp);
 
+   if (flip)
+      src_pitch = -src_pitch;
+
    return intelEmitCopyBlit(intel,
                            dst->cpp,
-                           src->pitch, src->buffer, src_offset, src->tiling,
+                           src_pitch, src->buffer, src_offset, src->tiling,
                            dst->pitch, dst->buffer, dst_offset, dst->tiling,
                            srcx, srcy, dstx, dsty, width, height,
                            logicop);
@@ -404,7 +416,7 @@ intel_region_attach_pbo(struct intel_context *intel,
                         struct intel_region *region,
                         struct intel_buffer_object *pbo)
 {
-   dri_bo *buffer;
+   drm_intel_bo *buffer;
 
    if (region->pbo == pbo)
       return;
@@ -422,7 +434,7 @@ intel_region_attach_pbo(struct intel_context *intel,
    }
 
    if (region->buffer) {
-      dri_bo_unreference(region->buffer);
+      drm_intel_bo_unreference(region->buffer);
       region->buffer = NULL;
    }
 
@@ -431,7 +443,7 @@ intel_region_attach_pbo(struct intel_context *intel,
 
    region->pbo = pbo;
    region->pbo->region = region;
-   dri_bo_reference(buffer);
+   drm_intel_bo_reference(buffer);
    region->buffer = buffer;
    region->tiling = I915_TILING_NONE;
 }
@@ -448,12 +460,13 @@ intel_region_release_pbo(struct intel_context *intel,
    assert(region->buffer == region->pbo->buffer);
    region->pbo->region = NULL;
    region->pbo = NULL;
-   dri_bo_unreference(region->buffer);
+   drm_intel_bo_unreference(region->buffer);
    region->buffer = NULL;
 
-   region->buffer = dri_bo_alloc(intel->bufmgr, "region",
-                                region->pitch * region->cpp * region->height,
-                                64);
+   region->buffer = drm_intel_bo_alloc(intel->bufmgr, "region",
+                                      region->pitch * region->cpp *
+                                      region->height,
+                                      64);
 }
 
 /* Break the COW tie to the pbo.  Both the pbo and the region end up
@@ -485,7 +498,7 @@ intel_region_cow(struct intel_context *intel, struct intel_region *region)
    assert(ok);
 }
 
-dri_bo *
+drm_intel_bo *
 intel_region_buffer(struct intel_context *intel,
                     struct intel_region *region, GLuint flag)
 {