From 302a9df1d50373c82923bb84ff665dfce584fb22 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Tue, 16 Aug 2011 13:55:02 -0700 Subject: Add an API to set the transform on a TextureView's surface texture. Bug #5156689 Change-Id: I635a625885c9b832a60d44ece0de7613ceb84109 --- core/java/android/view/TextureView.java | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'core/java/android/view/TextureView.java') diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 53a6bcba98c8..b72222ee9f99 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -19,6 +19,7 @@ package android.view; import android.content.Context; import android.graphics.Bitmap; import android.graphics.Canvas; +import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.SurfaceTexture; @@ -104,6 +105,9 @@ public class TextureView extends View { private boolean mOpaque = true; + private final Matrix mMatrix = new Matrix(); + private boolean mMatrixChanged; + private final Object[] mLock = new Object[0]; private boolean mUpdateLayer; @@ -312,6 +316,11 @@ public class TextureView extends View { applyUpdate(); + if (mMatrixChanged) { + mLayer.setTransform(mMatrix); + mMatrixChanged = false; + } + return mLayer; } @@ -357,6 +366,50 @@ public class TextureView extends View { } } + /** + *

Sets the transform to associate with this texture view. + * The specified transform applies to the underlying surface + * texture and does not affect the size or position of the view + * itself, only of its content.

+ * + *

Some transforms might prevent the content from drawing + * all the pixels contained within this view's bounds. In such + * situations, make sure this texture view is not marked opaque.

+ * + * @param transform The transform to apply to the content of + * this view. + * + * @see #getTransform(android.graphics.Matrix) + * @see #isOpaque() + * @see #setOpaque(boolean) + */ + public void setTransform(Matrix transform) { + mMatrix.set(transform); + mMatrixChanged = true; + invalidate(); + } + + /** + * Returns the transform associated with this texture view. + * + * @param transform The {@link Matrix} in which to copy the current + * transform. Can be null. + * + * @return The specified matrix if not null or a new {@link Matrix} + * instance otherwise. + * + * @see #setTransform(android.graphics.Matrix) + */ + public Matrix getTransform(Matrix transform) { + if (transform == null) { + transform = new Matrix(); + } + + transform.set(mMatrix); + + return transform; + } + /** *

Returns a {@link android.graphics.Bitmap} representation of the content * of the associated surface texture. If the surface texture is not available, -- cgit v1.2.3