Surface
public
class
Surface
extends Object
implements
Parcelable
| java.lang.Object | |
| ↳ | android.view.Surface |
Handle onto a raw buffer that is being managed by the screen compositor.
A Surface is generally created by or from a consumer of image buffers (such as a
SurfaceTexture, MediaRecorder, or
Allocation), and is handed to some kind of producer (such as
OpenGL,
MediaPlayer, or
CameraDevice) to draw
into.
Note: A Surface acts like a
weak reference to the consumer it is associated with. By
itself it will not keep its parent consumer from being reclaimed.
Summary
Nested classes | |
|---|---|
class |
Surface.OutOfResourcesException
Exception thrown when a Canvas couldn't be locked with |
Constants | |
|---|---|
int |
ROTATION_0
Rotation constant: 0 degree rotation (natural orientation) |
int |
ROTATION_180
Rotation constant: 180 degree rotation. |
int |
ROTATION_270
Rotation constant: 270 degree rotation. |
int |
ROTATION_90
Rotation constant: 90 degree rotation. |
Inherited constants |
|---|
Fields | |
|---|---|
public
static
final
Creator<Surface> |
CREATOR
|
Public constructors | |
|---|---|
Surface(SurfaceControl from)
Create a Surface assosciated with a given |
|
Surface(SurfaceTexture surfaceTexture)
Create Surface from a |
|
Public methods | |
|---|---|
int
|
describeContents()
Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
boolean
|
isValid()
Returns true if this object holds a valid surface. |
Canvas
|
lockCanvas(Rect inOutDirty)
Gets a |
Canvas
|
lockHardwareCanvas()
Gets a |
void
|
readFromParcel(Parcel source)
|
void
|
release()
Release the local reference to the server-side surface. |
String
|
toString()
Returns a string representation of the object. |
void
|
unlockCanvas(Canvas canvas)
This method was deprecated in API level 17. This API has been removed and is not supported. Do not use. |
void
|
unlockCanvasAndPost(Canvas canvas)
Posts the new contents of the |
void
|
writeToParcel(Parcel dest, int flags)
Flatten this object in to a Parcel. |
Protected methods | |
|---|---|
void
|
finalize()
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |
Inherited methods | |
|---|---|
Constants
ROTATION_0
public static final int ROTATION_0
Rotation constant: 0 degree rotation (natural orientation)
Constant Value: 0 (0x00000000)
ROTATION_180
public static final int ROTATION_180
Rotation constant: 180 degree rotation.
Constant Value: 2 (0x00000002)
ROTATION_270
public static final int ROTATION_270
Rotation constant: 270 degree rotation.
Constant Value: 3 (0x00000003)
ROTATION_90
public static final int ROTATION_90
Rotation constant: 90 degree rotation.
Constant Value: 1 (0x00000001)
Fields
Public constructors
Surface
public Surface (SurfaceControl from)
Create a Surface assosciated with a given SurfaceControl. Buffers submitted to this
surface will be displayed by the system compositor according to the parameters
specified by the control. Multiple surfaces may be constructed from one SurfaceControl,
but only one can be connected (e.g. have an active EGL context) at a time.
| Parameters | |
|---|---|
from |
SurfaceControl: The SurfaceControl to assosciate this Surface with |
Surface
public Surface (SurfaceTexture surfaceTexture)
Create Surface from a SurfaceTexture.
Images drawn to the Surface will be made available to the SurfaceTexture, which can attach them to an OpenGL ES texture via SurfaceTexture#updateTexImage.
Please note that holding onto the Surface created here is not enough to
keep the provided SurfaceTexture from being reclaimed. In that sense,
the Surface will act like a
weak reference to the SurfaceTexture.
| Parameters | |
|---|---|
surfaceTexture |
SurfaceTexture: The SurfaceTexture that is updated by this
Surface. |
| Throws | |
|---|---|
Surface.OutOfResourcesException |
if the surface could not be created. |
Public methods
describeContents
public int describeContents ()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation. For example, if the object will
include a file descriptor in the output of writeToParcel(android.os.Parcel, int),
the return value of this method must include the
CONTENTS_FILE_DESCRIPTOR bit.
| Returns | |
|---|---|
int |
a bitmask indicating the set of special object types marshaled
by this Parcelable object instance.
Value is either 0 or CONTENTS_FILE_DESCRIPTOR |
isValid
public boolean isValid ()
Returns true if this object holds a valid surface.
| Returns | |
|---|---|
boolean |
True if it holds a physical surface, so lockCanvas() will succeed. Otherwise returns false. |
lockCanvas
public Canvas lockCanvas (Rect inOutDirty)
Gets a Canvas for drawing into this surface.
After drawing into the provided Canvas, the caller must
invoke unlockCanvasAndPost(Canvas) to post the new contents to the surface.
| Parameters | |
|---|---|
inOutDirty |
Rect: A rectangle that represents the dirty region that the caller wants
to redraw. This function may choose to expand the dirty rectangle if for example
the surface has been resized or if the previous contents of the surface were
not available. The caller must redraw the entire dirty region as represented
by the contents of the inOutDirty rectangle upon return from this function.
The caller may also pass null instead, in the case where the
entire surface should be redrawn. |
| Returns | |
|---|---|
Canvas |
A canvas for drawing into the surface. |
| Throws | |
|---|---|
IllegalArgumentException |
If the inOutDirty rectangle is not valid. |
Surface.OutOfResourcesException |
If the canvas cannot be locked. |
lockHardwareCanvas
public Canvas lockHardwareCanvas ()
Gets a Canvas for drawing into this surface.
After drawing into the provided Canvas, the caller must
invoke unlockCanvasAndPost(Canvas) to post the new contents to the surface.
Unlike lockCanvas(android.graphics.Rect) this will return a hardware-accelerated
canvas. See the
unsupported drawing operations for a list of what is and isn't
supported in a hardware-accelerated canvas. It is also required to
fully cover the surface every time lockHardwareCanvas() is
called as the buffer is not preserved between frames. Partial updates
are not supported.
| Returns | |
|---|---|
Canvas |
A canvas for drawing into the surface. |
| Throws | |
|---|---|
IllegalStateException |
If the canvas cannot be locked. |
readFromParcel
public void readFromParcel (Parcel source)
| Parameters | |
|---|---|
source |
Parcel |
release
public void release ()
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.
toString
public String toString ()
Returns a string representation of the object. In general, the
toString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
| Returns | |
|---|---|
String |
a string representation of the object. |
unlockCanvas
public void unlockCanvas (Canvas canvas)
This method was deprecated
in API level 17.
This API has been removed and is not supported. Do not use.
| Parameters | |
|---|---|
canvas |
Canvas |
unlockCanvasAndPost
public void unlockCanvasAndPost (Canvas canvas)
Posts the new contents of the Canvas to the surface and
releases the Canvas.
| Parameters | |
|---|---|
canvas |
Canvas: The canvas previously obtained from lockCanvas(Rect). |
writeToParcel
public void writeToParcel (Parcel dest, int flags)
Flatten this object in to a Parcel.
| Parameters | |
|---|---|
dest |
Parcel: The Parcel in which the object should be written. |
flags |
int: Additional flags about how the object should be written.
May be 0 or Parcelable.PARCELABLE_WRITE_RETURN_VALUE.
Value is either 0 or a combination of Parcelable.PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
Protected methods
finalize
protected void finalize ()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
A subclass overrides the finalize method to dispose of
system resources or to perform other cleanup.
The general contract of finalize is that it is invoked
if and when the Java™ virtual
machine has determined that there is no longer any
means by which this object can be accessed by any thread that has
not yet died, except as a result of an action taken by the
finalization of some other object or class which is ready to be
finalized. The finalize method may take any action, including
making this object available again to other threads; the usual purpose
of finalize, however, is to perform cleanup actions before
the object is irrevocably discarded. For example, the finalize method
for an object that represents an input/output connection might perform
explicit I/O transactions to break the connection before the object is
permanently discarded.
The finalize method of class Object performs no
special action; it simply returns normally. Subclasses of
Object may override this definition.
The Java programming language does not guarantee which thread will
invoke the finalize method for any given object. It is
guaranteed, however, that the thread that invokes finalize will not
be holding any user-visible synchronization locks when finalize is
invoked. If an uncaught exception is thrown by the finalize method,
the exception is ignored and finalization of that object terminates.
After the finalize method has been invoked for an object, no
further action is taken until the Java virtual machine has again
determined that there is no longer any means by which this object can
be accessed by any thread that has not yet died, including possible
actions by other objects or classes which are ready to be finalized,
at which point the object may be discarded.
The finalize method is never invoked more than once by a Java
virtual machine for any given object.
Any exception thrown by the finalize method causes
the finalization of this object to be halted, but is otherwise
ignored.
| Throws | |
|---|---|
Throwable |
|
Content and code samples on this page are subject to the licenses described in the Content License. Java is a registered trademark of Oracle and/or its affiliates.