Can't get real device pixel ratio (taking into account page zoom)
Reported by
siarhei....@vizor-games.com,
Sep 22 2017
|
|||||
Issue descriptionUserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36 Steps to reproduce the problem: To make Adobe Flash StageScaleMode.NO_SCALE work in chromium I need to get real device pixel ratio Like in edge or internet explorer (window.screen.logicalXDPI, window.screen.deviceXDPI): https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms533721(v=vs.85).aspx Without this feature I can't make the game I'm porting to HTML5 Canvas from Adobe Flash work on both retina and non-retina the same way. In Chromium 200% window.devicePixelRatio on non-retina device equals retina 100%. So when running retina device on 100% scale images look twice smaller because I have to divide by "window.devicePixelRatio=2" to make NO_SCALE mode work in HTML5 Canvas What is the expected behavior? In Chromium 100% browser scale on non-retina device and on retina 100% images should look the same with the use of real and logical device dpi. Example from msdn docs for MSIE and MS Edge: https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms533721(v=vs.85).aspx What went wrong? In Chromium 200% browser dpi on non-retina device equals retina 100% (devicePixelRatio=2 for both devices) So when running retina device images look twice as small because I divide images dimensions by devicePixelRatio. for non-retina: 100% -> window.devicePixelRatio = 1; for retina: 100% -> window.devicePixelRatio = 2; Did this work before? N/A Does this work in other browsers? Yes Chrome version: 60.0.3112.113 Channel: n/a OS Version: 10.0 Flash Version: Can't support all devices properly in chromium without this feature. Thanks in advance.
,
Oct 2 2017
Many apps are getting this to work successfully. Could you attach an example to show us how your a doing it?
,
Oct 2 2017
,
Oct 3 2017
You can check it by link or in attachment: https://jsfiddle.net/cu6xjw61/2/ Rectangle on canvas doesnt change if you change window.devicePixelRatio (scroll mouse wheel or change browser scale) but the whole scene size (or main canvas size) changes based on browser scale. Test it on both retina and non retina. And compare the area of the whole scene and rectangle area. On retina screen objects look twice as small.
,
Oct 3 2017
Thank you for providing more feedback. Adding requester "junov@chromium.org" to the cc list and removing "Needs-Feedback" label. For more details visit https://www.chromium.org/issue-tracking/autotriage - Your friendly Sheriffbot
,
Oct 3 2017
That is the correct behavior as per the spec. The coordinate system of the 2d context is defined [1] such that one CSS pixel is equal to the size of one pixel in the canvas's bitmap. To get the behavior you are looking for, you need to scale the context. Like this: https://jsfiddle.net/cu6xjw61/3/ [1] https://html.spec.whatwg.org/multipage/canvas.html#2dcontext Excerpt: Using CSS pixels to describe the size of a rendering context's output bitmap does not mean that when rendered the canvas will cover an equivalent area in CSS pixels. CSS pixels are reused for ease of integration with CSS features, such as text layout. In other words, the canvas element below's rendering context has a 200x200 output bitmap (which internally uses CSS pixels as a unit for ease of integration with CSS) and is rendered as 100x100 CSS pixels: <canvas width=200 height=200 style=width:100px;width:100px>
,
Oct 4 2017
Please check adobe flash spec: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/StageScaleMode.html I need StageScaleMode.NO_SCALE: Specifies that the size of the application be fixed, so that it remains unchanged even as the size of the player window changes. Cropping might occur if the player window is smaller than the content. Refer to this game: https://apps.facebook.com/knightsbrides Elements on the stage remain the same 100% not depending on browser stage scale.
,
Oct 5 2017
Okay, I see. So basically you want the scale of the content of the canvas to not be affected by HTML/CSS content scaling. You can sniff any scaling done in CSS with this: canvas.getBoundingClientRect().width / parseInt(window.getComputedStyle(canvas).width) Unfortunately that will not take into account the full page zoom applied by the browser. Does that matter to you? Are you trying to make your content's scale independent of the browser's global page zoom? It seems flash's NO_SCALE mode has that behavior, but I can't image why you'd want to ignore the page zoom. That basically prevents visually impaired users (who need to magnify stuff) from using your web app. As far as I know, there's no inter-operable way of sniffing the page zoom. I found this page that shows a bunch of hacks (it's a bit dated): https://stackoverflow.com/questions/1713771/how-to-detect-page-zoom-level-in-all-modern-browsers Not sure if any of those tricks work in current versions of Chrome. It's possible that page zoom is purposely not sniffable in order to avoid leaking user preferences. Just to be clear, can you confirm whether your objective (or one of your objectives) is to prevent the canvas contents from being affected by the browser's page zoom setting?
,
Oct 9 2017
Yes. I confirm that we need to prevent the canvas contents from being affected by the browser's page zoom setting. All solutions solutions dont work or easily broken by opened devtools. We want our users not to notice any changes during switch from adobe flash to html5 client. We use both NO_SCALE and DEFAULT (SHOW_ALL) modes. We've tried to launch our client on a few users but had some really negative feedback about SHOW_ALL scale mode. So we need to implement NO_SCALE to give our users exact the same gaming experience.
,
Oct 9 2017
update: checked your solution: "canvas.getBoundingClientRect().width / parseInt(window.getComputedStyle(canvas).width" https://jsfiddle.net/cu6xjw61/6/ always returns 1 on both retina and non-retina in all browser scales. we need real device scale (system scale) for making NO_SCALE mode look the same on retina and non-retina (using both device (system) scale and window.devicePixelRatio)
,
Oct 13 2017
junov@: Could you please take a look and help in further triaging as per C#11.
,
Oct 13 2017
@11: That solution is only for sniffing scaling that is induced by the page's style. For example, if an hierarchical ancestor of the canvas element has a scale CSS transform. It seems there is now API for doing what you want. I am re-triaging this as a feature request, and assigning to the Zoom component for further triage and discussion.
,
Oct 17 2017
Can you make it as it is in MSIE or Edge Browsers? Something like: https://msdn.microsoft.com/ru-ru/library/windows/desktop/ms535868(v=vs.85).aspx * screen.systemXDPI (we always want the canvas element size to be affected by this parameter, cause user has set it on his own so he wants all elements to be larger scale) * screen.logicalXDPI * screen.deviceXDPI Thanks
,
Jul 25
|
|||||
►
Sign in to add a comment |
|||||
Comment 1 by nyerramilli@chromium.org
, Sep 25 2017