minigbm: use drv_array for combinations and kms_items
This de-deuplicates the various dynamic arrays we use.
BUG=chromium:764871
TEST=gbmtest passes
Change-Id: I94c8cf7c71fdb98b931aab00c5381853e2ae0d3f
Reviewed-on: https://chromium-review.googlesource.com/758149
Commit-Ready: Gurchetan Singh <gurchetansingh@chromium.org>
Tested-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Stéphane Marchesin <marcheu@chromium.org>
diff --git a/drv.c b/drv.c
index a1be245..5b6a116 100644
--- a/drv.c
+++ b/drv.c
@@ -136,18 +136,14 @@
if (!drv->mappings)
goto free_buffer_table;
- /* Start with a power of 2 number of allocations. */
- drv->combos.allocations = 2;
- drv->combos.size = 0;
-
- drv->combos.data = calloc(drv->combos.allocations, sizeof(struct combination));
- if (!drv->combos.data)
+ drv->combos = drv_array_init(sizeof(struct combination));
+ if (!drv->combos)
goto free_mappings;
if (drv->backend->init) {
ret = drv->backend->init(drv);
if (ret) {
- free(drv->combos.data);
+ drv_array_destroy(drv->combos);
goto free_mappings;
}
}
@@ -174,8 +170,7 @@
drmHashDestroy(drv->buffer_table);
drv_array_destroy(drv->mappings);
-
- free(drv->combos.data);
+ drv_array_destroy(drv->combos);
pthread_mutex_unlock(&drv->driver_lock);
pthread_mutex_destroy(&drv->driver_lock);
@@ -202,8 +197,8 @@
best = NULL;
uint32_t i;
- for (i = 0; i < drv->combos.size; i++) {
- curr = &drv->combos.data[i];
+ for (i = 0; i < drv_array_size(drv->combos); i++) {
+ curr = drv_array_at_idx(drv->combos, i);
if ((format == curr->format) && use_flags == (curr->use_flags & use_flags))
if (!best || best->metadata.priority < curr->metadata.priority)
best = curr;