Skip to content

Commit

Permalink
WIP: embedding support in vo_gpu_next on macOS
Browse files Browse the repository at this point in the history
  • Loading branch information
rcombs authored and Dudemanguy committed Sep 26, 2023
1 parent ee41202 commit c5a9e3e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 28 deletions.
5 changes: 2 additions & 3 deletions osdep/macos/libmpv_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,9 @@ class LibmpvHelper {
mpvHandle = mpv
log = LogHelper(mpLog)

guard let app = NSApp as? Application,
let ptr = mp_get_config_group(nil,
guard let ptr = mp_get_config_group(nil,
mp_client_get_global(mpvHandle),
app.getMacOSConf()) else
Application.getMacOSConf()) else
{
log.sendError("macOS config group couldn't be retrieved'")
exit(1)
Expand Down
5 changes: 2 additions & 3 deletions osdep/macos/mpv_helper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class MPVHelper {
self.vo = vo
self.log = log

guard let app = NSApp as? Application,
let cache = m_config_cache_alloc(vo, vo.pointee.global, app.getVoSubConf()) else
guard let cache = m_config_cache_alloc(vo, vo.pointee.global, Application.getVoSubConf()) else
{
log.sendError("NSApp couldn't be retrieved")
exit(1)
Expand All @@ -54,7 +53,7 @@ class MPVHelper {

guard let macCache = m_config_cache_alloc(vo,
vo.pointee.global,
app.getMacOSConf()) else
Application.getMacOSConf()) else
{
// will never be hit, mp_get_config_group asserts for invalid groups
exit(1)
Expand Down
4 changes: 2 additions & 2 deletions osdep/macosx_application.m
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,12 @@ - (void)setMpvHandle:(struct mpv_handle *)ctx
#endif
}

- (const struct m_sub_options *)getMacOSConf
+ (const struct m_sub_options *)getMacOSConf
{
return &macos_conf;
}

- (const struct m_sub_options *)getVoSubConf
+ (const struct m_sub_options *)getVoSubConf
{
return &vo_sub_opts;
}
Expand Down
4 changes: 2 additions & 2 deletions osdep/macosx_application_objc.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ struct mpv_handle;
- (void)stopMPV:(char *)cmd;
- (void)openFiles:(NSArray *)filenames;
- (void)setMpvHandle:(struct mpv_handle *)ctx;
- (const struct m_sub_options *)getMacOSConf;
- (const struct m_sub_options *)getVoSubConf;
+ (const struct m_sub_options *)getMacOSConf;
+ (const struct m_sub_options *)getVoSubConf;

@property(nonatomic, retain) MenuBar *menuBar;
@property(nonatomic, assign) size_t openCount;
Expand Down
21 changes: 16 additions & 5 deletions video/out/cocoa_cb_common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,22 @@ class CocoaCB: Common {
}

func initBackend(_ vo: UnsafeMutablePointer<vo>) {
let previousActiveApp = getActiveApp()
initApp()
initWindow(vo, previousActiveApp)
updateICCProfile()
initWindowState()
if (mpv?.opts.WinID ?? -1) != -1 {
guard let view = self.view else {
log.sendError("Something went wrong, no View was initialized")
exit(1)
}

let cView: View = unsafeBitCast(mpv!.opts.WinID, to: View.self)
cView.addSubview(view)
view.frame = cView.frame
} else {
let previousActiveApp = getActiveApp()
initApp()
initWindow(vo, previousActiveApp)
updateICCProfile()
initWindowState()
}

backendState = .initialized
}
Expand Down
47 changes: 34 additions & 13 deletions video/out/mac_common.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,48 @@ class MacCommon: Common {
mpv?.vo = vo

DispatchQueue.main.sync {
let previousActiveApp = getActiveApp()
initApp()

let (_, _, wr) = getInitProperties(vo)

guard let layer = self.layer else {
log.sendError("Something went wrong, no MetalLayer was initialized")
exit(1)
}

if window == nil {
initView(vo, layer)
initWindow(vo, previousActiveApp)
initWindowState()
}

if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) {
window?.updateSize(wr.size)
if (mpv?.opts.WinID ?? -1) != -1 {
if view == nil {
let cView: View = unsafeBitCast(mpv!.opts.WinID, to: View.self)

view = View(frame: cView.frame, common: self)
guard let view = self.view else {
log.sendError("Something went wrong, no View was initialized")
exit(1)
}

view.layer = layer
view.wantsLayer = true
view.layerContentsPlacement = .scaleProportionallyToFit

cView.addSubview(view)
view.frame = cView.frame
}
} else {
let previousActiveApp = getActiveApp()
initApp()

let (_, _, wr) = getInitProperties(vo)

if window == nil {
initView(vo, layer)
initWindow(vo, previousActiveApp)
initWindowState()
}

if !NSEqualSizes(window?.unfsContentFramePixel.size ?? NSZeroSize, wr.size) {
window?.updateSize(wr.size)
}

windowDidResize()
}

windowDidResize()
needsICCUpdate = true
}

Expand Down

0 comments on commit c5a9e3e

Please sign in to comment.