# androidx.compose.ui.graphics.layer

Common/AllAndroid/JVM

## Classes

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/CompositingStrategy` | Determines when to render the contents of a layer into an offscreen buffer before being drawn to the destination. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` | Drawing layer used to record drawing commands in a displaylist as well as additional properties that affect the rendering of the display list. | Cmn android |

## Constants summary

|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/package-summary#DefaultCameraDistance() = 8.0f` Default camera distance for all layers | Cmn |

## Extension functions summary

|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.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)(graphicsLayer: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer)` Draw the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` into the current `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope`. | Cmn |
| `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/package-summary#(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 |

## Constants

### DefaultCameraDistance

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+symbol:DefaultCameraDistance) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
const val DefaultCameraDistance = 8.0f: Float
```

Default camera distance for all layers

## Extension functions

### DrawScope.drawLayer

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:drawLayer) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

```
fun DrawScope.drawLayer(graphicsLayer: GraphicsLayer): Unit
```

Draw the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` into the current `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope`. The `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` provided must have `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)` invoked on it otherwise no visual output will be seen in the rendered result.

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

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

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

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

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

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

### 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) Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.7.0)

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