# GraphicsLayer

Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/layer/+class:androidx.compose.ui.graphics.layer.GraphicsLayer) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0) Common/AllAndroid/JVM
- Cmn

  ```
  class GraphicsLayer
  ```

*** ** * ** ***

Drawing layer used to record drawing commands in a displaylist as well as additional properties that affect the rendering of the display list. This provides an isolation boundary to divide a complex scene into smaller pieces that can be updated individually of one another without recreating the entire scene. Transformations made to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` can be done without re-recording the display list.

Usage of a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` requires a minimum of 2 steps.

1. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` must be built, which involves specifying the position alongside a list of drawing commands using `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)`

2. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` is then drawn into another destination `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas` using `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#draw(androidx.compose.ui.graphics.Canvas,androidx.compose.ui.graphics.layer.GraphicsLayer)`.

Additionally the contents of the displaylist can be transformed when it is drawn into a desintation `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas` by specifying either `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#scaleX()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#scaleY()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#translationX()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#translationY()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationX()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationY()`, or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationZ()`.

The rendered result of the displaylist can also be modified by configuring the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#blendMode()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#colorFilter()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#alpha()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#renderEffect()`

## Summary

| ### Public functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)( density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density, layoutDirection: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection, size: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntSize, block: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Constructs the display list of drawing commands into this layer that will be rendered when this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` is drawn elsewhere with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setOutsets(kotlin.Int,kotlin.Int,kotlin.Int,kotlin.Int)( left: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, top: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, right: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Configures the outsets for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setPathOutline(androidx.compose.ui.graphics.Path)(path: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path)` Specifies the given path to be configured as the outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size)(topLeft: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size)` Configures a rectangular outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRoundRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size,kotlin.Float)(topLeft: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset, size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size, cornerRadius: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Configures a rounded rect outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `suspend https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#toImageBitmap()()` Create an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` with the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` instance. | Cmn android |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#alpha()` Alpha of the content of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` between 0f and 1f. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#ambientShadowColor()` Sets the color of the ambient shadow that is drawn when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()`\> 0f. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#blendMode()` BlendMode to use when drawing this layer to the destination in `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#cameraDistance()` Sets the distance along the Z axis (orthogonal to the X/Y plane on which layers are drawn) from the camera to this layer. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()` Determines if the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` should be clipped to the rectangular bounds specified by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#size()`. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ColorFilter?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#colorFilter()` ColorFilter applied when drawing this layer to the destination in `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#compositingStrategy()` `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy` determines whether or not the contents of this layer are rendered into an offscreen buffer. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#isReleased()` Determines if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` has been released. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#layerId()` The ID of the layer. | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#outline()` Returns the outline specified by either `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setPathOutline(androidx.compose.ui.graphics.Path)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRoundRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size,kotlin.Float)`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#ownerViewId()` The uniqueDrawingId of the owner view of this graphics layer. | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#pivotOffset()` `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` in pixels used as the center for any rotation or scale transformation. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/RenderEffect?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#renderEffect()` Configure the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/RenderEffect` to apply to this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationX()` The rotation, in degrees, of the contents around the horizontal axis in degrees. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationY()` The rotation, in degrees, of the contents around the vertical axis in degrees. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#rotationZ()` The rotation, in degrees, of the contents around the Z axis in degrees. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#scaleX()` The horizontal scale of the drawn area. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#scaleY()` The vertical scale of the drawn area. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` Sets the elevation for the shadow in pixels. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#size()` Size in pixels of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#spotShadowColor()` Sets the color of the spot shadow that is drawn when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()`\> 0f. | Cmn android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntOffset` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()` Offset in pixels where this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will render within a provided canvas when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)` is called. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#translationX()` Horizontal pixel offset of the layer relative to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()`.x. | Cmn android |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#translationY()` Vertical pixel offset of the layer relative to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()`.y. | Cmn android |

| ### Extension functions |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer.https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#(androidx.compose.ui.graphics.layer.GraphicsLayer).setOutline(androidx.compose.ui.graphics.Outline)(outline: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline)` Configures an outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` based on the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` object. | Cmn |

## Public functions

### record

Cmn android

```
fun record(
    density: Density,
    layoutDirection: LayoutDirection,
    size: IntSize,
    block: DrawScope.() -> Unit
): Unit
```

