androidx.compose.remote.creation.compose.capture

Classes

CapturedDocument

Represents the result of a remote Composable capture operation.

RemoteCreationDisplayInfo

Represents the virtual display metrics and configuration used as guide values for rendering a RemoteCompose document.

RemoteDensity

Represents the screen density and font scale factor used for unit conversions in a remote composition context.

RemoteImageVector

A base class for defining vector graphics that can be drawn in a remote compose.

RemoteImageVector.Builder

Builder used to construct a Vector graphic tree.

WriterEvents

A callback interface used during the capture process to write out the captured composable information.

Objects

Enums

RemoteDensityBehavior

Density behavior for the RemoteCompose document.

Composables

createCreationDisplayInfo

Creates a RemoteCreationDisplayInfo instance from display metrics.

vectorResource

Load a RemoteImageVector from an Android vector resource.

Top-level functions summary

RemoteCreationDisplayInfo
RemoteCreationDisplayInfo(
    width: Int,
    height: Int,
    densityDpi: Int,
    fontScale: Float,
    isInspectionMode: Boolean,
    densityBehavior: RemoteDensityBehavior
)

Creates a RemoteCreationDisplayInfo instance from width, height, and density metrics.

Flow<ByteArray>
captureRemoteDocument(
    context: Context,
    creationDisplayInfo: RemoteCreationDisplayInfo,
    remoteDensity: RemoteDensity,
    layoutDirection: LayoutDirection?,
    writerEvents: WriterEvents,
    clock: RemoteClock,
    profile: Profile,
    coroutineContext: CoroutineContext,
    content: @Composable @RemoteComposable () -> Unit
)

Capture a stream of RemoteCompose documents by rendering the specified content Composable in a virtual display and emitting the resulting byte arrays whenever recomposition occurs and the layout visually changes.

suspend CapturedDocument
captureSingleRemoteDocument(
    context: Context,
    creationDisplayInfo: RemoteCreationDisplayInfo,
    remoteDensity: RemoteDensity,
    layoutDirection: LayoutDirection,
    clock: RemoteClock,
    profile: Profile,
    writerEvents: WriterEvents,
    content: @Composable @RemoteComposable () -> Unit
)

Capture a single RemoteCompose document from the specified content Composable by rendering it once inside a virtual display.

RemoteCreationDisplayInfo
createCreationDisplayInfo(
    context: Context,
    size: Size,
    isInspectionMode: Boolean,
    densityBehavior: RemoteDensityBehavior
)

Creates a RemoteCreationDisplayInfo instance from the provided Context.

Profile
createProfile(
    docApiLevel: Int,
    profileFlags: Int,
    supportedOperations: IntSet?
)

Creates a Profile configured for Android RemoteCompose creation.

Extension functions summary

RemoteImageVector.Builder
RemoteImageVector.Builder.path(
    name: String,
    fill: Brush?,
    fillAlpha: RemoteFloat,
    stroke: Brush?,
    strokeAlpha: RemoteFloat,
    strokeLineWidth: RemoteFloat,
    strokeLineCap: StrokeCap,
    strokeLineJoin: StrokeJoin,
    strokeLineMiter: RemoteFloat,
    pathFillType: PathFillType,
    pathBuilder: RemotePathScope.() -> Unit
)

DSL extension for adding a RemoteVectorPath to this.

RemoteImageVector

Converts a Compose UI ImageVector to a RemoteImageVector.

Extension properties summary

Dp

The height of the display in Dp units.

Dp

The width of the display in Dp units.

Top-level functions

RemoteCreationDisplayInfo

fun RemoteCreationDisplayInfo(
    width: Int,
    height: Int,
    densityDpi: Int,
    fontScale: Float = 1.0f,
    isInspectionMode: Boolean = false,
    densityBehavior: RemoteDensityBehavior = RemoteDensityBehavior.Legacy
): RemoteCreationDisplayInfo

Creates a RemoteCreationDisplayInfo instance from width, height, and density metrics.

Parameters
width: Int

The width of the display in pixels.

height: Int

The height of the display in pixels.

densityDpi: Int

The logical densityDpi of the display.

fontScale: Float = 1.0f

The user preference for the scaling factor for fonts, relative to the base density scaling.

isInspectionMode: Boolean = false

Whether the capture is happening in inspection mode (e.g. for a preview). Defaults to false.

densityBehavior: RemoteDensityBehavior = RemoteDensityBehavior.Legacy

The RemoteDensityBehavior to use. Defaults to RemoteDensityBehavior.Legacy.

Returns
RemoteCreationDisplayInfo

A RemoteCreationDisplayInfo object containing the specified display metrics.

