[Xcode9] Add IOSurface bindings (#2363)

* 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).

* 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
This commit is contained in:
Miguel de Icaza 2017-09-05 08:57:58 -04:00 коммит произвёл Sebastien Pouliot
Родитель 03711e698d
Коммит c453776ac0
17 изменённых файлов: 413 добавлений и 5 удалений

Просмотреть файл

@ -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";
}
}

Просмотреть файл

@ -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";
}

Просмотреть файл

@ -99,6 +99,7 @@ namespace XamCore.Foundation {
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

38
src/IOSurface/IODefs.cs Normal file
Просмотреть файл

@ -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,
};
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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 \

221
src/iosurface.cs Normal file
Просмотреть файл

@ -0,0 +1,221 @@
//
// IOSurface bindings
//
// Authors:
// Miguel de Icaza <miguel@microsoft.com>
//
// 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<NSString, NSObject> 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

Просмотреть файл

@ -215,6 +215,10 @@ namespace Introspection {
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

Просмотреть файл

@ -71,7 +71,7 @@ namespace Introspection {
/// Override if you want to skip testing the specified constant.
/// </summary>
/// <param name="constantName">Constant name to ignore.</param>
protected virtual bool Skip (string constantName)
protected virtual bool Skip (string constantName, string libraryName)
{
return false;
}
@ -227,7 +227,7 @@ namespace Introspection {
continue;
string name = f.SymbolName;
if (Skip (name))
if (Skip (name, f.LibraryName))
continue;
string path = FindLibrary (f.LibraryName);

Просмотреть файл

@ -134,6 +134,7 @@ namespace Introspection
"Conflictserror",
"Connnect",
"Counterclock",
"Copyback",
"Craete",
"Crosstraining",
"Cubemap",

Просмотреть файл

@ -160,7 +160,7 @@ namespace Introspection {
}
}
protected override bool Skip (string constantName)
protected override bool Skip (string constantName, string libraryName)
{
switch (constantName) {
case "CBUUIDValidRangeString":
@ -183,7 +183,7 @@ namespace Introspection {
return true;
goto default;
default:
return base.Skip (constantName);
return base.Skip (constantName, libraryName);
}
}

Просмотреть файл

@ -212,6 +212,8 @@ namespace Introspection {
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);
}

Просмотреть файл

@ -58,6 +58,10 @@ namespace Introspection {
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 @@ namespace Introspection {
}
}
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)

Просмотреть файл

@ -136,6 +136,7 @@ public class Frameworks : Dictionary <string, Framework>
{ "ModelIO", 10, 11 },
{ "Intents", 10, 12 },
{ "IOSurface", "IOSurface", 10, 12 },
{ "SafariServices", "SafariServices", 10, 12 },
{ "MediaPlayer", "MediaPlayer", 10, 12, 1 },
@ -244,6 +245,7 @@ public class Frameworks : Dictionary <string, Framework>
{ "UserNotificationsUI", "UserNotificationsUI", 10 },
{ "Intents", "Intents", 10 },
{ "IntentsUI", "IntentsUI", 10 },
{ "IOSurface", "IOSurface", 10 },
{ "ARKit", "ARKit", 11 },
{ "CoreNFC", "CoreNFC", 11 },

Просмотреть файл

@ -1837,6 +1837,13 @@ namespace XamCore.Registrar {
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 = "<IOSurface/IOSurfaceObjC.h>";
break;
default:
h = string.Format ("<{0}/{0}.h>", ns);
break;

Просмотреть файл

@ -59,6 +59,7 @@ namespace Xamarin.Linker {
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 @@ namespace Xamarin.Linker {
public static string Vision { get; private set; }
public static string IOSurface { get; private set; }
public static string PdfKit { get; private set; }
#if MONOMAC

Просмотреть файл

@ -71,6 +71,7 @@ namespace MonoMac.Tuner {
{ Constants.PrintCoreLibrary, Namespaces.PrintCore },
{ Constants.CoreMLLibrary, Namespaces.CoreML },
{ Constants.VisionLibrary, Namespaces.Vision },
{ Constants.IOSurfaceLibrary, Namespaces.IOSurface },
{ Constants.ExternalAccessoryLibrary, Namespaces.ExternalAccessory },
};