Constructs the display list of drawing commands into this layer that will be rendered when this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` is drawn elsewhere with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntOffset

// Build the layer with the density, layout direction and size from the DrawScope
// and position the top left to be 20 pixels from the left and 30 pixels from the top.
// This will the bounds of the layer with a red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    this.topLeft = IntOffset(20, 30)
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize

val drawScopeSize = size
val topLeft = IntOffset((drawScopeSize.width / 4).toInt(), (drawScopeSize.height / 4).toInt())
val layerSize = IntSize((drawScopeSize.width / 2).toInt(), (drawScopeSize.height / 2).toInt())

// Build the GraphicsLayer with the specified offset and size that is filled
// with a red rectangle.
layer.apply {
    record(size = layerSize) { drawRect(Color.Red) }
    this.topLeft = topLeft
    // Specify the Xor blend mode here so that layer contents will be shown in the
    // destination only if it is transparent, otherwise the destination would be cleared
    // by the source pixels. The color of the rect drawn in this layer is irrelevant as only
    // the area shown by the layer is important when using the Xor BlendMode
    blendMode = BlendMode.Xor
}

// Fill the destination DrawScope with a green rectangle
drawRect(Color.Green)
// Draw the layer into the destination. Due to usage of the xor blend mode on the layer, the
// region occupied by the red rectangle in the layer will be used to clear contents in the
// destination
drawLayer(layer)

// Draw a blue rectangle *underneath* the current destination pixels. Because the
// drawing of the layer cleared the region in the center, this will fill the transparent
// pixels left in this hole to blue while leaving the bordering green pixels alone.
drawRect(Color.Blue, blendMode = BlendMode.DstOver)
```

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Configuring the translationX + Y will translate the red square
    // by 100 pixels to the right and 50 pixels from the top when drawn
    // into the destination DrawScope
    translationX = 100f
    translationY = 50f
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

| Parameters |
|---|---|
| `density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` used to assist in conversions of density independent pixels to raw pixels to draw. |
| `layoutDirection: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` of the layout being drawn in. |
| `size: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` |
| `block: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | lambda that is called to issue drawing commands on this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` |

### setOutsets

Cmn android Added in [1.12.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.12.0)

```
fun setOutsets(
    left: @IntRange(from = 0) Int,
    top: @IntRange(from = 0) Int,
    right: @IntRange(from = 0) Int,
    bottom: @IntRange(from = 0) Int
): Unit
```

Configures the outsets for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. GraphicsLayer implicitly clips to its bounds when promoted to an offscreen buffer such as when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#alpha()` is set to a value less than 1.0f or a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#colorFilter()` is applied. Outsets can be used to increase the visual bounds of the layer to avoid clipping the underlying content in case the layer is promoted to an offscreen buffer. Note that increasing the outsets will also increase the overhead of the Offscreen buffer since it increases its bounds. This does not affect `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` or transformations.

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.inset

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    // Renders the content of the layer with 50% alpha when it is drawn
    // into the destination
    alpha = 0.5f
    // Increase the visual bounds of layer by 20px to avoid clipping the underlying content if
    // any.
    setOutsets(20, 20, 20, 20)
}
```

| Parameters |
|---|---|
| `left: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of pixels to extend the layer to the left |
| `top: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of pixels to extend the layer to the top |
| `right: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of pixels to extend the layer to the right |
| `bottom: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The number of pixels to extend the layer to the bottom |

### setPathOutline

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
fun setPathOutline(path: Path): Unit
```

Specifies the given path to be configured as the outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. When `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` is non-zero a shadow is produced with an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` created from the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setPathOutline(androidx.compose.ui.graphics.Path)`. Additionally if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()` is true, the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will be clipped to this geometry.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    // Apply a shadow that is clipped to the specified round rect
    shadowElevation = 20f
    setRoundRectOutline(Offset.Zero, Size(300f, 180f), 30f)
}

drawLayer(layer)
```

| Parameters |
|---|---|
| `path: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Path` | Path to be used as the Outline for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` |

### setRectOutline

Cmn android Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun setRectOutline(topLeft: Offset = Offset.Zero, size: Size = Size.Unspecified): Unit
```

