Merge change 7707 into donut

* changes:
  * scale surface view's canvas   This will not affect GL/Video views as they're directly using surfce but not canvas.
This commit is contained in:
Android (Google) Code Review
2009-07-17 11:50:51 -07:00

View File

@@ -17,7 +17,6 @@
package android.view; package android.view;
import android.content.Context; import android.content.Context;
import android.content.res.CompatibilityInfo;
import android.content.res.CompatibilityInfo.Translator; import android.content.res.CompatibilityInfo.Translator;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
@@ -256,7 +255,7 @@ public class SurfaceView extends View {
public boolean dispatchTouchEvent(MotionEvent event) { public boolean dispatchTouchEvent(MotionEvent event) {
// SurfaceView uses pre-scaled size unless fixed size is requested. This hook // SurfaceView uses pre-scaled size unless fixed size is requested. This hook
// scales the event back to the pre-scaled coordinates for such surface. // scales the event back to the pre-scaled coordinates for such surface.
if (mRequestedWidth < 0 && mTranslator != null) { if (mScaled) {
MotionEvent scaledBack = MotionEvent.obtain(event); MotionEvent scaledBack = MotionEvent.obtain(event);
scaledBack.scale(mTranslator.applicationScale); scaledBack.scale(mTranslator.applicationScale);
try { try {
@@ -290,6 +289,8 @@ public class SurfaceView extends View {
public void setWindowType(int type) { public void setWindowType(int type) {
mWindowType = type; mWindowType = type;
} }
boolean mScaled = false;
private void updateWindow(boolean force) { private void updateWindow(boolean force) {
if (!mHaveFrame) { if (!mHaveFrame) {
@@ -309,6 +310,9 @@ public class SurfaceView extends View {
if (mRequestedWidth <= 0 && mTranslator != null) { if (mRequestedWidth <= 0 && mTranslator != null) {
myWidth *= appScale; myWidth *= appScale;
myHeight *= appScale; myHeight *= appScale;
mScaled = true;
} else {
mScaled = false;
} }
getLocationInWindow(mLocation); getLocationInWindow(mLocation);
@@ -533,6 +537,7 @@ public class SurfaceView extends View {
private SurfaceHolder mSurfaceHolder = new SurfaceHolder() { private SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
private static final String LOG_TAG = "SurfaceHolder"; private static final String LOG_TAG = "SurfaceHolder";
private int mSaveCount;
public boolean isCreating() { public boolean isCreating() {
return mIsCreating; return mIsCreating;
@@ -627,6 +632,10 @@ public class SurfaceView extends View {
if (localLOGV) Log.i(TAG, "Returned canvas: " + c); if (localLOGV) Log.i(TAG, "Returned canvas: " + c);
if (c != null) { if (c != null) {
mLastLockTime = SystemClock.uptimeMillis(); mLastLockTime = SystemClock.uptimeMillis();
if (mScaled) {
mSaveCount = c.save();
mTranslator.translateCanvas(c);
}
return c; return c;
} }
@@ -649,6 +658,9 @@ public class SurfaceView extends View {
} }
public void unlockCanvasAndPost(Canvas canvas) { public void unlockCanvasAndPost(Canvas canvas) {
if (mScaled) {
canvas.restoreToCount(mSaveCount);
}
mSurface.unlockCanvasAndPost(canvas); mSurface.unlockCanvasAndPost(canvas);
mSurfaceLock.unlock(); mSurfaceLock.unlock();
} }