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
public 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 Implies "HARDWARE", the surface is to be used by the GPU additionally the backbuffer is never preserved for these surfaces.
int HARDWARE The surface is to be used by hardware accelerators or DMA engines
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 Freeze the surface.
int SURFACE_BLUR_FREEZE
int SURFACE_DITHER Enable dithering when compositing this 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()
Is called before the object's memory is being reclaimed by the VM.
[Expand]
Inherited Methods
From class java.lang.Object
From interface android.os.Parcelable

Constants

public static final Creator<Surface> CREATOR

public static final int FX_SURFACE_BLUR

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

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

Mask used for FX values above

Constant Value: 983040 (0x000f0000)

public static final int FX_SURFACE_NORMAL

Creates a normal surface. This is the default

Constant Value: 0 (0x00000000)

public static final int GPU

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

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

Constant Value: 16 (0x00000010)

public static final int HIDDEN

Surface is created hidden

Constant Value: 4 (0x00000004)

public static final int NON_PREMULTIPLIED

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

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

Constant Value: 0 (0x00000000)

public static final int ROTATION_180

Constant Value: 2 (0x00000002)

public static final int ROTATION_270

Constant Value: 3 (0x00000003)

public static final int ROTATION_90

Constant Value: 1 (0x00000001)

public static final int SECURE

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

Freeze the surface. Equivalent to calling freeze()

Constant Value: 2 (0x00000002)

public static final int SURFACE_BLUR_FREEZE

Constant Value: 16 (0x00000010)

public static final int SURFACE_DITHER

Enable dithering when compositing this surface

Constant Value: 4 (0x00000004)

public static final int SURFACE_HIDDEN

Hide the surface. Equivalent to calling hide()

Constant Value: 1 (0x00000001)

Public Methods

public int describeContents ()

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

public void hide ()

public boolean isValid ()

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)

draw into a surface

public void readFromParcel (Parcel source)

public void setAlpha (float alpha)

public void setFlags (int flags, int mask)

public void setFreezeTint (int tint)

public void setLayer (int zorder)

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

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

public static void setOrientation (int display, int orientation)

set the orientation of the given display.

public void setPosition (int x, int y)

public void setSize (int w, int h)

public void setTransparentRegionHint (Region region)

public void show ()

public String toString ()

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 simply concatenates the class name, the '@' sign and a hexadecimal representation of the object's hashCode(), that is, it is equivalent to the following expression:

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

Returns
  • a printable representation of this object.

public void unfreeze ()

public void unlockCanvas (Canvas canvas)

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

public void unlockCanvasAndPost (Canvas canvas)

unlock the surface and asks a page flip

public void writeToParcel (Parcel dest, int flags)

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

Is called before the object's memory is being reclaimed by the VM. This can only happen once the VM has detected, during a run of the garbage collector, 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