OSDN Git Service

Revert "Revert "Add support to query tiling mode.""
[android-x86/external-minigbm.git] / helpers.c
index 07044da..6bfeb09 100644 (file)
--- a/helpers.c
+++ b/helpers.c
@@ -16,6 +16,7 @@
 
 #include "drv_priv.h"
 #include "helpers.h"
+#include "i915_private.h"
 #include "util.h"
 
 static uint32_t subsample_stride(uint32_t stride, uint32_t format, size_t plane)
@@ -100,8 +101,7 @@ static uint32_t bpp_from_format(uint32_t format, size_t plane)
                return 32;
        }
 
-       fprintf(stderr, "drv: UNKNOWN FORMAT %d\n", format);
-       return 0;
+       return i915_private_bpp_from_format(format, plane);
 }
 
 uint32_t drv_bo_get_stride_in_pixels(struct bo *bo)
@@ -139,7 +139,7 @@ uint32_t drv_size_from_format(uint32_t format, uint32_t stride, uint32_t height,
                vertical_subsampling = (plane == 0) ? 1 : 2;
                break;
        default:
-               vertical_subsampling = 1;
+               i915_private_vertical_subsampling_from_format(&vertical_subsampling, format, plane);
        }
 
        return stride * DIV_ROUND_UP(height, vertical_subsampling);
@@ -300,11 +300,11 @@ int drv_prime_bo_import(struct bo *bo, struct drv_import_fd_data *data)
                bo->handles[plane].u32 = prime_handle.handle;
        }
 
+       ATOMIC_LOCK(&bo->drv->driver_lock);
        for (plane = 0; plane < bo->num_planes; plane++) {
-               pthread_mutex_lock(&bo->drv->driver_lock);
                drv_increment_reference_count(bo->drv, bo, plane);
-               pthread_mutex_unlock(&bo->drv->driver_lock);
        }
+       ATOMIC_UNLOCK(&bo->drv->driver_lock);
 
        return 0;
 }
@@ -605,3 +605,23 @@ int drv_modify_linear_combinations(struct driver *drv)
        free(items);
        return 0;
 }
+
+/*
+ * Pick the best modifier from modifiers, according to the ordering
+ * given by modifier_order.
+ */
+uint64_t drv_pick_modifier(const uint64_t *modifiers, uint32_t count,
+                          const uint64_t *modifier_order, uint32_t order_count)
+{
+       uint32_t i, j;
+
+       for (i = 0; i < order_count; i++) {
+               for (j = 0; j < count; j++) {
+                       if (modifiers[j] == modifier_order[i]) {
+                               return modifiers[j];
+                       }
+               }
+       }
+
+       return DRM_FORMAT_MOD_LINEAR;
+}