# DrawContext

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

  ```
  interface DrawContext
  ```

*** ** * ** ***

Object that provides the dependencies to support a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` drawing environment. Namely this provides the drawing bounds represented as a size as well as the target `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas` to issue drawing commands into. Additionally the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext` handles updating `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas` state during transformations and updating the size of the drawing bounds that may occur during these transformations.

This exposes necessary internal state to the implementation of the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` in order to support inline scoped transformation calls without allowing consumers of `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope` to modify state directly thus maintaining the stateless API surface

## Summary

| ### Public properties |
|---|---|---|
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/Canvas` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#canvas()` The target canvas to issue drawing commands | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#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 | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer?` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#graphicsLayer()` Current `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` we are drawing into. | Cmn |
| `open https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#layoutDirection()` `https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` of the layout being drawn in. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Size` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#size()` The current size of the drawing environment | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawTransform` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#transform()` The controller for issuing transformations to the drawing environment | Cmn |

## Public properties

### canvas

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

```
open var canvas: Canvas
```

The target canvas to issue drawing commands

### density

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

```
open var density: 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

### graphicsLayer

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

```
open var graphicsLayer: GraphicsLayer?
```

Current `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer` we are drawing into. Might be null if the `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawContext#canvas()` is not provided by a `https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/layer/GraphicsLayer`, for example in the case of a software-accelerated drawing.

### layoutDirection

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

```
open var layoutDirection: LayoutDirection
```

`https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/LayoutDirection` of the layout being drawn in.

### size

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

```
var size: Size
```

The current size of the drawing environment

### transform

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

```
val transform: DrawTransform
```

The controller for issuing transformations to the drawing environment