to top
Android APIs
public class

Surface

extends Object
implements Parcelable
java.lang.Object
   ↳ android.view.Surface

Class Overview

Handle onto a raw buffer that is being managed by the screen compositor.

Summary

Nested Classes
class Surface.OutOfResourcesException Exception thrown when a surface couldn't be created or resized  
Constants
int ROTATION_0
int ROTATION_180
int ROTATION_270
int ROTATION_90
[Expand]
Inherited Constants
From interface android.os.Parcelable
Fields
public static final Creator<Surface> CREATOR
Public Constructors
Surface(SurfaceTexture surfaceTexture)
Create Surface from a SurfaceTexture.
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
boolean isValid()
Does this object hold a valid surface? Returns true if it holds a physical surface, so lockCanvas() will succeed.
Canvas lockCanvas(Rect dirty)
draw into a surface
void readFromParcel(Parcel source)
void release()
Release the local reference to the server-side surface.
String toString()
Returns a string containing a concise, human-readable description of this object.
void unlockCanvas(Canvas canvas)
unlock the surface.
void unlockCanvasAndPost(Canvas canvas)
unlock the surface and asks a page flip
void writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel.
Protected Methods
void finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final int ROTATION_0

Since: API Level 1

Constant Value: 0 (0x00000000)

public static final int ROTATION_180

Since: API Level 1

Constant Value: 2 (0x00000002)

public static final int ROTATION_270

Since: API Level 1

Constant Value: 3 (0x00000003)

public static final int ROTATION_90

Since: API Level 1

Constant Value: 1 (0x00000001)

Fields

public static final Creator<Surface> CREATOR

Since: API Level 1

Public Constructors

public Surface (SurfaceTexture surfaceTexture)

Since: API Level 14

Create Surface from a SurfaceTexture. Images drawn to the Surface will be made available to the SurfaceTexture, which can attach them an OpenGL ES texture via updateTexImage().

Parameters
surfaceTexture The SurfaceTexture that is updated by this Surface.

Public Methods

public int describeContents ()

Since: API Level 1

Describe the kinds of special objects contained in this Parcelable's marshalled representation.

Returns
  • a bitmask indicating the set of special object types marshalled by the Parcelable.

public boolean isValid ()

Since: API Level 1

Does this object hold a valid surface? Returns true if it holds a physical surface, so lockCanvas() will succeed. Otherwise returns false.

public Canvas lockCanvas (Rect dirty)

Since: API Level 1

public void readFromParcel (Parcel source)

Since: API Level 1

public void release ()

Since: API Level 14

Release the local reference to the server-side surface. Always call release() when you're done with a Surface. This will make the surface invalid.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method.

Returns
  • a printable representation of this object.

public void unlockCanvas (Canvas canvas)

Since: API Level 1

unlock the surface. the screen won't be updated until post() or postAll() is called

public void unlockCanvasAndPost (Canvas canvas)

Since: API Level 1

unlock the surface and asks a page flip

public void writeToParcel (Parcel dest, int flags)

Since: API Level 1

Flatten this object in to a Parcel.

Parameters
dest The Parcel in which the object should be written.
flags Additional flags about how the object should be written. May be 0 or PARCELABLE_WRITE_RETURN_VALUE.

Protected Methods

protected void finalize ()

Since: API Level 1

Invoked when the garbage collector has detected that this instance is no longer reachable. The default implementation does nothing, but this method can be overridden to free resources.

Note that objects that override finalize are significantly more expensive than objects that don't. Finalizers may be run a long time after the object is no longer reachable, depending on memory pressure, so it's a bad idea to rely on them for cleanup. Note also that finalizers are run on a single VM-wide finalizer thread, so doing blocking work in a finalizer is a bad idea. A finalizer is usually only necessary for a class that has a native peer and needs to call a native method to destroy that peer. Even then, it's better to provide an explicit close method (and implement Closeable), and insist that callers manually dispose of instances. This works well for something like files, but less well for something like a BigInteger where typical calling code would have to deal with lots of temporaries. Unfortunately, code that creates lots of temporaries is the worst kind of code from the point of view of the single finalizer thread.

If you must use finalizers, consider at least providing your own ReferenceQueue and having your own thread process that queue.

Unlike constructors, finalizers are not automatically chained. You are responsible for calling super.finalize() yourself.

Uncaught exceptions thrown by finalizers are ignored and do not terminate the finalizer thread. See Effective Java Item 7, "Avoid finalizers" for more.

Throws
Throwable