fun captureRemoteDocument(
    context: Context,
    creationDisplayInfo: RemoteCreationDisplayInfo,
    remoteDensity: RemoteDensity = RemoteDensity( creationDisplayInfo.density.density.rf, creationDisplayInfo.density.fontScale.rf, ),
    layoutDirection: LayoutDirection? = null,
    writerEvents: WriterEvents = WriterEvents(),
    clock: RemoteClock = RemoteClock.SYSTEM,
    profile: Profile = RcPlatformProfiles.ANDROIDX,
    coroutineContext: CoroutineContext = Dispatchers.Default,
    content: @Composable @RemoteComposable () -> Unit
): Flow<ByteArray>

Capture a stream of RemoteCompose documents by rendering the specified content Composable in a virtual display and emitting the resulting byte arrays whenever recomposition occurs and the layout visually changes.

This API allows capturing dynamic Compose content (e.g., containing animations, transitions, or state updates) as a Flow of serialized document byte arrays.

Crucially, recomposition is handled cleanly, and duplicate documents (where nothing visually changed in the layout tree) are automatically filtered out, so new byte arrays are only emitted when the document actually changes.

Parameters
context: Context

The Android Context to use.

creationDisplayInfo: RemoteCreationDisplayInfo

Details about the virtual display to capture for (size, density, etc.).

remoteDensity: RemoteDensity = RemoteDensity( creationDisplayInfo.density.density.rf, creationDisplayInfo.density.fontScale.rf, )

The logical screen density and font scale to use for unit conversions. Defaults to density derived from creationDisplayInfo. Note: If passing custom values, they should typically match the density and font scale specified in creationDisplayInfo to avoid layout scaling discrepancies.

layoutDirection: LayoutDirection? = null

The layout direction (LTR or RTL) to use. Defaults to LTR.

writerEvents: WriterEvents = WriterEvents()

Callback to handle non-serializable events (e.g. pending intents).

clock: RemoteClock = RemoteClock.SYSTEM

The clock used for the recomposer timeline. Defaults to RemoteClock.SYSTEM.

profile: Profile = RcPlatformProfiles.ANDROIDX

The writing profile that determines supported operations. Defaults to RcPlatformProfiles.ANDROIDX.

coroutineContext: CoroutineContext = Dispatchers.Default

The CoroutineContext to run recomposition and rendering on. Defaults to Dispatchers.Default.

content: @Composable @RemoteComposable () -> Unit

The Composable content to render and capture.

Returns
Flow<ByteArray>

A Flow of ByteArrays containing the serialized RemoteCompose documents.

captureSingleRemoteDocument

suspend fun captureSingleRemoteDocument(
    context: Context,
    creationDisplayInfo: RemoteCreationDisplayInfo = createCreationDisplayInfo(context),
    remoteDensity: RemoteDensity = RemoteDensity( creationDisplayInfo.density.density.rf, creationDisplayInfo.density.fontScale.rf, ),
    layoutDirection: LayoutDirection = toLayoutDirection(context.resources.configuration.layoutDirection),
    clock: RemoteClock = RemoteClock.SYSTEM,
    profile: Profile = RcPlatformProfiles.ANDROIDX,
    writerEvents: WriterEvents = WriterEvents(),
    content: @Composable @RemoteComposable () -> Unit
): CapturedDocument

Capture a single RemoteCompose document from the specified content Composable by rendering it once inside a virtual display.

This is a suspending function that performs the composition and rendering, returning a CapturedDocument which contains the serialized bytes and metadata.

Parameters
context: Context

The Android Context to use.

creationDisplayInfo: RemoteCreationDisplayInfo = createCreationDisplayInfo(context)

Details about the virtual display to capture for (size, density, etc.). Defaults to display metrics derived from context.

remoteDensity: RemoteDensity = RemoteDensity( creationDisplayInfo.density.density.rf, creationDisplayInfo.density.fontScale.rf, )

The logical screen density and font scale to use for unit conversions. Defaults to density derived from creationDisplayInfo. Note: If passing custom values, they should typically match the density and font scale specified in creationDisplayInfo to avoid layout scaling discrepancies.

layoutDirection: LayoutDirection = toLayoutDirection(context.resources.configuration.layoutDirection)

The layout direction (LTR or RTL) to use. Defaults to the system layout direction.

clock: RemoteClock = RemoteClock.SYSTEM

The clock used for the composition timeline. Defaults to RemoteClock.SYSTEM.

profile: Profile = RcPlatformProfiles.ANDROIDX

The writing profile that determines supported operations. Defaults to RcPlatformProfiles.ANDROIDX.

writerEvents: WriterEvents = WriterEvents()

Callback to handle non-serializable events (e.g. pending intents).

content: @Composable @RemoteComposable () -> Unit

