[vlc-commits] [Git][videolan/vlc][master] 4 commits: caopengllayer: move Open to avoid forward declarations

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Nov 21 19:30:58 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
c59ed71c by Alexandre Janniaux at 2024-11-21T18:59:06+00:00
caopengllayer: move Open to avoid forward declarations

- - - - -
6873b7f8 by Alexandre Janniaux at 2024-11-21T18:59:06+00:00
caopengllayer: move vout_display_operations

...and use designated initializers to ensure the fields are correct.
This will allow removing the forward declarations.

- - - - -
3eb8d1fb by Alexandre Janniaux at 2024-11-21T18:59:06+00:00
caopengllayer: remove forward declarations

No functional changes.

- - - - -
089d8cba by Alexandre Janniaux at 2024-11-21T18:59:06+00:00
caopengllayer: move opengl startup to dedicated function

The code will be moved towards a real OpenGL provider module in the
future. This commit starts writing the module like so by ensuring there
is a valid OpenGL startup function for the module.

Currently, the usage of the vout_display prevents from allocating the
views and everything from within the OpenOpenGL function, but they'll
get moved in later patches which will include setting up dedicated
callbacks for the rendering.

- - - - -


1 changed file:

- modules/video_output/caopengllayer.m


Changes:

=====================================
modules/video_output/caopengllayer.m
=====================================
@@ -46,17 +46,6 @@
 #include "opengl/renderer.h"
 #include "opengl/vout_helper.h"
 
-/*****************************************************************************
- * Vout interface
- *****************************************************************************/
-static int Open(vout_display_t *vd, video_format_t *fmt, vlc_video_context *context);
-static void Close(vout_display_t *vd);
-
-static void PictureRender   (vout_display_t *vd, picture_t *pic, const vlc_render_subpicture *subpicture,
-                             vlc_tick_t date);
-static void PictureDisplay  (vout_display_t *vd, picture_t *pic);
-static int Control          (vout_display_t *vd, int);
-
 /**
  * Protocol declaration that drawable-nsobject should follow
  */
@@ -251,10 +240,6 @@ static int SetViewpoint(vout_display_t *vd, const vlc_viewpoint_t *vp)
     return ret;
 }
 
