virglrenderer: add support for a private pointer in resources. (v2)

This adds a new api to set/get a private pointer.

v2: add private ptr test

Reviewed-By: Gert Wollny <gert.wollny@collabora.com>
Signed-off-by: Dave Airlie <airlied@redhat.com>
macos/master
Dave Airlie 6 years ago
parent d61fc12340
commit aa910dfa6a
  1. 10
      src/virglrenderer.c
  2. 3
      src/virglrenderer.h
  3. 18
      src/vrend_renderer.c
  4. 3
      src/vrend_renderer.h
  5. 18
      tests/test_virgl_resource.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);

@ -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);

@ -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);

@ -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,

@ -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;

Loading…
Cancel
Save