[vlc-devel] [PATCH 05/19] picture: do not use picture_NewFromResource for picture_InternalClone

Steve Lhomme robux4 at ycbcr.xyz
Thu Jul 30 14:16:46 CEST 2020


picture_InternalClone() doesn't need to call picture_NewFromResource() and
cast the result anymore. It creates its own picture_priv_t.

We check/set the gc of the clone before initializing the picture_priv_t. It
doesn't need to be passed in the fake resource anymore.

We can use the picture planes directly, rather than setting up a fake resource
structure to set the same fields.
---
 src/misc/picture.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 167fd6826b1..3c23d1230d4 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -420,22 +420,26 @@ static void picture_DestroyClone(picture_t *clone)
 
 picture_t *picture_InternalClone(picture_t *picture, picture_gc_t *pic_gc)
 {
-    picture_resource_t res = {
-        .p_sys = picture->p_sys,
-    };
-
-    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_priv_t *clone = malloc(sizeof(*clone));
+    if (unlikely(clone == NULL))
+        return NULL;
+    if (unlikely(!picture_InitPrivate(&picture->format, &clone->picture))) {
+        free(clone);
+        return NULL;
     }
 
-    picture_t *clone = picture_NewFromResource(&picture->format, &res);
-    if (likely(clone != NULL)) {
-        ((picture_priv_t *)clone)->gc = *pic_gc;
-        picture_Hold(picture);
+    assert(pic_gc->destroy != NULL); // we need to release the held picture
+    clone->gc = *pic_gc;
+
+    clone->picture.p_sys = picture->p_sys;
+    for( int i = 0; i < clone->picture.i_planes; i++ )
+    {
+        clone->picture.p[i].p_pixels = picture->p[i].p_pixels;
+        clone->picture.p[i].i_lines  = picture->p[i].i_lines;
+        clone->picture.p[i].i_pitch  = picture->p[i].i_pitch;
     }
-    return clone;
+    picture_Hold(picture);
+    return &clone->picture;
 }
 
 picture_t *picture_Clone(picture_t *picture)
-- 
2.26.2



More information about the vlc-devel mailing list