summaryrefslogtreecommitdiffstats
path: root/core/java/android/view/SurfaceView.java
diff options
context:
space:
mode:
authorIgor Murashkin <iam@google.com>2013-09-11 17:22:40 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-09-11 17:22:40 -0700
commit33069f40e5ba5a8c036671a67668b6bdfe6eb3a9 (patch)
tree4d3600fa42c5519380c0040e27ea8445118d2979 /core/java/android/view/SurfaceView.java
parent2805ec5753d2ee50b9b3241f0d3c837de511c23c (diff)
parent47869404cb8233c536a0a5d2c5ce4d0089e39882 (diff)
downloadframeworks_base-33069f40e5ba5a8c036671a67668b6bdfe6eb3a9.zip
frameworks_base-33069f40e5ba5a8c036671a67668b6bdfe6eb3a9.tar.gz
frameworks_base-33069f40e5ba5a8c036671a67668b6bdfe6eb3a9.tar.bz2
am 47869404: am 2cad64c0: Merge "Surface: Change OutOfResourcesException to be a runtime exception" into klp-dev
* commit '47869404cb8233c536a0a5d2c5ce4d0089e39882': Surface: Change OutOfResourcesException to be a runtime exception
Diffstat (limited to 'core/java/android/view/SurfaceView.java')
-rw-r--r--core/java/android/view/SurfaceView.java94
1 files changed, 56 insertions, 38 deletions
diff --git a/core/java/android/view/SurfaceView.java b/core/java/android/view/SurfaceView.java
index de86afc..c283170 100644
--- a/core/java/android/view/SurfaceView.java
+++ b/core/java/android/view/SurfaceView.java
@@ -43,7 +43,7 @@ import java.util.concurrent.locks.ReentrantLock;
* You can control the format of this surface and, if you like, its size; the
* SurfaceView takes care of placing the surface at the correct location on the
* screen
- *
+ *
* <p>The surface is Z ordered so that it is behind the window holding its
* SurfaceView; the SurfaceView punches a hole in its window to allow its
* surface to be displayed. The view hierarchy will take care of correctly
@@ -52,7 +52,7 @@ import java.util.concurrent.locks.ReentrantLock;
* buttons on top of the Surface, though note however that it can have an
* impact on performance since a full alpha-blended composite will be performed
* each time the Surface changes.
- *
+ *
* <p> The transparent region that makes the surface visible is based on the
* layout positions in the view hierarchy. If the post-layout transform
* properties are used to draw a sibling view on top of the SurfaceView, the
@@ -60,16 +60,16 @@ import java.util.concurrent.locks.ReentrantLock;
*
* <p>Access to the underlying surface is provided via the SurfaceHolder interface,
* which can be retrieved by calling {@link #getHolder}.
- *
+ *
* <p>The Surface will be created for you while the SurfaceView's window is
* visible; you should implement {@link SurfaceHolder.Callback#surfaceCreated}
* and {@link SurfaceHolder.Callback#surfaceDestroyed} to discover when the
* Surface is created and destroyed as the window is shown and hidden.
- *
+ *
* <p>One of the purposes of this class is to provide a surface in which a
* secondary thread can render into the screen. If you are going to use it
* this way, you need to be aware of some threading semantics:
- *
+ *
* <ul>
* <li> All SurfaceView and
* {@link SurfaceHolder.Callback SurfaceHolder.Callback} methods will be called
@@ -91,7 +91,7 @@ public class SurfaceView extends View {
= new ArrayList<SurfaceHolder.Callback>();
final int[] mLocation = new int[2];
-
+
final ReentrantLock mSurfaceLock = new ReentrantLock();
final Surface mSurface = new Surface(); // Current surface in use
final Surface mNewSurface = new Surface(); // New surface we are switching to
@@ -106,13 +106,13 @@ public class SurfaceView extends View {
final Rect mOverscanInsets = new Rect();
final Rect mContentInsets = new Rect();
final Configuration mConfiguration = new Configuration();
-
+
static final int KEEP_SCREEN_ON_MSG = 1;
static final int GET_NEW_SURFACE_MSG = 2;
static final int UPDATE_WINDOW_MSG = 3;
-
+
int mWindowType = WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
-
+
boolean mIsCreating = false;
final Handler mHandler = new Handler() {
@@ -131,14 +131,15 @@ public class SurfaceView extends View {
}
}
};
-
+
final ViewTreeObserver.OnScrollChangedListener mScrollChangedListener
= new ViewTreeObserver.OnScrollChangedListener() {
+ @Override
public void onScrollChanged() {
updateWindow(false, false);
}
};
-
+
boolean mRequestedVisible = false;
boolean mWindowVisibility = false;
boolean mViewVisibility = false;
@@ -152,7 +153,7 @@ public class SurfaceView extends View {
boolean mHaveFrame = false;
boolean mSurfaceCreated = false;
long mLastLockTime = 0;
-
+
boolean mVisible = false;
int mLeft = -1;
int mTop = -1;
@@ -169,7 +170,7 @@ public class SurfaceView extends View {
new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
- // reposition ourselves where the surface is
+ // reposition ourselves where the surface is
mHaveFrame = getWidth() > 0 && getHeight() > 0;
updateWindow(false, false);
return true;
@@ -181,7 +182,7 @@ public class SurfaceView extends View {
super(context);
init();
}
-
+
public SurfaceView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
@@ -200,11 +201,11 @@ public class SurfaceView extends View {
private void init() {
setWillNotDraw(true);
}
-
+
/**
* Return the SurfaceHolder providing access and control over this
* SurfaceView's underlying surface.
- *
+ *
* @return SurfaceHolder The holder of the surface.
*/
public SurfaceHolder getHolder() {
@@ -290,7 +291,7 @@ public class SurfaceView extends View {
: getDefaultSize(0, heightMeasureSpec);
setMeasuredDimension(width, height);
}
-
+
/** @hide */
@Override
protected boolean setFrame(int left, int top, int right, int bottom) {
@@ -304,7 +305,7 @@ public class SurfaceView extends View {
if (mWindowType == WindowManager.LayoutParams.TYPE_APPLICATION_PANEL) {
return super.gatherTransparentRegion(region);
}
-
+
boolean opaque = true;
if ((mPrivateFlags & PFLAG_SKIP_DRAW) == 0) {
// this view draws, remove it from the transparent region
@@ -355,10 +356,10 @@ public class SurfaceView extends View {
* regular surface view in the window (but still behind the window itself).
* This is typically used to place overlays on top of an underlying media
* surface view.
- *
+ *
* <p>Note that this must be set before the surface view's containing
* window is attached to the window manager.
- *
+ *
* <p>Calling this overrides any previous call to {@link #setZOrderOnTop}.
*/
public void setZOrderMediaOverlay(boolean isMediaOverlay) {
@@ -366,7 +367,7 @@ public class SurfaceView extends View {
? WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY
: WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA;
}
-
+
/**
* Control whether the surface view's surface is placed on top of its
* window. Normally it is placed behind the window, to allow it to
@@ -374,10 +375,10 @@ public class SurfaceView extends View {
* hierarchy. By setting this, you cause it to be placed above the
* window. This means that none of the contents of the window this
* SurfaceView is in will be visible on top of its surface.
- *
+ *
* <p>Note that this must be set before the surface view's containing
* window is attached to the window manager.
- *
+ *
* <p>Calling this overrides any previous call to {@link #setZOrderMediaOverlay}.
*/
public void setZOrderOnTop(boolean onTop) {
@@ -432,7 +433,7 @@ public class SurfaceView extends View {
if (mTranslator != null) {
mSurface.setCompatibilityTranslator(mTranslator);
}
-
+
int myWidth = mRequestedWidth;
if (myWidth <= 0) myWidth = getWidth();
int myHeight = mRequestedHeight;
@@ -463,7 +464,7 @@ public class SurfaceView extends View {
mFormat = mRequestedFormat;
// Scaling/Translate window's layout here because mLayout is not used elsewhere.
-
+
// Places the window relative
mLayout.x = mLeft;
mLayout.y = mTop;
@@ -472,7 +473,7 @@ public class SurfaceView extends View {
if (mTranslator != null) {
mTranslator.translateLayoutParamsInAppWindowToScreen(mLayout);
}
-
+
mLayout.format = mRequestedFormat;
mLayout.flags |=WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
@@ -494,7 +495,7 @@ public class SurfaceView extends View {
mSession.addToDisplayWithoutInputChannel(mWindow, mWindow.mSeq, mLayout,
mVisible ? VISIBLE : GONE, display.getDisplayId(), mContentInsets);
}
-
+
boolean realSizeChanged;
boolean reportDrawNeeded;
@@ -506,7 +507,7 @@ public class SurfaceView extends View {
reportDrawNeeded = mReportDrawNeeded;
mReportDrawNeeded = false;
mDrawingStopped = !visible;
-
+
if (DEBUG) Log.i(TAG, "Cur surface: " + mSurface);
relayoutResult = mSession.relayout(
@@ -532,7 +533,7 @@ public class SurfaceView extends View {
mSurfaceFrame.right = (int) (mWinFrame.width() * appInvertedScale + 0.5f);
mSurfaceFrame.bottom = (int) (mWinFrame.height() * appInvertedScale + 0.5f);
}
-
+
final int surfaceWidth = mSurfaceFrame.right;
final int surfaceHeight = mSurfaceFrame.bottom;
realSizeChanged = mLastSurfaceWidth != surfaceWidth
@@ -672,10 +673,12 @@ public class SurfaceView extends View {
}
}
+ @Override
public void dispatchAppVisibility(boolean visible) {
// The point of SurfaceView is to let the app control the surface.
}
+ @Override
public void dispatchGetNewSurface() {
SurfaceView surfaceView = mSurfaceView.get();
if (surfaceView != null) {
@@ -684,10 +687,12 @@ public class SurfaceView extends View {
}
}
+ @Override
public void windowFocusChanged(boolean hasFocus, boolean touchEnabled) {
Log.w("SurfaceView", "Unexpected focus in surface: focus=" + hasFocus + ", touchEnabled=" + touchEnabled);
}
+ @Override
public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
}
@@ -695,30 +700,34 @@ public class SurfaceView extends View {
int mCurHeight = -1;
}
- private SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
-
+ private final SurfaceHolder mSurfaceHolder = new SurfaceHolder() {
+
private static final String LOG_TAG = "SurfaceHolder";
-
+
+ @Override
public boolean isCreating() {
return mIsCreating;
}
+ @Override
public void addCallback(Callback callback) {
synchronized (mCallbacks) {
- // This is a linear search, but in practice we'll
+ // This is a linear search, but in practice we'll
// have only a couple callbacks, so it doesn't matter.
- if (mCallbacks.contains(callback) == false) {
+ if (mCallbacks.contains(callback) == false) {
mCallbacks.add(callback);
}
}
}
+ @Override
public void removeCallback(Callback callback) {
synchronized (mCallbacks) {
mCallbacks.remove(callback);
}
}
-
+
+ @Override
public void setFixedSize(int width, int height) {
if (mRequestedWidth != width || mRequestedHeight != height) {
mRequestedWidth = width;
@@ -727,6 +736,7 @@ public class SurfaceView extends View {
}
}
+ @Override
public void setSizeFromLayout() {
if (mRequestedWidth != -1 || mRequestedHeight != -1) {
mRequestedWidth = mRequestedHeight = -1;
@@ -734,6 +744,7 @@ public class SurfaceView extends View {
}
}
+ @Override
public void setFormat(int format) {
// for backward compatibility reason, OPAQUE always
@@ -750,15 +761,17 @@ public class SurfaceView extends View {
/**
* @deprecated setType is now ignored.
*/
+ @Override
@Deprecated
public void setType(int type) { }
+ @Override
public void setKeepScreenOn(boolean screenOn) {
Message msg = mHandler.obtainMessage(KEEP_SCREEN_ON_MSG);
msg.arg1 = screenOn ? 1 : 0;
mHandler.sendMessage(msg);
}
-
+
/**
* Gets a {@link Canvas} for drawing into the SurfaceView's Surface
*
@@ -768,6 +781,7 @@ public class SurfaceView extends View {
* The caller must redraw the entire surface.
* @return A canvas for drawing into the surface.
*/
+ @Override
public Canvas lockCanvas() {
return internalLockCanvas(null);
}
@@ -787,6 +801,7 @@ public class SurfaceView extends View {
* entire surface should be redrawn.
* @return A canvas for drawing into the surface.
*/
+ @Override
public Canvas lockCanvas(Rect inOutDirty) {
return internalLockCanvas(inOutDirty);
}
@@ -811,7 +826,7 @@ public class SurfaceView extends View {
mLastLockTime = SystemClock.uptimeMillis();
return c;
}
-
+
// If the Surface is not ready to be drawn, then return null,
// but throttle calls to this function so it isn't called more
// than every 100ms.
@@ -826,7 +841,7 @@ public class SurfaceView extends View {
}
mLastLockTime = now;
mSurfaceLock.unlock();
-
+
return null;
}
@@ -836,15 +851,18 @@ public class SurfaceView extends View {
*
* @param canvas The canvas previously obtained from {@link #lockCanvas}.
*/
+ @Override
public void unlockCanvasAndPost(Canvas canvas) {
mSurface.unlockCanvasAndPost(canvas);
mSurfaceLock.unlock();
}
+ @Override
public Surface getSurface() {
return mSurface;
}
+ @Override
public Rect getSurfaceFrame() {
return mSurfaceFrame;
}