Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Nested Classes](https://developer.android.com/reference/android/view/Surface#nestedclasses) \| [Constants](https://developer.android.com/reference/android/view/Surface#constants) \| [Inherited Constants](https://developer.android.com/reference/android/view/Surface#inhconstants) \| [Fields](https://developer.android.com/reference/android/view/Surface#lfields) \| [Ctors](https://developer.android.com/reference/android/view/Surface#pubctors) \| [Methods](https://developer.android.com/reference/android/view/Surface#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/view/Surface#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/Surface#inhmethods)

# Surface

*** ** * ** ***

` public class Surface `   
` extends https://developer.android.com/reference/java/lang/Object ` ` implements https://developer.android.com/reference/android/os/Parcelable `

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.Surface |

<br />

*** ** * ** ***

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 `https://developer.android.com/reference/android/graphics/SurfaceTexture`, `https://developer.android.com/reference/android/media/MediaRecorder`, or `https://developer.android.com/reference/android/renderscript/Allocation`), and is handed to some kind of producer (such as `https://developer.android.com/reference/android/opengl/EGL14#eglCreateWindowSurface(android.opengl.EGLDisplay,%20android.opengl.EGLConfig,%20java.lang.Object,%20int[],%20int)`, `https://developer.android.com/reference/android/media/MediaPlayer#setSurface(android.view.Surface)`, or `https://developer.android.com/reference/android/hardware/camera2/CameraDevice#createCaptureSession(android.hardware.camera2.params.SessionConfiguration)`) to draw into.

**Note:** A Surface acts like a `https://developer.android.com/reference/java/lang/ref/WeakReference` to the consumer it is associated with. By itself it will not keep its parent consumer from being reclaimed.

<br />

## Summary

| ### Nested classes ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/view/Surface.OutOfResourcesException` Exception thrown when a Canvas couldn't be locked with `https://developer.android.com/reference/android/view/Surface#lockCanvas(android.graphics.Rect)`, or when a SurfaceTexture could not successfully be allocated. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/view/Surface#CHANGE_FRAME_RATE_ALWAYS` Change the frame rate even if the transition is going to be non-seamless, i.e. |
| `int` | `https://developer.android.com/reference/android/view/Surface#CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS` Change the frame rate only if the transition is going to be seamless. |
| `int` | `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_AT_LEAST` The surface requests a frame rate that is at least the specified frame rate. |
| `int` | `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_DEFAULT` There are no inherent restrictions on the frame rate of this surface. |
| `int` | `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` This surface is being used to display content with an inherently fixed frame rate, e.g. a video that has a specific frame rate. |
| `int` | `https://developer.android.com/reference/android/view/Surface#ROTATION_0` Rotation constant: 0 degree rotation (natural orientation) |
| `int` | `https://developer.android.com/reference/android/view/Surface#ROTATION_180` Rotation constant: 180 degree rotation. |
| `int` | `https://developer.android.com/reference/android/view/Surface#ROTATION_270` Rotation constant: 270 degree rotation. |
| `int` | `https://developer.android.com/reference/android/view/Surface#ROTATION_90` Rotation constant: 90 degree rotation. |

### Inherited constants

From interface `https://developer.android.com/reference/android/os/Parcelable` `int` `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR`

Descriptor bit used with `https://developer.android.com/reference/android/os/Parcelable#describeContents()`: indicates that the Parcelable object's flattened representation includes a file descriptor.
`int` `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`

Flag for use with `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`: the object being written is a return value, that is the result of a function such as "`Parcelable someFunction()`", "`void someFunction(out Parcelable)`", or "`void someFunction(inout Parcelable)`".

| ### Fields ||
|---|---|
| ` public static final https://developer.android.com/reference/android/os/Parcelable.Creator<https://developer.android.com/reference/android/view/Surface>` | `https://developer.android.com/reference/android/view/Surface#CREATOR` <br /> |

| ### Public constructors ||
|---|---|
| ` https://developer.android.com/reference/android/view/Surface#Surface(android.graphics.SurfaceTexture)(https://developer.android.com/reference/android/graphics/SurfaceTexture surfaceTexture) ` Create Surface from a `https://developer.android.com/reference/android/graphics/SurfaceTexture`. |
| ` https://developer.android.com/reference/android/view/Surface#Surface(android.view.SurfaceControl)(https://developer.android.com/reference/android/view/SurfaceControl from) ` Create a Surface associated with a given `https://developer.android.com/reference/android/view/SurfaceControl`. |

| ### Public methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/Surface#clearFrameRate()() ` Clears the frame rate which was set for this surface. |
| ` int` | ` https://developer.android.com/reference/android/view/Surface#describeContents()() ` Describe the kinds of special objects contained in this Parcelable instance's marshaled representation. |
| ` boolean` | ` https://developer.android.com/reference/android/view/Surface#isProducerThrottlingEnabled()() ` Check if CPU throttling is enabled. |
| ` boolean` | ` https://developer.android.com/reference/android/view/Surface#isValid()() ` Returns true if this object holds a valid surface. |
| ` https://developer.android.com/reference/android/graphics/Canvas` | ` https://developer.android.com/reference/android/view/Surface#lockCanvas(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect inOutDirty) ` Gets a `https://developer.android.com/reference/android/graphics/Canvas` for drawing into this surface. |
| ` https://developer.android.com/reference/android/graphics/Canvas` | ` https://developer.android.com/reference/android/view/Surface#lockHardwareCanvas()() ` Gets a `https://developer.android.com/reference/android/graphics/Canvas` for drawing into this surface. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#readFromParcel(android.os.Parcel)(https://developer.android.com/reference/android/os/Parcel source) ` |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#release()() ` Release the local reference to the server-side surface. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int,%20int)(float frameRate, int compatibility, int changeFrameRateStrategy) ` Sets the intended frame rate for this surface. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int)(float frameRate, int compatibility) ` Sets the intended frame rate for this surface. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#setProducerThrottlingEnabled(boolean)(boolean enabled) ` Control CPU throttling for Vulkan/EGL producers. |
| ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/android/view/Surface#toString()() ` Returns a string representation of the object. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#unlockCanvas(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` *This method was deprecated in API level 17. This API has been removed and is not supported. Do not use.* |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#unlockCanvasAndPost(android.graphics.Canvas)(https://developer.android.com/reference/android/graphics/Canvas canvas) ` Posts the new contents of the `https://developer.android.com/reference/android/graphics/Canvas` to the surface and releases the `https://developer.android.com/reference/android/graphics/Canvas`. |
| ` void` | ` https://developer.android.com/reference/android/view/Surface#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) ` Flatten this object in to a Parcel. |

| ### Protected methods ||
|---|---|
| ` void` | ` https://developer.android.com/reference/android/view/Surface#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. |

### Inherited methods

From class ` https://developer.android.com/reference/java/lang/Object ` ` https://developer.android.com/reference/java/lang/Object` ` https://developer.android.com/reference/java/lang/Object#clone()() `

Creates and returns a copy of this object.
` boolean` ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) `

Indicates whether some other object is "equal to" this one.
` void` ` https://developer.android.com/reference/java/lang/Object#finalize()() `

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.
` final https://developer.android.com/reference/java/lang/Class<?>` ` https://developer.android.com/reference/java/lang/Object#getClass()() `

Returns the runtime class of this `Object`.
` int` ` https://developer.android.com/reference/java/lang/Object#hashCode()() `

Returns a hash code value for the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#notify()() `

Wakes up a single thread that is waiting on this object's monitor.
` final void` ` https://developer.android.com/reference/java/lang/Object#notifyAll()() `

Wakes up all threads that are waiting on this object's monitor.
` https://developer.android.com/reference/java/lang/String` ` https://developer.android.com/reference/java/lang/Object#toString()() `

