| OLD | NEW |
| 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 12 matching lines...) Expand all Loading... |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * Represents the desired center of the viewport. This value may not repres
ent the actual | 25 * Represents the desired center of the viewport. This value may not repres
ent the actual |
| 26 * center of the viewport as adjustments are made to ensure as much of the d
esktop is visible as | 26 * center of the viewport as adjustments are made to ensure as much of the d
esktop is visible as |
| 27 * possible. This value needs to be a pair of floats so the desktop image c
an be positioned | 27 * possible. This value needs to be a pair of floats so the desktop image c
an be positioned |
| 28 * with sub-pixel accuracy for smoother panning animations at high zoom leve
ls. | 28 * with sub-pixel accuracy for smoother panning animations at high zoom leve
ls. |
| 29 */ | 29 */ |
| 30 private PointF mViewportPosition = new PointF(); | 30 private PointF mViewportPosition = new PointF(); |
| 31 | 31 |
| 32 /** | 32 /** |
| 33 * Represents the amount of space, in pixels, used by system UI. | 33 * Represents the amount of space, in pixels, used by System UI. |
| 34 */ | 34 */ |
| 35 private Rect mSystemUiOffsetPixels = new Rect(); | 35 private Rect mSystemUiOffsetPixels = new Rect(); |
| 36 | 36 |
| 37 public DesktopCanvas(RenderStub renderStub, RenderData renderData) { | 37 public DesktopCanvas(RenderStub renderStub, RenderData renderData) { |
| 38 mRenderStub = renderStub; | 38 mRenderStub = renderStub; |
| 39 mRenderData = renderData; | 39 mRenderData = renderData; |
| 40 } | 40 } |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Shifts the viewport by the passed in deltas (in image coordinates). | 43 * Shifts the viewport by the passed in deltas (in image coordinates). |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 ((float) mRenderData.screenWidth / 2), ((float) mRenderData.scre
enHeight / 2)}; | 97 ((float) mRenderData.screenWidth / 2), ((float) mRenderData.scre
enHeight / 2)}; |
| 98 | 98 |
| 99 // Convert the screen position to an image position. | 99 // Convert the screen position to an image position. |
| 100 Matrix screenToImage = new Matrix(); | 100 Matrix screenToImage = new Matrix(); |
| 101 mRenderData.transform.invert(screenToImage); | 101 mRenderData.transform.invert(screenToImage); |
| 102 screenToImage.mapPoints(viewportPosition); | 102 screenToImage.mapPoints(viewportPosition); |
| 103 return new PointF(viewportPosition[0], viewportPosition[1]); | 103 return new PointF(viewportPosition[0], viewportPosition[1]); |
| 104 } | 104 } |
| 105 | 105 |
| 106 /** | 106 /** |
| 107 * 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. |
| 108 * | 108 * |
| 109 * @param left The space used by system UI on the left edge of the screen. | 109 * @param left The space used by System UI on the left edge of the screen. |
| 110 * @param top The space used by system UI on the top edge of the screen. | 110 * @param top The space used by System UI on the top edge of the screen. |
| 111 * @param right The space used by system UI on the right edge of the screen. | 111 * @param right The space used by System UI on the right edge of the screen. |
| 112 * @param bottom The space used by system UI on the bottom edge of the scree
n. | 112 * @param bottom The space used by System UI on the bottom edge of the scree
n. |
| 113 */ | 113 */ |
| 114 public void setSystemUiOffsetValues(int left, int top, int right, int bottom
) { | 114 public void setSystemUiOffsetValues(int left, int top, int right, int bottom
) { |
| 115 mSystemUiOffsetPixels.set(left, top, right, bottom); | 115 mSystemUiOffsetPixels.set(left, top, right, bottom); |
| 116 } | 116 } |
| 117 | 117 |
| 118 /** Called to indicate that no System UI is visible. */ |
| 119 public void clearSystemUiOffsets() { |
| 120 mSystemUiOffsetPixels.setEmpty(); |
| 121 } |
| 122 |
| 118 /** Repositions the image by zooming it such that the image is displayed wit
hout borders. */ | 123 /** Repositions the image by zooming it such that the image is displayed wit
hout borders. */ |
| 119 public void resizeImageToFitScreen() { | 124 public void resizeImageToFitScreen() { |
| 120 // Protect against being called before the image has been initialized. | 125 // Protect against being called before the image has been initialized. |
| 121 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) { | 126 if (mRenderData.imageWidth == 0 || mRenderData.imageHeight == 0) { |
| 122 return; | 127 return; |
| 123 } | 128 } |
| 124 | 129 |
| 125 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi
dth; | 130 float widthRatio = (float) mRenderData.screenWidth / mRenderData.imageWi
dth; |
| 126 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image
Height; | 131 float heightRatio = (float) mRenderData.screenHeight / mRenderData.image
Height; |
| 127 float screenToImageScale = Math.max(widthRatio, heightRatio); | 132 float screenToImageScale = Math.max(widthRatio, heightRatio); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // Displayed image is too small in both directions, so apply the min
imum zoom | 231 // Displayed image is too small in both directions, so apply the min
imum zoom |
| 227 // level needed to fit either the width or height. | 232 // level needed to fit either the width or height. |
| 228 float scale = Math.min((float) mRenderData.screenWidth / mRenderData
.imageWidth, | 233 float scale = Math.min((float) mRenderData.screenWidth / mRenderData
.imageWidth, |
| 229 (float) mRenderData.screenHeight / mRenderDat
a.imageHeight); | 234 (float) mRenderData.screenHeight / mRenderDat
a.imageHeight); |
| 230 mRenderData.transform.setScale(scale, scale); | 235 mRenderData.transform.setScale(scale, scale); |
| 231 } | 236 } |
| 232 | 237 |
| 233 repositionImage(centerViewport); | 238 repositionImage(centerViewport); |
| 234 } | 239 } |
| 235 } | 240 } |
| OLD | NEW |