[vlc-devel] [PATCH] vout/vulkan: add macosx extension module

Steve Lhomme robux4 at ycbcr.xyz
Thu Jan 9 07:36:56 CET 2020


On 2020-01-09 1:06, Marvin Scholz wrote:
> diff --git a/modules/video_output/vulkan/platform_macosx.m b/modules/video_output/vulkan/platform_macosx.m
> new file mode 100644
> index 0000000000..a2b4c478a0
> --- /dev/null
> +++ b/modules/video_output/vulkan/platform_macosx.m
> @@ -0,0 +1,86 @@
> +/**
> + * @file platform_macosx.c
> + * @brief Vulkan platform-specific code for macOS
> + */
> +
> +/*
> + * Copyright © 2019 Niklas Haas, Marvin Scholz
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms of the GNU Lesser General Public License as published by
> + * the Free Software Foundation; either version 2.1 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
> + * GNU Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public License
> + * along with this program; if not, write to the Free Software Foundation,
> + * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
> + */
> +
> +#ifdef HAVE_CONFIG_H
> +# include "config.h"
> +#endif
> +
> +#import <Cocoa/Cocoa.h>
> +#import <MetalKit/MetalKit.h>
> +
> +#import <MoltenVK/mvk_vulkan.h>
> +
> +#include "platform.h"
> +
> +int vlc_vk_InitPlatform(vlc_vk_t *vk)
> +{
> +    if (vk->window->type != VOUT_WINDOW_TYPE_NSOBJECT)
> +        return VLC_EGENERIC;
> +
> +    return VLC_SUCCESS;
> +}
> +
> +void vlc_vk_ClosePlatform(vlc_vk_t *vk)
> +{
> +    VLC_UNUSED(vk);
> +}
> +
> +const char * const vlc_vk_PlatformExt = VK_MVK_MACOS_SURFACE_EXTENSION_NAME;
> +
> +int vlc_vk_CreateSurface(vlc_vk_t *vk)
> +{
> +    VkInstance vkinst = vk->instance->instance;
> +
> +    // Create Metal view
> +    NSView *containerView = vk->window->handle.nsobject;
> +    MTKView *metalView = [[MTKView alloc] initWithFrame:containerView.frame
> +                                                 device:nil];
> +
> +    if (metalView == nil) {
> +        msg_Err(vk, "Failed creating MTKView");
> +        return VLC_EGENERIC;
> +    }
> +
> +    // Add as subview to our container view
> +    [metalView setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
> +    [containerView addSubview:metalView];
> +
> +    VkMacOSSurfaceCreateInfoMVK sinfo = {
> +         .sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK,
> +         .pView = (void*)metalView,
> +    };
> +
> +    // TODO: Use newer VK_EXT_metal_surface extension?
> +
> +    __block VkResult res;
> +    dispatch_sync(dispatch_get_main_queue(), ^{
> +        res = vkCreateMacOSSurfaceMVK(vkinst, &sinfo, NULL, &vk->surface);
> +    });
> +
> +    if (res != VK_SUCCESS) {
> +        msg_Err(vk, "Failed creating macOS surface");
> +        return VLC_EGENERIC;

Shouldn't you remove the metalView from the container if it fails ?

Is the metalView automatically freed when the container is freed ?

> +    }
> +
> +    return VLC_SUCCESS;
> +}
> -- 
> 2.20.1 (Apple Git-117)
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel
> 


More information about the vlc-devel mailing list