Skip to content

Commit

Permalink
[metalperformanceshaders] Fix MPSImageLanczosScale base class change (#…
Browse files Browse the repository at this point in the history
…3170)

Sadly this creates a breaking change since the `ScaleTransform`
property was re-introduced with an incorrect signature in the new
base class `MPSImageScale`

Unless someone has an idea how to avoid it (I don't see an option)
then we'll have to document it in the 15.7 release notes.

Also add missing _SetScaleTransform call and related unit tests
  • Loading branch information
spouliot committed Jan 9, 2018
1 parent 4b667e4 commit f9ceb5c
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace XamCore.MetalPerformanceShaders {

public partial class MPSImageLanczosScale {
public partial class MPSImageScale {
static int size_of_scale_transform = Marshal.SizeOf (typeof(MPSScaleTransform));

public virtual MPSScaleTransform? ScaleTransform {
Expand All @@ -24,6 +24,7 @@ public virtual MPSScaleTransform? ScaleTransform {
IntPtr ptr = Marshal.AllocHGlobal (size_of_scale_transform);
try {
Marshal.StructureToPtr<MPSScaleTransform> (value.Value, ptr, false);
_SetScaleTransform (ptr);
}
finally {
Marshal.FreeHGlobal (ptr);
Expand Down
2 changes: 1 addition & 1 deletion src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1008,7 +1008,7 @@ METALPERFORMANCESHADERS_CORE_SOURCES = \
MetalPerformanceShaders/MPSKernel.cs \

METALPERFORMANCESHADERS_SOURCES = \
MetalPerformanceShaders/MPSImageLanczosScale.cs \
MetalPerformanceShaders/MPSImageScale.cs \
MetalPerformanceShaders/MPSCnnConvolutionDescriptor.cs \
MetalPerformanceShaders/MPSCnnNeuron.cs \
MetalPerformanceShaders/MPSCnnKernel.cs \
Expand Down
25 changes: 11 additions & 14 deletions src/metalperformanceshaders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -499,20 +499,9 @@ interface MPSImageErode {
// MPSImageResampling.h

[iOS (9,0)][Mac (10, 13, onlyOn64: true)]
[BaseType (typeof (MPSUnaryImageKernel))]
[BaseType (typeof (MPSImageScale))]
[DisableDefaultCtor]
interface MPSImageLanczosScale {
// scaleTransform property should be like:
// unsafe MPSScaleTransform* ScaleTransform { get; set; }
// which is both ugly and not supported by the generator
[Export ("scaleTransform")]
[Internal]
IntPtr _GetScaleTransform ();

[Export ("setScaleTransform:")]
[Internal]
void _SetScaleTransform (IntPtr value);

// inlining .ctor from base class

[Export ("initWithDevice:")]
Expand Down Expand Up @@ -1979,8 +1968,16 @@ interface MPSImageScale {
[DesignatedInitializer]
IntPtr Constructor (IMTLDevice device);

[NullAllowed, Export ("scaleTransform", ArgumentSemantic.Assign)]
MPSScaleTransform ScaleTransform { get; set; }
// scaleTransform property should be like:
// unsafe MPSScaleTransform* ScaleTransform { get; set; }
// which is both ugly and not supported by the generator
[Export ("scaleTransform")]
[Internal]
IntPtr _GetScaleTransform ();

[Export ("setScaleTransform:")]
[Internal]
void _SetScaleTransform (IntPtr value);

[Export ("initWithCoder:device:")]
[DesignatedInitializer]
Expand Down
56 changes: 56 additions & 0 deletions tests/monotouch-test/MetalPerformanceShaders/ImageScaleTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#if !__WATCHOS__

using System;
using Foundation;

#if XAMCORE_2_0
using Metal;
using MetalPerformanceShaders;
#else
using MonoTouch.Metal;
using MonoTouch.MetalPerformanceShaders;
#endif

using NUnit.Framework;

namespace MonoTouchFixtures.MetalPerformanceShaders {

[TestFixture]
public class ImageScaleTest {

IMTLDevice device;

[TestFixtureSetUp]
public void Metal ()
{
TestRuntime.AssertXcodeVersion (9,0);

device = MTLDevice.SystemDefault;
// some older hardware won't have a default
if (device == null)
Assert.Inconclusive ("Metal is not supported");
}

[Test]
public void ScaleTransform ()
{
var st = new MPSScaleTransform () {
ScaleX = 1,
ScaleY = 2,
TranslateX = 3,
TranslateY = 4,
};
using (var scale = new MPSImageScale (device)) {
scale.ScaleTransform = st;
// roundtrip with our (non generated) code
var rt = scale.ScaleTransform.Value;
Assert.That (rt.ScaleX, Is.EqualTo (st.ScaleX), "ScaleX");
Assert.That (rt.ScaleY, Is.EqualTo (st.ScaleY), "ScaleY");
Assert.That (rt.TranslateX, Is.EqualTo (st.TranslateX), "TranslateX");
Assert.That (rt.TranslateY, Is.EqualTo (st.TranslateY), "TranslateY");
}
}
}
}

#endif
1 change: 0 additions & 1 deletion tests/xtro-sharpie/iOS-MetalPerformanceShaders.todo

This file was deleted.

1 change: 0 additions & 1 deletion tests/xtro-sharpie/macOS-MetalPerformanceShaders.todo

This file was deleted.

1 change: 0 additions & 1 deletion tests/xtro-sharpie/tvOS-MetalPerformanceShaders.todo

This file was deleted.

0 comments on commit f9ceb5c

Please sign in to comment.