| 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; |
| 11 | 11 |
| 12 /** | 12 /** |
| 13 * This class is responsible for transforming the desktop image matrix. | 13 * This class is responsible for transforming the desktop image matrix. |
| 14 */ | 14 */ |
| 15 public class DesktopCanvas { | 15 public class DesktopCanvas { |
| 16 /** | 16 /** |
| 17 * Maximum allowed zoom level - see {@link #repositionImageWithZoom()}. | 17 * Maximum allowed zoom level - see {@link #repositionImageWithZoom()}. |
| 18 */ | 18 */ |
| 19 private static final float MAX_ZOOM_FACTOR = 100.0f; | 19 private static final float MAX_ZOOM_FACTOR = 100.0f; |
| 20 | 20 |
| 21 private final DesktopView mViewer; | 21 private final RenderStub mRenderStub; |
| 22 private final RenderData mRenderData; | 22 private final RenderData mRenderData; |
| 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(DesktopView viewer, RenderData renderData) { | 37 public DesktopCanvas(RenderStub renderStub, RenderData renderData) { |
| 38 mViewer = viewer; | 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). |
| 44 * | 44 * |
| 45 * @param useScreenCenter Determines whether to use the desired viewport pos
ition or the actual | 45 * @param useScreenCenter Determines whether to use the desired viewport pos
ition or the actual |
| 46 * center of the screen for positioning. | 46 * center of the screen for positioning. |
| 47 * @param deltaX The distance (in image coordinates) to move the viewport al
ong the x-axis. | 47 * @param deltaX The distance (in image coordinates) to move the viewport al
ong the x-axis. |
| 48 * @param deltaY The distance (in image coordinates) to move the viewport al
ong the y-axis. | 48 * @param deltaY The distance (in image coordinates) to move the viewport al
ong the y-axis. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 if (rectScreen.bottom - rectScreen.top < viewportSize.y) { | 201 if (rectScreen.bottom - rectScreen.top < viewportSize.y) { |
| 202 yAdjust = -(bottomDelta + topDelta) / 2; | 202 yAdjust = -(bottomDelta + topDelta) / 2; |
| 203 } else if (topDelta > 0 && bottomDelta > 0) { | 203 } else if (topDelta > 0 && bottomDelta > 0) { |
| 204 yAdjust = -Math.min(topDelta, bottomDelta); | 204 yAdjust = -Math.min(topDelta, bottomDelta); |
| 205 } else if (topDelta < 0 && bottomDelta < 0) { | 205 } else if (topDelta < 0 && bottomDelta < 0) { |
| 206 yAdjust = Math.min(-topDelta, -bottomDelta); | 206 yAdjust = Math.min(-topDelta, -bottomDelta); |
| 207 } | 207 } |
| 208 | 208 |
| 209 mRenderData.transform.postTranslate(xAdjust, yAdjust); | 209 mRenderData.transform.postTranslate(xAdjust, yAdjust); |
| 210 | 210 |
| 211 mViewer.transformationChanged(mRenderData.transform); | 211 mRenderStub.setTransformation(mRenderData.transform); |
| 212 } | 212 } |
| 213 | 213 |
| 214 /** | 214 /** |
| 215 * Repositions the image by translating and zooming it, to keep the zoom lev
el within sensible | 215 * Repositions the image by translating and zooming it, to keep the zoom lev
el within sensible |
| 216 * limits. The minimum zoom level is chosen to avoid black space around all
4 sides. The | 216 * limits. The minimum zoom level is chosen to avoid black space around all
4 sides. The |
| 217 * maximum zoom level is set arbitrarily, so that the user can zoom out agai
n in a reasonable | 217 * maximum zoom level is set arbitrarily, so that the user can zoom out agai
n in a reasonable |
| 218 * time, and to prevent arithmetic overflow problems from displaying the ima
ge. | 218 * time, and to prevent arithmetic overflow problems from displaying the ima
ge. |
| 219 * | 219 * |
| 220 * @param centerViewport Determines whether the viewport will be translated
to the desired | 220 * @param centerViewport Determines whether the viewport will be translated
to the desired |
| 221 * center position before being adjusted to fit the sc
reen boundaries. | 221 * center position before being adjusted to fit the sc
reen boundaries. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 240 // Displayed image is too small in both directions, so apply the min
imum zoom | 240 // Displayed image is too small in both directions, so apply the min
imum zoom |
| 241 // level needed to fit either the width or height. | 241 // level needed to fit either the width or height. |
| 242 float scale = Math.min((float) mRenderData.screenWidth / mRenderData
.imageWidth, | 242 float scale = Math.min((float) mRenderData.screenWidth / mRenderData
.imageWidth, |
| 243 (float) mRenderData.screenHeight / mRenderDat
a.imageHeight); | 243 (float) mRenderData.screenHeight / mRenderDat
a.imageHeight); |
| 244 mRenderData.transform.setScale(scale, scale); | 244 mRenderData.transform.setScale(scale, scale); |
| 245 } | 245 } |
| 246 | 246 |
| 247 repositionImage(centerViewport); | 247 repositionImage(centerViewport); |
| 248 } | 248 } |
| 249 } | 249 } |
| OLD | NEW |