-static const struct vlc_display_operations ops = {
-    Close, PictureRender, PictureDisplay, Control, NULL, SetViewpoint, NULL,
-};
-
 /**
  * Flush the OpenGL context
  * In case of double-buffering swaps the back buffer with the front buffer.
@@ -336,146 +321,41 @@ static void *gl_cb_GetProcAddress(vlc_gl_t *vlc_gl, const char *name)
     return dlsym(RTLD_DEFAULT, name);
 }
 
-
-#pragma mark -
-#pragma mark Module functions
-
-/*****************************************************************************
- * Open: This function allocates and initializes the OpenGL vout method.
- *****************************************************************************/
-static int Open (vout_display_t *vd,
-                 video_format_t *fmt, vlc_video_context *context)
+static int OpenOpenGL(vlc_gl_t *gl, unsigned width, unsigned height,
+                      const struct vlc_gl_cfg *cfg)
 {
-    vout_display_sys_t *sys;
-    if (vd->cfg->window->type != VLC_WINDOW_TYPE_NSOBJECT)
+    struct vlc_gl_sys *glsys = calloc(1, sizeof(*glsys));
+    if (unlikely(!glsys))
+        return VLC_ENOMEM;
+
+    // Create the CGL context
+    CGLContextObj cgl_ctx = vlc_CreateCGLContext();
+    if (cgl_ctx == NULL) {
+        msg_Err(gl, "Failure to create CGL context!");
+        free(glsys);
         return VLC_EGENERIC;
+    }
 
-    @autoreleasepool {
-        vout_display_sys_t *sys;
-
-        // Only use this video output on macOS 10.14 or higher
-        // currently, as it has some issues on at least macOS 10.7
-        // and the old NSView based output still works fine on old
-        // macOS versions.
-        if (@available(macOS 10.14, *)) {
-            // This is intentionally left empty, as the check
-            // can not be negated or combined with other conditions!
-        } else if (!vd->obj.force) {
-            return VLC_EGENERIC;
-        }
-
-        vd->sys = sys = calloc(1, sizeof(*sys));
-        if (sys == NULL)
-            return VLC_ENOMEM;
-
-        id container = (__bridge id)vd->cfg->window->handle.nsobject;
-        if (!container) {
-            msg_Err(vd, "No drawable-nsobject found!");
-            Close(vd);
-            return VLC_EGENERIC;
-        }
-
-        // Retain container, released in Close
-        sys->container = container;
-
-        // Create the CGL context
-        CGLContextObj cgl_ctx = vlc_CreateCGLContext();
-        if (cgl_ctx == NULL) {
-            msg_Err(vd, "Failure to create CGL context!");
-            Close(vd);
-            return VLC_EGENERIC;
-        }
-
-        // Create a pseudo-context object which provides needed callbacks
-        // for VLC to deal with the CGL context. Usually this should be done
-        // by a proper opengl provider module, but we do not have that currently.
-        sys->gl = vlc_object_create(vd, sizeof(*sys->gl));
-        if (unlikely(!sys->gl))
-        {
-            CGLReleaseContext(cgl_ctx);
-            Close(vd);
-            return VLC_ENOMEM;
-        }
-
-
-        static const struct vlc_gl_operations gl_ops =
-        {
-            .make_current = gl_cb_MakeCurrent,
-            .release_current = gl_cb_ReleaseCurrent,
-            .swap = gl_cb_Swap,
-            .get_proc_address = gl_cb_GetProcAddress,
-        };
-        sys->gl->ops = &gl_ops;
-        sys->gl->api_type = VLC_OPENGL;
-
-        struct vlc_gl_sys *glsys = sys->gl->sys = malloc(sizeof(*glsys));
-        if (unlikely(!glsys)) {
-            Close(vd);
-            return VLC_ENOMEM;
-        }
-        glsys->cgl = cgl_ctx;
-        glsys->cgl_prev = NULL;
-
-        dispatch_sync(dispatch_get_main_queue(), ^{
-           sys->cfg = *vd->cfg;
-
-            // Create video view
-            sys->videoView = [[VLCVideoLayerView alloc] initWithVoutDisplay:vd];
-            sys->videoLayer = (VLCCAOpenGLLayer*)[sys->videoView layer];
-            // Add video view to container
-            if ([container respondsToSelector:@selector(addVoutSubview:)]) {
-                [container addVoutSubview:sys->videoView];
-            } else if ([container isKindOfClass:[NSView class]]) {
-                NSView *containerView = container;
-                [containerView addSubview:sys->videoView];
-                [sys->videoView setFrame:containerView.bounds];
-            } else {
-                sys->videoView = nil;
-                sys->videoLayer = nil;
-            }
-
-            vout_display_PlacePicture(&sys->place, vd->source, &vd->cfg->display);
-            // Reverse vertical alignment as the GL tex are Y inverted
-            sys->place.y = vd->cfg->display.height - (sys->place.y + sys->place.height);
-        });
-
-        if (sys->videoView == nil) {
-            msg_Err(vd,
-                    "Invalid drawable-nsobject object, must either be an NSView "
-                    "or comply with the VLCOpenGLVideoViewEmbedding protocol");
-            Close(vd);
-            return VLC_EGENERIC;
-        }
-
-
-        // Initialize OpenGL video display
-        const vlc_fourcc_t *spu_chromas;
-
-        if (vlc_gl_MakeCurrent(sys->gl))
-        {
-            Close(vd);
-            return VLC_EGENERIC;
-        }
-
-        sys->vgl = vout_display_opengl_New(fmt, &spu_chromas, sys->gl,
-                                           &vd->cfg->viewpoint, context);
-        vlc_gl_ReleaseCurrent(sys->gl);
-
-        if (sys->vgl == NULL) {
-            msg_Err(vd, "Error while initializing OpenGL display");
-            Close(vd);
-            return VLC_EGENERIC;
-        }
-
-        vd->info.subpicture_chromas = spu_chromas;
+    glsys->cgl = cgl_ctx;
+    glsys->cgl_prev = NULL;
 
-        vd->ops = &ops;
+    static const struct vlc_gl_operations gl_ops =
+    {
+        .make_current = gl_cb_MakeCurrent,
+        .release_current = gl_cb_ReleaseCurrent,
+        .swap = gl_cb_Swap,
+        .get_proc_address = gl_cb_GetProcAddress,
+    };
+    gl->ops = &gl_ops;
+    gl->api_type = VLC_OPENGL;
+    gl->sys = glsys;
 
-        atomic_init(&sys->is_ready, false);
-        return VLC_SUCCESS;
-    }
+    return VLC_SUCCESS;
 }
 
+#pragma mark -
+#pragma mark Module functions
+
 static void Close(vout_display_t *vd)
 {
     vout_display_sys_t *sys = vd->sys;
@@ -587,6 +467,131 @@ static int Control (vout_display_t *vd, int query)
     return VLC_SUCCESS;
 }
 