The Composable content to render and capture.

Returns
CapturedDocument

A CapturedDocument containing the serialized document bytes.

createCreationDisplayInfo

fun createCreationDisplayInfo(
    context: Context,
    size: Size = Size( width = context.resources.displayMetrics.widthPixels.toFloat(), height = context.resources.displayMetrics.heightPixels.toFloat(), ),
    isInspectionMode: Boolean = false,
    densityBehavior: RemoteDensityBehavior = RemoteDensityBehavior.Legacy
): RemoteCreationDisplayInfo

Creates a RemoteCreationDisplayInfo instance from the provided Context.

This function extracts the display metrics (width, height, and density) from the Context's resources.

Parameters
context: Context

The Context used to access display metrics.

size: Size = Size( width = context.resources.displayMetrics.widthPixels.toFloat(), height = context.resources.displayMetrics.heightPixels.toFloat(), )

The size of the display.

isInspectionMode: Boolean = false

Whether the capture is happening in inspection mode (e.g. for a preview). Defaults to false.

densityBehavior: RemoteDensityBehavior = RemoteDensityBehavior.Legacy

The RemoteDensityBehavior to use. Defaults to RemoteDensityBehavior.Legacy.

Returns
RemoteCreationDisplayInfo

A RemoteCreationDisplayInfo object containing the display metrics from the context.

fun createProfile(
    docApiLevel: Int = CoreDocument.DOCUMENT_API_LEVEL,
    profileFlags: Int = RcProfiles.PROFILE_ANDROIDX,
    supportedOperations: IntSet? = null
): Profile

Creates a Profile configured for Android RemoteCompose creation.

This provides a Kotlin-friendly factory for Profile with sensible defaults, avoiding the need to manually configure internal platform services and writer implementations.

For predefined profiles, see RcPlatformProfiles, such as RcPlatformProfiles.ANDROIDX.

Parameters
docApiLevel: Int = CoreDocument.DOCUMENT_API_LEVEL

The document API level supported by this profile. Defaults to the latest document API level (CoreDocument.DOCUMENT_API_LEVEL).

profileFlags: Int = RcProfiles.PROFILE_ANDROIDX

The operation profile bitmask (from RcProfiles) specifying the profile category. Defaults to RcProfiles.PROFILE_ANDROIDX.

supportedOperations: IntSet? = null

An optional explicit set of supported operation IDs. If specified, only operations in this set will be enabled in the document buffer. If null, all the operations defined by docApiLevel and profileFlags are used.

Returns
Profile

A Profile configured for Android RemoteCompose creation.

Extension functions

RemoteImageVector.Builder.path

fun RemoteImageVector.Builder.path(
    name: String = DefaultPathName,
    fill: Brush? = null,
    fillAlpha: RemoteFloat = 1.0f.rf,
    stroke: Brush? = null,
    strokeAlpha: RemoteFloat = 1.0f.rf,
    strokeLineWidth: RemoteFloat = DefaultStrokeLineWidth,
    strokeLineCap: StrokeCap = DefaultStrokeLineCap,
    strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin,
    strokeLineMiter: RemoteFloat = DefaultStrokeLineMiter,
    pathFillType: PathFillType = DefaultFillType,
    pathBuilder: RemotePathScope.() -> Unit
): RemoteImageVector.Builder

DSL extension for adding a RemoteVectorPath to this.

Parameters
name: String = DefaultPathName

the name for this path

fill: Brush? = null

specifies the Brush used to fill the path

fillAlpha: RemoteFloat = 1.0f.rf

the alpha to fill the path

stroke: Brush? = null

specifies the Brush used to fill the stroke

strokeAlpha: RemoteFloat = 1.0f.rf

the alpha to stroke the path

strokeLineWidth: RemoteFloat = DefaultStrokeLineWidth

the width of the line to stroke the path

strokeLineCap: StrokeCap = DefaultStrokeLineCap

specifies the linecap for a stroked path

strokeLineJoin: StrokeJoin = DefaultStrokeLineJoin

specifies the linejoin for a stroked path

strokeLineMiter: RemoteFloat = DefaultStrokeLineMiter

specifies the miter limit for a stroked path

pathFillType: PathFillType = DefaultFillType

specifies the winding rule that decides how the interior of a Path is calculated.

pathBuilder: RemotePathScope.() -> Unit

RemotePathScope lambda for adding RemotePathNodes to this path.

Extension properties

RemoteCreationDisplayInfo.heightDp

val RemoteCreationDisplayInfo.heightDp: Dp

The height of the display in Dp units.

RemoteCreationDisplayInfo.widthDp

val RemoteCreationDisplayInfo.widthDp: Dp

The width of the display in Dp units.