From 41f290f54e385f28257bd24e8f399bcb7f3727b7 Mon Sep 17 00:00:00 2001 From: der richter Date: Sat, 25 May 2019 19:29:34 +0200 Subject: cocoa-cb: add support for 10bit opengl rendering this will request a 16bit half-float framebuffer instead if a 8bit integer framebuffer. Fixes #3613 --- osdep/macOS_mpv_helper.swift | 4 +++- osdep/macOS_swift_compat.swift | 14 ++++++++++++++ osdep/macosx_application.h | 1 + osdep/macosx_application.m | 2 ++ 4 files changed, 20 insertions(+), 1 deletion(-) (limited to 'osdep') diff --git a/osdep/macOS_mpv_helper.swift b/osdep/macOS_mpv_helper.swift index fdc458e834..3494c60cfd 100644 --- a/osdep/macOS_mpv_helper.swift +++ b/osdep/macOS_mpv_helper.swift @@ -139,12 +139,13 @@ class MPVHelper: NSObject { return flags & UInt64(MPV_RENDER_UPDATE_FRAME.rawValue) > 0 } - func drawRender(_ surface: NSSize, _ ctx: CGLContextObj, skip: Bool = false) { + func drawRender(_ surface: NSSize, _ depth: GLint, _ ctx: CGLContextObj, skip: Bool = false) { deinitLock.lock() if mpvRenderContext != nil { var i: GLint = 0 var flip: CInt = 1 var skip: CInt = skip ? 1 : 0 + var ditherDepth = depth glGetIntegerv(GLenum(GL_DRAW_FRAMEBUFFER_BINDING), &i) // CAOpenGLLayer has ownership of FBO zero yet can return it to us, // so only utilize a newly received FBO ID if it is nonzero. @@ -157,6 +158,7 @@ class MPVHelper: NSObject { var params: [mpv_render_param] = [ mpv_render_param(type: MPV_RENDER_PARAM_OPENGL_FBO, data: &data), mpv_render_param(type: MPV_RENDER_PARAM_FLIP_Y, data: &flip), + mpv_render_param(type: MPV_RENDER_PARAM_DEPTH, data: &ditherDepth), mpv_render_param(type: MPV_RENDER_PARAM_SKIP_RENDERING, data: &skip), mpv_render_param() ] diff --git a/osdep/macOS_swift_compat.swift b/osdep/macOS_swift_compat.swift index 381398e1bf..c14aa08282 100644 --- a/osdep/macOS_swift_compat.swift +++ b/osdep/macOS_swift_compat.swift @@ -23,6 +23,13 @@ extension NSAppearance.Name { static let accessibilityHighContrastVibrantLight: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityVibrantLight") static let accessibilityHighContrastVibrantDark: NSAppearance.Name = NSAppearance.Name(rawValue: "NSAppearanceNameAccessibilityVibrantDark") } + +@available(OSX 10.12, *) +extension String { + static let RGBA16Float: String = kCAContentsFormatRGBA16Float + static let RGBA8Uint: String = kCAContentsFormatRGBA8Uint + static let gray8Uint: String = kCAContentsFormatGray8Uint +} #endif extension NSPasteboard.PasteboardType { @@ -73,6 +80,13 @@ extension Array { } } +extension Array where Element == [CGLPixelFormatAttribute] { + + func contains(_ obj: [CGLPixelFormatAttribute]) -> Bool { + return self.contains(where:{ $0 == obj }) + } +} + extension NSWindow.Level { static func +(left: NSWindow.Level, right: Int) -> NSWindow.Level { diff --git a/osdep/macosx_application.h b/osdep/macosx_application.h index 7c22abaf84..7e233987fd 100644 --- a/osdep/macosx_application.h +++ b/osdep/macosx_application.h @@ -28,6 +28,7 @@ struct macos_opts { struct m_color macos_title_bar_color; int macos_fs_animation_duration; int cocoa_cb_sw_renderer; + int cocoa_cb_10bit_context; }; // multithreaded wrapper for mpv_main diff --git a/osdep/macosx_application.m b/osdep/macosx_application.m index 08b3fce901..a07f4f5db9 100644 --- a/osdep/macosx_application.m +++ b/osdep/macosx_application.m @@ -63,6 +63,7 @@ const struct m_sub_options macos_conf = { ({"default", -1})), OPT_CHOICE("cocoa-cb-sw-renderer", cocoa_cb_sw_renderer, 0, ({"auto", -1}, {"no", 0}, {"yes", 1})), + OPT_FLAG("cocoa-cb-10bit-context", cocoa_cb_10bit_context, 0), OPT_REMOVED("macos-title-bar-style", "Split into --macos-title-bar-appearance " "and --macos-title-bar-material"), {0} @@ -72,6 +73,7 @@ const struct m_sub_options macos_conf = { .macos_title_bar_color = {0, 0, 0, 0}, .macos_fs_animation_duration = -1, .cocoa_cb_sw_renderer = -1, + .cocoa_cb_10bit_context = 1 }, }; -- cgit v1.2.3