virgl: flatten virgl_renderer_resource_create_blob

Add has_{host,guest}_storage and reduce the indentation.  There
should be no real change.

Signed-off-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Chia-I Wu 4 years ago
parent 5e96edf216
commit 6761206ea9
  1. 54
      src/virglrenderer.c

@ -654,44 +654,56 @@ int virgl_renderer_execute(void *execute_args, uint32_t execute_size)
int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_create_blob_args *args) int virgl_renderer_resource_create_blob(const struct virgl_renderer_resource_create_blob_args *args)
{ {
struct virgl_context *ctx;
int ret;
uint32_t blob_mem = args->blob_mem;
uint64_t blob_id = args->blob_id;
uint32_t res_handle = args->res_handle;
struct pipe_resource *pipe_res; struct pipe_resource *pipe_res;
bool has_host_storage;
bool has_guest_storage;
int ret;
switch (args->blob_mem) {
case VIRGL_RENDERER_BLOB_MEM_GUEST:
has_host_storage = false;
has_guest_storage = true;
break;
case VIRGL_RENDERER_BLOB_MEM_HOST3D:
has_host_storage = true;
has_guest_storage = false;
break;
case VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST:
has_host_storage = true;
has_guest_storage = true;
break;
default:
return -EINVAL;
}
if (blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D || if (!has_host_storage) {
blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST) { return virgl_resource_create_from_iov(args->res_handle,
struct virgl_context *ctx = virgl_context_lookup(args->ctx_id); args->iovecs,
args->num_iovs);
}
ctx = virgl_context_lookup(args->ctx_id);
if (!ctx) if (!ctx)
return -EINVAL; return -EINVAL;
pipe_res = ctx->get_blob_pipe(ctx, blob_id); pipe_res = ctx->get_blob_pipe(ctx, args->blob_id);
if (!pipe_res) if (!pipe_res)
return -EINVAL; return -EINVAL;
ret = virgl_resource_create_from_pipe(res_handle, pipe_res); ret = virgl_resource_create_from_pipe(args->res_handle, pipe_res);
if (ret) { if (ret) {
vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res); vrend_renderer_resource_destroy((struct vrend_resource *)pipe_res);
return ret; return ret;
} }
if (blob_mem == VIRGL_RENDERER_BLOB_MEM_HOST3D_GUEST) { if (has_guest_storage) {
ret = virgl_renderer_resource_attach_iov(res_handle, args->iovecs, args->num_iovs); ret = virgl_renderer_resource_attach_iov(args->res_handle, args->iovecs, args->num_iovs);
if (ret) { if (ret) {
virgl_resource_remove(res_handle); virgl_resource_remove(args->res_handle);
return ret; return ret;
} }
} }
} else if (blob_mem == VIRGL_RENDERER_BLOB_MEM_GUEST) {
ret = virgl_resource_create_from_iov(res_handle, args->iovecs, args->num_iovs);
if (ret)
return -EINVAL;
} else {
return -EINVAL;
}
return 0; return 0;
} }

Loading…
Cancel
Save