Configures a rectangular outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. By default, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size)` is set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size#Zero()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size)` is set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size#Unspecified()` indicating that the outline should match the size of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. When `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` is non-zero a shadow is produced using an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` created from the round rect parameters provided. Additionally if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()` is true, the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will be clipped to this geometry.

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    // Apply a shadow and have the contents of the layer be clipped
    // to the size of the layer with a 20 pixel corner radius
    shadowElevation = 20f
    setRectOutline(size = Size(this.size.width / 2f, this.size.height.toFloat()))
}

drawLayer(layer)
```

| Parameters |
|---|---|
| `topLeft: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset = Offset.Zero` | The top left of the rounded rect outline |
| `size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size = Size.Unspecified` | The size of the rounded rect outline |

### setRoundRectOutline

Cmn android Added in [1.10.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.10.0)

```
fun setRoundRectOutline(
    topLeft: Offset = Offset.Zero,
    size: Size = Size.Unspecified,
    cornerRadius: Float = 0.0f
): Unit
```

Configures a rounded rect outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. By default, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRoundRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size,kotlin.Float)` is set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size#Zero()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRoundRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size,kotlin.Float)` is set to `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size#Unspecified()` indicating that the outline should match the size of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. When `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` is non-zero a shadow is produced using an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` created from the round rect parameters provided. Additionally if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()` is true, the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will be clipped to this geometry.

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    // Apply a shadow and have the contents of the layer be clipped
    // to the size of the layer with a 20 pixel corner radius
    shadowElevation = 20f
    setRoundRectOutline(cornerRadius = 20f)
}

drawLayer(layer)
```

| Parameters |
|---|---|
| `topLeft: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset = Offset.Zero` | The top left of the rounded rect outline |
| `size: https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size = Size.Unspecified` | The size of the rounded rect outline |
| `cornerRadius: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = 0.0f` | The corner radius of the rounded rect outline |

### toImageBitmap

Cmn android

```
suspend fun toImageBitmap(): ImageBitmap
```

Create an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/ImageBitmap` with the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` instance. Note that `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)` must be invoked first to record drawing operations before invoking this method.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.asAndroidBitmap
import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection

layer.record(Density(1f), LayoutDirection.Ltr, IntSize(300, 200)) {
    val half = Size(size.width / 2, size.height)
    drawRect(Color.Red, size = half)
    drawRect(Color.Blue, topLeft = Offset(size.width / 2f, 0f), size = half)
}

GlobalScope.launch(Dispatchers.IO) {
    val imageBitmap = layer.toImageBitmap()
    val outputStream = context.openFileOutput("MyGraphicsLayerImageBitmap.png", MODE_PRIVATE)
    imageBitmap.asAndroidBitmap().compress(Bitmap.CompressFormat.PNG, 100, outputStream)
}
```

## Public properties

### alpha

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var alpha: Float
```

Alpha of the content of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` between 0f and 1f. Any value between 0f and 1f will be translucent, where 0f will cause the layer to be completely invisible and 1f will be entirely opaque.

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { inset(20f, 20f) { drawRect(Color.Red) } }
    // Renders the content of the layer with 50% alpha when it is drawn
    // into the destination
    alpha = 0.5f
}

drawLayer(layer)
```

### ambientShadowColor

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var ambientShadowColor: Color
```

Sets the color of the ambient shadow that is drawn when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()`\> 0f.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different graphics layers with different colors.

The opacity of the final ambient shadow is a function of the shadow caster height, the alpha channel of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#ambientShadowColor()` (typically opaque), and the android.R.attr.ambientShadowAlpha theme attribute.

Note that this parameter is only supported on Android 9 (Pie) and above. On older versions, this property always returns `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color#Black()` and setting new values is ignored.

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Apply a shadow with specified colors that has an elevation of 20f when this layer is
    // drawn into the destination DrawScope.
    shadowElevation = 20f
    ambientShadowColor = Color.Cyan
    spotShadowColor = Color.Magenta
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### blendMode

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var blendMode: BlendMode
```

BlendMode to use when drawing this layer to the destination in `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`. The default is `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode#SrcOver()`. Any value other than `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode#SrcOver()` will force this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` to use an offscreen compositing layer for rendering and is equivalent to using `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy#Offscreen()`.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.BlendMode
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.GraphicsLayer
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntOffset
import androidx.compose.ui.unit.IntSize

val drawScopeSize = size
val topLeft = IntOffset((drawScopeSize.width / 4).toInt(), (drawScopeSize.height / 4).toInt())
val layerSize = IntSize((drawScopeSize.width / 2).toInt(), (drawScopeSize.height / 2).toInt())

