# CacheDrawScope

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/draw/DrawModifier.kt+class:androidx.compose.ui.draw.CacheDrawScope) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/compose-ui#1.0.0) Common/All
- Cmn

  ```
  class CacheDrawScope : Density
  ```

*** ** * ** ***

Handle to a drawing environment that enables caching of content based on the resolved size. Consumers define parameters and refer to them in the captured draw callback provided in `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawBehind(kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawWithContent(kotlin.Function1)`.

`https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawBehind(kotlin.Function1)` will draw behind the layout's drawing contents however, `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawWithContent(kotlin.Function1)` will provide the ability to draw before or after the layout's contents

## Summary

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#obtainGraphicsLayer()()` Returns a managed `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` instance. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/ShadowContext` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#obtainShadowContext()()` Returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/ShadowContext` used to create `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/InnerShadowPainter` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/DropShadowPainter` to render inner and drop shadows respectively | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/DrawResult` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawBehind(kotlin.Function1)(block: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Issue drawing commands to be executed before the layout content is drawn | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/DrawResult` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#onDrawWithContent(kotlin.Function1)(block: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/ContentDrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Issue drawing commands before or after the layout's drawing contents | 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/draw/CacheDrawScope#(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/ContentDrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Record the drawing commands into the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` with the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` are given from the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope` | Cmn |

| ### Public properties |
|---|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#density()` The logical density of the display. | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#fontScale()` Current user preference for the scaling factor for fonts. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#layoutDirection()` Provides the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope#size()` Provides the dimensions of the current drawing environment | Cmn |

| ### Inherited functions |
|---|
| From [androidx.compose.ui.unit.Density](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density) |---|---|---| | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).roundToPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).roundToPx()()` Convert Sp to `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` by rounding | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toDp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toDp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Dp | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.geometry.Size).toDpSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize`. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.Dp).toPx()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to pixels. | Cmn | | `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.TextUnit).toPx()()` Convert Sp to pixels. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpRect).toRect()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpRect` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Rect`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(androidx.compose.ui.unit.DpSize).toSize()()` Convert a `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/DpSize` to a `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size`. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Int).toSp()()` Convert an `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` pixel value to Sp. | Cmn | | `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density#(kotlin.Float).toSp()()` Convert a `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` pixel value to a Sp | Cmn | |
| From [androidx.compose.ui.unit.FontScaling](https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling) |---|---|---| | `abstract https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.TextUnit).toDp()()` Convert Sp to `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp`. | Cmn | | `abstract https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/TextUnit` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp.https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/FontScaling#(androidx.compose.ui.unit.Dp).toSp()()` Convert `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` to Sp. | Cmn | |

## Public functions

### obtainGraphicsLayer

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

```
fun obtainGraphicsLayer(): GraphicsLayer
```

Returns a managed `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` instance. This `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` maybe newly created or return a previously allocated instance. Consumers are not expected to release this instance as it is automatically recycled upon invalidation of the CacheDrawScope and released when the `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/DrawCacheModifier` is detached.

### obtainShadowContext

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

```
fun obtainShadowContext(): ShadowContext
```

Returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/ShadowContext` used to create `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/InnerShadowPainter` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/shadow/DropShadowPainter` to render inner and drop shadows respectively

### onDrawBehind

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

```
fun onDrawBehind(block: DrawScope.() -> Unit): DrawResult
```

Issue drawing commands to be executed before the layout content is drawn

### onDrawWithContent

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

```
fun onDrawWithContent(block: ContentDrawScope.() -> Unit): DrawResult
```

Issue drawing commands before or after the layout's drawing contents

### GraphicsLayer.record

Cmn 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/draw/DrawModifier.kt+function:record)

```
fun GraphicsLayer.record(
    density: Density = this@CacheDrawScope,
    layoutDirection: LayoutDirection = this@CacheDrawScope.layoutDirection,
    size: IntSize = this@CacheDrawScope.size.toIntSize(),
    block: ContentDrawScope.() -> Unit
): Unit
```

Record the drawing commands into the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` with the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density`, `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` and `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` are given from the provided `https://developer.android.com/reference/kotlin/androidx/compose/ui/draw/CacheDrawScope`

## Public properties

### density

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

```
open val density: Float
```

The logical density of the display. This is a scaling factor for the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Dp` unit.

### fontScale

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

```
open val fontScale: Float
```

Current user preference for the scaling factor for fonts.

### layoutDirection

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

```
val layoutDirection: LayoutDirection
```

Provides the `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection`.

### size

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

```
val size: Size
```

Provides the dimensions of the current drawing environment