ilo: add more convenient intel_bo_{ref,unref}()
authorChia-I Wu <olvaffe@gmail.com>
Thu, 5 Mar 2015 18:03:10 +0000 (02:03 +0800)
committerChia-I Wu <olvaffe@gmail.com>
Thu, 5 Mar 2015 18:25:03 +0000 (02:25 +0800)
They both check for NULL and intel_bo_ref() returns the referenced bo.  They
replace intel_bo_{reference,unreference}().

src/gallium/drivers/ilo/ilo_builder.c
src/gallium/drivers/ilo/ilo_cp.c
src/gallium/drivers/ilo/ilo_query.c
src/gallium/drivers/ilo/ilo_render.c
src/gallium/drivers/ilo/ilo_resource.c
src/gallium/drivers/ilo/ilo_screen.c
src/gallium/drivers/ilo/intel_winsys.h
src/gallium/winsys/intel/drm/intel_drm_winsys.c

index 52c4b2184358f27314029e2ee2508305c363f7f8..56920e5bfb63cedb4489cb422b643d6ceb716605 100644 (file)
@@ -99,10 +99,8 @@ ilo_builder_writer_reset(struct ilo_builder *builder,
       writer->ptr = NULL;
    }
 
-   if (writer->bo) {
-      intel_bo_unreference(writer->bo);
-      writer->bo = NULL;
-   }
+   intel_bo_unref(writer->bo);
+   writer->bo = NULL;
 
    writer->used = 0;
    writer->stolen = 0;
