public class Surface extends Object implements Parcelable
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.
Modifier and Type | Class and Description |
---|---|
static class |
Surface.OutOfResourcesException
Exception thrown when a Canvas couldn't be locked with
lockCanvas(android.graphics.Rect) , or
when a SurfaceTexture could not successfully be allocated. |
static interface |
Surface.Rotation |
static interface |
Surface.ScalingMode |
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static Parcelable.Creator<Surface> |
CREATOR |
static int |
ROTATION_0
Rotation constant: 0 degree rotation (natural orientation)
|
static int |
ROTATION_180
Rotation constant: 180 degree rotation.
|
static int |
ROTATION_270
Rotation constant: 270 degree rotation.
|
static int |
ROTATION_90
Rotation constant: 90 degree rotation.
|
static int |
SCALING_MODE_FREEZE |
static int |
SCALING_MODE_NO_SCALE_CROP |
static int |
SCALING_MODE_SCALE_CROP |
static int |
SCALING_MODE_SCALE_TO_WINDOW |
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_ELIDE_DUPLICATES, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
Surface()
Create an empty surface, which will later be filled in by readFromParcel().
|
Surface(SurfaceTexture surfaceTexture)
Create Surface from a
SurfaceTexture . |
Modifier and Type | Method and Description |
---|---|
void |
allocateBuffers()
Allocate buffers ahead of time to avoid allocation delays during rendering
|
void |
copyFrom(SurfaceControl other)
Copy another surface to this one.
|
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable
instance's marshaled representation.
|
void |
destroy()
Free all server-side state associated with this surface and
release this object's reference.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
int |
getGenerationId()
Gets the generation number of this surface, incremented each time
the native surface contained within this object changes.
|
long |
getNextFrameNumber()
Returns the next frame number which will be dequeued for rendering.
|
boolean |
isConsumerRunningBehind()
Returns true if the consumer of this Surface is running behind the producer.
|
boolean |
isSingleBuffered()
Returns whether or not this Surface is backed by a single-buffered SurfaceTexture
|
boolean |
isValid()
Returns true if this object holds a valid surface.
|
Canvas |
lockCanvas(Rect inOutDirty)
Gets a
Canvas for drawing into this surface. |
Canvas |
lockHardwareCanvas()
Gets a
Canvas for drawing into this surface. |
void |
readFromParcel(Parcel source) |
void |
release()
Release the local reference to the server-side surface.
|
static String |
rotationToString(int rotation)
Returns a human readable representation of a rotation.
|
String |
toString()
Returns a string representation of the object.
|
void |
transferFrom(Surface other)
Deprecated.
|
void |
unlockCanvas(Canvas canvas)
Deprecated.
This API has been removed and is not supported. Do not use.
|
void |
unlockCanvasAndPost(Canvas canvas)
|
void |
writeToParcel(Parcel dest,
int flags)
Flatten this object in to a Parcel.
|
public static final Parcelable.Creator<Surface> CREATOR
public static final int SCALING_MODE_FREEZE
public static final int SCALING_MODE_SCALE_TO_WINDOW
public static final int SCALING_MODE_SCALE_CROP
public static final int SCALING_MODE_NO_SCALE_CROP
public static final int ROTATION_0
public static final int ROTATION_90
public static final int ROTATION_180
public static final int ROTATION_270
public Surface()
public Surface(SurfaceTexture surfaceTexture)
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()
.surfaceTexture
- The SurfaceTexture
that is updated by this
Surface.Surface.OutOfResourcesException
- if the surface could not be created.protected void finalize() throws Throwable
Object
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 JavaTM 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.
public void release()
public void destroy()
public boolean isValid()
public int getGenerationId()
public long getNextFrameNumber()
public boolean isConsumerRunningBehind()
public Canvas lockCanvas(Rect inOutDirty) throws Surface.OutOfResourcesException, IllegalArgumentException
Canvas
for drawing into this surface.
After drawing into the provided Canvas
, the caller must
invoke unlockCanvasAndPost(android.graphics.Canvas)
to post the new contents to the surface.inOutDirty
- 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.IllegalArgumentException
- If the inOutDirty rectangle is not valid.Surface.OutOfResourcesException
- If the canvas cannot be locked.public void unlockCanvasAndPost(Canvas canvas)
canvas
- The canvas previously obtained from lockCanvas(android.graphics.Rect)
.public Canvas lockHardwareCanvas()
Canvas
for drawing into this surface.
After drawing into the provided Canvas
, the caller must
invoke unlockCanvasAndPost(android.graphics.Canvas)
to post the new contents to the surface.
Unlike lockCanvas(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.IllegalStateException
- If the canvas cannot be locked.@Deprecated public void unlockCanvas(Canvas canvas)
public void copyFrom(SurfaceControl other)
@Deprecated public void transferFrom(Surface other)
SurfaceView.updateWindow(boolean, boolean)
only.other
- access is not thread safepublic int describeContents()
Parcelable
Parcelable.writeToParcel(Parcel, int)
,
the return value of this method must include the
Parcelable.CONTENTS_FILE_DESCRIPTOR
bit.describeContents
in interface Parcelable
Parcelable.CONTENTS_FILE_DESCRIPTOR
public void readFromParcel(Parcel source)
public void writeToParcel(Parcel dest, int flags)
Parcelable
writeToParcel
in interface Parcelable
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.PARCELABLE_WRITE_RETURN_VALUE
.public String toString()
Object
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())
public void allocateBuffers()
public boolean isSingleBuffered()
public static String rotationToString(int rotation)
rotation
- The rotation.