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

Side by Side Diff: remoting/android/java/src/org/chromium/chromoting/DesktopCanvas.java

Issue 2367423002: Change Viewport calculations to use screen size without System UI (Closed)
Patch Set: Created 4 years, 2 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 | no next file » | 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 package org.chromium.chromoting; 5 package org.chromium.chromoting;
6 6
7 import android.graphics.Matrix; 7 import android.graphics.Matrix;
8 import android.graphics.PointF; 8 import android.graphics.PointF;
9 import android.graphics.Rect; 9 import android.graphics.Rect;
10 import android.graphics.RectF; 10 import android.graphics.RectF;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 * Sets the desired center position of the viewport. 80 * Sets the desired center position of the viewport.
81 * 81 *
82 * @param newX The new x coordinate value for the desired center position. 82 * @param newX The new x coordinate value for the desired center position.
83 * @param newY The new y coordinate value for the desired center position. 83 * @param newY The new y coordinate value for the desired center position.
84 */ 84 */
85 public void setViewportPosition(float newX, float newY) { 85 public void setViewportPosition(float newX, float newY) {
86 mViewportPosition.set(newX, newY); 86 mViewportPosition.set(newX, newY);
87 } 87 }
88 88
89 /** 89 /**
90 * Returns the current size of the viewport. This size includes the offset calculations for
91 * any visible system UI.
92 *
93 * @return A point representing the current size of the viewport.
94 */
95 private PointF getViewportSize() {
96 float adjustedScreenWidth = mRenderData.screenWidth - mSystemUiOffsetPix els.right;
97 float adjustedScreenHeight = mRenderData.screenHeight - mSystemUiOffsetP ixels.bottom;
98
99 return new PointF(adjustedScreenWidth, adjustedScreenHeight);
100 }
101
102 /**
103 * Returns the true center position of the viewport (in image coordinates). 90 * Returns the true center position of the viewport (in image coordinates).
104 * 91 *
105 * @return A point representing the true center position of the viewport. 92 * @return A point representing the true center position of the viewport.
106 */ 93 */
107 private PointF getTrueViewportCenter() { 94 private PointF getTrueViewportCenter() {
108 PointF viewportSize = getViewportSize();
109
110 // Find the center point of the viewport on the screen. 95 // Find the center point of the viewport on the screen.
111 float[] viewportPosition = {((float) viewportSize.x / 2), ((float) viewp ortSize.y / 2)}; 96 float[] viewportPosition = {
97 ((float) mRenderData.screenWidth / 2), ((float) mRenderData.scre enHeight / 2)};
112 98
113 // Convert the screen position to an image position. 99 // Convert the screen position to an image position.
114 Matrix screenToImage = new Matrix(); 100 Matrix screenToImage = new Matrix();
115 mRenderData.transform.invert(screenToImage); 101 mRenderData.transform.invert(screenToImage);
116 screenToImage.mapPoints(viewportPosition); 102 screenToImage.mapPoints(viewportPosition);
117 return new PointF(viewportPosition[0], viewportPosition[1]); 103 return new PointF(viewportPosition[0], viewportPosition[1]);
118 } 104 }
119 105
120 /** 106 /**
121 * Sets the offset values used to calculate the space used by system UI. 107 * Sets the offset values used to calculate the space used by system UI.
(...skipping 27 matching lines...) Expand all
149 repositionImage(false); 135 repositionImage(false);
150 } 136 }
151 137
152 /** 138 /**
153 * Repositions the image by translating it (without affecting the zoom level ). 139 * Repositions the image by translating it (without affecting the zoom level ).
154 * 140 *
155 * @param centerViewport Determines whether the viewport will be translated to the desired 141 * @param centerViewport Determines whether the viewport will be translated to the desired
156 * center position before being adjusted to fit the sc reen boundaries. 142 * center position before being adjusted to fit the sc reen boundaries.
157 */ 143 */
158 public void repositionImage(boolean centerViewport) { 144 public void repositionImage(boolean centerViewport) {
159 PointF viewportSize = getViewportSize();
160 // The goal of the code below is to position the viewport as close to th e desired center 145 // The goal of the code below is to position the viewport as close to th e desired center
161 // position as possible whilst keeping as much of the desktop in view as possible. 146 // position as possible whilst keeping as much of the desktop in view as possible.
162 // To achieve these goals, we first position the desktop image at the de sired center 147 // To achieve these goals, we first position the desktop image at the de sired center
163 // point and then re-position it to maximize the viewable area. 148 // point and then re-position it to maximize the viewable area.
164 if (centerViewport) { 149 if (centerViewport) {
165 // Map the current viewport position to screen coordinates. 150 // Map the current viewport position to screen coordinates.
166 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y }; 151 float[] viewportPosition = {mViewportPosition.x, mViewportPosition.y };
167 mRenderData.transform.mapPoints(viewportPosition); 152 mRenderData.transform.mapPoints(viewportPosition);
168 153
154 float viewportTransX = ((float) mRenderData.screenWidth / 2) - viewp ortPosition[0];
155 float viewportTransY = ((float) mRenderData.screenHeight / 2) - view portPosition[1];
156
169 // Translate so the viewport is displayed in the middle of the scree n. 157 // Translate so the viewport is displayed in the middle of the scree n.
170 mRenderData.transform.postTranslate( 158 mRenderData.transform.postTranslate(viewportTransX, viewportTransY);
171 ((float) viewportSize.x / 2) - viewportPosition[0],
172 ((float) viewportSize.y / 2) - viewportPosition[1]);
173 } 159 }
174 160
175 // Get the coordinates of the desktop rectangle (top-left/bottom-right c orners) in 161 // Get the coordinates of the desktop rectangle (top-left/bottom-right c orners) in
176 // screen coordinates. Order is: left, top, right, bottom. 162 // screen coordinates. Order is: left, top, right, bottom.
177 RectF rectScreen = new RectF(0, 0, mRenderData.imageWidth, mRenderData.i mageHeight); 163 RectF rectScreen = new RectF(0, 0, mRenderData.imageWidth, mRenderData.i mageHeight);
178 mRenderData.transform.mapRect(rectScreen); 164 mRenderData.transform.mapRect(rectScreen);
179 165
180 float leftDelta = rectScreen.left; 166 float leftDelta = rectScreen.left;
181 float rightDelta = 167 float rightDelta =
182 rectScreen.right - mRenderData.screenWidth + mSystemUiOffsetPixe ls.right; 168 rectScreen.right - mRenderData.screenWidth + mSystemUiOffsetPixe ls.right;
183 float topDelta = rectScreen.top; 169 float topDelta = rectScreen.top;
184 float bottomDelta = 170 float bottomDelta =
185 rectScreen.bottom - mRenderData.screenHeight + mSystemUiOffsetPi xels.bottom; 171 rectScreen.bottom - mRenderData.screenHeight + mSystemUiOffsetPi xels.bottom;
186 float xAdjust = 0; 172 float xAdjust = 0;
187 float yAdjust = 0; 173 float yAdjust = 0;
188 174
189 if (rectScreen.right - rectScreen.left < viewportSize.x) { 175 if (rectScreen.right - rectScreen.left < mRenderData.screenWidth) {
190 // Image is narrower than the screen, so center it. 176 // Image is narrower than the screen, so center it.
191 xAdjust = -(rightDelta + leftDelta) / 2; 177 xAdjust = -(rightDelta + leftDelta) / 2;
192 } else if (leftDelta > 0 && rightDelta > 0) { 178 } else if (leftDelta > 0 && rightDelta > 0) {
193 // Panning the image left will show more of it. 179 // Panning the image left will show more of it.
194 xAdjust = -Math.min(leftDelta, rightDelta); 180 xAdjust = -Math.min(leftDelta, rightDelta);
195 } else if (leftDelta < 0 && rightDelta < 0) { 181 } else if (leftDelta < 0 && rightDelta < 0) {
196 // Pan the image right. 182 // Pan the image right.
197 xAdjust = Math.min(-leftDelta, -rightDelta); 183 xAdjust = Math.min(-leftDelta, -rightDelta);
198 } 184 }
199 185
200 // Apply similar logic for yAdjust. 186 // Apply similar logic for yAdjust.
201 if (rectScreen.bottom - rectScreen.top < viewportSize.y) { 187 if (rectScreen.bottom - rectScreen.top < mRenderData.screenHeight) {
202 yAdjust = -(bottomDelta + topDelta) / 2; 188 yAdjust = -(bottomDelta + topDelta) / 2;
203 } else if (topDelta > 0 && bottomDelta > 0) { 189 } else if (topDelta > 0 && bottomDelta > 0) {
204 yAdjust = -Math.min(topDelta, bottomDelta); 190 yAdjust = -Math.min(topDelta, bottomDelta);
205 } else if (topDelta < 0 && bottomDelta < 0) { 191 } else if (topDelta < 0 && bottomDelta < 0) {
206 yAdjust = Math.min(-topDelta, -bottomDelta); 192 yAdjust = Math.min(-topDelta, -bottomDelta);
207 } 193 }
208 194
209 mRenderData.transform.postTranslate(xAdjust, yAdjust); 195 mRenderData.transform.postTranslate(xAdjust, yAdjust);
210 196
211 mRenderStub.setTransformation(mRenderData.transform); 197 mRenderStub.setTransformation(mRenderData.transform);
(...skipping 28 matching lines...) Expand all
240 // Displayed image is too small in both directions, so apply the min imum zoom 226 // Displayed image is too small in both directions, so apply the min imum zoom
241 // level needed to fit either the width or height. 227 // level needed to fit either the width or height.
242 float scale = Math.min((float) mRenderData.screenWidth / mRenderData .imageWidth, 228 float scale = Math.min((float) mRenderData.screenWidth / mRenderData .imageWidth,
243 (float) mRenderData.screenHeight / mRenderDat a.imageHeight); 229 (float) mRenderData.screenHeight / mRenderDat a.imageHeight);
244 mRenderData.transform.setScale(scale, scale); 230 mRenderData.transform.setScale(scale, scale);
245 } 231 }
246 232
247 repositionImage(centerViewport); 233 repositionImage(centerViewport);
248 } 234 }
249 } 235 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698