[virglrenderer-devel] [PATCH 1/2] vrend: extract allocate function from vrend_renderer_resource_create

Gert Wollny gert.wollny at collabora.com
Wed May 30 08:55:46 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.

Signed-off-by: Gert Wollny <gert.wollny at collabora.com>
---
 src/vrend_renderer.c | 38 +++++++++++++++++++++++++++-----------
 1 file changed, 27 insertions(+), 11 deletions(-)

diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index b49731c..a9841dc 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -4556,23 +4556,18 @@ static int check_resource_valid(struct vrend_renderer_resource_create_args *args
    }
    return 0;
 }
-int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs)
+
+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;
@@ -4592,7 +4587,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;
@@ -4749,6 +4744,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.16.1



More information about the virglrenderer-devel mailing list