diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 262c52e..dd3253c 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -72,6 +72,16 @@ int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_creat #endif } +void virgl_renderer_resource_set_priv(uint32_t res_handle, void *priv) +{ + vrend_renderer_resource_set_priv(res_handle, priv); +} + +void *virgl_renderer_resource_get_priv(uint32_t res_handle) +{ + return vrend_renderer_resource_get_priv(res_handle); +} + void virgl_renderer_resource_unref(uint32_t res_handle) { vrend_renderer_resource_unref(res_handle); diff --git a/src/virglrenderer.h b/src/virglrenderer.h index bc7cedf..609f447 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -115,6 +115,9 @@ VIRGL_EXPORT int virgl_renderer_resource_create(struct virgl_renderer_resource_c VIRGL_EXPORT int virgl_renderer_resource_import_eglimage(struct virgl_renderer_resource_create_args *args, void *image); VIRGL_EXPORT void virgl_renderer_resource_unref(uint32_t res_handle); +VIRGL_EXPORT void virgl_renderer_resource_set_priv(uint32_t res_handle, void *priv); +VIRGL_EXPORT void *virgl_renderer_resource_get_priv(uint32_t res_handle); + VIRGL_EXPORT int virgl_renderer_context_create(uint32_t handle, uint32_t nlen, const char *name); VIRGL_EXPORT void virgl_renderer_context_destroy(uint32_t handle); diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 2103f66..64fe7a6 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -8626,6 +8626,24 @@ void vrend_renderer_get_rect(int res_handle, struct iovec *iov, unsigned int num vrend_renderer_transfer_iov(&transfer_info, VREND_TRANSFER_READ); } +void vrend_renderer_resource_set_priv(uint32_t res_handle, void *priv) +{ + struct vrend_resource *res = vrend_resource_lookup(res_handle, 0); + if (!res) + return; + + res->priv = priv; +} + +void *vrend_renderer_resource_get_priv(uint32_t res_handle) +{ + struct vrend_resource *res = vrend_resource_lookup(res_handle, 0); + if (!res) + return NULL; + + return res->priv; +} + void vrend_renderer_attach_res_ctx(int ctx_id, int resource_id) { struct vrend_context *ctx = vrend_lookup_renderer_ctx(ctx_id); diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index 01ac910..6075aea 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -64,6 +64,7 @@ struct vrend_resource { GLuint handle; + void *priv; char *ptr; struct iovec *iov; uint32_t num_iovs; @@ -160,6 +161,8 @@ struct vrend_renderer_resource_create_args { int vrend_renderer_resource_create(struct vrend_renderer_resource_create_args *args, struct iovec *iov, uint32_t num_iovs, void *image_eos); void vrend_renderer_resource_unref(uint32_t handle); +void vrend_renderer_resource_set_priv(uint32_t res_handle, void *priv); +void *vrend_renderer_resource_get_priv(uint32_t res_handle); int vrend_create_surface(struct vrend_context *ctx, uint32_t handle, diff --git a/tests/test_virgl_resource.c b/tests/test_virgl_resource.c index ec69038..77a5106 100644 --- a/tests/test_virgl_resource.c +++ b/tests/test_virgl_resource.c @@ -287,6 +287,23 @@ START_TEST(cubemaparray_res_tests) } END_TEST +START_TEST(private_ptr) +{ + int ret; + ret = testvirgl_init_single_ctx(); + ck_assert_int_eq(ret, 0); + struct virgl_renderer_resource_create_args args = { 1, PIPE_BUFFER, PIPE_FORMAT_R8_UNORM, 0, 50, 1, 1, 1, 0, 0, 0 }; + ret = virgl_renderer_resource_create(&args, NULL, 0); + ck_assert_int_eq(ret, 0); + + void *init_priv = (void*)0xabab; + virgl_renderer_resource_set_priv(1, init_priv); + void *priv = virgl_renderer_resource_get_priv(1); + ck_assert_int_eq((unsigned long)priv, 0xabab); + testvirgl_fini_single_ctx(); +} +END_TEST + static Suite *virgl_init_suite(void) { Suite *s; @@ -297,6 +314,7 @@ static Suite *virgl_init_suite(void) tcase_add_loop_test(tc_core, virgl_res_tests, 0, ARRAY_SIZE(testlist)); tcase_add_loop_test(tc_core, cubemaparray_res_tests, 0, ARRAY_SIZE(cubemaparray_testlist)); + tcase_add_test(tc_core, private_ptr); suite_add_tcase(s, tc_core); return s;