[WIP] Add basic support for PlayerDisplayMetrics.devicePixelRatio on macOS#213
[WIP] Add basic support for PlayerDisplayMetrics.devicePixelRatio on macOS#213JustinFincher wants to merge 4 commits intoUnityTech:masterfrom
Conversation
Basic support for NSScreen.backingScaleFactor. Notice this solution don’t subscribe to NSScreen change (didChangeScreenProfileNotification), thus won’t respond to the screen change.
|
hi, sorry for this late response. Thanks your efforts and this PR looks great! As to your concerns, (1) yes, we should not write the dirty mark in every frame update. I have made some changes in #243 to fix this; (2) do you have any idea on this issue? maybe we can come up with some fallback solutions? (3) since we have implemented UIWidgetsMessageManager for ios and android already, it is ok to use our own UIWidgetsMessageManager on Mac too. |
|
@zhuxingwei 1) Alright, I will be looking into #243 to get this PR fully working and qualified to be merged when I am available. Also currently I am in a TOFEL school so probably cannot do much about this issue right now, sorry! 2) 2x NSWindow situation is actually rare (if you don't count the standalone resolution dialog). If so, there would be extra work but still can be solved on the native side. 3) Great, though I would like my implementation of UIWidgetsMessageManager to be reviewed by you guys as my implementation is just a POC. |
This is a working proof of concept of devicePixelRatio support on macOS standalone player. As that being said, the current progress may not suitable for direct production usage, but to provide an idea on how to do this on macOS.
Added Features
OSXDeviceScaleFactormethodViewportMatricsChangedeventChanges
How this works
This is achieved by providing
OSXDeviceScaleFactorthe NSScreenUtils.m file:This is a bit tricky because:
unity-classes.jarand call 'com.unity3d.player.UnityPlayer.UnitySendMessage') or iOS (importUnityInterface.h). So I have to build a custom UnitySendMessage clone and name it UnityOSXSendMessage. If there is an official way to call UnitySendMessage in macOS plugins then please ignore this issue.As the UnityOSXSendMessage link is established, we now send a "ViewportMatricsChanged" message whenever the screen change notification is triggered. The "UIWidgetViewController.keyboardChanged" argument is copied from the Java implementation and may need to change to a more suitable name.
In the Update function of DisplayMetrics.cs I added a line to invalidate the current scale factor, then in the next cycle UIWidgets would call OSXDeviceScaleFactor to get a new scale value.
Concern & To-do
displayMetrics.Updateis called in UIWidgetsPanel.Update(), which is expensive on CPU usage. I wonder if there is a solution to calldisplayMetrics.Updateonly if needed.Reference
Demo Video
demo.mp4.zip