This commit is contained in:
Jon Larimer
2009-01-02 18:55:15 -05:00
parent e1dc1d6dc8
commit 9bdf576615

View File

@@ -30,8 +30,9 @@ import android.os.ParcelFileDescriptor;
import android.util.AttributeSet;
import android.util.Config;
import android.util.Log;
import java.util.ArrayList;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.concurrent.locks.ReentrantLock;
/**
@@ -308,7 +309,7 @@ public class SurfaceView extends View {
mLayout.memoryType = mRequestedType;
if (mWindow == null) {
mWindow = new MyWindow();
mWindow = new MyWindow(this);
mLayout.type = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
mLayout.gravity = Gravity.LEFT|Gravity.TOP;
mSession.add(mWindow, mLayout,
@@ -393,32 +394,48 @@ public class SurfaceView extends View {
updateWindow(false);
}
private class MyWindow extends IWindow.Stub {
private static class MyWindow extends IWindow.Stub {
private WeakReference<SurfaceView> mSurfaceView;
public MyWindow(SurfaceView surfaceView) {
mSurfaceView = new WeakReference<SurfaceView>(surfaceView);
}
public void resized(int w, int h, Rect coveredInsets,
Rect visibleInsets, boolean reportDraw) {
if (localLOGV) Log.v(
"SurfaceView", SurfaceView.this + " got resized: w=" +
w + " h=" + h + ", cur w=" + mCurWidth + " h=" + mCurHeight);
synchronized (this) {
if (mCurWidth != w || mCurHeight != h) {
mCurWidth = w;
mCurHeight = h;
}
if (reportDraw) {
try {
mSession.finishDrawing(mWindow);
} catch (RemoteException e) {
SurfaceView surfaceView = mSurfaceView.get();
if (surfaceView != null) {
if (localLOGV) Log.v(
"SurfaceView", surfaceView + " got resized: w=" +
w + " h=" + h + ", cur w=" + mCurWidth + " h=" +
mCurHeight);
synchronized (this) {
if (mCurWidth != w || mCurHeight != h) {
mCurWidth = w;
mCurHeight = h;
}
if (reportDraw) {
try {
surfaceView.mSession.finishDrawing(
surfaceView.mWindow);
} catch (RemoteException e) {
}
}
}
}
}
public void dispatchKey(KeyEvent event) {
//Log.w("SurfaceView", "Unexpected key event in surface: " + event);
if (mSession != null && mSurface != null) {
try {
mSession.finishKey(mWindow);
} catch (RemoteException ex) {
SurfaceView surfaceView = mSurfaceView.get();
if (surfaceView != null) {
//Log.w("SurfaceView", "Unexpected key event in surface: "
// + event);
if (surfaceView.mSession != null && surfaceView.mSurface !=
null) {
try {
surfaceView.mSession.finishKey(surfaceView.mWindow);
} catch (RemoteException ex) {
}
}
}
}
@@ -448,8 +465,12 @@ public class SurfaceView extends View {
}
public void dispatchGetNewSurface() {
Message msg = mHandler.obtainMessage(GET_NEW_SURFACE_MSG);
mHandler.sendMessage(msg);
SurfaceView surfaceView = mSurfaceView.get();
if (surfaceView != null) {
Message msg = surfaceView.mHandler.obtainMessage(
GET_NEW_SURFACE_MSG);
surfaceView.mHandler.sendMessage(msg);
}
}
public void windowFocusChanged(boolean hasFocus, boolean touchEnabled) {