From 5ba09488d600aa4914001ae1dd806fa63d1fec14 Mon Sep 17 00:00:00 2001
From: John Reck A TextureView can be used to display a content stream. Such a content
* stream can for instance be a video or an OpenGL scene. The content stream
* can come from the application's process as well as a remote process. TextureView can only be used in a hardware accelerated window. When
* rendered in software, TextureView will draw nothing. Unlike {@link SurfaceView}, TextureView does not create a separate
* window but behaves as a regular View. This key difference allows a
* TextureView to be moved, transformed, animated, etc. For instance, you
* can make a TextureView semi-translucent by calling
* Using a TextureView is simple: all you need to do is get its
* {@link SurfaceTexture}. The {@link SurfaceTexture} can then be used to
- * render content. The following example demonstrates how to render the
+ * render content. The following example demonstrates how to render the
* camera preview into a TextureView: A TextureView's SurfaceTexture can be obtained either by invoking
* {@link #getSurfaceTexture()} or by using a {@link SurfaceTextureListener}.
* It is important to know that a SurfaceTexture is available only after the
* TextureView is attached to a window (and {@link #onAttachedToWindow()} has
* been invoked.) It is therefore highly recommended you use a listener to
* be notified when the SurfaceTexture becomes available. It is important to note that only one producer can use the TextureView.
* For instance, if you use a TextureView to display the camera preview, you
* cannot use {@link #lockCanvas()} to draw onto the TextureView at the same
* time.myView.setAlpha(0.5f).
* public class LiveCameraActivity extends Activity implements TextureView.SurfaceTextureListener {
* private Camera mCamera;
@@ -85,19 +85,19 @@ import android.util.Log;
* }
* }
*
- *
+ *
*
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) + * + * @see #getTransform(android.graphics.Matrix) + * @see #isOpaque() + * @see #setOpaque(boolean) */ public void setTransform(Matrix transform) { mMatrix.set(transform); @@ -469,14 +469,14 @@ public class TextureView extends View { /** * 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) + * + * @see #setTransform(android.graphics.Matrix) */ public Matrix getTransform(Matrix transform) { if (transform == null) { @@ -499,21 +499,21 @@ public class TextureView extends View { *Returns a {@link android.graphics.Bitmap} representation of the content * of the associated surface texture. If the surface texture is not available, * this method returns null.
- * + * *The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888} * pixel format and its dimensions are the same as this view's.
- * + * *Do not invoke this method from a drawing method * ({@link #onDraw(android.graphics.Canvas)} for instance).
- * + * *If an error occurs during the copy, an empty bitmap will be returned.
- * + * * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface * texture is not available or the width <= 0 or the height <= 0 - * - * @see #isAvailable() - * @see #getBitmap(android.graphics.Bitmap) - * @see #getBitmap(int, int) + * + * @see #isAvailable() + * @see #getBitmap(android.graphics.Bitmap) + * @see #getBitmap(int, int) */ public Bitmap getBitmap() { return getBitmap(getWidth(), getHeight()); @@ -523,24 +523,24 @@ public class TextureView extends View { *Returns a {@link android.graphics.Bitmap} representation of the content * of the associated surface texture. If the surface texture is not available, * this method returns null.
- * + * *The bitmap returned by this method uses the {@link Bitmap.Config#ARGB_8888} * pixel format.
- * + * *Do not invoke this method from a drawing method * ({@link #onDraw(android.graphics.Canvas)} for instance).
- * + * *If an error occurs during the copy, an empty bitmap will be returned.
- * + * * @param width The width of the bitmap to create * @param height The height of the bitmap to create - * + * * @return A valid {@link Bitmap.Config#ARGB_8888} bitmap, or null if the surface * texture is not available or width is <= 0 or height is <= 0 - * - * @see #isAvailable() - * @see #getBitmap(android.graphics.Bitmap) - * @see #getBitmap() + * + * @see #isAvailable() + * @see #getBitmap(android.graphics.Bitmap) + * @see #getBitmap() */ public Bitmap getBitmap(int width, int height) { if (isAvailable() && width > 0 && height > 0) { @@ -555,21 +555,21 @@ public class TextureView extends View { * bitmap. If the surface texture is not available, the copy is not executed. * The content of the surface texture will be scaled to fit exactly inside * the specified bitmap. - * + * *Do not invoke this method from a drawing method * ({@link #onDraw(android.graphics.Canvas)} for instance).
- * + * *If an error occurs, the bitmap is left unchanged.
- * + * * @param bitmap The bitmap to copy the content of the surface texture into, * cannot be null, all configurations are supported - * + * * @return The bitmap specified as a parameter - * - * @see #isAvailable() - * @see #getBitmap(int, int) - * @see #getBitmap() - * + * + * @see #isAvailable() + * @see #getBitmap(int, int) + * @see #getBitmap() + * * @throws IllegalStateException if the hardware rendering context cannot be * acquired to capture the bitmap */ @@ -609,21 +609,21 @@ public class TextureView extends View { * to implement * {@link SurfaceTextureListener#onSurfaceTextureAvailable(android.graphics.SurfaceTexture, int, int)} * to find out when the Surface is available for use. - * + * *The content of the Surface is never preserved between unlockCanvas() * and lockCanvas(), for this reason, every pixel within the Surface area * must be written. The only exception to this rule is when a dirty * rectangle is specified, in which case, non-dirty pixels will be * preserved.
- * + * *This method can only be used if the underlying surface is not already * owned by another producer. For instance, if the TextureView is being used * to render the camera's preview you cannot invoke this method.
- * + * * @return A Canvas used to draw into the surface. - * - * @see #lockCanvas(android.graphics.Rect) - * @see #unlockCanvasAndPost(android.graphics.Canvas) + * + * @see #lockCanvas(android.graphics.Rect) + * @see #unlockCanvasAndPost(android.graphics.Canvas) */ public Canvas lockCanvas() { return lockCanvas(null); @@ -639,12 +639,12 @@ public class TextureView extends View { * available (see {@link #isAvailable()} or if the surface texture is * already connected to an image producer (for instance: the camera, * OpenGL, a media player, etc.) - * + * * @param dirty Area of the surface that will be modified. * @return A Canvas used to draw into the surface. - * - * @see #lockCanvas() + * + * @see #lockCanvas() * @see #unlockCanvasAndPost(android.graphics.Canvas) * @see #isAvailable() */ @@ -670,11 +670,11 @@ public class TextureView extends View { * current pixels will be shown on the screen, but its content is lost, * in particular there is no guarantee that the content of the Surface * will remain unchanged when lockCanvas() is called again. - * + * * @param canvas The Canvas previously returned by lockCanvas() - * + * * @see #lockCanvas() - * @see #lockCanvas(android.graphics.Rect) + * @see #lockCanvas(android.graphics.Rect) */ public void unlockCanvasAndPost(Canvas canvas) { if (mCanvas != null && canvas == mCanvas) { @@ -691,8 +691,8 @@ public class TextureView extends View { * Returns the {@link SurfaceTexture} used by this view. This method * may return null if the view is not attached to a window or if the surface * texture has not been initialized yet. - * - * @see #isAvailable() + * + * @see #isAvailable() */ public SurfaceTexture getSurfaceTexture() { return mSurface; @@ -746,8 +746,8 @@ public class TextureView extends View { /** * Returns the {@link SurfaceTextureListener} currently associated with this * texture view. - * - * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener) + * + * @see #setSurfaceTextureListener(android.view.TextureView.SurfaceTextureListener) * @see SurfaceTextureListener */ public SurfaceTextureListener getSurfaceTextureListener() { @@ -757,8 +757,8 @@ public class TextureView extends View { /** * Sets the {@link SurfaceTextureListener} used to listen to surface * texture events. - * - * @see #getSurfaceTextureListener() + * + * @see #getSurfaceTextureListener() * @see SurfaceTextureListener */ public void setSurfaceTextureListener(SurfaceTextureListener listener) { @@ -781,7 +781,7 @@ public class TextureView extends View { public static interface SurfaceTextureListener { /** * Invoked when a {@link TextureView}'s SurfaceTexture is ready for use. - * + * * @param surface The surface returned by * {@link android.view.TextureView#getSurfaceTexture()} * @param width The width of the surface @@ -791,7 +791,7 @@ public class TextureView extends View { /** * Invoked when the {@link SurfaceTexture}'s buffers size changed. - * + * * @param surface The surface returned by * {@link android.view.TextureView#getSurfaceTexture()} * @param width The new width of the surface @@ -804,7 +804,7 @@ public class TextureView extends View { * If returns true, no rendering should happen inside the surface texture after this method * is invoked. If returns false, the client needs to call {@link SurfaceTexture#release()}. * Most applications should return true. - * + * * @param surface The surface about to be destroyed */ public boolean onSurfaceTextureDestroyed(SurfaceTexture surface); @@ -812,7 +812,7 @@ public class TextureView extends View { /** * Invoked when the specified {@link SurfaceTexture} is updated through * {@link SurfaceTexture#updateTexImage()}. - * + * * @param surface The surface just updated */ public void onSurfaceTextureUpdated(SurfaceTexture surface);