Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

[Enhancement] DeviceDisplay/DisplayInfo should report refresh rate #1443

Closed
janusw opened this issue Oct 12, 2020 · 5 comments · Fixed by #1505
Closed

[Enhancement] DeviceDisplay/DisplayInfo should report refresh rate #1443

janusw opened this issue Oct 12, 2020 · 5 comments · Fixed by #1505
Labels
feature-request A request for a new feature.
Milestone

Comments

@janusw
Copy link
Contributor

janusw commented Oct 12, 2020

Summary

DisplayInfo already contains various information about the display, like width/height, density, orientation, rotation, etc. It should also include the device's screen refresh rate.

API Changes

The DisplayInfo struct should obtain a new property called RefreshRate or similar:

public readonly struct DisplayInfo : IEquatable<DisplayInfo>
{
    [...]
    public double RefreshRate { get; }
    [...]
}

Example usage:

// Get Metrics
var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;

// display refresh rate in Hz (i.e. "frames per second")
var rate = mainDisplayInfo.RefreshRate;

Intended Use Case

The refresh rate can be useful for example in connection with sensor update rates, which are configurable via SensorSpeed (or can be throttled manually). If one knows the screen refresh rate, one can make sharper constraints on the necessary sensor rates. E.g. if my screen updates only with 30 Hz, I probably don't need to sample the OrientationSensor with 50 Hz, because the information can not be displayed that quickly. Or the other way around: If I know that my screen updates with 60 or even 120 Hz, then I might want to increase the sensor updates accordingly, so that I can get a smoother display (e.g. think of an "augmented-reality"-type camera overlay).

Implementation

Some pointers that might be useful for the implementation:

@janusw janusw added the feature-request A request for a new feature. label Oct 12, 2020
@janusw
Copy link
Contributor Author

janusw commented Oct 25, 2020

Getting the refresh rate on iOS and Android seems to be straightforward, but I did not find a way to obtain it on MacOS :(

The class AppKit.NSScreen, which is already being used in DeviceDisplay.macos.cs does not seem to provide anything in this direction: https://developer.apple.com/documentation/appkit/nsscreen

In principle there is a CGDisplayMode.refreshRate in Apple's CoreGraphics for MacOS: https://developer.apple.com/documentation/coregraphics/cgdisplaymode/1454661-refreshrate

However, in the .NET APIs for Xamarin.Mac, I only find a CGDisplay class, but no way to get a fresh rate or even just a CGDisplayMode.

@janusw
Copy link
Contributor Author

janusw commented Oct 25, 2020

In principle there is a CGDisplayMode.refreshRate in Apple's CoreGraphics for MacOS: https://developer.apple.com/documentation/coregraphics/cgdisplaymode/1454661-refreshrate

However, in the .NET APIs for Xamarin.Mac, I only find a CGDisplay class, but no way to get a fresh rate or even just a CGDisplayMode.

Maybe one should open a feature request in https://github.com/xamarin/xamarin-macios (or am I just missing something)?

@janusw
Copy link
Contributor Author

janusw commented Oct 25, 2020

Maybe one should open a feature request in https://github.com/xamarin/xamarin-macios (or am I just missing something)?

Just did that: xamarin/xamarin-macios#9958

@janusw
Copy link
Contributor Author

janusw commented Oct 25, 2020

Finally, the following might be relevant for an UWP implementation: https://docs.microsoft.com/en-us/uwp/api/windows.graphics.display.core.hdmidisplaymode.refreshrate

janusw added a commit to janusw/Essentials that referenced this issue Oct 26, 2020
janusw added a commit to janusw/Essentials that referenced this issue Oct 26, 2020
janusw added a commit to janusw/Essentials that referenced this issue Oct 27, 2020
janusw added a commit to janusw/Essentials that referenced this issue Oct 27, 2020
janusw added a commit to janusw/Essentials that referenced this issue Nov 5, 2020
janusw added a commit to janusw/Essentials that referenced this issue Nov 5, 2020
janusw added a commit to janusw/Essentials that referenced this issue Nov 5, 2020
janusw added a commit to janusw/Essentials that referenced this issue Nov 6, 2020
* with a proper implementation on Android and iOS
* MacOS and UWP always give a rate of zero
janusw added a commit to janusw/Essentials that referenced this issue Nov 6, 2020
janusw added a commit to janusw/Essentials that referenced this issue Nov 6, 2020
janusw added a commit to janusw/Essentials that referenced this issue Dec 1, 2020
* with a proper implementation on Android and iOS
* MacOS and UWP always give a rate of zero
janusw added a commit to janusw/Essentials that referenced this issue Dec 1, 2020
janusw added a commit to janusw/Essentials that referenced this issue Dec 1, 2020
@mattleibow mattleibow added this to the 1.6.1 milestone Jan 19, 2021
@mattleibow
Copy link
Contributor

Thanks for all the work and research on this one!

mattleibow added a commit that referenced this issue Jan 25, 2021
* DisplayInfo: add a property 'RefreshRate' (#1443)
* Samples: show RefreshRate on DeviceInfoPage (#1443)
* Add documentation for DisplayInfo.RefreshRate (#1443)
* Add the logic to read the macos refresh rate
  Based on xamarin-macios issue: xamarin/xamarin-macios#9958
  Copied code from: https://gist.github.com/chamons/1eae64a2e5e10cbaf18b140e92ec4ca3
* Try to guess the Hz, but fall back to 60
  This is not the most correct way, but is probably good enough. If there are any better ways in future, we can just add them in or replace this logic.

Co-authored-by: Matthew Leibowitz <mattleibow@live.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request A request for a new feature.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants