Commit 00425a25 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

picture: add picture_Clone()

parent d9a0c08a
......@@ -188,6 +188,17 @@ VLC_API void plane_CopyPixels( plane_t *p_dst, const plane_t *p_src );
*/
VLC_API void picture_Copy( picture_t *p_dst, const picture_t *p_src );
/**
* Perform a shallow picture copy
*
* This function makes a shallow copy of an existing picture. The same planes
* and resources will be used, and the cloned picture reference count will be
* incremented.
*
* \return A clone picture on success, NULL on error.
*/
VLC_API picture_t *picture_Clone(picture_t *pic);
/**
* This function will export a picture to an encoded bitstream.
*
......
......@@ -295,6 +295,7 @@ net_vaPrintf
net_Write
NTPtime64
picture_BlendSubpicture
picture_Clone
picture_CopyPixels
picture_Hold
picture_Release
......
......@@ -374,6 +374,38 @@ void picture_Copy( picture_t *p_dst, const picture_t *p_src )
picture_CopyProperties( p_dst, p_src );
}
static void picture_DestroyClone(picture_t *clone)
{
picture_t *picture = ((picture_priv_t *)clone)->gc.opaque;
free(clone);
picture_Release(picture);
}
picture_t *picture_Clone(picture_t *picture)
{
/* TODO: merge common code with picture_pool_ClonePicture(). */
picture_resource_t res = {
.p_sys = picture->p_sys,
.pf_destroy = picture_DestroyClone,
};
for (int i = 0; i < picture->i_planes; i++) {
res.p[i].p_pixels = picture->p[i].p_pixels;
res.p[i].i_lines = picture->p[i].i_lines;
res.p[i].i_pitch = picture->p[i].i_pitch;
}
picture_t *clone = picture_NewFromResource(&picture->format, &res);
if (likely(clone != NULL)) {
((picture_priv_t *)clone)->gc.opaque = picture;
picture_Hold(picture);
if (picture->context != NULL)
clone->context = picture->context->copy(picture->context);
}
return clone;
}
/*****************************************************************************
*
......
......@@ -299,6 +299,12 @@ void picture_pool_Cancel(picture_pool_t *pool, bool canceled)
bool picture_pool_OwnsPic(picture_pool_t *pool, picture_t *pic)
{
picture_priv_t *priv = (picture_priv_t *)pic;
while (priv->gc.destroy != picture_pool_ReleasePicture) {
pic = priv->gc.opaque;
priv = (picture_priv_t *)pic;
}
uintptr_t sys = (uintptr_t)priv->gc.opaque;
picture_pool_t *picpool = (void *)(sys & ~(POOL_MAX - 1));
return pool == picpool;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment