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

add new property DisplayInfo.RefreshRate #1505

Merged
merged 15 commits into from
Jan 25, 2021

Conversation

janusw
Copy link
Contributor

@janusw janusw commented Nov 6, 2020

Description of Change

This enhancement was proposed in #1443. It extends the DisplayInfo class with information about the display's refresh rate.

The new property has an implementation on Android, iOS and UWP. On MacOS it is always zero at present, because the corresponding Xamarin API is missing on MacOS (see also xamarin/xamarin-macios#9958).

I have tested the implementation on real hardware with Android 10 and iOS14.

Bugs Fixed

API Changes

List all API changes here (or just put None), example:

Added:

  • public float DisplayInfo.RefreshRate { get; }
  • constructor: DisplayInfo(double width, double height, double density, DisplayOrientation orientation, DisplayRotation rotation, float rate)

Behavioral Changes

None.

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Has samples (if omitted, state reason in description)
  • Rebased on top of main at time of PR
  • Changes adhere to coding standard
  • Updated documentation (see walkthrough)

Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking really good. We just can't break API.

@janusw janusw force-pushed the issue1443_displayinfo_refreshrate branch from affa970 to 0994f1f Compare November 6, 2020 19:58
@janusw janusw force-pushed the issue1443_displayinfo_refreshrate branch from 0994f1f to 46a0f8b Compare December 1, 2020 07:48
mattleibow
mattleibow previously approved these changes Jan 19, 2021
@mattleibow mattleibow added this to the 1.6.1 milestone Jan 19, 2021
@mattleibow
Copy link
Contributor

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

mattleibow
mattleibow previously approved these changes Jan 19, 2021
Copy link
Contributor

@mattleibow mattleibow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested on my Razer Phone and got that sweet extra Hz

@mattleibow
Copy link
Contributor

CI seems unhappy on some devices. Can't seem to repro it locally :(

using var display = GetDefaultDisplay();
var display = GetDefaultDisplay();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this, it appears that Android 21-24 throws a ObjectDisposedException for the Display object

@janusw
Copy link
Contributor Author

janusw commented Jan 19, 2021

I tested on my Razer Phone and got that sweet extra Hz

Cool :)
I only tested it on standard 60 Hz devices so far ...

@janusw
Copy link
Contributor Author

janusw commented Jan 19, 2021

Thanks a lot for adding a MacOS implementation, @mattleibow! I just ran Samples.Mac on a MacBook with Big Sur, but unfortunately I see a Refresh Rate of zero :/
Did you test it and could you observe a more meaningful value?

@mattleibow
Copy link
Contributor

mattleibow commented Jan 19, 2021

I got 60 on my Mac mini. I saw in the docs that sometimes it will be 0, but let me see if there is more info or another way.

Docs: https://developer.apple.com/documentation/coregraphics/1454661-cgdisplaymodegetrefreshrate

Not sure if this is the best now that you say it isn't working...

@mattleibow
Copy link
Contributor

@janusw I think I may have found a solution... But it doesn't work for my screen...

I saw this issue: glfw/glfw#137
And this commit: glfw/glfw@aab0871

Maybe if you tweak some things it works for you?

@janusw
Copy link
Contributor Author

janusw commented Jan 20, 2021

@janusw I think I may have found a solution... But it doesn't work for my screen...

I saw this issue: glfw/glfw#137
And this commit: glfw/glfw@aab0871

Maybe if you tweak some things it works for you?

Thanks for your efforts here, Matt! I tried your solution, but I still only get a RefreshRate of 0 on the MacBook.

I see CVDisplayLinkInterop.GetRefreshRate being called twice. The first time, all components of period are zero. The second time, period.Flags and period.TimeScale have rather odd non-zero values, but period.TimeValue is still zero. I have no idea why this is the case.

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.
@mattleibow mattleibow merged commit 90a40a3 into xamarin:main Jan 25, 2021
@janusw
Copy link
Contributor Author

janusw commented Jan 25, 2021

Awesome! Thanks for merging 😃

@janusw janusw deleted the issue1443_displayinfo_refreshrate branch January 25, 2021 20:11
dimonovdd added a commit to dimonovdd/Essentials that referenced this pull request Jan 26, 2021
* main:
  Update docs
  Add new property DisplayInfo.RefreshRate (xamarin#1505)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] DeviceDisplay/DisplayInfo should report refresh rate
2 participants