public class SurfaceControl extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SurfaceControl.PhysicalDisplayInfo
Describes the properties of a physical display known to surface flinger.
|
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 int |
CURSOR_WINDOW
Surface creation flag: Window represents a cursor glyph.
|
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 |
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 |
POWER_MODE_DOZE
Display power mode doze: used while putting the screen into low power mode.
|
static int |
POWER_MODE_DOZE_SUSPEND
Display power mode doze: used while putting the screen into a suspended
low power mode.
|
static int |
POWER_MODE_NORMAL
Display power mode normal: used while unblanking the screen.
|
static int |
POWER_MODE_OFF |
static int |
PROTECTED_APP
Surface creation flag: Application requires a hardware-protected path to an
external display sink.
|
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.
|
Constructor and Description |
---|
SurfaceControl(SurfaceSession session,
String name,
int w,
int h,
int format,
int flags)
Create a surface with a name.
|
Modifier and Type | Method and Description |
---|---|
static boolean |
clearAnimationFrameStats() |
boolean |
clearContentFrameStats() |
static void |
closeTransaction()
end a transaction
|
static void |
closeTransactionSync() |
static IBinder |
createDisplay(String name,
boolean secure) |
void |
deferTransactionUntil(IBinder handle,
long frame) |
void |
destroy()
Free all server-side state associated with this surface and
release this object's reference.
|
static void |
destroyDisplay(IBinder displayToken) |
void |
disconnect()
Disconnect any client still connected to the surface.
|
protected void |
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
static int |
getActiveColorMode(IBinder displayToken) |
static int |
getActiveConfig(IBinder displayToken) |
static boolean |
getAnimationFrameStats(WindowAnimationFrameStats outStats) |
static IBinder |
getBuiltInDisplay(int builtInDisplayId) |
boolean |
getContentFrameStats(WindowContentFrameStats outStats) |
static int[] |
getDisplayColorModes(IBinder displayToken) |
static SurfaceControl.PhysicalDisplayInfo[] |
getDisplayConfigs(IBinder displayToken) |
IBinder |
getHandle() |
static Display.HdrCapabilities |
getHdrCapabilities(IBinder displayToken) |
boolean |
getTransformToDisplayInverse() |
void |
hide() |
static void |
openTransaction()
start a transaction
|
void |
release()
Release the local reference to the server-side surface.
|
static void |
screenshot(IBinder display,
Surface consumer)
Copy the current screen contents into the provided
Surface |
static void |
screenshot(IBinder display,
Surface consumer,
int width,
int height)
Copy the current screen contents into the provided
Surface |
static void |
screenshot(IBinder display,
Surface consumer,
int width,
int height,
int minLayer,
int maxLayer,
boolean useIdentityTransform)
Copy the current screen contents into the provided
Surface |
static Bitmap |
screenshot(int width,
int height)
Like
SurfaceControl#screenshot(int, int, int, int, boolean) but
includes all Surfaces in the screenshot. |
static Bitmap |
screenshot(Rect sourceCrop,
int width,
int height,
int minLayer,
int maxLayer,
boolean useIdentityTransform,
int rotation)
Copy the current screen contents into a bitmap and return it.
|
static boolean |
setActiveColorMode(IBinder displayToken,
int colorMode) |
static boolean |
setActiveConfig(IBinder displayToken,
int id) |
void |
setAlpha(float alpha)
Sets an alpha value for the entire Surface.
|
static void |
setAnimationTransaction()
flag the transaction as an animation
|
static void |
setDisplayLayerStack(IBinder displayToken,
int layerStack) |
static void |
setDisplayPowerMode(IBinder displayToken,
int mode) |
static void |
setDisplayProjection(IBinder displayToken,
int orientation,
Rect layerStackRect,
Rect displayRect) |
static void |
setDisplaySize(IBinder displayToken,
int width,
int height) |
static void |
setDisplaySurface(IBinder displayToken,
Surface surface) |
void |
setFinalCrop(Rect crop) |
void |
setGeometryAppliesWithResize()
If the buffer size changes in this transaction, position and crop updates specified
in this transaction will not complete until a buffer of the new size
arrives.
|
void |
setLayer(int zorder) |
void |
setLayerStack(int layerStack) |
void |
setMatrix(float dsdx,
float dtdx,
float dsdy,
float dtdy) |
void |
setOpaque(boolean isOpaque)
Sets the opacity of the surface.
|
void |
setOverrideScalingMode(int scalingMode) |
void |
setPosition(float x,
float y) |
void |
setSecure(boolean isSecure)
Sets the security of the surface.
|
void |
setSize(int w,
int h) |
void |
setTransparentRegionHint(Region region) |
void |
setWindowCrop(Rect crop) |
void |
show() |
String |
toString()
Returns a string representation of the object.
|
public static final int HIDDEN
public static final int SECURE
public static final int NON_PREMULTIPLIED
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.
public static final int OPAQUE
This flag is ignored if setAlpha() is used to make the surface non-opaque. Combined effects are (assuming a buffer format with an alpha channel):
public static final int PROTECTED_APP
public static final int CURSOR_WINDOW
public static final int FX_SURFACE_NORMAL
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_MASK
public static final int BUILT_IN_DISPLAY_ID_MAIN
getBuiltInDisplay(int)
.public static final int BUILT_IN_DISPLAY_ID_HDMI
getBuiltInDisplay(int)
.public static final int POWER_MODE_OFF
public static final int POWER_MODE_DOZE
setDisplayPowerMode(android.os.IBinder, int)
.public static final int POWER_MODE_NORMAL
setDisplayPowerMode(android.os.IBinder, int)
.public static final int POWER_MODE_DOZE_SUSPEND
setDisplayPowerMode(android.os.IBinder, int)
.public SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags) throws Surface.OutOfResourcesException
The surface creation flags specify what kind of surface to create and
certain options such as whether the surface can be assumed to be opaque
and whether it should be initially hidden. Surfaces should always be
created with the 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.throws
- OutOfResourcesException If the SurfaceControl cannot be created.Surface.OutOfResourcesException
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 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 release()
public void destroy()
public void disconnect()
public static void openTransaction()
public static void closeTransaction()
public static void closeTransactionSync()
public void deferTransactionUntil(IBinder handle, long frame)
public void setOverrideScalingMode(int scalingMode)
public IBinder getHandle()
public boolean getTransformToDisplayInverse()
public static void setAnimationTransaction()
public void setLayer(int zorder)
public void setPosition(float x, float y)
public void setGeometryAppliesWithResize()
public void setSize(int w, int h)
public void hide()
public void show()
public void setTransparentRegionHint(Region region)
public boolean clearContentFrameStats()
public boolean getContentFrameStats(WindowContentFrameStats outStats)
public static boolean clearAnimationFrameStats()
public static boolean getAnimationFrameStats(WindowAnimationFrameStats outStats)
public void setAlpha(float alpha)
public void setMatrix(float dsdx, float dtdx, float dsdy, float dtdy)
public void setWindowCrop(Rect crop)
public void setFinalCrop(Rect crop)
public void setLayerStack(int layerStack)
public void setOpaque(boolean isOpaque)
OPAQUE
flag.public void setSecure(boolean isSecure)
SECURE
flag.public static void setDisplayPowerMode(IBinder displayToken, int mode)
public static SurfaceControl.PhysicalDisplayInfo[] getDisplayConfigs(IBinder displayToken)
public static int getActiveConfig(IBinder displayToken)
public static boolean setActiveConfig(IBinder displayToken, int id)
public static int[] getDisplayColorModes(IBinder displayToken)
public static int getActiveColorMode(IBinder displayToken)
public static boolean setActiveColorMode(IBinder displayToken, int colorMode)
public static void setDisplayProjection(IBinder displayToken, int orientation, Rect layerStackRect, Rect displayRect)
public static void setDisplayLayerStack(IBinder displayToken, int layerStack)
public static void setDisplaySize(IBinder displayToken, int width, int height)
public static Display.HdrCapabilities getHdrCapabilities(IBinder displayToken)
public static void destroyDisplay(IBinder displayToken)
public static IBinder getBuiltInDisplay(int builtInDisplayId)
public static void screenshot(IBinder display, Surface consumer, int width, int height, int minLayer, int maxLayer, boolean useIdentityTransform)
Surface
display
- The display to take the screenshot of.consumer
- The Surface
to take the screenshot into.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.useIdentityTransform
- Replace whatever transformation (rotation,
scaling, translation) the surface layers are currently using with the
identity transformation while taking the screenshot.public static void screenshot(IBinder display, Surface consumer, int width, int height)
Surface
display
- The display to take the screenshot of.consumer
- The Surface
to take the screenshot into.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.public static void screenshot(IBinder display, Surface consumer)
Surface
display
- The display to take the screenshot of.consumer
- The Surface
to take the screenshot into.public static Bitmap screenshot(Rect sourceCrop, int width, int height, int minLayer, int maxLayer, boolean useIdentityTransform, int rotation)
Bitmap
can
be extremely slow; avoid use unless absolutely necessary; prefer
the versions that use a Surface
instead, such as
screenshot(IBinder, Surface)
.sourceCrop
- The portion of the screen to capture into the Bitmap;
caller may pass in 'new Rect()' if no cropping is desired.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.useIdentityTransform
- Replace whatever transformation (rotation,
scaling, translation) the surface layers are currently using with the
identity transformation while taking the screenshot.rotation
- Apply a custom clockwise rotation to the screenshot, i.e.
Surface.ROTATION_0,90,180,270. Surfaceflinger will always take
screenshots in its native portrait orientation by default, so this is
useful for returning screenshots that are independent of device
orientation.public static Bitmap screenshot(int width, int height)
SurfaceControl#screenshot(int, int, int, int, boolean)
but
includes all Surfaces in the screenshot.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.