diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index 1e2607c8c306..faf63e2fb3c8 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -115,6 +115,17 @@ namespace MonoTouch { public const string VisionLibrary = "/System/Library/Frameworks/Vision.framework/Vision"; public const string FileProviderLibrary = "/System/Library/Frameworks/FileProvider.framework/FileProvider"; public const string FileProviderUILibrary = "/System/Library/Frameworks/FileProviderUI.framework/FileProviderUI"; + public static string IOSurfaceLibrary { + get { +// Disabled because of bug #59201 +// #if !COREBUILD && !MTOUCH +// // Sidenote: this is in /System/Library/Frameworks/IOSurface.framework/IOSurface in macOS 10.12. +// if (!XamCore.UIKit.UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) +// return "/System/Library/PrivateFrameworks/IOSurface.framework/IOSurface"; +// #endif + return "/System/Library/Frameworks/IOSurface.framework/IOSurface"; + } + } public const string PdfKitLibrary = "/System/Library/Frameworks/PDFKit.framework/PDFKit"; } } diff --git a/src/Constants.mac.cs.in b/src/Constants.mac.cs.in index 61947fffd987..5f08f1c7a019 100644 --- a/src/Constants.mac.cs.in +++ b/src/Constants.mac.cs.in @@ -129,6 +129,7 @@ namespace MonoMac { // macOS 10.13 public const string CoreMLLibrary = "/System/Library/Frameworks/CoreML.framework/CoreML"; public const string VisionLibrary = "/System/Library/Frameworks/Vision.framework/Vision"; + public const string IOSurfaceLibrary = "/System/Library/Frameworks/IOSurface.framework/IOSurface"; public const string PhotosUILibrary = "/System/Library/Frameworks/Photos.framework/PhotosUI"; public const string ExternalAccessoryLibrary = "/System/Library/Frameworks/ExternalAccessory.framework/ExternalAccessory"; } diff --git a/src/Foundation/NSObject.mac.cs b/src/Foundation/NSObject.mac.cs index 0da225467e91..c548884f31f0 100644 --- a/src/Foundation/NSObject.mac.cs +++ b/src/Foundation/NSObject.mac.cs @@ -99,6 +99,7 @@ public partial class NSObject : INativeObject static IntPtr pc = Dlfcn.dlopen (Constants.PrintCoreLibrary, 1); static IntPtr cml = Dlfcn.dlopen (Constants.CoreMLLibrary, 1); static IntPtr vn = Dlfcn.dlopen (Constants.VisionLibrary, 1); + static IntPtr ios = Dlfcn.dlopen (Constants.IOSurfaceLibrary, 1); static IntPtr ex = Dlfcn.dlopen (Constants.ExternalAccessoryLibrary, 1); #endif // ** IF YOU ADD ITEMS HERE PLEASE UPDATE linker/ObjCExtensions.cs and mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs diff --git a/src/IOSurface/IODefs.cs b/src/IOSurface/IODefs.cs new file mode 100644 index 000000000000..071e28a4e57a --- /dev/null +++ b/src/IOSurface/IODefs.cs @@ -0,0 +1,38 @@ +// +// IOSurface +// +// Authors: +// Miguel de Icaza (miguel@xamarin.com) +// +// Copyright 2017 Microsoft +// + +using System; +using XamCore.ObjCRuntime; + +namespace XamCore.IOSurface { + + public enum IOSurfaceLockOptions : uint { + ReadOnly = 1, + AvoidSync = 2, + } + + public enum IOSurfacePurgeabilityState : uint { + NonVolatile = 0, + Volatile = 1, + Empty = 2, + KeepCurrent = 3, + } + + // To be used with kIOSurfaceCacheMode or IOSurfacePropertyKeyCacheMode + public enum IOSurfaceMemoryMap { + DefaultCache = 0, + InhibitCache = 1 << 8, + WriteThruCache = 2 << 8, + CopybackCache = 3 << 8, + WriteCombineCache = 4 << 8, + CopybackInnerCache = 5 << 8, + }; + + +} diff --git a/src/IOSurface/IOSurface.cs b/src/IOSurface/IOSurface.cs new file mode 100644 index 000000000000..dc8d640353a7 --- /dev/null +++ b/src/IOSurface/IOSurface.cs @@ -0,0 +1,98 @@ +// +// IOSurface.cs +// +// Copyright 2016 Microsoft +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// +#if XAMCORE_2_0 +using System; +using System.Runtime.InteropServices; +using XamCore.CoreFoundation; +using XamCore.ObjCRuntime; + +namespace XamCore.IOSurface { + public partial class IOSurface { + + // kern_return_t + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] + public int Lock (IOSurfaceLockOptions options, ref int seed) + { + unsafe { + fixed (int *p = &seed){ + return _Lock (options, (IntPtr) p); + } + } + } + + // kern_return_t + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] + public int Lock (IOSurfaceLockOptions options) + { + return _Lock (options, IntPtr.Zero); + } + + // kern_return_t + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] + public int Unlock (IOSurfaceLockOptions options, ref int seed) + { + unsafe { + fixed (int *p = &seed){ + return _Unlock (options, (IntPtr) p); + } + } + } + + // kern_return_t + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] + public int Unlock (IOSurfaceLockOptions options) + { + return _Unlock (options, IntPtr.Zero); + } + +#if !MONOMAC + // kern_return_t + [iOS (11, 0)] + public int SetPurgeable (IOSurfacePurgeabilityState newState, ref IOSurfacePurgeabilityState oldState) + { + unsafe { + fixed (IOSurfacePurgeabilityState *p = &oldState){ + return _SetPurgeable (newState, (IntPtr) p); + } + } + } + + [iOS (11, 0)] + public int SetPurgeable (IOSurfacePurgeabilityState newState) + { + return _SetPurgeable (newState, IntPtr.Zero); + } +#endif + } +} +#endif \ No newline at end of file diff --git a/src/frameworks.sources b/src/frameworks.sources index 196189f49bed..3d080041ba95 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -879,6 +879,13 @@ INTENTS_SOURCES = \ Intents/INWorkoutGoalUnitTypeResolutionResult.cs \ Intents/INWorkoutLocationTypeResolutionResult.cs \ +# IOSurface +IOSURFACE_CORE_SOURCES = \ + IOSurface/IODefs.cs + +IOSURFACE_SOURCES = \ + IOSurface/IOSurface.cs + # JavaScriptCore JAVASCRIPTCORE_SOURCES = \ @@ -1614,6 +1621,7 @@ MAC_FRAMEWORKS = \ ImageIO \ ImageKit \ Intents \ + IOSurface \ JavaScriptCore \ LocalAuthentication \ MapKit \ @@ -1695,6 +1703,7 @@ IOS_FRAMEWORKS = \ ImageIO \ Intents \ IntentsUI \ + IOSurface \ JavaScriptCore \ LocalAuthentication \ MapKit \ diff --git a/src/iosurface.cs b/src/iosurface.cs new file mode 100644 index 000000000000..d9fd903cbb4f --- /dev/null +++ b/src/iosurface.cs @@ -0,0 +1,221 @@ +// +// IOSurface bindings +// +// Authors: +// Miguel de Icaza +// +// Copyright 2017 Microsoft Inc. All rights reserved. +// + +#if XAMCORE_2_0 + +using System; +using XamCore.CoreFoundation; +using XamCore.Foundation; +using XamCore.ObjCRuntime; + +namespace XamCore.IOSurface { + + [Static] + [Internal] + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] + interface IOSurfacePropertyKey { + [Field ("IOSurfacePropertyAllocSizeKey")] + NSString AllocSizeKey { get; } + + [Field ("IOSurfacePropertyKeyWidth")] + NSString WidthKey { get; } + + [Field ("IOSurfacePropertyKeyHeight")] + NSString HeightKey { get; } + + [Field ("IOSurfacePropertyKeyBytesPerRow")] + NSString BytesPerRowKey { get; } + + [Field ("IOSurfacePropertyKeyBytesPerElement")] + NSString BytesPerElementKey { get; } + + [Field ("IOSurfacePropertyKeyElementWidth")] + NSString ElementWidthKey { get; } + + [Field ("IOSurfacePropertyKeyElementHeight")] + NSString ElementHeightKey { get; } + + [Field ("IOSurfacePropertyKeyOffset")] + NSString OffsetKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneInfo")] + NSString PlaneInfoKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneWidth")] + NSString PlaneWidthKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneHeight")] + NSString PlaneHeightKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBytesPerRow")] + NSString PlaneBytesPerRowKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneOffset")] + NSString PlaneOffsetKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneSize")] + NSString PlaneSizeKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBase")] + NSString PlaneBaseKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBytesPerElement")] + NSString PlaneBytesPerElementKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneElementWidth")] + NSString PlaneElementWidthKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneElementHeight")] + NSString PlaneElementHeightKey { get; } + + [Field ("IOSurfacePropertyKeyCacheMode")] + NSString CacheModeKey { get; } + + [Field ("IOSurfacePropertyKeyPixelFormat")] + NSString PixelFormatKey { get; } + + [Field ("IOSurfacePropertyKeyPixelSizeCastingAllowed")] + NSString PixelSizeCastingAllowedKey { get; } + } + + [StrongDictionary ("IOSurfacePropertyKey")] + partial interface IOSurfaceOptions { + nint AllocSize { get; set; } + nint Width { get; set; } + nint Height { get; set; } + nint BytesPerRow { get; set; } + nint BytesPerElement { get; set; } + nint ElementWidth { get; set; } + nint ElementHeight { get; set; } + nint Offset { get; set; } + NSDictionary [] PlaneInfo { get; set; } + nint PlaneWidth { get; set; } + nint PlaneHeight { get; set; } + nint PlaneBytesPerRow { get; set; } + nint PlaneOffset { get; set; } + nint PlaneSize { get; set; } + nint PlaneBase { get; set; } + nint PlaneBytesPerElement { get; set; } + nint PlaneElementWidth { get; set; } + nint PlaneElementHeight { get; set; } + IOSurfaceMemoryMap CacheMode { get; set; } + uint PixelFormat { get; set; } + bool PixelSizeCastingAllowed { get; set; } + } + + [iOS (10,0), Mac(10,12)] + [BaseType (typeof(NSObject))] + interface IOSurface : NSSecureCoding + { + [Internal, Export ("initWithProperties:")] + IntPtr Constructor (NSDictionary properties); + + [Wrap ("this (properties == null ? null : properties.Dictionary)")] + IntPtr Constructor (IOSurfaceOptions properties); + + [Internal, Export ("lockWithOptions:seed:")] + int _Lock (IOSurfaceLockOptions options, IntPtr seedPtr); + + [Internal, Export ("unlockWithOptions:seed:")] + int _Unlock (IOSurfaceLockOptions options, IntPtr seed); + + [Export ("allocationSize")] + nint AllocationSize { get; } + + [Export ("width")] + nint Width { get; } + + [Export ("height")] + nint Height { get; } + + [Export ("baseAddress")] + IntPtr BaseAddress { get; } + + [Export ("pixelFormat")] + uint PixelFormat { get; } + + [Export ("bytesPerRow")] + nint BytesPerRow { get; } + + [Export ("bytesPerElement")] + nint BytesPerElement { get; } + + [Export ("elementWidth")] + nint ElementWidth { get; } + + [Export ("elementHeight")] + nint ElementHeight { get; } + + [Export ("seed")] + uint Seed { get; } + + [Export ("planeCount")] + nuint PlaneCount { get; } + + [Export ("widthOfPlaneAtIndex:")] + nint GetWidth (nuint planeIndex); + + [Export ("heightOfPlaneAtIndex:")] + nint GetHeight (nuint planeIndex); + + [Export ("bytesPerRowOfPlaneAtIndex:")] + nint GetBytesPerRow (nuint planeIndex); + + [Export ("bytesPerElementOfPlaneAtIndex:")] + nint GetBytesPerElement (nuint planeIndex); + + [Export ("elementWidthOfPlaneAtIndex:")] + nint GetElementWidth (nuint planeIndex); + + [Export ("elementHeightOfPlaneAtIndex:")] + nint GetElementHeight (nuint planeIndex); + + [Export ("baseAddressOfPlaneAtIndex:")] + IntPtr GetBaseAddress (nuint planeIndex); + + [Export ("setAttachment:forKey:")] + void SetAttachment (NSObject anObject, NSString key); + + [Export ("attachmentForKey:")] + [return: NullAllowed] + NSObject GetAttachment (NSString key); + + [Export ("removeAttachmentForKey:")] + void RemoveAttachment (NSString key); + + [NullAllowed, Export ("allAttachments")] + NSDictionary AllAttachments { get; set; } + + [Export ("removeAllAttachments")] + void RemoveAllAttachments (); + + [Export ("inUse")] + bool InUse { [Bind ("isInUse")] get; } + + [Export ("incrementUseCount")] + void IncrementUseCount (); + + [Export ("decrementUseCount")] + void DecrementUseCount (); + + [Export ("localUseCount")] + int LocalUseCount { get; } + + [Export ("allowsPixelSizeCasting")] + bool AllowsPixelSizeCasting { get; } + + [iOS (11,0)][Mac (10,13)] + [Internal, Export ("setPurgeable:oldState:")] + int _SetPurgeable (IOSurfacePurgeabilityState newState, IntPtr oldStatePtr); + } +} + +#endif // XAMCORE_2_0 \ No newline at end of file diff --git a/tests/introspection/ApiBaseTest.cs b/tests/introspection/ApiBaseTest.cs index f525480cda9f..b79c1d78487a 100644 --- a/tests/introspection/ApiBaseTest.cs +++ b/tests/introspection/ApiBaseTest.cs @@ -215,6 +215,10 @@ protected virtual string FindLibrary (string libname, bool requiresFullPath = fa case "AudioUnit": libname = "AudioToolbox"; break; + case "IOSurface": + if (!TestRuntime.CheckXcodeVersion (9, 0)) + prefix = Path.Combine (Path.GetDirectoryName (prefix), "PrivateFrameworks"); + break; #endif case "CoreAnimation": // generated code uses QuartzCore correctly - even if the [Field] property is wrong diff --git a/tests/introspection/ApiFieldTest.cs b/tests/introspection/ApiFieldTest.cs index 4df2ff2a5422..50e926b7b84a 100644 --- a/tests/introspection/ApiFieldTest.cs +++ b/tests/introspection/ApiFieldTest.cs @@ -71,7 +71,7 @@ protected virtual bool Skip (PropertyInfo property) /// Override if you want to skip testing the specified constant. /// /// Constant name to ignore. - protected virtual bool Skip (string constantName) + protected virtual bool Skip (string constantName, string libraryName) { return false; } @@ -227,7 +227,7 @@ public void FieldExists () continue; string name = f.SymbolName; - if (Skip (name)) + if (Skip (name, f.LibraryName)) continue; string path = FindLibrary (f.LibraryName); diff --git a/tests/introspection/ApiTypoTest.cs b/tests/introspection/ApiTypoTest.cs index ab78b3433a56..7218d5269da4 100644 --- a/tests/introspection/ApiTypoTest.cs +++ b/tests/introspection/ApiTypoTest.cs @@ -134,6 +134,7 @@ public virtual bool Skip (MemberInfo methodName, string typo) { "Conflictserror", "Connnect", "Counterclock", + "Copyback", "Craete", "Crosstraining", "Cubemap", diff --git a/tests/introspection/Mac/MacApiFieldTest.cs b/tests/introspection/Mac/MacApiFieldTest.cs index c8b05093a7df..9026a486d726 100644 --- a/tests/introspection/Mac/MacApiFieldTest.cs +++ b/tests/introspection/Mac/MacApiFieldTest.cs @@ -160,7 +160,7 @@ protected override bool Skip (PropertyInfo p) } } - protected override bool Skip (string constantName) + protected override bool Skip (string constantName, string libraryName) { switch (constantName) { case "CBUUIDValidRangeString": @@ -183,7 +183,7 @@ protected override bool Skip (string constantName) return true; goto default; default: - return base.Skip (constantName); + return base.Skip (constantName, libraryName); } } diff --git a/tests/introspection/iOS/iOSApiCtorInitTest.cs b/tests/introspection/iOS/iOSApiCtorInitTest.cs index 784feed0d3a6..f32ba9b3a6a1 100644 --- a/tests/introspection/iOS/iOSApiCtorInitTest.cs +++ b/tests/introspection/iOS/iOSApiCtorInitTest.cs @@ -212,6 +212,8 @@ protected override bool Skip (Type type) return true; case "MPVolumeView": // Started failing with Xcode 9 beta 3 return true; + case "IOSurface": // Only works on device + return Runtime.Arch == Arch.SIMULATOR; default: return base.Skip (type); } diff --git a/tests/introspection/iOS/iOSApiFieldTest.cs b/tests/introspection/iOS/iOSApiFieldTest.cs index 80422dca8d36..0e964664fb77 100644 --- a/tests/introspection/iOS/iOSApiFieldTest.cs +++ b/tests/introspection/iOS/iOSApiFieldTest.cs @@ -58,6 +58,10 @@ protected override bool Skip (PropertyInfo p) if (Runtime.Arch == Arch.SIMULATOR) return true; break; + case "IOSurface": + // Available in the simulator starting with iOS 11 + return Runtime.Arch == Arch.SIMULATOR && !TestRuntime.CheckXcodeVersion (9, 0); + } switch (p.Name) { @@ -106,8 +110,13 @@ protected override bool Skip (PropertyInfo p) } } - protected override bool Skip (string constantName) + protected override bool Skip (string constantName, string libraryName) { + switch (libraryName) { + case "IOSurface": + return Runtime.Arch == Arch.SIMULATOR && !TestRuntime.CheckXcodeVersion (9, 0); + } + switch (constantName) { // grep ImageIO binary shows those symbols are not part of the binary // that match older results (nil) when loading them (see above) diff --git a/tools/common/Frameworks.cs b/tools/common/Frameworks.cs index ca3e5f903c60..eed1ce1cc158 100644 --- a/tools/common/Frameworks.cs +++ b/tools/common/Frameworks.cs @@ -136,6 +136,7 @@ public static Frameworks MacFrameworks { { "ModelIO", 10, 11 }, { "Intents", 10, 12 }, + { "IOSurface", "IOSurface", 10, 12 }, { "SafariServices", "SafariServices", 10, 12 }, { "MediaPlayer", "MediaPlayer", 10, 12, 1 }, @@ -244,6 +245,7 @@ public static Frameworks GetiOSFrameworks (Application app) { "UserNotificationsUI", "UserNotificationsUI", 10 }, { "Intents", "Intents", 10 }, { "IntentsUI", "IntentsUI", 10 }, + { "IOSurface", "IOSurface", 10 }, { "ARKit", "ARKit", 11 }, { "CoreNFC", "CoreNFC", 11 }, diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index bf9075661f0e..68dd98d0928b 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -1837,6 +1837,13 @@ void CheckNamespace (string ns, List exceptions) return; // 10.12 removed the header files for QTKit #endif goto default; + case "IOSurface": // There is no IOSurface.h +#if !MONOMAC + if (IsSimulator) + return; // Not available in the simulator (the header is there, but broken). +#endif + h = ""; + break; default: h = string.Format ("<{0}/{0}.h>", ns); break; diff --git a/tools/linker/ObjCExtensions.cs b/tools/linker/ObjCExtensions.cs index 306301c08ac4..1fb5bd234002 100644 --- a/tools/linker/ObjCExtensions.cs +++ b/tools/linker/ObjCExtensions.cs @@ -59,6 +59,7 @@ internal static void Initialize () Photos = profile.GetNamespace ("Photos"); CoreML = profile.GetNamespace ("CoreML"); Vision = profile.GetNamespace ("Vision"); + IOSurface = profile.GetNamespace ("IOSurface"); PdfKit = profile.GetNamespace ("PdfKit"); #if MONOMAC IOBluetooth = profile.GetNamespace ("IOBluetooth"); @@ -141,6 +142,8 @@ internal static void Initialize () public static string Vision { get; private set; } + public static string IOSurface { get; private set; } + public static string PdfKit { get; private set; } #if MONOMAC diff --git a/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs b/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs index d4a0727d8469..80a88f7f4102 100644 --- a/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs +++ b/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs @@ -71,6 +71,7 @@ public class MonoMacNamespaces : IStep { { Constants.PrintCoreLibrary, Namespaces.PrintCore }, { Constants.CoreMLLibrary, Namespaces.CoreML }, { Constants.VisionLibrary, Namespaces.Vision }, + { Constants.IOSurfaceLibrary, Namespaces.IOSurface }, { Constants.ExternalAccessoryLibrary, Namespaces.ExternalAccessory }, };