@@ -168,8 +166,7 @@ ilo_builder_writer_alloc_and_map(struct ilo_builder *builder,
 
       bo = alloc_writer_bo(builder->winsys, which, writer->size);
       if (bo) {
-         if (writer->bo)
-            intel_bo_unreference(writer->bo);
+         intel_bo_unref(writer->bo);
          writer->bo = bo;
       } else if (writer->bo) {
          /* reuse the old bo */
@@ -273,7 +270,7 @@ ilo_builder_writer_grow(struct ilo_builder *builder,
    }
 
    if (!new_ptr) {
-      intel_bo_unreference(new_bo);
+      intel_bo_unref(new_bo);
       return false;
    }
 
@@ -282,7 +279,7 @@ ilo_builder_writer_grow(struct ilo_builder *builder,
    else if (!preserve)
       FREE(writer->ptr);
 
-   intel_bo_unreference(writer->bo);
+   intel_bo_unref(writer->bo);
 
    writer->size = new_size;
    writer->bo = new_bo;
index f78fd1f62f9e8c5943b3755dd7a3dca4993f7e63..9d2dffd5e16ec83b7a650473c3a14c88b43f28a0 100644 (file)
@@ -163,10 +163,8 @@ ilo_cp_submit_internal(struct ilo_cp *cp)
    if (!err) {
       bool guilty;
 
-      if (cp->last_submitted_bo)
-         intel_bo_unreference(cp->last_submitted_bo);
-      cp->last_submitted_bo = bo;
-      intel_bo_reference(cp->last_submitted_bo);
+      intel_bo_unref(cp->last_submitted_bo);
+      cp->last_submitted_bo = intel_bo_ref(bo);
 
       guilty = ilo_cp_detect_hang(cp);
 
index 942df2d683da1bc298ffd959dc811e4171fe05f1..7a2e5030e00749f999dbdf9ea0c57601f803023b 100644 (file)
@@ -107,9 +107,7 @@ ilo_destroy_query(struct pipe_context *pipe, struct pipe_query *query)
 {
    struct ilo_query *q = ilo_query(query);
 
-   if (q->bo)
-      intel_bo_unreference(q->bo);
-
+   intel_bo_unref(q->bo);
    FREE(q);
 }
 
index c5492562de05eaf95247b5daa3e3ff514621aee1..a6614f1508af3dd379e0e34496e3dfc8c9bf401e 100644 (file)
@@ -154,9 +154,7 @@ ilo_render_create(struct ilo_builder *builder)
 void
 ilo_render_destroy(struct ilo_render *render)
 {
-   if (render->workaround_bo)
-      intel_bo_unreference(render->workaround_bo);
-
+   intel_bo_unref(render->workaround_bo);
    FREE(render);
 }
 
index 9f4ee4012c16867116ab319c553575cf9dca162c..7815354be013824d85f8f852bd6f2d7fef92648b 100644 (file)
@@ -171,7 +171,7 @@ tex_import_handle(struct ilo_texture *tex,
    if (!ilo_layout_update_for_imported_bo(&tex->layout,
             winsys_to_surface_tiling(tiling), pitch)) {
       ilo_err("imported handle has incompatible tiling/pitch\n");
-      intel_bo_unreference(tex->bo);
+      intel_bo_unref(tex->bo);
       tex->bo = NULL;
       return false;
    }
@@ -197,7 +197,7 @@ tex_create_bo(struct ilo_texture *tex)
          surface_to_winsys_tiling(tex->layout.tiling);
 
       if (intel_bo_set_tiling(bo, tiling, tex->layout.bo_stride)) {
-         intel_bo_unreference(bo);
+         intel_bo_unref(bo);
          bo = NULL;
       }
    }
@@ -278,14 +278,11 @@ tex_create_mcs(struct ilo_texture *tex)
 static void
 tex_destroy(struct ilo_texture *tex)
 {
-   if (tex->aux_bo)
-      intel_bo_unreference(tex->aux_bo);
-
    if (tex->separate_s8)
       tex_destroy(tex->separate_s8);
 
-   if (tex->bo)
-      intel_bo_unreference(tex->bo);
+   intel_bo_unref(tex->aux_bo);
+   intel_bo_unref(tex->bo);
 
    tex_free_slices(tex);
    FREE(tex);
@@ -418,7 +415,7 @@ buf_create_bo(struct ilo_buffer *buf)
 static void
 buf_destroy(struct ilo_buffer *buf)
 {
-   intel_bo_unreference(buf->bo);
+   intel_bo_unref(buf->bo);
    FREE(buf);
 }
 
@@ -554,7 +551,7 @@ ilo_buffer_rename_bo(struct ilo_buffer *buf)
    struct intel_bo *old_bo = buf->bo;
 
    if (buf_create_bo(buf)) {
-      intel_bo_unreference(old_bo);
+      intel_bo_unref(old_bo);
       return true;
    }
    else {
@@ -573,7 +570,7 @@ ilo_texture_rename_bo(struct ilo_texture *tex)
       return false;
 
    if (tex_create_bo(tex)) {
-      intel_bo_unreference(old_bo);
+      intel_bo_unref(old_bo);
       return true;
    }
    else {
index c9577c8be4172b202a56c4f338b64ad7d0ee2e1b..bf0a84a44eb4ae95f1a7762419e0157c2a2e7265 100644 (file)
@@ -600,15 +600,13 @@ ilo_fence_reference(struct pipe_screen *screen,
    if (likely(p)) {
       old = ilo_fence(*p);
       *p = f;
-   }
-   else {
+   } else {
       old = NULL;
    }
 
    STATIC_ASSERT(&((struct ilo_fence *) NULL)->reference == NULL);
    if (pipe_reference(&old->reference, &fence->reference)) {
-      if (old->bo)
-         intel_bo_unreference(old->bo);
+      intel_bo_unref(old->bo);
       FREE(old);
    }
 }
@@ -621,7 +619,7 @@ ilo_fence_signalled(struct pipe_screen *screen,
 
    /* mark signalled if the bo is idle */
    if (fence->bo && !intel_bo_is_busy(fence->bo)) {
-      intel_bo_unreference(fence->bo);
+      intel_bo_unref(fence->bo);
       fence->bo = NULL;
    }
 
@@ -645,7 +643,7 @@ ilo_fence_finish(struct pipe_screen *screen,
       return false;
 
    /* mark signalled */
-   intel_bo_unreference(fence->bo);
+   intel_bo_unref(fence->bo);
    fence->bo = NULL;
 
    return true;
@@ -666,9 +664,7 @@ ilo_fence_create(struct pipe_screen *screen, struct intel_bo *bo)
 
    pipe_reference_init(&fence->reference, 1);
 
-   if (bo)
-      intel_bo_reference(bo);
-   fence->bo = bo;
+   fence->bo = intel_bo_ref(bo);
 
    return fence;
 }
index 77eb030efadce343a8f6b46ee3c980620c5f7905..afd038c45f3b8493a57ff91ef4f3de4b70c1b074 100644 (file)
@@ -203,17 +203,17 @@ intel_winsys_decode_bo(struct intel_winsys *winsys,
                        struct intel_bo *bo, int used);
 
 /**
- * Increase the reference count of \p bo.
+ * Increase the reference count of \p bo.  No-op when \p bo is NULL.
  */
-void
-intel_bo_reference(struct intel_bo *bo);
+struct intel_bo *
+intel_bo_ref(struct intel_bo *bo);
 
 /**
  * Decrease the reference count of \p bo.  When the reference count reaches
- * zero, \p bo is destroyed.
+ * zero, \p bo is destroyed.  No-op when \p bo is NULL.
  */
 void
-intel_bo_unreference(struct intel_bo *bo);
+intel_bo_unref(struct intel_bo *bo);
 
 /**
  * Set the tiling of \p bo.  The info is used by GTT mapping and bo export.
index d05e0362a6c37c0703448110522b99cb1760c49a..b5ffceb7e65bee0988d18eec1315d32d660e2ca1 100644 (file)
@@ -464,16 +464,20 @@ intel_winsys_decode_bo(struct intel_winsys *winsys,
    intel_bo_unmap(bo);
 }
 
-void
-intel_bo_reference(struct intel_bo *bo)
+struct intel_bo *
+intel_bo_ref(struct intel_bo *bo)
 {
-   drm_intel_bo_reference(gem_bo(bo));
+   if (bo)
+      drm_intel_bo_reference(gem_bo(bo));
+
+   return bo;
 }
 
 void
-intel_bo_unreference(struct intel_bo *bo)
+intel_bo_unref(struct intel_bo *bo)
 {
-   drm_intel_bo_unreference(gem_bo(bo));
+   if (bo)
+      drm_intel_bo_unreference(gem_bo(bo));
 }
 
 int