Surface
open class Surface : Parcelable
| kotlin.Any | |
| ↳ | 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 android.graphics.SurfaceTexture, android.media.MediaRecorder, or android.renderscript.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 | |
|---|---|
| open |
Exception thrown when a Canvas couldn't be locked with |
| Constants | |
|---|---|
| static Int |
There are no inherent restrictions on the frame rate of this surface. |
| static Int |
This surface is being used to display content with an inherently fixed frame rate, e. |
| static Int |
Rotation constant: 0 degree rotation (natural orientation) |
| static Int |
Rotation constant: 180 degree rotation. |
| static Int |
Rotation constant: 270 degree rotation. |
| static Int |
Rotation constant: 90 degree rotation. |
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
<init>(from: SurfaceControl)Create a Surface assosciated with a given |
|
<init>(surfaceTexture: SurfaceTexture!)Create Surface from a |
|
| Public methods | |
|---|---|
| open Int | |
| open Boolean |
isValid()Returns true if this object holds a valid surface. |
| open Canvas! |
lockCanvas(inOutDirty: Rect!)Gets a |
| open Canvas! |
Gets a |
| open Unit |
readFromParcel(source: Parcel!) |
| open Unit |
release()Release the local reference to the server-side surface. |
| open Unit |
setFrameRate(frameRate: Float, compatibility: Int)Sets the intended frame rate for this surface. |
| open String |
toString() |
| open Unit |
unlockCanvas(canvas: Canvas!) |
| open Unit |
unlockCanvasAndPost(canvas: Canvas!)Posts the new contents of the |
| open Unit |
writeToParcel(dest: Parcel!, flags: Int) |
| Protected methods | |
|---|---|
| open Unit |
finalize() |
| Properties | |
|---|---|
| static Parcelable.Creator<Surface!> | |
Constants
FRAME_RATE_COMPATIBILITY_DEFAULT
static val FRAME_RATE_COMPATIBILITY_DEFAULT: Int
There are no inherent restrictions on the frame rate of this surface. When the system selects a frame rate other than what the app requested, the app will be able to run at the system frame rate without requiring pull down. This value should be used when displaying game content, UIs, and anything that isn't video.
Value: 0
FRAME_RATE_COMPATIBILITY_FIXED_SOURCE
static val FRAME_RATE_COMPATIBILITY_FIXED_SOURCE: Int
This surface is being used to display content with an inherently fixed frame rate, e.g. a video that has a specific frame rate. When the system selects a frame rate other than what the app requested, the app will need to do pull down or use some other technique to adapt to the system's frame rate. The user experience is likely to be worse (e.g. more frame stuttering) than it would be if the system had chosen the app's requested frame rate. This value should be used for video content.
Value: 1
ROTATION_0
static val ROTATION_0: Int
Rotation constant: 0 degree rotation (natural orientation)
Value: 0
ROTATION_180
static val ROTATION_180: Int
Rotation constant: 180 degree rotation.
Value: 2
ROTATION_270
static val ROTATION_270: Int
Rotation constant: 270 degree rotation.
Value: 3
ROTATION_90
static val ROTATION_90: Int
Rotation constant: 90 degree rotation.
Value: 1
Public constructors
<init>
Surface(from: SurfaceControl)
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 This value cannot be null. |
<init>
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. |
| Exceptions | |
|---|---|
android.view.Surface.OutOfResourcesException |
if the surface could not be created. |
Public methods
describeContents
open fun describeContents(): Int
| Return | |
|---|---|
Int |
a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either 0 or android.os.Parcelable#CONTENTS_FILE_DESCRIPTOR |
isValid
open fun isValid(): Boolean
Returns true if this object holds a valid surface.
| Return | |
|---|---|
Boolean |
True if it holds a physical surface, so lockCanvas() will succeed. Otherwise returns false. |
lockCanvas
open fun lockCanvas(inOutDirty: Rect!): Canvas!
Gets a Canvas for drawing into this surface. After drawing into the provided Canvas, the caller must invoke unlockCanvasAndPost 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. |
| Return | |
|---|---|
Canvas! |
A canvas for drawing into the surface. |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
If the inOutDirty rectangle is not valid. |
android.view.Surface.OutOfResourcesException |
If the canvas cannot be locked. |
lockHardwareCanvas
open fun lockHardwareCanvas(): Canvas!
Gets a Canvas for drawing into this surface. After drawing into the provided Canvas, the caller must invoke unlockCanvasAndPost 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.
| Return | |
|---|---|
Canvas! |
A canvas for drawing into the surface. |
| Exceptions | |
|---|---|
java.lang.IllegalStateException |
If the canvas cannot be locked. |
release
open fun release(): Unit
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.
setFrameRate
open fun setFrameRate(
frameRate: Float,
compatibility: Int
): Unit
Sets the intended frame rate for this surface.
On devices that are capable of running the display at different refresh rates, the system may choose a display refresh rate to better match this surface's frame rate. Usage of this API won't introduce frame rate throttling, or affect other aspects of the application's frame production pipeline. However, because the system may change the display refresh rate, calls to this function may result in changes to Choreographer callback timings, and changes to the time interval at which the system releases buffers back to the application.
Note that this only has an effect for surfaces presented on the display. If this surface is consumed by something other than the system compositor, e.g. a media codec, this call has no effect.
| Parameters | |
|---|---|
frameRate |
Float: The intended frame rate of this surface, in frames per second. 0 is a special value that indicates the app will accept the system's choice for the display frame rate, which is the default behavior if this function isn't called. The frameRate param does not need to be a valid refresh rate for this device's display - e.g., it's fine to pass 30fps to a device that can only run the display at 60fps. Value is 0.0 or greater |
compatibility |
Int: The frame rate compatibility of this surface. The compatibility value may influence the system's choice of display frame rate. See the FRAME_RATE_COMPATIBILITY_* values for more info. Value is android.view.Surface#FRAME_RATE_COMPATIBILITY_DEFAULT, or android.view.Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE |
| Exceptions | |
|---|---|
java.lang.IllegalArgumentException |
If frameRate or compatibility are invalid. |
toString
open fun toString(): String
| Return | |
|---|---|
String |
a string representation of the object. |
unlockCanvas
open fununlockCanvas(canvas: Canvas!): Unit
Deprecated: This API has been removed and is not supported. Do not use.
unlockCanvasAndPost
open fun unlockCanvasAndPost(canvas: Canvas!): Unit
Posts the new contents of the Canvas to the surface and releases the Canvas.
| Parameters | |
|---|---|
canvas |
Canvas!: The canvas previously obtained from lockCanvas. |
writeToParcel
open fun writeToParcel(
dest: Parcel!,
flags: Int
): Unit
| 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_WRITE_RETURN_VALUE. Value is either 0 or a combination of android.os.Parcelable#PARCELABLE_WRITE_RETURN_VALUE, and android.os.Parcelable.PARCELABLE_ELIDE_DUPLICATES |
Protected methods
finalize
protected open fun finalize(): Unit
| Exceptions | |
|---|---|
java.lang.Throwable |
the Exception raised by this method |