Returns a string representation of the object.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.
` final void` ` https://developer.android.com/reference/java/lang/Object#wait()() `

Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.
From interface ` https://developer.android.com/reference/android/os/Parcelable ` ` abstract int` ` https://developer.android.com/reference/android/os/Parcelable#describeContents()() `

Describe the kinds of special objects contained in this Parcelable instance's marshaled representation.
` abstract void` ` https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)(https://developer.android.com/reference/android/os/Parcel dest, int flags) `

Flatten this object in to a Parcel.

## Constants

### CHANGE_FRAME_RATE_ALWAYS

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CHANGE_FRAME_RATE_ALWAYS
```

Change the frame rate even if the transition is going to be non-seamless, i.e. with visual interruptions for the user. Non-seamless switches might be used when the benefit of matching the content's frame rate outweighs the cost of the transition, for example when displaying long-running video content.

<br />

Constant Value: 1 (0x00000001)

### CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS
```

Change the frame rate only if the transition is going to be seamless.

<br />

Constant Value: 0 (0x00000000)

### FRAME_RATE_COMPATIBILITY_AT_LEAST

Added in [API level 36](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FRAME_RATE_COMPATIBILITY_AT_LEAST
```

The surface requests a frame rate that is at least the specified frame rate. This value should be used for UIs, animations, scrolling and fling, and anything that is not a game or video. For video, use `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` instead. For game content, use `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_DEFAULT`.

<br />

Constant Value: 2 (0x00000002)

### FRAME_RATE_COMPATIBILITY_DEFAULT

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FRAME_RATE_COMPATIBILITY_DEFAULT
```

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. In Android version `https://developer.android.com/reference/android/os/Build.VERSION_CODES#BAKLAVA` and above, use `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_DEFAULT` for game content. For other cases, see `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` and `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_AT_LEAST`.

<br />

Constant Value: 0 (0x00000000)

### FRAME_RATE_COMPATIBILITY_FIXED_SOURCE

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int FRAME_RATE_COMPATIBILITY_FIXED_SOURCE
```

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.

<br />

Constant Value: 1 (0x00000001)

### ROTATION_0

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ROTATION_0
```

Rotation constant: 0 degree rotation (natural orientation)

<br />

Constant Value: 0 (0x00000000)

### ROTATION_180

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ROTATION_180
```

Rotation constant: 180 degree rotation.

<br />

Constant Value: 2 (0x00000002)

### ROTATION_270

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ROTATION_270
```

Rotation constant: 270 degree rotation.

<br />

Constant Value: 3 (0x00000003)

### ROTATION_90

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final int ROTATION_90
```

Rotation constant: 90 degree rotation.

<br />

Constant Value: 1 (0x00000001)

## Fields

### CREATOR

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public static final Creator<Surface> CREATOR
```

<br />

<br />

## Public constructors

### Surface

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Surface (SurfaceTexture surfaceTexture)
```

Create Surface from a `https://developer.android.com/reference/android/graphics/SurfaceTexture`. Images drawn to the Surface will be made available to the `https://developer.android.com/reference/android/graphics/SurfaceTexture`, which can attach them to an OpenGL ES texture via `https://developer.android.com/reference/android/graphics/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 `https://developer.android.com/reference/java/lang/ref/WeakReference` to the SurfaceTexture.

<br />

| Parameters ||
|---|---|
| `surfaceTexture` | `SurfaceTexture`: The `https://developer.android.com/reference/android/graphics/SurfaceTexture` that is updated by this Surface. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/view/Surface.OutOfResourcesException` | if the surface could not be created. |

### Surface

Added in [API level 29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Surface (SurfaceControl from)
```

Create a Surface associated with a given `https://developer.android.com/reference/android/view/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.

<br />

| Parameters ||
|---|---|
| `from` | `SurfaceControl`: The SurfaceControl to associate this Surface with. This value cannot be `null`. <br /> |

## Public methods

### clearFrameRate

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void clearFrameRate ()
```

Clears the frame rate which was set for this surface.

This is equivalent to calling `https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int,%20int)` using `0` for `frameRate`.

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.

<br />

<br />

**See also:**

- `https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int,%20int)`

### describeContents

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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 `https://developer.android.com/reference/android/os/Parcelable#writeToParcel(android.os.Parcel,%20int)`, the return value of this method must include the `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` bit.

<br />

| Returns ||
|---|---|
| `int` | a bitmask indicating the set of special object types marshaled by this Parcelable object instance. Value is either `0` or - `https://developer.android.com/reference/android/os/Parcelable#CONTENTS_FILE_DESCRIPTOR` |

### isProducerThrottlingEnabled

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isProducerThrottlingEnabled ()
```

Check if CPU throttling is enabled.

<br />

| Returns ||
|---|---|
| `boolean` | true if back-pressure is enabled, false otherwise. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the native window is invalid. |

**See also:**

- `https://developer.android.com/reference/android/view/Surface#setProducerThrottlingEnabled(boolean)`

### isValid

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean isValid ()
```

Returns true if this object holds a valid surface.

<br />

| Returns ||
|---|---|
| `boolean` | True if it holds a physical surface, so lockCanvas() will succeed. Otherwise returns false. <br /> |

### lockCanvas

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Canvas lockCanvas (Rect inOutDirty)
```

Gets a `https://developer.android.com/reference/android/graphics/Canvas` for drawing into this surface. After drawing into the provided `https://developer.android.com/reference/android/graphics/Canvas`, the caller must invoke `https://developer.android.com/reference/android/view/Surface#unlockCanvasAndPost(android.graphics.Canvas)` to post the new contents to the surface.

<br />

| 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. <br /> |

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Canvas` | A canvas for drawing into the surface. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/android/view/Surface.OutOfResourcesException` | If the canvas cannot be locked. |
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the inOutDirty rectangle is not valid. |

### lockHardwareCanvas

Added in [API level 23](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public Canvas lockHardwareCanvas ()
```

Gets a `https://developer.android.com/reference/android/graphics/Canvas` for drawing into this surface. After drawing into the provided `https://developer.android.com/reference/android/graphics/Canvas`, the caller must invoke `https://developer.android.com/reference/android/view/Surface#unlockCanvasAndPost(android.graphics.Canvas)` to post the new contents to the surface. Unlike `https://developer.android.com/reference/android/view/Surface#lockCanvas(android.graphics.Rect)` this will return a hardware-accelerated canvas. See the [unsupported drawing operations](https://developer.android.com/guide/topics/graphics/hardware-accel#unsupported) 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 `https://developer.android.com/reference/android/view/Surface#lockHardwareCanvas()` is called as the buffer is not preserved between frames. Partial updates are not supported.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/graphics/Canvas` | A canvas for drawing into the surface. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | If the canvas cannot be locked. |

### readFromParcel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void readFromParcel (Parcel source)
```

<br />

<br />

| Parameters ||
|---|---|
| `source` | `Parcel` <br /> |

### release

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

### setFrameRate

Added in [API level 31](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setFrameRate (float frameRate, 
                int compatibility, 
                int changeFrameRateStrategy)
```

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.

<br />

<br />

| 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` parameter 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.0f or greater <br /> |
| `compatibility` | `int`: The frame rate compatibility of this surface. The compatibility value may influence the system's choice of display frame rate. This parameter is ignored when `frameRate` is 0. Value is one of the following: - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_DEFAULT` - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_AT_LEAST` |
| `changeFrameRateStrategy` | `int`: Whether display refresh rate transitions caused by this surface should be seamless. A seamless transition is one that doesn't have any visual interruptions, such as a black screen for a second or two. This parameter is ignored when `frameRate` is 0. Value is one of the following: - `https://developer.android.com/reference/android/view/Surface#CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS` - `https://developer.android.com/reference/android/view/Surface#CHANGE_FRAME_RATE_ALWAYS` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If `frameRate`, `compatibility` or `changeFrameRateStrategy` are invalid. |

**See also:**

- `https://developer.android.com/reference/android/view/Surface#clearFrameRate()`

### setFrameRate

Added in [API level 30](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setFrameRate (float frameRate, 
                int compatibility)
```

Sets the intended frame rate for this surface. Any switching of refresh rates is most probably going to be seamless.

<br />

| Parameters ||
|---|---|
| `frameRate` | `float`: Value is 0.0f or greater <br /> |
| `compatibility` | `int`: Value is one of the following: - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_DEFAULT` - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_FIXED_SOURCE` - `https://developer.android.com/reference/android/view/Surface#FRAME_RATE_COMPATIBILITY_AT_LEAST` |

**See also:**

- `https://developer.android.com/reference/android/view/Surface#setFrameRate(float,%20int,%20int)`

### setProducerThrottlingEnabled

Added in [API level 37](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void setProducerThrottlingEnabled (boolean enabled)
```

Control CPU throttling for Vulkan/EGL producers.

By default Vulkan and EGL producers are CPU throttled when they queue a buffer and the consumer is still processing the previous buffer. In practice, it means that eglSwapBuffers() or vkPresentKHR() calls will stall the CPU until the GPU is done processing the previous frame. This API allows to disable this throttling while queueing a buffer.

While the default it to have throttling enabled, the more correct and efficient behavior is to have it disabled. Unfortunately, some Vulkan applications may inadvertently rely on this stall which effectively behaves as consumer/producer synchronization, albeit, inefficiently. It is therefore recommended to always disable throttling and perform proper synchronization in Vulkan.

If the CPU produces frames faster than the GPU, natural throttling will happen when a buffer is dequeued, based on the size of the queue. This typically happen during the first drawing in OpenGL ES and in vkAcquireNextImageKHR() in Vulkan.

This API has no effect in asynchronous mode, where throttling is always enabled.

<br />

<br />

| Parameters ||
|---|---|
| `enabled` | `boolean`: true to enable back-pressure, false to disable it. <br /> |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalArgumentException` | If the native window is invalid. |

**See also:**

- `https://developer.android.com/reference/android/view/Surface#isProducerThrottlingEnabled()`

### toString

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public String toString ()
```

Returns a string representation of the object.

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/lang/String` | a string representation of the object. <br /> |

### unlockCanvas

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level 17](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void unlockCanvas (Canvas canvas)
```

<br />

**This method was deprecated in API level 17.**   

This API has been removed and is not supported. Do not use.

<br />

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas` <br /> |

### unlockCanvasAndPost

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void unlockCanvasAndPost (Canvas canvas)
```

Posts the new contents of the `https://developer.android.com/reference/android/graphics/Canvas` to the surface and releases the `https://developer.android.com/reference/android/graphics/Canvas`.

<br />

| Parameters ||
|---|---|
| `canvas` | `Canvas`: The canvas previously obtained from `https://developer.android.com/reference/android/view/Surface#lockCanvas(android.graphics.Rect)`. <br /> |

### writeToParcel

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public void writeToParcel (Parcel dest, 
                int flags)
```

Flatten this object in to a Parcel.

<br />

| Parameters ||
|---|---|
| `dest` | `Parcel`: The Parcel in which the object should be written. This value cannot be `null`. <br /> |
| `flags` | `int`: Additional flags about how the object should be written. May be 0 or `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE`. Value is either `0` or a combination of the following: - `https://developer.android.com/reference/android/os/Parcelable#PARCELABLE_WRITE_RETURN_VALUE` |

## Protected methods

### finalize

Added in [API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
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.

<br />

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/Throwable` |   |