diff --git a/src/CoreGraphics/CGDisplay.cs b/src/CoreGraphics/CGDisplay.cs index 5b36223d1560..8f5660d6a185 100644 --- a/src/CoreGraphics/CGDisplay.cs +++ b/src/CoreGraphics/CGDisplay.cs @@ -271,6 +271,28 @@ public static int GetShieldingWindowID (int display) public static int ShieldingWindowLevel { get { return CGShieldingWindowLevel (); } } + + [DllImport (Constants.CoreGraphicsLibrary)] + extern static IntPtr CGDisplayCopyDisplayMode (uint display); + + [DllImport (Constants.CoreGraphicsLibrary)] + extern static void CGDisplayModeRelease (IntPtr mode); + + [DllImport (Constants.CoreGraphicsLibrary)] + extern static double CGDisplayModeGetRefreshRate (IntPtr mode); + + /// Get the refresh rate for the specified display. + /// The identifier for the display. + /// The display rate, in hertz, of the specified display, or in case of failure. + public static double? GetRefreshRate (int display) + { + var mode = CGDisplayCopyDisplayMode ((uint) display); + if (mode == IntPtr.Zero) + return null; + var refreshRate = CGDisplayModeGetRefreshRate (mode); + CGDisplayModeRelease (mode); + return refreshRate; + } #endif } } diff --git a/tests/monotouch-test/CoreGraphics/CGDisplayTest.cs b/tests/monotouch-test/CoreGraphics/CGDisplayTest.cs new file mode 100644 index 000000000000..e45bd71f7d94 --- /dev/null +++ b/tests/monotouch-test/CoreGraphics/CGDisplayTest.cs @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; + +using Foundation; +using ObjCRuntime; +using CoreGraphics; + +using NUnit.Framework; + +#if __MONOMAC__ || __MACCATALYST__ + +namespace MonoTouchFixtures.CoreGraphics { + + [TestFixture] + [Preserve (AllMembers = true)] + public class CGDisplayTest { + + [Test] + public void GetRefreshRate () + { + Assert.That (CGDisplay.GetRefreshRate (CGDisplay.MainDisplayID), Is.Not.EqualTo (0), "RefreshRate"); + } + } +} + +#endif // __MONOMAC__ || __MACCATALYST__ diff --git a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore index b5a001140b69..46b089df0dc6 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/MacCatalyst-CoreGraphics.ignore @@ -36,7 +36,6 @@ !missing-pinvoke! CGDirectDisplayCopyCurrentMetalDevice is not bound !missing-pinvoke! CGDisplayCopyAllDisplayModes is not bound !missing-pinvoke! CGDisplayCopyColorSpace is not bound -!missing-pinvoke! CGDisplayCopyDisplayMode is not bound !missing-pinvoke! CGDisplayFade is not bound !missing-pinvoke! CGDisplayGetDrawingContext is not bound !missing-pinvoke! CGDisplayIsActive is not bound @@ -54,10 +53,8 @@ !missing-pinvoke! CGDisplayModeGetIOFlags is not bound !missing-pinvoke! CGDisplayModeGetPixelHeight is not bound !missing-pinvoke! CGDisplayModeGetPixelWidth is not bound -!missing-pinvoke! CGDisplayModeGetRefreshRate is not bound !missing-pinvoke! CGDisplayModeGetWidth is not bound !missing-pinvoke! CGDisplayModeIsUsableForDesktopGUI is not bound -!missing-pinvoke! CGDisplayModeRelease is not bound !missing-pinvoke! CGDisplayModeRetain is not bound !missing-pinvoke! CGDisplayModelNumber is not bound !missing-pinvoke! CGDisplayPrimaryDisplay is not bound diff --git a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore index e73b7d078547..49eb263f857d 100644 --- a/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore +++ b/tests/xtro-sharpie/api-annotations-dotnet/macOS-CoreGraphics.ignore @@ -35,7 +35,6 @@ !missing-pinvoke! CGDirectDisplayCopyCurrentMetalDevice is not bound !missing-pinvoke! CGDisplayCopyAllDisplayModes is not bound !missing-pinvoke! CGDisplayCopyColorSpace is not bound -!missing-pinvoke! CGDisplayCopyDisplayMode is not bound !missing-pinvoke! CGDisplayFade is not bound !missing-pinvoke! CGDisplayGetDrawingContext is not bound !missing-pinvoke! CGDisplayIsActive is not bound @@ -53,11 +52,9 @@ !missing-pinvoke! CGDisplayModeGetIOFlags is not bound !missing-pinvoke! CGDisplayModeGetPixelHeight is not bound !missing-pinvoke! CGDisplayModeGetPixelWidth is not bound -!missing-pinvoke! CGDisplayModeGetRefreshRate is not bound !missing-pinvoke! CGDisplayModeGetWidth is not bound !missing-pinvoke! CGDisplayModeIsUsableForDesktopGUI is not bound !missing-pinvoke! CGDisplayModelNumber is not bound -!missing-pinvoke! CGDisplayModeRelease is not bound !missing-pinvoke! CGDisplayModeRetain is not bound !missing-pinvoke! CGDisplayPrimaryDisplay is not bound !missing-pinvoke! CGDisplayRegisterReconfigurationCallback is not bound