mirror of
https://gitlab.freedesktop.org/monado/monado.git
synced 2025-01-01 12:46:12 +00:00
aux/util: Add u_frame_clone
This commit is contained in:
parent
815aa47ac2
commit
a1b683385f
|
@ -42,3 +42,39 @@ u_frame_create_one_off(enum xrt_format f, uint32_t width, uint32_t height, struc
|
|||
|
||||
xrt_frame_reference(out_frame, xf);
|
||||
}
|
||||
|
||||
static void
|
||||
free_clone(struct xrt_frame *xf)
|
||||
{
|
||||
assert(xf->reference.count == 0);
|
||||
free(xf->data);
|
||||
free(xf);
|
||||
}
|
||||
|
||||
void
|
||||
u_frame_clone(struct xrt_frame *to_copy, struct xrt_frame **out_frame)
|
||||
{
|
||||
struct xrt_frame *xf = U_TYPED_CALLOC(struct xrt_frame);
|
||||
|
||||
// Paranoia: Explicitly only copy the fields we want
|
||||
xf->width = to_copy->width;
|
||||
xf->height = to_copy->height;
|
||||
xf->stride = to_copy->stride;
|
||||
xf->size = to_copy->size;
|
||||
|
||||
xf->format = to_copy->format;
|
||||
xf->stereo_format = to_copy->stereo_format;
|
||||
|
||||
xf->timestamp = to_copy->timestamp;
|
||||
xf->source_timestamp = to_copy->source_timestamp;
|
||||
xf->source_sequence = to_copy->source_sequence;
|
||||
xf->source_id = to_copy->source_id;
|
||||
|
||||
xf->destroy = free_clone;
|
||||
|
||||
xf->data = malloc(xf->size);
|
||||
|
||||
memcpy(xf->data, to_copy->data, xf->size);
|
||||
|
||||
xrt_frame_reference(out_frame, xf);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,12 @@ extern "C" {
|
|||
void
|
||||
u_frame_create_one_off(enum xrt_format f, uint32_t width, uint32_t height, struct xrt_frame **out_frame);
|
||||
|
||||
/*!
|
||||
* Clones a frame. The cloned frame is not freed when the original frame is freed; instead the cloned frame is freed
|
||||
* when its reference reaches zero.
|
||||
*/
|
||||
void
|
||||
u_frame_clone(struct xrt_frame *to_copy, struct xrt_frame **out_frame);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue