#include "RenderStateComposer.h"

RenderStateCompositionResult RenderStateComposer::BuildFrameState(const LayeredRenderStateInput& input) const
{
	RenderStateCompositionResult result;
	const std::vector<RuntimeRenderState>* layerStates =
		input.committedLiveLayerStates ? input.committedLiveLayerStates : input.basePersistedLayerStates;
	if (!layerStates)
		return result;

	result.layerStates = *layerStates;
	result.hasLayerStates = !result.layerStates.empty();
	if (input.transientAutomationOverlay)
	{
		RuntimeLiveStateApplyOptions options;
		options.allowCommit = input.allowTransientAutomationCommits;
		options.smoothing = input.transientAutomationSmoothing;
		options.commitDelay = input.transientAutomationCommitDelay;
		options.now = input.now;
		input.transientAutomationOverlay->ApplyToLayerStates(
			result.layerStates,
			options,
			input.collectTransientAutomationCommitRequests ? &result.commitRequests : nullptr);
	}
	return result;
}
