From 79a593c2ca040e3695a756e85db2b85af2314ea9 Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Mon, 24 Jul 2017 22:18:04 -0400 Subject: [PATCH 01/14] [Xcode9] Add IOSurface bindings --- src/Constants.iOS.cs.in | 1 + src/Constants.mac.cs.in | 1 + src/IOSurface/IODefs.cs | 38 ++++++ src/IOSurface/IOSurface.cs | 90 ++++++++++++++ src/frameworks.sources | 15 ++- src/iosurface.cs | 239 +++++++++++++++++++++++++++++++++++++ 6 files changed, 381 insertions(+), 3 deletions(-) create mode 100644 src/IOSurface/IODefs.cs create mode 100644 src/IOSurface/IOSurface.cs create mode 100644 src/iosurface.cs diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index bba21b28b3f..a21eb7077ca 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -115,5 +115,6 @@ 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 const string IOSurfaceLibrary = "/System/Library/Frameworks/IOSurface.framework/IOSurface"; } } diff --git a/src/Constants.mac.cs.in b/src/Constants.mac.cs.in index 32fef06f7fa..c59f8589298 100644 --- a/src/Constants.mac.cs.in +++ b/src/Constants.mac.cs.in @@ -129,5 +129,6 @@ 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"; } } diff --git a/src/IOSurface/IODefs.cs b/src/IOSurface/IODefs.cs new file mode 100644 index 00000000000..a2da68951ec --- /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 + }; + + +} \ No newline at end of file diff --git a/src/IOSurface/IOSurface.cs b/src/IOSurface/IOSurface.cs new file mode 100644 index 00000000000..6defe22da6f --- /dev/null +++ b/src/IOSurface/IOSurface.cs @@ -0,0 +1,90 @@ +// +// 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 + [iOS (10,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 + [iOS (10,0), Mac(10,12)] + public int Lock (IOSurfaceLockOptions options) + { + return _Lock (options, IntPtr.Zero); + } + + // kern_return_t + [iOS (10,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 + [iOS (10,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 e0694962734..e27dbc570bb 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -863,6 +863,13 @@ INTENTS_SOURCES = \ Intents/INStartWorkoutIntent.cs \ Intents/INSaveProfileInCarIntent.cs \ +# IOSurface +IOSURFACE_CORE_SOURCES = \ + IOSurface/IODefs.cs + +IOSURFACE_SOURCES = \ + IOSurface/IOSurface.cs + # JavaScriptCore JAVASCRIPTCORE_SOURCES = \ @@ -1587,7 +1594,8 @@ MAC_FRAMEWORKS = \ GLKit \ ImageIO \ ImageKit \ - Intents \ + Intents \ + IOSurface \ JavaScriptCore \ LocalAuthentication \ MapKit \ @@ -1670,6 +1678,7 @@ IOS_FRAMEWORKS = \ ImageIO \ Intents \ IntentsUI \ + IOSurface \ JavaScriptCore \ LocalAuthentication \ MapKit \ @@ -1781,12 +1790,12 @@ TVOS_FRAMEWORKS = \ StoreKit \ SystemConfiguration \ TVMLKit \ - TVServices \ + TVServices \ UIKit \ UserNotifications \ VideoSubscriberAccount \ VideoToolbox \ - Vision \ + Vision # # Compute the SOURCES variables. diff --git a/src/iosurface.cs b/src/iosurface.cs new file mode 100644 index 00000000000..8042eaae5ae --- /dev/null +++ b/src/iosurface.cs @@ -0,0 +1,239 @@ +// +// 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] + interface IOSurfacePropertyKey { + [Field ("IOSurfacePropertyAllocSizeKey")] + [iOS (10,0), Mac (10,12)] + NSString AllocSizeKey { get; } + + [Field ("IOSurfacePropertyKeyWidth")] + [iOS (10,0), Mac (10,12)] + NSString WidthKey { get; } + + [Field ("IOSurfacePropertyKeyHeight")] + [iOS (10,0), Mac (10,12)] + NSString HeightKey { get; } + + [Field ("IOSurfacePropertyKeyBytesPerRow")] + [iOS (10,0), Mac (10,12)] + NSString BytesPerRowKey { get; } + + [Field ("IOSurfacePropertyKeyBytesPerElement")] + [iOS (10,0), Mac (10,12)] + NSString BytesPerElementKey { get; } + + [Field ("IOSurfacePropertyKeyElementWidth")] + [iOS (10,0), Mac (10,12)] + NSString ElementWidthKey { get; } + + [Field ("IOSurfacePropertyKeyElementHeight")] + [iOS (10,0), Mac (10,12)] + NSString ElementHeightKey { get; } + + [Field ("IOSurfacePropertyKeyOffset")] + [iOS (10,0), Mac (10,12)] + NSString OffsetKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneInfo")] + [iOS (10,0), Mac (10,12)] + NSString PlaneInfoKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneWidth")] + [iOS (10,0), Mac (10,12)] + NSString PlaneWidthKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneHeight")] + [iOS (10,0), Mac (10,12)] + NSString PlaneHeightKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBytesPerRow")] + [iOS (10,0), Mac (10,12)] + NSString PlaneBytesPerRowKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneOffset")] + [iOS (10,0), Mac (10,12)] + NSString PlaneOffsetKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneSize")] + [iOS (10,0), Mac (10,12)] + NSString PlaneSizeKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBase")] + [iOS (10,0), Mac (10,12)] + NSString PlaneBaseKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneBytesPerElement")] + [iOS (10,0), Mac (10,12)] + NSString PlaneBytesPerElementKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneElementWidth")] + [iOS (10,0), Mac (10,12)] + NSString PlaneElementWidthKey { get; } + + [Field ("IOSurfacePropertyKeyPlaneElementHeight")] + [iOS (10,0), Mac (10,12)] + NSString PlaneElementHeightKey { get; } + + [Field ("IOSurfacePropertyKeyCacheMode")] + [iOS (10,0), Mac (10,12)] + NSString CacheModeKey { get; } + + [Field ("IOSurfacePropertyKeyPixelFormat")] + [iOS (10,0), Mac (10,12)] + NSString PixelFormatKey { get; } + + [Field ("IOSurfacePropertyKeyPixelSizeCastingAllowed")] + [iOS (10,0), Mac (10,12)] + 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; } + } + + // @interface IOSurface : NSObject + [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 WidthOfPlane (nuint planeIndex); + + [Export ("heightOfPlaneAtIndex:")] + nint HeightOfPlane (nuint planeIndex); + + [Export ("bytesPerRowOfPlaneAtIndex:")] + nint BytesPerRowOfPlane (nuint planeIndex); + + [Export ("bytesPerElementOfPlaneAtIndex:")] + nint BytesPerElementOfPlane (nuint planeIndex); + + [Export ("elementWidthOfPlaneAtIndex:")] + nint ElementWidthOfPlane (nuint planeIndex); + + [Export ("elementHeightOfPlaneAtIndex:")] + nint ElementHeightOfPlane (nuint planeIndex); + + [Export ("baseAddressOfPlaneAtIndex:")] + IntPtr BaseAddressOfPlane (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)] + [Internal, Export ("setPurgeable:oldState:")] + int _SetPurgeable (IOSurfacePurgeabilityState newState, IntPtr oldStatePtr); + } +} + +#endif // XAMCORE_2_0 \ No newline at end of file From 7d45675c4fcaa999fde4f0a12a3eaedd96f3d9bd Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 25 Jul 2017 08:10:11 -0400 Subject: [PATCH 02/14] Make dictionary internal, change the naming of these methods per Sebastien's review --- src/iosurface.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/iosurface.cs b/src/iosurface.cs index 8042eaae5ae..6ddd950a2fd 100644 --- a/src/iosurface.cs +++ b/src/iosurface.cs @@ -17,6 +17,7 @@ namespace XamCore.IOSurface { [Static] + [Internal] interface IOSurfacePropertyKey { [Field ("IOSurfacePropertyAllocSizeKey")] [iOS (10,0), Mac (10,12)] @@ -179,25 +180,25 @@ interface IOSurface : NSSecureCoding nuint PlaneCount { get; } [Export ("widthOfPlaneAtIndex:")] - nint WidthOfPlane (nuint planeIndex); + nint GetWidth (nuint planeIndex); [Export ("heightOfPlaneAtIndex:")] - nint HeightOfPlane (nuint planeIndex); + nint GetHeight (nuint planeIndex); [Export ("bytesPerRowOfPlaneAtIndex:")] - nint BytesPerRowOfPlane (nuint planeIndex); + nint GetBytesPerRow (nuint planeIndex); [Export ("bytesPerElementOfPlaneAtIndex:")] - nint BytesPerElementOfPlane (nuint planeIndex); + nint GetBytesPerElement (nuint planeIndex); [Export ("elementWidthOfPlaneAtIndex:")] - nint ElementWidthOfPlane (nuint planeIndex); + nint GetElementWidth (nuint planeIndex); [Export ("elementHeightOfPlaneAtIndex:")] - nint ElementHeightOfPlane (nuint planeIndex); + nint GetElementHeight (nuint planeIndex); [Export ("baseAddressOfPlaneAtIndex:")] - IntPtr BaseAddressOfPlane (nuint planeIndex); + IntPtr GetBaseAddress (nuint planeIndex); [Export ("setAttachment:forKey:")] void SetAttachment (NSObject anObject, NSString key); From e8372bf5b9c235a34fe19ce430ef317626f26323 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Tue, 25 Jul 2017 10:19:56 -0500 Subject: [PATCH 03/14] Let tooling know about IOSurface --- src/Foundation/NSObject.mac.cs | 1 + tools/common/Frameworks.cs | 2 ++ tools/linker/ObjCExtensions.cs | 3 +++ tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs | 1 + 4 files changed, 7 insertions(+) diff --git a/src/Foundation/NSObject.mac.cs b/src/Foundation/NSObject.mac.cs index d68db95b93e..15bec5f89de 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); #endif // ** IF YOU ADD ITEMS HERE PLEASE UPDATE linker/ObjCExtensions.cs and mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs diff --git a/tools/common/Frameworks.cs b/tools/common/Frameworks.cs index 2f4b0640a5d..329243ebf0e 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/linker/ObjCExtensions.cs b/tools/linker/ObjCExtensions.cs index abea8f72617..e0cbfe33667 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"); #if MONOMAC IOBluetooth = profile.GetNamespace ("IOBluetooth"); IOBluetoothUI = profile.GetNamespace ("IOBluetoothUI"); @@ -140,6 +141,8 @@ internal static void Initialize () public static string Vision { get; private set; } + public static string IOSurface { get; private set; } + #if MONOMAC public static string IOBluetooth { get; private set; } public static string IOBluetoothUI { get; private set; } diff --git a/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs b/tools/mmp/linker/MonoMac.Tuner/MonoMacNamespaces.cs index 513773896c3..c04ef30e95f 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 }, }; public void Process (LinkContext context) From 849eb56c23efed1135e6a9bf14cc252cb602719f Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Tue, 25 Jul 2017 12:09:36 -0400 Subject: [PATCH 04/14] Move the availability to the top definition --- src/iosurface.cs | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/src/iosurface.cs b/src/iosurface.cs index 6ddd950a2fd..d7c20dc7ea5 100644 --- a/src/iosurface.cs +++ b/src/iosurface.cs @@ -18,89 +18,69 @@ namespace XamCore.IOSurface { [Static] [Internal] + [iOS (10,0), Mac (10,12)] interface IOSurfacePropertyKey { [Field ("IOSurfacePropertyAllocSizeKey")] - [iOS (10,0), Mac (10,12)] NSString AllocSizeKey { get; } [Field ("IOSurfacePropertyKeyWidth")] - [iOS (10,0), Mac (10,12)] NSString WidthKey { get; } [Field ("IOSurfacePropertyKeyHeight")] - [iOS (10,0), Mac (10,12)] NSString HeightKey { get; } [Field ("IOSurfacePropertyKeyBytesPerRow")] - [iOS (10,0), Mac (10,12)] NSString BytesPerRowKey { get; } [Field ("IOSurfacePropertyKeyBytesPerElement")] - [iOS (10,0), Mac (10,12)] NSString BytesPerElementKey { get; } [Field ("IOSurfacePropertyKeyElementWidth")] - [iOS (10,0), Mac (10,12)] NSString ElementWidthKey { get; } [Field ("IOSurfacePropertyKeyElementHeight")] - [iOS (10,0), Mac (10,12)] NSString ElementHeightKey { get; } [Field ("IOSurfacePropertyKeyOffset")] - [iOS (10,0), Mac (10,12)] NSString OffsetKey { get; } [Field ("IOSurfacePropertyKeyPlaneInfo")] - [iOS (10,0), Mac (10,12)] NSString PlaneInfoKey { get; } [Field ("IOSurfacePropertyKeyPlaneWidth")] - [iOS (10,0), Mac (10,12)] NSString PlaneWidthKey { get; } [Field ("IOSurfacePropertyKeyPlaneHeight")] - [iOS (10,0), Mac (10,12)] NSString PlaneHeightKey { get; } [Field ("IOSurfacePropertyKeyPlaneBytesPerRow")] - [iOS (10,0), Mac (10,12)] NSString PlaneBytesPerRowKey { get; } [Field ("IOSurfacePropertyKeyPlaneOffset")] - [iOS (10,0), Mac (10,12)] NSString PlaneOffsetKey { get; } [Field ("IOSurfacePropertyKeyPlaneSize")] - [iOS (10,0), Mac (10,12)] NSString PlaneSizeKey { get; } [Field ("IOSurfacePropertyKeyPlaneBase")] - [iOS (10,0), Mac (10,12)] NSString PlaneBaseKey { get; } [Field ("IOSurfacePropertyKeyPlaneBytesPerElement")] - [iOS (10,0), Mac (10,12)] NSString PlaneBytesPerElementKey { get; } [Field ("IOSurfacePropertyKeyPlaneElementWidth")] - [iOS (10,0), Mac (10,12)] NSString PlaneElementWidthKey { get; } [Field ("IOSurfacePropertyKeyPlaneElementHeight")] - [iOS (10,0), Mac (10,12)] NSString PlaneElementHeightKey { get; } [Field ("IOSurfacePropertyKeyCacheMode")] - [iOS (10,0), Mac (10,12)] NSString CacheModeKey { get; } [Field ("IOSurfacePropertyKeyPixelFormat")] - [iOS (10,0), Mac (10,12)] NSString PixelFormatKey { get; } [Field ("IOSurfacePropertyKeyPixelSizeCastingAllowed")] - [iOS (10,0), Mac (10,12)] NSString PixelSizeCastingAllowedKey { get; } } From 8275514be98c3789fe91ae156a2cab5352aca397 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Tue, 1 Aug 2017 16:33:04 +0200 Subject: [PATCH 05/14] Add trailing comma in last enum value --- src/IOSurface/IODefs.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/IOSurface/IODefs.cs b/src/IOSurface/IODefs.cs index a2da68951ec..071e28a4e57 100644 --- a/src/IOSurface/IODefs.cs +++ b/src/IOSurface/IODefs.cs @@ -14,14 +14,14 @@ namespace XamCore.IOSurface { public enum IOSurfaceLockOptions : uint { ReadOnly = 1, - AvoidSync = 2 + AvoidSync = 2, } public enum IOSurfacePurgeabilityState : uint { NonVolatile = 0, Volatile = 1, Empty = 2, - KeepCurrent = 3 + KeepCurrent = 3, } // To be used with kIOSurfaceCacheMode or IOSurfacePropertyKeyCacheMode @@ -31,8 +31,8 @@ public enum IOSurfaceMemoryMap { WriteThruCache = 2 << 8, CopybackCache = 3 << 8, WriteCombineCache = 4 << 8, - CopybackInnerCache = 5 << 8 + CopybackInnerCache = 5 << 8, }; -} \ No newline at end of file +} From 92945109b78d0f310253fc12b7973cd71bca7493 Mon Sep 17 00:00:00 2001 From: Alex Soto Date: Tue, 1 Aug 2017 13:28:37 -0500 Subject: [PATCH 06/14] Fix registrar error --- tools/common/StaticRegistrar.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index bf9075661f0..c53fd63b770 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -1837,6 +1837,9 @@ 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 + h = ""; + break; default: h = string.Format ("<{0}/{0}.h>", ns); break; From 8408b2ebc66a62d9e0546e3861cd49d46b399377 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 31 Aug 2017 16:08:16 +0200 Subject: [PATCH 07/14] [src] Fix whitespace changes. --- src/frameworks.sources | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/frameworks.sources b/src/frameworks.sources index 9f97da02cff..df47ba74786 100644 --- a/src/frameworks.sources +++ b/src/frameworks.sources @@ -1617,7 +1617,7 @@ MAC_FRAMEWORKS = \ GLKit \ ImageIO \ ImageKit \ - Intents \ + Intents \ IOSurface \ JavaScriptCore \ LocalAuthentication \ @@ -1811,12 +1811,12 @@ TVOS_FRAMEWORKS = \ StoreKit \ SystemConfiguration \ TVMLKit \ - TVServices \ + TVServices \ UIKit \ UserNotifications \ VideoSubscriberAccount \ VideoToolbox \ - Vision + Vision \ # # Compute the SOURCES variables. From d5beb917e7d129e0d204e4f8929d84f254b46784 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 31 Aug 2017 17:04:22 +0200 Subject: [PATCH 08/14] [IOSurface] This framework was a private framework before iOS 11. This framework was a private framework before iOS 11, yet the headers claim many API were introduced in iOS 10. So take account of this difference by using the private framework location in iOS 10.3 or earlier. Testing these API from Xcode works fine when run on an iOS 10.3 device, and I've confirmed the IOSurface framework is loaded from the private frameworks path on older devices (and when built using Xcode 9 and linked with the public framework path). --- src/Constants.iOS.cs.in | 10 +++++++++- tests/introspection/ApiBaseTest.cs | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index d7247c38c0f..59467b85b76 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -115,7 +115,15 @@ 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 const string IOSurfaceLibrary = "/System/Library/Frameworks/IOSurface.framework/IOSurface"; + public static string IOSurfaceLibrary { + get { +#if !COREBUILD && !MTOUCH + 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/tests/introspection/ApiBaseTest.cs b/tests/introspection/ApiBaseTest.cs index 9300bdf360f..8c43a06fe5f 100644 --- a/tests/introspection/ApiBaseTest.cs +++ b/tests/introspection/ApiBaseTest.cs @@ -213,6 +213,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 From 5bc4782fc1d87c81f3757f57ea94921c9eb7dea5 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 31 Aug 2017 17:08:02 +0200 Subject: [PATCH 09/14] [introspection] Expand vocabulary to include 'Copyback'. --- tests/introspection/ApiTypoTest.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/introspection/ApiTypoTest.cs b/tests/introspection/ApiTypoTest.cs index b61d67120e7..4c8606b2417 100644 --- a/tests/introspection/ApiTypoTest.cs +++ b/tests/introspection/ApiTypoTest.cs @@ -132,6 +132,7 @@ public virtual bool Skip (MemberInfo methodName, string typo) { "Conflictserror", "Connnect", "Counterclock", + "Copyback", "Craete", "Crosstraining", "Cubemap", From ed599c86817a932626b093cade92116f75b74808 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 31 Aug 2017 17:08:17 +0200 Subject: [PATCH 10/14] [introspection/mtouch] The IOSurface only works in the simulator. --- tests/introspection/iOS/iOSApiCtorInitTest.cs | 2 ++ tools/common/StaticRegistrar.cs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/tests/introspection/iOS/iOSApiCtorInitTest.cs b/tests/introspection/iOS/iOSApiCtorInitTest.cs index e2846798bb9..146a7abf110 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/tools/common/StaticRegistrar.cs b/tools/common/StaticRegistrar.cs index c53fd63b770..68dd98d0928 100644 --- a/tools/common/StaticRegistrar.cs +++ b/tools/common/StaticRegistrar.cs @@ -1838,6 +1838,10 @@ void CheckNamespace (string ns, List exceptions) #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: From 35318a73f0be0d11c7107294554942056e918bb4 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Thu, 31 Aug 2017 17:14:43 +0200 Subject: [PATCH 11/14] [IOSurface] Remove unneeded comment. --- src/iosurface.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/iosurface.cs b/src/iosurface.cs index d7c20dc7ea5..7104ecdb60d 100644 --- a/src/iosurface.cs +++ b/src/iosurface.cs @@ -109,7 +109,6 @@ partial interface IOSurfaceOptions { bool PixelSizeCastingAllowed { get; set; } } - // @interface IOSurface : NSObject [iOS (10,0), Mac(10,12)] [BaseType (typeof(NSObject))] interface IOSurface : NSSecureCoding From f3d172b4e23ef14ac52be87034645ee994422e91 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 1 Sep 2017 13:11:29 +0200 Subject: [PATCH 12/14] [IOSurface] Add missing availability attribute. --- src/iosurface.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/iosurface.cs b/src/iosurface.cs index 7104ecdb60d..ca82b268822 100644 --- a/src/iosurface.cs +++ b/src/iosurface.cs @@ -210,7 +210,7 @@ interface IOSurface : NSSecureCoding [Export ("allowsPixelSizeCasting")] bool AllowsPixelSizeCasting { get; } - [iOS (11,0)] + [iOS (11,0)][Mac (10,13)] [Internal, Export ("setPurgeable:oldState:")] int _SetPurgeable (IOSurfacePurgeabilityState newState, IntPtr oldStatePtr); } From 923606056a4057a7c1b1d45781edddb3c0879566 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Fri, 1 Sep 2017 18:03:31 +0200 Subject: [PATCH 13/14] [introspection] IOSurface is only available in the simulator starting with iOS 11. --- tests/introspection/ApiFieldTest.cs | 4 ++-- tests/introspection/Mac/MacApiFieldTest.cs | 4 ++-- tests/introspection/iOS/iOSApiFieldTest.cs | 11 ++++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/tests/introspection/ApiFieldTest.cs b/tests/introspection/ApiFieldTest.cs index 4df2ff2a542..50e926b7b84 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/Mac/MacApiFieldTest.cs b/tests/introspection/Mac/MacApiFieldTest.cs index c8b05093a7d..9026a486d72 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/iOSApiFieldTest.cs b/tests/introspection/iOS/iOSApiFieldTest.cs index 80422dca8d3..0e964664fb7 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) From 3c99edbc261bb664d0c91f4df6142a8b326db5bf Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Mon, 4 Sep 2017 08:48:07 +0200 Subject: [PATCH 14/14] [IOSurface] Disable code to make IOSurface work on iOS 10. Disable the code to make IOSurface work on iOS 10, since it may be rejected by the App Store. This also means adjusting the availability attributes, so that the introspection tests pass (and to document that technically these API won't work when used with Xamarin.iOS in iOS 10). I've filed bug #[59201][1] to keep track of this, maybe we can re-enable this later. [1]: https://bugzilla.xamarin.com/show_bug.cgi?id=59201 --- src/Constants.iOS.cs.in | 10 ++++++---- src/IOSurface/IOSurface.cs | 16 ++++++++++++---- src/iosurface.cs | 4 +++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Constants.iOS.cs.in b/src/Constants.iOS.cs.in index 59467b85b76..faf63e2fb3c 100644 --- a/src/Constants.iOS.cs.in +++ b/src/Constants.iOS.cs.in @@ -117,10 +117,12 @@ namespace MonoTouch { public const string FileProviderUILibrary = "/System/Library/Frameworks/FileProviderUI.framework/FileProviderUI"; public static string IOSurfaceLibrary { get { -#if !COREBUILD && !MTOUCH - if (!XamCore.UIKit.UIDevice.CurrentDevice.CheckSystemVersion (11, 0)) - return "/System/Library/PrivateFrameworks/IOSurface.framework/IOSurface"; -#endif +// 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"; } } diff --git a/src/IOSurface/IOSurface.cs b/src/IOSurface/IOSurface.cs index 6defe22da6f..dc8d640353a 100644 --- a/src/IOSurface/IOSurface.cs +++ b/src/IOSurface/IOSurface.cs @@ -32,7 +32,9 @@ namespace XamCore.IOSurface { public partial class IOSurface { // kern_return_t - [iOS (10,0), Mac(10,12)] + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] public int Lock (IOSurfaceLockOptions options, ref int seed) { unsafe { @@ -43,14 +45,18 @@ public int Lock (IOSurfaceLockOptions options, ref int seed) } // kern_return_t - [iOS (10,0), Mac(10,12)] + // 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 - [iOS (10,0), Mac(10,12)] + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] public int Unlock (IOSurfaceLockOptions options, ref int seed) { unsafe { @@ -61,7 +67,9 @@ public int Unlock (IOSurfaceLockOptions options, ref int seed) } // kern_return_t - [iOS (10,0), Mac(10,12)] + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] public int Unlock (IOSurfaceLockOptions options) { return _Unlock (options, IntPtr.Zero); diff --git a/src/iosurface.cs b/src/iosurface.cs index ca82b268822..d9fd903cbb4 100644 --- a/src/iosurface.cs +++ b/src/iosurface.cs @@ -18,7 +18,9 @@ namespace XamCore.IOSurface { [Static] [Internal] - [iOS (10,0), Mac (10,12)] + // See bug #59201 [iOS (10,0)] + [iOS (11, 0)] + [Mac (10, 12)] interface IOSurfacePropertyKey { [Field ("IOSurfacePropertyAllocSizeKey")] NSString AllocSizeKey { get; }