public class

Surface

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

Class Overview

Handle on to 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
Creator<Surface> CREATOR
int FX_SURFACE_BLUR Creates a Blur surface.
int FX_SURFACE_DIM Creates a Dim surface.
int FX_SURFACE_MASK Mask used for FX values above
int FX_SURFACE_NORMAL Creates a normal surface.
int GPU This constant is deprecated. this is ignored, this value is set automatically when needed.
int HARDWARE This constant is deprecated. this is ignored, this value is set automatically when needed.
int HIDDEN Surface is created hidden
int NON_PREMULTIPLIED Creates a surface where color components are interpreted as "non pre-multiplied" by their alpha channel.
int PUSH_BUFFERS Creates a surface without a rendering buffer.
int ROTATION_0
int ROTATION_180
int ROTATION_270
int ROTATION_90
int SECURE The surface contains secure content, special measures will be taken to disallow the surface's content to be copied from another process.
int SURACE_FROZEN This constant is deprecated. use SURFACE_FROZEN instead.
int SURFACE_BLUR_FREEZE
int SURFACE_DITHER Enable dithering when compositing this surface
int SURFACE_FROZEN Freeze the surface.
int SURFACE_HIDDEN Hide the surface.
[Expand]
Inherited Constants
From interface android.os.Parcelable
Public Methods
int describeContents()
Describe the kinds of special objects contained in this Parcelable's marshalled representation.
void freeze()
void hide()
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 setAlpha(float alpha)
void setFlags(int flags, int mask)
void setFreezeTint(int tint)
void setLayer(int zorder)
set surface parameters.
void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy)
static void setOrientation(int display, int orientation)
set the orientation of the given display.
void setPosition(int x, int y)
void setSize(int w, int h)
void setTransparentRegionHint(Region region)
void show()
String toString()
Returns a string containing a concise, human-readable description of this object.
void unfreeze()
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()
Called before the object's memory is reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final Creator<Surface> CREATOR

Since: API Level 1

public static final int FX_SURFACE_BLUR

Since: API Level 1

Creates a Blur surface. Everything behind this surface is blurred by some amount. The quality and refresh speed of the blur effect is not settable or guaranteed. It is an error to lock a Blur surface, since it doesn't have a backing store.

Constant Value: 65536 (0x00010000)

public static final int FX_SURFACE_DIM

Since: API Level 1

Creates a Dim surface. Everything behind this surface is dimmed by the amount specified in setAlpha(). It is an error to lock a Dim surface, since it doesn't have a backing store.

Constant Value: 131072 (0x00020000)

public static final int FX_SURFACE_MASK

Since: API Level 1

Mask used for FX values above

Constant Value: 983040 (0x000f0000)

public static final int FX_SURFACE_NORMAL

Since: API Level 1

Creates a normal surface. This is the default

Constant Value: 0 (0x00000000)

public static final int GPU

Since: API Level 1

This constant is deprecated.
this is ignored, this value is set automatically when needed.

Implies "HARDWARE", the surface is to be used by the GPU additionally the backbuffer is never preserved for these surfaces.

Constant Value: 40 (0x00000028)

public static final int HARDWARE

Since: API Level 1

This constant is deprecated.
this is ignored, this value is set automatically when needed.

The surface is to be used by hardware accelerators or DMA engines

Constant Value: 16 (0x00000010)

public static final int HIDDEN

Since: API Level 1

Surface is created hidden

Constant Value: 4 (0x00000004)

public static final int NON_PREMULTIPLIED

Since: API Level 1

Creates a surface where color components are interpreted as "non pre-multiplied" by their alpha channel. Of course this flag is meaningless for surfaces without an alpha channel. By default surfaces are pre-multiplied, which means that each color component is already multiplied by its alpha value. In this case the blending equation used is: DEST = SRC + DEST * (1-SRC_ALPHA) By contrast, non pre-multiplied surfaces use the following equation: DEST = SRC * SRC_ALPHA * DEST * (1-SRC_ALPHA) pre-multiplied surfaces must always be used if transparent pixels are composited on top of each-other into the surface. A pre-multiplied surface can never lower the value of the alpha component of a given pixel. In some rare situations, a non pre-multiplied surface is preferable.

Constant Value: 256 (0x00000100)

public static final int PUSH_BUFFERS

Since: API Level 1

Creates a surface without a rendering buffer. Instead, the content of the surface must be pushed by an external entity. This is type of surface can be used for efficient camera preview or movie play back.

Constant Value: 512 (0x00000200)

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)

public static final int SECURE

Since: API Level 1

The surface contains secure content, special measures will be taken to disallow the surface's content to be copied from another process. In particular, screenshots and VNC servers will be disabled, but other measures can take place, for instance the surface might not be hardware accelerated.

Constant Value: 128 (0x00000080)

public static final int SURACE_FROZEN

Since: API Level 1

This constant is deprecated.
use SURFACE_FROZEN instead.

Constant Value: 2 (0x00000002)

public static final int SURFACE_BLUR_FREEZE

Since: API Level 1

Constant Value: 16 (0x00000010)

public static final int SURFACE_DITHER

Since: API Level 1

Enable dithering when compositing this surface

Constant Value: 4 (0x00000004)

public static final int SURFACE_FROZEN

Since: API Level 4

Freeze the surface. Equivalent to calling freeze()

Constant Value: 2 (0x00000002)

public static final int SURFACE_HIDDEN

Since: API Level 1

Hide the surface. Equivalent to calling hide()

Constant Value: 1 (0x00000001)

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 void freeze ()

Since: API Level 1

public void hide ()

Since: API Level 1

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 setAlpha (float alpha)

Since: API Level 1

public void setFlags (int flags, int mask)

Since: API Level 1

public void setFreezeTint (int tint)

Since: API Level 1

public void setLayer (int zorder)

Since: API Level 1

set surface parameters. needs to be inside open/closeTransaction block

public void setMatrix (float dsdx, float dtdx, float dsdy, float dtdy)

Since: API Level 1

public static void setOrientation (int display, int orientation)

Since: API Level 1

set the orientation of the given display.

public void setPosition (int x, int y)

Since: API Level 1

public void setSize (int w, int h)

Since: API Level 1

public void setTransparentRegionHint (Region region)

Since: API Level 1

public void show ()

Since: API Level 1

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 unfreeze ()

Since: API Level 1

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

Called before the object's memory is reclaimed by the VM. This can only happen once the garbage collector has detected that the object is no longer reachable by any thread of the running application.

The method can be used to free system resources or perform other cleanup before the object is garbage collected. The default implementation of the method is empty, which is also expected by the VM, but subclasses can override finalize() as required. Uncaught exceptions which are thrown during the execution of this method cause it to terminate immediately but are otherwise ignored.

Note that the VM does guarantee that finalize() is called at most once for any object, but it doesn't guarantee when (if at all) finalize() will be called. For example, object B's finalize() can delay the execution of object A's finalize() method and therefore it can delay the reclamation of A's memory. To be safe, use a ReferenceQueue, because it provides more control over the way the VM deals with references during garbage collection.

Throws
Throwable