diff options
| author | Jeff Brown <jeffbrown@google.com> | 2014-05-06 16:00:38 -0700 |
|---|---|---|
| committer | Jeff Brown <jeffbrown@google.com> | 2014-05-06 17:13:43 -0700 |
| commit | c7282e57cd01f1576baac04356bf99bee34e4c18 (patch) | |
| tree | c1b446ceed5a4ccc9cd68e7edcfbebfec7abe45d /core/java/android | |
| parent | cedde01622a6798f5c4526ef1227bd906b6e59ef (diff) | |
| download | frameworks_base-c7282e57cd01f1576baac04356bf99bee34e4c18.zip frameworks_base-c7282e57cd01f1576baac04356bf99bee34e4c18.tar.gz frameworks_base-c7282e57cd01f1576baac04356bf99bee34e4c18.tar.bz2 | |
Fix crash due to texture view callback threading invariants.
Allow the client of a SurfaceTexture to specify the Handler to
which the update callback should be directed to avoid unnecessary
scheduling ping-pong between threads.
Fixed an invalid assumption in TextureView that it is attached
to the main looper which could result in a crash under certain
circumstances. In normal app processes, it is true that TextureViews
must be created on the main looper since hardware rendering is
currently only supported on the main looper. However, in the
system server, UI components run a different thread. Although
hardware rendering is normally disabled in the system server,
it may be enabled for certain developer features.
Bug: 14445309
Change-Id: I5ae17ad018b9ef05ba87ec2f972c7c82e2bca70a
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/TextureView.java | 30 |
1 files changed, 11 insertions, 19 deletions
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 3cfe5e9..1765c43 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -23,7 +23,6 @@ import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.SurfaceTexture; -import android.os.Looper; import android.util.AttributeSet; import android.util.Log; @@ -119,8 +118,6 @@ public class TextureView extends View { private boolean mUpdateLayer; private boolean mUpdateSurface; - private SurfaceTexture.OnFrameAvailableListener mUpdateListener; - private Canvas mCanvas; private int mSaveCount; @@ -370,21 +367,7 @@ public class TextureView extends View { mSurface.setDefaultBufferSize(getWidth(), getHeight()); nCreateNativeWindow(mSurface); - mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() { - @Override - public void onFrameAvailable(SurfaceTexture surfaceTexture) { - // Per SurfaceTexture's documentation, the callback may be invoked - // from an arbitrary thread - updateLayer(); - - if (Looper.myLooper() == Looper.getMainLooper()) { - invalidate(); - } else { - postInvalidate(); - } - } - }; - mSurface.setOnFrameAvailableListener(mUpdateListener); + mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); if (mListener != null && !mUpdateSurface) { mListener.onSurfaceTextureAvailable(mSurface, getWidth(), getHeight()); @@ -422,7 +405,7 @@ public class TextureView extends View { // To cancel updates, the easiest thing to do is simply to remove the // updates listener if (visibility == VISIBLE) { - mSurface.setOnFrameAvailableListener(mUpdateListener); + mSurface.setOnFrameAvailableListener(mUpdateListener, mAttachInfo.mHandler); updateLayerAndInvalidate(); } else { mSurface.setOnFrameAvailableListener(null); @@ -767,6 +750,15 @@ public class TextureView extends View { mListener = listener; } + private final SurfaceTexture.OnFrameAvailableListener mUpdateListener = + new SurfaceTexture.OnFrameAvailableListener() { + @Override + public void onFrameAvailable(SurfaceTexture surfaceTexture) { + updateLayer(); + invalidate(); + } + }; + /** * This listener can be used to be notified when the surface texture * associated with this texture view is available. |
