From 589cebe2d58591403de4a77077941c0454bc91bc Mon Sep 17 00:00:00 2001 From: Mitsuru Oshima Date: Wed, 22 Jul 2009 20:38:58 -0700 Subject: [PATCH] * Use the scaled size for surface view instead of native. The surface will be always scaled by surface flinger in compatiblity mode. The original approach confused the app because the surface size and the view size were different. * a few clean up. removed unsed arguments, obsolete conditions from getTranslator() (expandable check was a bug) --- .../content/res/CompatibilityInfo.java | 15 +---- core/java/android/view/SurfaceView.java | 60 +++---------------- core/java/android/view/ViewRoot.java | 2 +- .../android/server/WindowManagerService.java | 4 ++ 4 files changed, 17 insertions(+), 64 deletions(-) diff --git a/core/java/android/content/res/CompatibilityInfo.java b/core/java/android/content/res/CompatibilityInfo.java index e2abfd175a05b..50faf57a096f7 100644 --- a/core/java/android/content/res/CompatibilityInfo.java +++ b/core/java/android/content/res/CompatibilityInfo.java @@ -228,20 +228,11 @@ public class CompatibilityInfo { } /** - * Returns the translator which can translate the coordinates of the window. - * There are five different types of Translator. + * Returns the translator which translates the coordinates in compatibility mode. * @param params the window's parameter */ - public Translator getTranslator(WindowManager.LayoutParams params) { - if ( (mCompatibilityFlags & SCALING_EXPANDABLE_MASK) - == (EXPANDABLE|LARGE_SCREENS)) { - if (DBG) Log.d(TAG, "no translation required"); - return null; - } - if (!isScalingRequired()) { - return null; - } - return new Translator(); + public Translator getTranslator() { + return isScalingRequired() ? new Translator() : null; } /** diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java index 938104c8d7d5e..9cf7092491c4b 100644 --- a/core/java/android/view/SurfaceView.java +++ b/core/java/android/view/SurfaceView.java @@ -141,13 +141,6 @@ public class SurfaceView extends View { final Rect mSurfaceFrame = new Rect(); private Translator mTranslator; - // A flag to indicate that the Canvas has to be scaled - private boolean mScaleCanvas = false; - // A flag to indicate that the Canvas is in use and being scaled. - // This may remain to be false even if mScaleCanvas is true if the applicatio - // does not use the canvas (such as GLSurfaceView, VideoView). - private boolean mCanvasScaled = false; - public SurfaceView(Context context) { super(context); setWillNotDraw(true); @@ -259,26 +252,6 @@ public class SurfaceView extends View { super.draw(canvas); } - @Override - public boolean dispatchTouchEvent(MotionEvent event) { - if (mTranslator == null || mCanvasScaled) { - // Use the event as is if no scaling is required, or the surface's canvas - // is scaled too. - return super.dispatchTouchEvent(event); - } else { - // The surface is in native size, so we need to scale the event - // back to native location. - MotionEvent scaledBack = MotionEvent.obtain(event); - // scale back to original - scaledBack.scale(mTranslator.applicationScale); - try { - return super.dispatchTouchEvent(scaledBack); - } finally { - scaledBack.recycle(); - } - } - } - @Override protected void dispatchDraw(Canvas canvas) { // if SKIP_DRAW is cleared, draw() has already punched a hole @@ -308,8 +281,6 @@ public class SurfaceView extends View { ViewRoot viewRoot = (ViewRoot) getRootView().getParent(); mTranslator = viewRoot.mTranslator; - float appScale = mTranslator == null ? 1.0f : mTranslator.applicationScale; - Resources res = getContext().getResources(); if (mTranslator != null || !res.getCompatibilityInfo().supportsScreen()) { mSurface.setCompatibleDisplayMetrics(res.getDisplayMetrics(), mTranslator); @@ -320,17 +291,6 @@ public class SurfaceView extends View { int myHeight = mRequestedHeight; if (myHeight <= 0) myHeight = getHeight(); - // Use requested size if the app specified the size of the view - // and let the flinger to scale up. Otherwise, use the native size - // (* appScale) and assume the application can handle it. - if (mRequestedWidth <= 0 && mTranslator != null) { - myWidth = (int) (myWidth * appScale + 0.5f); - myHeight = (int) (myHeight * appScale + 0.5f); - mScaleCanvas = true; - } else { - mScaleCanvas = false; - } - getLocationInWindow(mLocation); final boolean creating = mWindow == null; final boolean formatChanged = mFormat != mRequestedFormat; @@ -403,10 +363,17 @@ public class SurfaceView extends View { if (localLOGV) Log.i(TAG, "New surface: " + mSurface + ", vis=" + visible + ", frame=" + mWinFrame); + mSurfaceFrame.left = 0; mSurfaceFrame.top = 0; - mSurfaceFrame.right = mWinFrame.width(); - mSurfaceFrame.bottom = mWinFrame.height(); + if (mTranslator == null) { + mSurfaceFrame.right = mWinFrame.width(); + mSurfaceFrame.bottom = mWinFrame.height(); + } else { + float appInvertedScale = mTranslator.applicationInvertedScale; + mSurfaceFrame.right = (int) (mWinFrame.width() * appInvertedScale + 0.5f); + mSurfaceFrame.bottom = (int) (mWinFrame.height() * appInvertedScale + 0.5f); + } mSurfaceLock.unlock(); try { @@ -650,12 +617,6 @@ public class SurfaceView extends View { if (localLOGV) Log.i(TAG, "Returned canvas: " + c); if (c != null) { mLastLockTime = SystemClock.uptimeMillis(); - if (mScaleCanvas) { - // When the canvas is scaled, don't scale back the event's location. - mCanvasScaled = true; - mSaveCount = c.save(); - mTranslator.translateCanvas(c); - } return c; } @@ -678,9 +639,6 @@ public class SurfaceView extends View { } public void unlockCanvasAndPost(Canvas canvas) { - if (mCanvasScaled) { - canvas.restoreToCount(mSaveCount); - } mSurface.unlockCanvasAndPost(canvas); mSurfaceLock.unlock(); } diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index c6c3324d37839..bb61ad3c93c55 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -389,7 +389,7 @@ public final class ViewRoot extends Handler implements ViewParent, attrs = mWindowAttributes; Resources resources = mView.getContext().getResources(); CompatibilityInfo compatibilityInfo = resources.getCompatibilityInfo(); - mTranslator = compatibilityInfo.getTranslator(attrs); + mTranslator = compatibilityInfo.getTranslator(); if (mTranslator != null || !compatibilityInfo.supportsScreen()) { mSurface.setCompatibleDisplayMetrics(resources.getDisplayMetrics(), diff --git a/services/java/com/android/server/WindowManagerService.java b/services/java/com/android/server/WindowManagerService.java index 0be841790d871..49989451ac908 100644 --- a/services/java/com/android/server/WindowManagerService.java +++ b/services/java/com/android/server/WindowManagerService.java @@ -6837,6 +6837,10 @@ public class WindowManagerService extends IWindowManager.Stub implements Watchdo pw.print(mOrientationChanging); pw.print(" mAppFreezing="); pw.println(mAppFreezing); } + if (mHScale != 1 || mVScale != 1) { + pw.print(prefix); pw.print("mHScale="); pw.print(mHScale); + pw.print(" mVScale="); pw.println(mVScale); + } } @Override