summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/SurfaceView.java
diff options
context:
space:
mode:
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
-rw-r--r--core/java/android/view/SurfaceView.java34
1 files changed, 29 insertions, 5 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index 71da9cf..49e4e4c 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -257,6 +257,23 @@ public class SurfaceView extends View {
}
@Override
+ public boolean dispatchTouchEvent(MotionEvent event) {
+ // SurfaceView uses pre-scaled size unless fixed size is requested. This hook
+ // scales the event back to the pre-scaled coordinates for such surface.
+ if (mRequestedWidth < 0 && mAppScale != 1.0f) {
+ MotionEvent scaledBack = MotionEvent.obtain(event);
+ scaledBack.scale(mAppScale);
+ try {
+ return super.dispatchTouchEvent(scaledBack);
+ } finally {
+ scaledBack.recycle();
+ }
+ } else {
+ return super.dispatchTouchEvent(event);
+ }
+ }
+
+ @Override
protected void dispatchDraw(Canvas canvas) {
// if SKIP_DRAW is cleared, draw() has already punched a hole
if ((mPrivateFlags & SKIP_DRAW) == SKIP_DRAW) {
@@ -278,7 +295,13 @@ public class SurfaceView extends View {
if (myWidth <= 0) myWidth = getWidth();
int myHeight = mRequestedHeight;
if (myHeight <= 0) myHeight = getHeight();
-
+
+ // Use original size for surface unless fixed size is requested.
+ if (mRequestedWidth <= 0) {
+ myWidth *= mAppScale;
+ myHeight *= mAppScale;
+ }
+
getLocationInWindow(mLocation);
final boolean creating = mWindow == null;
final boolean formatChanged = mFormat != mRequestedFormat;
@@ -304,8 +327,9 @@ public class SurfaceView extends View {
mFormat = mRequestedFormat;
mType = mRequestedType;
- mLayout.x = mLeft;
- mLayout.y = mTop;
+ // Scaling window's layout here beause mLayout is not used elsewhere.
+ mLayout.x = (int) (mLeft * mAppScale);
+ mLayout.y = (int) (mTop * mAppScale);
mLayout.width = (int) (getWidth() * mAppScale);
mLayout.height = (int) (getHeight() * mAppScale);
mLayout.format = mRequestedFormat;
@@ -334,7 +358,7 @@ public class SurfaceView extends View {
mSurfaceLock.lock();
mDrawingStopped = !visible;
final int relayoutResult = mSession.relayout(
- mWindow, mLayout, (int) (mWidth * mAppScale), (int) (mHeight * mAppScale),
+ mWindow, mLayout, mWidth, mHeight,
visible ? VISIBLE : GONE, false, mWinFrame, mContentInsets,
mVisibleInsets, mSurface);
@@ -358,7 +382,7 @@ public class SurfaceView extends View {
synchronized (mCallbacks) {
callbacks = new SurfaceHolder.Callback[mCallbacks.size()];
mCallbacks.toArray(callbacks);
- }
+ }
if (visibleChanged) {
mIsCreating = true;