public class Surface extends Object implements Parcelable
Modifier and Type | Class and Description |
---|---|
static class |
Surface.OutOfResourcesException
Exception thrown when a surface couldn't be created or resized.
|
static class |
Surface.PhysicalDisplayInfo
Describes the properties of a physical display known to surface flinger.
|
Parcelable.ClassLoaderCreator<T>, Parcelable.Creator<T>
Modifier and Type | Field and Description |
---|---|
static int |
BUILT_IN_DISPLAY_ID_HDMI
Built-in physical display id: Attached HDMI display.
|
static int |
BUILT_IN_DISPLAY_ID_MAIN
Built-in physical display id: Main display.
|
static Parcelable.Creator<Surface> |
CREATOR |
static int |
FX_SURFACE_BLUR
Deprecated.
|
static int |
FX_SURFACE_DIM
Surface creation flag: Creates a Dim surface.
|
static int |
FX_SURFACE_MASK
Mask used for FX values above.
|
static int |
FX_SURFACE_NORMAL
Surface creation flag: Creates a normal surface.
|
static int |
FX_SURFACE_SCREENSHOT |
static int |
HIDDEN
Surface creation flag: Surface is created hidden
|
static int |
NON_PREMULTIPLIED
Surface creation flag: Creates a surface where color components are interpreted
as "non pre-multiplied" by their alpha channel.
|
static int |
OPAQUE
Surface creation flag: Indicates that the surface must be considered opaque,
even if its pixel format is set to translucent.
|
static int |
PROTECTED_APP
Surface creation flag: Application requires a hardware-protected path to an
external display sink.
|
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 |
SECURE
Surface creation flag: The surface contains secure content, special
measures will be taken to disallow the surface's content to be copied
from another process.
|
static int |
SURFACE_HIDDEN
Surface flag: Hide the surface.
|
CONTENTS_FILE_DESCRIPTOR, PARCELABLE_WRITE_RETURN_VALUE
Constructor and Description |
---|
Surface()
Create an empty surface, which will later be filled in by readFromParcel().
|
Surface(SurfaceSession session,
String name,
int w,
int h,
int format,
int flags)
Create a surface with a name.
|
Surface(SurfaceTexture surfaceTexture)
Create Surface from a
SurfaceTexture . |
Modifier and Type | Method and Description |
---|---|
static void |
blankDisplay(IBinder displayToken) |
static void |
closeTransaction()
end a transaction @hide
|
void |
copyFrom(Surface other)
Copy another surface to this one.
|
static IBinder |
createDisplay(String name,
boolean secure) |
int |
describeContents()
Describe the kinds of special objects contained in this Parcelable's
marshalled representation.
|
void |
destroy()
Free all server-side state associated with this surface and
release this object's reference.
|
protected void |
finalize()
Invoked when the garbage collector has detected that this instance is no longer reachable.
|
static IBinder |
getBuiltInDisplay(int builtInDisplayId) |
static boolean |
getDisplayInfo(IBinder displayToken,
Surface.PhysicalDisplayInfo outInfo) |
int |
getGenerationId()
Gets the generation number of this surface, incremented each time
the native surface contained within this object changes.
|
void |
hide() |
boolean |
isConsumerRunningBehind()
Returns true if the consumer of this Surface is running behind the producer.
|
boolean |
isValid()
Returns true if this object holds a valid surface.
|
Canvas |
lockCanvas(Rect dirty)
Gets a
Canvas for drawing into this surface. |
static void |
openTransaction()
start a transaction @hide
|
void |
readFromParcel(Parcel source) |
void |
release()
Release the local reference to the server-side surface.
|
static Bitmap |
screenshot(int width,
int height)
Like
screenshot(int, int, int, int) but includes all
Surfaces in the screenshot. |
static Bitmap |
screenshot(int width,
int height,
int minLayer,
int maxLayer)
Copy the current screen contents into a bitmap and return it.
|
void |
setAlpha(float alpha) |
static void |
setAnimationTransaction()
flag the transaction as an animation @hide
|
static void |
setDisplayLayerStack(IBinder displayToken,
int layerStack) |
static void |
setDisplayProjection(IBinder displayToken,
int orientation,
Rect layerStackRect,
Rect displayRect) |
static void |
setDisplaySurface(IBinder displayToken,
Surface surface) |
void |
setFlags(int flags,
int mask) |
void |
setLayer(int zorder) |
void |
setLayerStack(int layerStack) |
void |
setMatrix(float dsdx,
float dtdx,
float dsdy,
float dtdy) |
void |
setPosition(float x,
float y) |
void |
setPosition(int x,
int y) |
void |
setSize(int w,
int h) |
void |
setTransparentRegionHint(Region region) |
void |
setWindowCrop(Rect crop) |
void |
show() |
String |
toString()
Returns a string containing a concise, human-readable description of this
object.
|
void |
transferFrom(Surface other)
Transfer the native state from 'other' to this surface, releasing it
from 'other'.
|
static void |
unblankDisplay(IBinder displayToken) |
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 ROTATION_0
public static final int ROTATION_90
public static final int ROTATION_180
public static final int ROTATION_270
public static final int BUILT_IN_DISPLAY_ID_MAIN
#getBuiltInDisplay()
.public static final int BUILT_IN_DISPLAY_ID_HDMI
#getBuiltInDisplay()
.public static final int HIDDEN
public static final int SECURE
public static final int NON_PREMULTIPLIED
public static final int OPAQUE
public static final int PROTECTED_APP
public static final int FX_SURFACE_NORMAL
@Deprecated public static final int FX_SURFACE_BLUR
public static final int FX_SURFACE_DIM
setAlpha(float)
. It is an error to lock a Dim surface, since it
doesn't have a backing store.public static final int FX_SURFACE_SCREENSHOT
public static final int FX_SURFACE_MASK
public static final int SURFACE_HIDDEN
public Surface()
public Surface(SurfaceSession session, String name, int w, int h, int format, int flags) throws Surface.OutOfResourcesException
HIDDEN
flag set to ensure that they are not
made visible prematurely before all of the surface's properties have been
configured.
Good practice is to first create the surface with the HIDDEN
flag
specified, open a transaction, set the surface layer, layer stack, alpha,
and position, call show()
if appropriate, and close the transaction.session
- The surface session, must not be null.name
- The surface name, must not be null.w
- The surface initial width.h
- The surface initial height.flags
- The surface creation flags. Should always include HIDDEN
in the creation flags.Surface.OutOfResourcesException
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.protected void finalize() throws Throwable
Object
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.
public void release()
public void destroy()
public boolean isValid()
public int getGenerationId()
public boolean isConsumerRunningBehind()
public Canvas lockCanvas(Rect dirty) throws Surface.OutOfResourcesException, IllegalArgumentException
Canvas
for drawing into this surface.
After drawing into the provided Canvas
, the caller should
invoke unlockCanvasAndPost(android.graphics.Canvas)
to post the new contents to the surface.dirty
- 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 should redraw the entire dirty region as represented
by the contents of the dirty rect upon return from this function.
The caller may also pass null
instead, in the case where the
entire surface should be redrawn.Surface.OutOfResourcesException
IllegalArgumentException
public void unlockCanvasAndPost(Canvas canvas)
canvas
- The canvas previously obtained from lockCanvas(android.graphics.Rect)
.@Deprecated public void unlockCanvas(Canvas canvas)
public static Bitmap screenshot(int width, int height)
screenshot(int, int, int, int)
but includes all
Surfaces in the screenshot.public static Bitmap screenshot(int width, int height, int minLayer, int maxLayer)
width
- The desired width of the returned bitmap; the raw
screen will be scaled down to this size.height
- The desired height of the returned bitmap; the raw
screen will be scaled down to this size.minLayer
- The lowest (bottom-most Z order) surface layer to
include in the screenshot.maxLayer
- The highest (top-most Z order) surface layer to
include in the screenshot.public static void openTransaction()
public static void closeTransaction()
public static void setAnimationTransaction()
public void setLayer(int zorder)
public void setPosition(int x, int y)
public void setPosition(float x, float y)
public void setSize(int w, int h)
public void hide()
public void show()
public void setTransparentRegionHint(Region region)
public void setAlpha(float alpha)
public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy)
public void setFlags(int flags, int mask)
public void setWindowCrop(Rect crop)
public void setLayerStack(int layerStack)
public static IBinder getBuiltInDisplay(int builtInDisplayId)
public static void setDisplayLayerStack(IBinder displayToken, int layerStack)
public static void setDisplayProjection(IBinder displayToken, int orientation, Rect layerStackRect, Rect displayRect)
public static boolean getDisplayInfo(IBinder displayToken, Surface.PhysicalDisplayInfo outInfo)
public static void blankDisplay(IBinder displayToken)
public static void unblankDisplay(IBinder displayToken)
public void copyFrom(Surface other)
public void transferFrom(Surface other)
public int describeContents()
Parcelable
describeContents
in interface Parcelable
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
getClass().getName() + '@' + Integer.toHexString(hashCode())
See Writing a useful
toString
method
if you intend implementing your own toString
method.