Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: remoting/webapp/base/js/viewport.js

Issue 1237763002: Support fractional desktopScale values in choosePluginDimensions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | remoting/webapp/base/js/viewport_unittest.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Provides shared view port management utilities. 7 * Provides shared view port management utilities.
8 */ 8 */
9 9
10 /** @suppress {duplicate} */ 10 /** @suppress {duplicate} */
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 // 4. Avoid having huge "letterboxes" around the desktop, if it's really 56 // 4. Avoid having huge "letterboxes" around the desktop, if it's really
57 // small. 57 // small.
58 // 5. Compensate for mismatched DPIs, so that the behaviour of features like 58 // 5. Compensate for mismatched DPIs, so that the behaviour of features like
59 // shrink-to-fit matches their "natural" rather than their pixel size. 59 // shrink-to-fit matches their "natural" rather than their pixel size.
60 // e.g. with shrink-to-fit active a 1024x768 low-DPI host on a 640x480 60 // e.g. with shrink-to-fit active a 1024x768 low-DPI host on a 640x480
61 // high-DPI client will be up-scaled to 1280x960, rather than displayed 61 // high-DPI client will be up-scaled to 1280x960, rather than displayed
62 // at 1:1 host:physical client pixels. 62 // at 1:1 host:physical client pixels.
63 // 63 //
64 // To determine the ideal size we follow a four-stage process: 64 // To determine the ideal size we follow a four-stage process:
65 // 1. Determine the "natural" size at which to display the desktop. 65 // 1. Determine the "natural" size at which to display the desktop.
66 // a. Initially assume 1:1 mapping of desktop to client device pixels. 66 // a. Initially assume 1:1 mapping of desktop to client device pixels,
67 // adjusting for the specified desktopScale.
67 // b. If host DPI is less than the client's then up-scale accordingly. 68 // b. If host DPI is less than the client's then up-scale accordingly.
68 // c. If desktopScale is configured for the host then allow that to
69 // reduce the amount of up-scaling from (b). e.g. if the client:host
70 // DPIs are 2:1 then a desktopScale of 1.5 would reduce the up-scale
71 // to 4:3, while a desktopScale of 3.0 would result in no up-scaling.
72 // 2. If the natural size of the desktop is smaller than the client device 69 // 2. If the natural size of the desktop is smaller than the client device
73 // then apply up-scaling by an integer scale factor to avoid excessive 70 // then apply up-scaling by an integer scale factor to avoid excessive
74 // letterboxing. 71 // letterboxing.
75 // 3. If shrink-to-fit is configured then: 72 // 3. If shrink-to-fit is configured then:
76 // a. If the natural size exceeds the client size then apply down-scaling 73 // a. If the natural size exceeds the client size then apply down-scaling
77 // by an arbitrary scale factor. 74 // by an arbitrary scale factor.
78 // b. If we're in full-screen mode and the client & host aspect-ratios 75 // b. If we're in full-screen mode and the client & host aspect-ratios
79 // are radically different (e.g. the host is actually multi-monitor) 76 // are radically different (e.g. the host is actually multi-monitor)
80 // then shrink-to-fit to the shorter dimension, rather than leaving 77 // then shrink-to-fit to the shorter dimension, rather than leaving
81 // huge letterboxes; the user can then bump-scroll around the desktop. 78 // huge letterboxes; the user can then bump-scroll around the desktop.
82 // 4. If the overall scale factor is fractionally over an integer factor 79 // 4. If the overall scale factor is fractionally over an integer factor
83 // then reduce it to that integer factor, to avoid blurring. 80 // then reduce it to that integer factor, to avoid blurring.
84 81
85 // All calculations are performed in device pixels. 82 // All calculations are performed in client device pixels, but taking into
86 var clientWidth = clientSizeDips.width * clientPixelRatio; 83 // account |desktopScale|.
87 var clientHeight = clientSizeDips.height * clientPixelRatio; 84 var clientWidth = clientSizeDips.width * clientPixelRatio / desktopScale;
85 var clientHeight = clientSizeDips.height * clientPixelRatio / desktopScale;
88 86
89 // 1. Determine a "natural" size at which to display the desktop. 87 // 1. Determine a "natural" size at which to display the desktop.
90 var scale = 1.0; 88 var scale = 1.0;
91 89
92 // Determine the effective host device pixel ratio. 90 // Determine the effective host device pixel ratio.
93 // Note that we round up or down to the closest integer pixel ratio. 91 // Note that we round up or down to the closest integer pixel ratio.
94 var hostPixelRatioX = Math.round(desktopDpi.x / 96); 92 var hostPixelRatioX = Math.round(desktopDpi.x / 96);
95 var hostPixelRatioY = Math.round(desktopDpi.y / 96); 93 var hostPixelRatioY = Math.round(desktopDpi.y / 96);
96 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY); 94 var hostPixelRatio = Math.min(hostPixelRatioX, hostPixelRatioY);
97 95
98 // Allow up-scaling to account for DPI. 96 // Allow up-scaling to account for DPI.
99 scale = Math.max(scale, clientPixelRatio / hostPixelRatio); 97 scale = Math.max(scale, clientPixelRatio / hostPixelRatio);
100 98
101 // Allow some or all of the up-scaling to be cancelled by the desktopScale.
102 if (desktopScale > 1.0) {
103 scale = Math.max(1.0, scale / desktopScale);
104 }
105
106 // 2. If the host is still much smaller than the client, then up-scale to 99 // 2. If the host is still much smaller than the client, then up-scale to
107 // avoid wasting space, but only by an integer factor, to avoid blurring. 100 // avoid wasting space, but only by an integer factor, to avoid blurring.
108 if (desktopSize.width * scale <= clientWidth && 101 if (desktopSize.width * scale <= clientWidth &&
109 desktopSize.height * scale <= clientHeight) { 102 desktopSize.height * scale <= clientHeight) {
110 var scaleX = Math.floor(clientWidth / desktopSize.width); 103 var scaleX = Math.floor(clientWidth / desktopSize.width);
111 var scaleY = Math.floor(clientHeight / desktopSize.height); 104 var scaleY = Math.floor(clientHeight / desktopSize.height);
112 scale = Math.min(scaleX, scaleY); 105 scale = Math.min(scaleX, scaleY);
113 console.assert(scale >= 1.0, 'Bad scale: ' + scale + '.'); 106 console.assert(scale >= 1.0, 'Bad scale: ' + scale + '.');
114 } 107 }
115 108
(...skipping 26 matching lines...) Expand all
142 // 4. Avoid blurring for close-to-integer up-scaling factors. 135 // 4. Avoid blurring for close-to-integer up-scaling factors.
143 if (scale > 1.0) { 136 if (scale > 1.0) {
144 var scaleBlurriness = scale / Math.floor(scale); 137 var scaleBlurriness = scale / Math.floor(scale);
145 if (scaleBlurriness < 1.1) { 138 if (scaleBlurriness < 1.1) {
146 scale = Math.floor(scale); 139 scale = Math.floor(scale);
147 } 140 }
148 } 141 }
149 142
150 // Return the necessary plugin dimensions in DIPs. 143 // Return the necessary plugin dimensions in DIPs.
151 scale = scale / clientPixelRatio; 144 scale = scale / clientPixelRatio;
145 scale = scale * desktopScale;
152 var pluginWidth = Math.round(desktopSize.width * scale); 146 var pluginWidth = Math.round(desktopSize.width * scale);
153 var pluginHeight = Math.round(desktopSize.height * scale); 147 var pluginHeight = Math.round(desktopSize.height * scale);
154 return { width: pluginWidth, height: pluginHeight }; 148 return { width: pluginWidth, height: pluginHeight };
155 }; 149 };
156 150
157 }()); 151 }());
OLDNEW
« no previous file with comments | « no previous file | remoting/webapp/base/js/viewport_unittest.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698