summaryrefslogtreecommitdiff
path: root/core/java/android/view/TextureView.java
diff options
context:
space:
mode:
authorJamie Gennis <jgennis@google.com>2012-04-05 11:44:30 -0700
committerJamie Gennis <jgennis@google.com>2012-04-05 16:11:43 -0700
commit2af3524beb75150d347accc925022daa53b4a789 (patch)
tree59cfc11680f13d6d4589db9c40c387ee63cbd185 /core/java/android/view/TextureView.java
parentc6d993077761fc737bbb0f4db44b961a4e7b6bbb (diff)
TextureView: add setSurfaceTexture method
This change adds support for transferring control of a TextureView's SurfaceTexture between the UI framework and the application. It makes the TextureView detach the SurfaceTexture from the UI framework's GLES context before calling the surfaceTextureDestroyed callback, allowing the app to use the SurfaceTexture in its own GLES context if it so chooses. This change also adds the TextureView#setSurfaceTexture method, allowing an app have the TextureView use a SurfaceTexture that already exists rather than creating a new one. Change-Id: Iac9cc917687e4239dd1c24eae553709aa37512da
Diffstat (limited to 'core/java/android/view/TextureView.java')
-rw-r--r--core/java/android/view/TextureView.java48
1 files changed, 45 insertions, 3 deletions
diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java
index 83999a1c3a79..3cd8b715b669 100644
--- a/core/java/android/view/TextureView.java
+++ b/core/java/android/view/TextureView.java
@@ -115,6 +115,7 @@ public class TextureView extends View {
private final Object[] mLock = new Object[0];
private boolean mUpdateLayer;
+ private boolean mUpdateSurface;
private SurfaceTexture.OnFrameAvailableListener mUpdateListener;
@@ -208,6 +209,8 @@ public class TextureView extends View {
private void destroySurface() {
if (mLayer != null) {
+ mSurface.detachFromGLContext();
+
boolean shouldRelease = true;
if (mListener != null) {
shouldRelease = mListener.onSurfaceTextureDestroyed(mSurface);
@@ -322,9 +325,13 @@ public class TextureView extends View {
}
mLayer = mAttachInfo.mHardwareRenderer.createHardwareLayer(mOpaque);
- mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
+ if (!mUpdateSurface) {
+ // We already have a SurfaceTexture to use, and we will pass it
+ // to mLayer below.
+ mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
+ }
nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
- nCreateNativeWindow(mSurface);
+ nCreateNativeWindow(mSurface);
mUpdateListener = new SurfaceTexture.OnFrameAvailableListener() {
@Override
@@ -344,6 +351,15 @@ public class TextureView extends View {
}
}
+ if (mUpdateSurface) {
+ // Someone has requested that we use a specific SurfaceTexture, so
+ // tell mLayer about it and set the SurfaceTexture to use the
+ // current view size.
+ mUpdateSurface = false;
+ mAttachInfo.mHardwareRenderer.setSurfaceTexture(mLayer, mSurface);
+ nSetDefaultBufferSize(mSurface, getWidth(), getHeight());
+ }
+
applyUpdate();
applyTransformMatrix();
@@ -371,7 +387,7 @@ public class TextureView extends View {
mUpdateLayer = true;
invalidate();
}
-
+
private void applyUpdate() {
if (mLayer == null) {
return;
@@ -636,6 +652,32 @@ public class TextureView extends View {
}
/**
+ * Set the {@link SurfaceTexture} for this view to use. If a {@link
+ * SurfaceTexture} is already being used by this view, it is immediately
+ * released and not be usable any more. The {@link
+ * SurfaceTextureListener#onSurfaceTextureDestroyed} callback is <b>not</b>
+ * called.
+ *
+ * The {@link SurfaceTexture} object must be detached from all OpenGL ES
+ * contexts prior to calling this method.
+ *
+ * @param surfaceTexture The {@link SurfaceTexture} that the view should use.
+ * @see SurfaceTexture#detachFromGLContext()
+ * @hide
+ */
+ public void setSurfaceTexture(SurfaceTexture surfaceTexture) {
+ if (surfaceTexture == null) {
+ throw new NullPointerException("surfaceTexture must not be null");
+ }
+ if (mSurface != null) {
+ mSurface.release();
+ }
+ mSurface = surfaceTexture;
+ mUpdateSurface = true;
+ invalidateParentIfNeeded();
+ }
+
+ /**
* Returns the {@link SurfaceTextureListener} currently associated with this
* texture view.
*