virgl: refactor virgl_resource_create_from_pipe

Add a helper, virgl_resource_create, to allocate and add the
virgl_resource to the table.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
Reviewed-by: Gert Wollny <gert.wollny@collabora.com>
macos/master
Chia-I Wu 4 years ago committed by Gurchetan Singh
parent 29a87d629c
commit 7b6b643878
  1. 21
      src/virgl_resource.c

@ -72,25 +72,38 @@ virgl_resource_table_reset(void)
util_hash_table_clear(virgl_resource_table); util_hash_table_clear(virgl_resource_table);
} }
int static struct virgl_resource *
virgl_resource_create_from_pipe(uint32_t res_id, struct pipe_resource *pres) virgl_resource_create(uint32_t res_id)
{ {
struct virgl_resource *res; struct virgl_resource *res;
enum pipe_error err; enum pipe_error err;
res = calloc(1, sizeof(*res)); res = calloc(1, sizeof(*res));
if (!res) if (!res)
return ENOMEM; return NULL;
err = util_hash_table_set(virgl_resource_table, err = util_hash_table_set(virgl_resource_table,
uintptr_to_pointer(res_id), uintptr_to_pointer(res_id),
res); res);
if (err != PIPE_OK) { if (err != PIPE_OK) {
free(res); free(res);
return ENOMEM; return NULL;
} }
res->res_id = res_id; res->res_id = res_id;
return res;
}
int
virgl_resource_create_from_pipe(uint32_t res_id, struct pipe_resource *pres)
{
struct virgl_resource *res;
res = virgl_resource_create(res_id);
if (!res)
return ENOMEM;
/* take ownership */ /* take ownership */
res->pipe_resource = pres; res->pipe_resource = pres;

Loading…
Cancel
Save