CompositionSettings


class CompositionSettings


Composition settings for dual concurrent camera. It includes alpha value for blending, offset in x, y coordinates, scale of width and height. The offset, and scale of width and height are specified in normalized device coordinates(NDCs). The offset is applied after scale. The origin of normalized device coordinates is at the center of the viewing volume. The positive X-axis extends to the right, the positive Y-axis extends upwards.The x, y values range from -1 to 1. E.g. scale with (0.5f, 0.5f) and offset with (0.5f, 0.5f) is the bottom-right quadrant of the output device.

Composited dual camera frames preview and recording can be supported using CompositionSettings and SingleCameraConfig. The z-order of composition is determined by the order of camera configs to bind. Currently the background color will be black by default. The resolution of camera frames for preview and recording will be determined by resolution selection strategy configured for each use case and the scale of width and height set in CompositionSettings, so it is recommended to use 16:9 aspect ratio strategy for preview if 16:9 quality selector is configured for video capture. The mirroring and rotation of the camera frame will be applied after composition because both cameras are using the same use cases.

The following code snippet demonstrates how to display in Picture-in-Picture mode:

                       16
        --------------------------------
        |               c0             |
        |                              |
        |                              |
        |                              |
        |  ---------                   |  9
        |  |       |                   |
        |  |   c1  |                   |
        |  |       |                   |
        |  ---------                   |
        --------------------------------
        c0: primary camera
        c1: secondary camera
    
      
        ResolutionSelector resolutionSelector = new ResolutionSelector.Builder()
                .setAspectRatioStrategy(
                        AspectRatioStrategy.RATIO_16_9_FALLBACK_AUTO_STRATEGY)
                .build();
        Preview preview = new Preview.Builder()
                .setResolutionSelector(resolutionSelector)
                .build();
        preview.setSurfaceProvider(mSinglePreviewView.getSurfaceProvider());
        UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
                .addUseCase(preview)
                .addUseCase(mVideoCapture)
                .build();
        SingleCameraConfig primary = new SingleCameraConfig(
                cameraSelectorPrimary,
                useCaseGroup,
                new CompositionSettings.Builder()
                        .setAlpha(1.0f)
                        .setOffset(0.0f, 0.0f)
                        .setScale(1.0f, 1.0f)
                        .build(),
                lifecycleOwner);
        SingleCameraConfig secondary = new SingleCameraConfig(
                cameraSelectorSecondary,
                useCaseGroup,
                new CompositionSettings.Builder()
                        .setAlpha(1.0f)
                        .setOffset(-0.3f, -0.4f)
                        .setScale(0.3f, 0.3f)
                        .build(),
                lifecycleOwner);
        cameraProvider.bindToLifecycle(ImmutableList.of(primary, secondary));

Summary

Nested types

A builder for CompositionSettings instances.

Constants

const CompositionSettings!

Default composition settings, which will display in full screen with no offset and scale.

Public functions

Float

Gets the alpha.

Pair<Float!, Float!>

Gets the offset.

Pair<Float!, Float!>

Gets the scale.

Constants

DEFAULT

Added in 1.5.0-alpha04
const val DEFAULTCompositionSettings!

Default composition settings, which will display in full screen with no offset and scale.

Public functions

getAlpha

Added in 1.5.0-alpha04
fun getAlpha(): Float

Gets the alpha.

Returns
Float

alpha value.

getOffset

Added in 1.5.0-alpha04
fun getOffset(): Pair<Float!, Float!>

Gets the offset.

Returns
Pair<Float!, Float!>

offset value.

getScale

Added in 1.5.0-alpha04
fun getScale(): Pair<Float!, Float!>

Gets the scale. Negative value means mirroring in X or Y direction.

Returns
Pair<Float!, Float!>

scale value.