+/*****************************************************************************
+ * Open: This function allocates and initializes the OpenGL vout method.
+ *****************************************************************************/
+static int Open (vout_display_t *vd,
+                 video_format_t *fmt, vlc_video_context *context)
+{
+    vout_display_sys_t *sys;
+    if (vd->cfg->window->type != VLC_WINDOW_TYPE_NSOBJECT)
+        return VLC_EGENERIC;
+
+    @autoreleasepool {
+        vout_display_sys_t *sys;
+
+        // Only use this video output on macOS 10.14 or higher
+        // currently, as it has some issues on at least macOS 10.7
+        // and the old NSView based output still works fine on old
+        // macOS versions.
+        if (@available(macOS 10.14, *)) {
+            // This is intentionally left empty, as the check
+            // can not be negated or combined with other conditions!
+        } else if (!vd->obj.force) {
+            return VLC_EGENERIC;
+        }
+
+        vd->sys = sys = calloc(1, sizeof(*sys));
+        if (sys == NULL)
+            return VLC_ENOMEM;
+
+        id container = (__bridge id)vd->cfg->window->handle.nsobject;
+        if (!container) {
+            msg_Err(vd, "No drawable-nsobject found!");
+            Close(vd);
+            return VLC_EGENERIC;
+        }
+
+        // Retain container, released in Close
+        sys->container = container;
+
+        // Create a pseudo-context object which provides needed callbacks
+        // for VLC to deal with the CGL context. Usually this should be done
+        // by a proper opengl provider module, but we do not have that currently.
+        sys->gl = vlc_object_create(vd, sizeof(*sys->gl));
+        if (unlikely(!sys->gl))
+        {
+            Close(vd);
+            return VLC_ENOMEM;
+        }
+
+        const struct vlc_gl_cfg gl_cfg = {
+            .need_alpha = false,
+        };
+
+        int ret = OpenOpenGL(sys->gl, vd->cfg->display.width, vd->cfg->display.height, &gl_cfg);
+        if (ret != VLC_SUCCESS) {
+            Close(vd);
+            return ret;
+        }
+
+        dispatch_sync(dispatch_get_main_queue(), ^{
+           sys->cfg = *vd->cfg;
+
+            // Create video view
+            sys->videoView = [[VLCVideoLayerView alloc] initWithVoutDisplay:vd];
+            sys->videoLayer = (VLCCAOpenGLLayer*)[sys->videoView layer];
+            // Add video view to container
+            if ([container respondsToSelector:@selector(addVoutSubview:)]) {
+                [container addVoutSubview:sys->videoView];
+            } else if ([container isKindOfClass:[NSView class]]) {
+                NSView *containerView = container;
+                [containerView addSubview:sys->videoView];
+                [sys->videoView setFrame:containerView.bounds];
+            } else {
+                sys->videoView = nil;
+                sys->videoLayer = nil;
+            }
+
+            vout_display_PlacePicture(&sys->place, vd->source, &vd->cfg->display);
+            // Reverse vertical alignment as the GL tex are Y inverted
+            sys->place.y = vd->cfg->display.height - (sys->place.y + sys->place.height);
+        });
+
+        if (sys->videoView == nil) {
+            msg_Err(vd,
+                    "Invalid drawable-nsobject object, must either be an NSView "
+                    "or comply with the VLCOpenGLVideoViewEmbedding protocol");
+            Close(vd);
+            return VLC_EGENERIC;
+        }
+
+
+        // Initialize OpenGL video display
+        const vlc_fourcc_t *spu_chromas;
+
+        if (vlc_gl_MakeCurrent(sys->gl))
+        {
+            Close(vd);
+            return VLC_EGENERIC;
+        }
+
+        sys->vgl = vout_display_opengl_New(fmt, &spu_chromas, sys->gl,
+                                           &vd->cfg->viewpoint, context);
+        vlc_gl_ReleaseCurrent(sys->gl);
+
+        if (sys->vgl == NULL) {
+            msg_Err(vd, "Error while initializing OpenGL display");
+            Close(vd);
+            return VLC_EGENERIC;
+        }
+
+        vd->info.subpicture_chromas = spu_chromas;
+
+        static const struct vlc_display_operations ops = {
+            .close = Close,
+            .prepare = PictureRender,
+            .display = PictureDisplay,
+            .control = Control,
+            .set_viewpoint = SetViewpoint,
+        };
+        vd->ops = &ops;
+
+        atomic_init(&sys->is_ready, false);
+        return VLC_SUCCESS;
+    }
+}
+
 #pragma mark -
 #pragma mark VLCVideoLayerView
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bfd6ba9ec90c71aa3f8f307a9c703079a39aa2cc...089d8cbac11f7ccaf7941ad37117f0a507a57d38

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/bfd6ba9ec90c71aa3f8f307a9c703079a39aa2cc...089d8cbac11f7ccaf7941ad37117f0a507a57d38
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list