# CompositingStrategy

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

  ```
  value class CompositingStrategy
  ```

*** ** * ** ***

Determines when to render the contents of a layer into an offscreen buffer before being drawn to the destination.

## Summary

| ### Public companion properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#Auto()` Rendering to an offscreen buffer will be determined automatically by the rest of the graphicsLayer parameters. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#ModulateAlpha()` Modulates alpha for each of the drawing instructions recorded within the graphicsLayer. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#Offscreen()` Rendering of content will always be rendered into an offscreen buffer first then drawn to the destination regardless of the other parameters configured on the graphics layer. | Cmn |

## Public companion properties

### Auto

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

```
val Auto: CompositingStrategy
```

Rendering to an offscreen buffer will be determined automatically by the rest of the graphicsLayer parameters. This is the default behavior. For example, whenever an alpha value less than 1.0f is provided on `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/graphicsLayer.modifier#(androidx.compose.ui.Modifier).graphicsLayer(kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,kotlin.Float,androidx.compose.ui.graphics.TransformOrigin,androidx.compose.ui.graphics.Shape,kotlin.Boolean,androidx.compose.ui.graphics.RenderEffect,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.Color,androidx.compose.ui.graphics.CompositingStrategy,androidx.compose.ui.graphics.BlendMode,androidx.compose.ui.graphics.ColorFilter,androidx.compose.ui.graphics.LayerOutsets)`, a compositing layer is created automatically to first render the contents fully opaque, then draw this offscreen buffer to the destination with the corresponding alpha. This is necessary for correctness otherwise alpha applied to individual drawing instructions that overlap will have a different result than expected. Additionally usage of `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/RenderEffect` on the graphicsLayer will also render into an intermediate offscreen buffer before being drawn into the destination.

### ModulateAlpha

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

```
val ModulateAlpha: CompositingStrategy
```

Modulates alpha for each of the drawing instructions recorded within the graphicsLayer. This avoids usage of an offscreen buffer for purposes of alpha rendering. `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#ModulateAlpha()` is more efficient than `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#Auto()` in performance in scenarios where an alpha value less than 1.0f is provided. Otherwise the performance is similar to that of `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#Auto()`. However, this can provide different results than `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/CompositingStrategy#Auto()` if there is overlapping content within the layer and alpha is applied. This should only be used if the contents of the layer are known well in advance and are expected to not be overlapping.

### Offscreen

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

```
val Offscreen: CompositingStrategy
```

Rendering of content will always be rendered into an offscreen buffer first then drawn to the destination regardless of the other parameters configured on the graphics layer. This is useful for leveraging different blending algorithms for masking content. For example, the contents can be drawn into this graphics layer and masked out by drawing additional shapes with `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/BlendMode#Clear()`