[virglrenderer-devel] [PATCH v2 1/2] vrend: extract allocate function from vrend_renderer_resource_create
Gert Wollny
gert.wollny at collabora.com
Thu May 31 16:49:38 UTC 2018
Because vrend_renderer_resource_create requires a valid handle that is
requested by the guest, this function can not directly be used to create
a resource from within virglrenderer.
Therefore, in order to be able to allocate and delete resources not
requested by the client a function vrend_renderer_resource_allocate is
extracted from vrend_renderer_resource_create. This resource is created
with handle=0 and will not be handled by the virgilrenderer resource
management.
v2: * make vrend_renderer_resource_allocate static
* rebase patch
Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
src/vrend_renderer.c | 37 +++++++++++++++++++++++++++----------
1 file changed, 27 insertions(+), 10 deletions(-)
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index df575b1..0c42a59 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4588,23 +4588,19 @@ static void vrend_create_buffer(struct vrend_resource *gr, uint32_t width)
gr->is_buffer = true;
}
-int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
+
+static struct vrend_resource *
+vrend_renderer_resource_allocate(struct vrend_renderer_resource_create_args *args)
{
struct vrend_resource *gr;
int level;
int ret;
- ret = check_resource_valid(args);
- if (ret)
- return EINVAL;
-
gr = (struct vrend_resource *)CALLOC_STRUCT(vrend_texture);
if (!gr)
- return ENOMEM;
+ return NULL;
- gr->handle = args->handle;
- gr->iov = iov;
- gr->num_iovs = num_iovs;
+ gr->handle = 0;
gr->base.width0 = args->width;
gr->base.height0 = args->height;
gr->base.depth0 = args->depth;
@@ -4624,7 +4620,7 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
gr->ptr = malloc(args->width);
if (!gr->ptr) {
FREE(gr);
- return ENOMEM;
+ return NULL;
}
} else if (args->bind == VREND_RES_BIND_INDEX_BUFFER) {
gr->target = GL_ELEMENT_ARRAY_BUFFER_ARB;
@@ -4759,6 +4755,27 @@ int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *a
gt->state.max_lod = -1;
gt->cur_swizzle_r = gt->cur_swizzle_g = gt->cur_swizzle_b = gt->cur_swizzle_a = -1;
}
+ return gr;
+}
+
+int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
+{
+
+ struct vrend_resource *gr;
+ int ret;
+
+ ret = check_resource_valid(args);
+ if (ret)
+ return EINVAL;
+
+ gr = vrend_renderer_resource_allocate(args);
+
+ if (!gr)
+ return ENOMEM;
+
+ gr->handle = args->handle;
+ gr->iov = iov;
+ gr->num_iovs = num_iovs;
ret = vrend_resource_insert(gr, args->handle);
if (ret == 0) {
--
2.17.0
More information about the virglrenderer-devel
mailing list