// Build the GraphicsLayer with the specified offset and size that is filled
// with a red rectangle.
layer.apply {
    record(size = layerSize) { drawRect(Color.Red) }
    this.topLeft = topLeft
    // Specify the Xor blend mode here so that layer contents will be shown in the
    // destination only if it is transparent, otherwise the destination would be cleared
    // by the source pixels. The color of the rect drawn in this layer is irrelevant as only
    // the area shown by the layer is important when using the Xor BlendMode
    blendMode = BlendMode.Xor
}

// Fill the destination DrawScope with a green rectangle
drawRect(Color.Green)
// Draw the layer into the destination. Due to usage of the xor blend mode on the layer, the
// region occupied by the red rectangle in the layer will be used to clear contents in the
// destination
drawLayer(layer)

// Draw a blue rectangle *underneath* the current destination pixels. Because the
// drawing of the layer cleared the region in the center, this will fill the transparent
// pixels left in this hole to blue while leaving the bordering green pixels alone.
drawRect(Color.Blue, blendMode = BlendMode.DstOver)
```

### cameraDistance

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var cameraDistance: Float
```

Sets the distance along the Z axis (orthogonal to the X/Y plane on which layers are drawn) from the camera to this layer. The camera's distance affects 3D transformations, for instance rotations around the X and Y axis. If the rotationX or rotationY properties are changed and this view is large (more than half the size of the screen), it is recommended to always use a camera distance that's greater than the height (X axis rotation) or the width (Y axis rotation) of this view.

The distance of the camera from the drawing plane can have an affect on the perspective distortion of the layer when it is rotated around the x or y axis. For example, a large distance will result in a large viewing angle, and there will not be much perspective distortion of the view as it rotates. A short distance may cause much more perspective distortion upon rotation, and can also result in some drawing artifacts if the rotated view ends up partially behind the camera (which is why the recommendation is to use a distance at least as far as the size of the view, if the view is to be rotated.)

The distance is expressed in pixels and must always be positive. Default value is `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#DefaultCameraDistance()`

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.layer.drawLayer

layer.apply {
    record { drawRect(Color.Yellow) }
    // Rotates the yellow rect 45f clockwise relative to the y axis
    rotationY = 45f
    cameraDistance = 5.0f
}

drawLayer(layer)
```

### clip

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var clip: Boolean
```

Determines if the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` should be clipped to the rectangular bounds specified by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#size()`. The default is false, however, contents will always be clipped to their bounds when the GraphicsLayer is promoted off an offscreen rendering buffer (i.e. CompositingStrategy.Offscreen is used, a non-null ColorFilter, RenderEffect is applied or if the BlendMode is not equivalent to BlendMode.SrcOver

### colorFilter

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var colorFilter: ColorFilter?
```

ColorFilter applied when drawing this layer to the destination in `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)`. Setting of this to any non-null will force this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` to use an offscreen compositing layer for rendering and is equivalent to using `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy#Offscreen()`

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer with the same configuration as the destination DrawScope
// and draw a red rectangle in the layer
layer.apply {
    record { drawRect(Color.Red) }
    // Apply a ColorFilter that will tint the contents of the layer to blue
    // when it is drawn into the destination DrawScope
    colorFilter = ColorFilter.tint(Color.Blue)
}

drawLayer(layer)
```

### compositingStrategy

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var compositingStrategy: CompositingStrategy
```

`https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy` determines whether or not the contents of this layer are rendered into an offscreen buffer. This is useful in order to optimize alpha usages with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy#ModulateAlpha()` which will skip the overhead of an offscreen buffer but can generate different rendering results depending on whether or not the contents of the layer are overlapping. Similarly leveraging `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy#Offscreen()` is useful in situations where creating an offscreen buffer is preferred usually in conjunction with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode` usage.

When `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#blendMode()` is anything other than `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode#SrcOver()` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#colorFilter()` is non-null, `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#compositingStrategy()`'s value will be overridden and is forced to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy#Offscreen()`.

### isReleased

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val isReleased: Boolean
```

Determines if this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` has been released. Any attempts to use a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` after it has been released is an error.

### layerId

android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val layerId: Long
```

The ID of the layer. This is used by tooling to match a layer to the associated LayoutNode.

### outline

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val outline: Outline
```

Returns the outline specified by either `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setPathOutline(androidx.compose.ui.graphics.Path)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#setRoundRectOutline(androidx.compose.ui.geometry.Offset,androidx.compose.ui.geometry.Size,kotlin.Float)`. By default this will return `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline.Rectangle` with the size of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` specified by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/IntSize#Zero()` if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)` was not previously invoked.

### ownerViewId

android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val ownerViewId: Long
```

The uniqueDrawingId of the owner view of this graphics layer. This is used by tooling to match a layer to the associated owner View.

### pivotOffset

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var pivotOffset: Offset
```

`https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset` in pixels used as the center for any rotation or scale transformation. If this value is `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset#Unspecified()`, then the center of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` is used relative to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#size()`

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that has a red rectangle drawn in the lower right
// corner.
layer.apply {
    record(size = IntSize(200, 200)) {
        drawRect(Color.Red, topLeft = Offset(size.width / 2f, size.height / 2f))
    }
    // Scale the layer by 1.5x in both the x and y axis relative to the bottom
    // right corner
    scaleX = 1.5f
    scaleY = 1.5f
    pivotOffset = Offset(this.size.width.toFloat(), this.size.height.toFloat())
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### renderEffect

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var renderEffect: RenderEffect?
```

Configure the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/RenderEffect` to apply to this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. This will apply a visual effect to the results of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` before it is drawn. For example if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlurEffect` is provided, the contents will be drawn in a separate layer, then this layer will be blurred when this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` is drawn.

Note this parameter is only supported on Android 12 and above. Attempts to use this Modifier on older Android versions will be ignored.

```kotlin
import androidx.compose.ui.graphics.BlurEffect
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.TileMode
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.drawscope.inset
import androidx.compose.ui.graphics.layer.drawLayer

// Create a layer sized to the destination draw scope that is comprised
// of an inset red rectangle
layer.apply {
    record { inset(20f, 20f) { drawRect(Color.Red) } }
    // Configure a blur to the contents of the layer that is applied
    // when drawn to the destination DrawScope
    renderEffect = BlurEffect(20f, 20f, TileMode.Decal)
}

drawLayer(layer)
```

### rotationX

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var rotationX: Float
```

The rotation, in degrees, of the contents around the horizontal axis in degrees. Default value is `0`.

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.layer.drawLayer

layer.apply {
    record { drawRect(Color.Yellow) }
    // Rotates the yellow rect 45f clockwise relative to the x axis
    rotationX = 45f
}

drawLayer(layer)
```

### rotationY

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var rotationY: Float
```

The rotation, in degrees, of the contents around the vertical axis in degrees. Default value is `0`.

```kotlin
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.layer.drawLayer

layer.apply {
    record { drawRect(Color.Yellow) }
    // Rotates the yellow rect 45f clockwise relative to the y axis
    rotationY = 45f
    cameraDistance = 5.0f
}

drawLayer(layer)
```

### rotationZ

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var rotationZ: Float
```

The rotation, in degrees, of the contents around the Z axis in degrees. Default value is `0`.

### scaleX

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var scaleX: Float
```

The horizontal scale of the drawn area. Default value is `1`.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that has a red rectangle drawn in the lower right
// corner.
layer.apply {
    record(size = IntSize(200, 200)) {
        drawRect(Color.Red, topLeft = Offset(size.width / 2f, size.height / 2f))
    }
    // Scale the layer by 1.5x in both the x and y axis relative to the bottom
    // right corner
    scaleX = 1.5f
    scaleY = 1.5f
    pivotOffset = Offset(this.size.width.toFloat(), this.size.height.toFloat())
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### scaleY

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var scaleY: Float
```

The vertical scale of the drawn area. Default value is `1`.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that has a red rectangle drawn in the lower right
// corner.
layer.apply {
    record(size = IntSize(200, 200)) {
        drawRect(Color.Red, topLeft = Offset(size.width / 2f, size.height / 2f))
    }
    // Scale the layer by 1.5x in both the x and y axis relative to the bottom
    // right corner
    scaleX = 1.5f
    scaleY = 1.5f
    pivotOffset = Offset(this.size.width.toFloat(), this.size.height.toFloat())
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### shadowElevation

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var shadowElevation: Float
```

Sets the elevation for the shadow in pixels. With the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()`\> 0f and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` set, a shadow is produced. Default value is `0` and the value must not be negative. Configuring a non-zero `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` enables clipping of `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` content.

Note that if you provide a non-zero `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` and if the passed `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` is concave the shadow will not be drawn on Android versions less than 10.

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Apply a shadow with specified colors that has an elevation of 20f when this layer is
    // drawn into the destination DrawScope.
    shadowElevation = 20f
    ambientShadowColor = Color.Cyan
    spotShadowColor = Color.Magenta
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### size

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
val size: IntSize
```

Size in pixels of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`. By default `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` contents can draw outside of the bounds specified by `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#size()`, however, rasterization of this layer into an offscreen buffer will be sized according to the specified size. This is configured by calling `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#record(androidx.compose.ui.unit.Density,androidx.compose.ui.unit.LayoutDirection,androidx.compose.ui.unit.IntSize,kotlin.Function1)`

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Build the layer with the density, layout direction from the DrawScope that is
// sized to 200 x 100 pixels and draw a red rectangle that occupies these bounds
layer.record(size = IntSize(200, 100)) { drawRect(Color.Red) }

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### spotShadowColor

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var spotShadowColor: Color
```

Sets the color of the spot shadow that is drawn when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()`\> 0f.

By default the shadow color is black. Generally, this color will be opaque so the intensity of the shadow is consistent between different graphics layers with different colors.

The opacity of the final spot shadow is a function of the shadow caster height, the alpha channel of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#spotShadowColor()` (typically opaque), and the android.R.attr.spotShadowAlpha theme attribute.

Note that this parameter is only supported on Android 9 (Pie) and above. On older versions, this property always returns `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Color#Black()` and setting new values is ignored.

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Apply a shadow with specified colors that has an elevation of 20f when this layer is
    // drawn into the destination DrawScope.
    shadowElevation = 20f
    ambientShadowColor = Color.Cyan
    spotShadowColor = Color.Magenta
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### topLeft

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var topLeft: IntOffset
```

Offset in pixels where this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will render within a provided canvas when `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#(androidx.compose.ui.graphics.drawscope.DrawScope).drawLayer(androidx.compose.ui.graphics.layer.GraphicsLayer)` is called.

```kotlin
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntOffset

// Build the layer with the density, layout direction and size from the DrawScope
// and position the top left to be 20 pixels from the left and 30 pixels from the top.
// This will the bounds of the layer with a red rectangle
layer.apply {
    record { drawRect(Color.Red) }
    this.topLeft = IntOffset(20, 30)
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### translationX

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var translationX: Float
```

Horizontal pixel offset of the layer relative to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()`.x. Default value is `0`.

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Configuring the translationX + Y will translate the red square
    // by 100 pixels to the right and 50 pixels from the top when drawn
    // into the destination DrawScope
    translationX = 100f
    translationY = 50f
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

### translationY

Cmn android Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
var translationY: Float
```

Vertical pixel offset of the layer relative to `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#topLeft()`.y. Default value is `0`

```kotlin
import androidx.compose.ui.geometry.Size
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.drawscope.DrawScope
import androidx.compose.ui.graphics.layer.drawLayer
import androidx.compose.ui.unit.IntSize

// Create a 200 x 200 pixel layer that draws a red square
layer.apply {
    record(size = IntSize(200, 200)) { drawRect(Color.Red) }
    // Configuring the translationX + Y will translate the red square
    // by 100 pixels to the right and 50 pixels from the top when drawn
    // into the destination DrawScope
    translationX = 100f
    translationY = 50f
}

// Draw the layer into the provided DrawScope
drawLayer(layer)
```

## Extension functions

### GraphicsLayer.setOutline

Cmn Artifact: [androidx.compose.ui:ui-graphics](https://developer.android.com/jetpack/androidx/releases/compose-ui) [View Source](https://cs.android.com/search?q=file:androidx/compose/ui/graphics/layer/GraphicsLayer.kt+function:setOutline)

```
fun GraphicsLayer.setOutline(outline: Outline): Unit
```

Configures an outline for this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` based on the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` object.

When `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#shadowElevation()` is non-zero a shadow is produced using a provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline`. Additionally if `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer#clip()` is true, the contents of this `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` will be clipped to this geometry.

| Parameters |
|---|---|
| `outline: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` | an `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Outline` to apply for the layer. |