Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new AVP::AnimationOptimization property #6269

Merged
merged 12 commits into from
Jan 25, 2022
16 changes: 13 additions & 3 deletions dev/AnimatedVisualPlayer/AnimatedVisualPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,12 @@ void AnimatedVisualPlayer::OnAutoPlayPropertyChanged(
void AnimatedVisualPlayer::OnAnimationOptimizationPropertyChanged(
winrt::DependencyPropertyChangedEventArgs const& args)
{
// We do not support animated visuals below RS5, so nothing to do.
aborziak-ms marked this conversation as resolved.
Show resolved Hide resolved
if (!SharedHelpers::IsRS5OrHigher())
{
return;
}

auto optimization = unbox_value<winrt::PlayerAnimationOptimization>(args.NewValue());

if (m_nowPlaying)
Expand All @@ -804,7 +810,7 @@ void AnimatedVisualPlayer::OnAnimationOptimizationPropertyChanged(
void AnimatedVisualPlayer::CreateAnimations() {
m_createAnimationsCounter++;

if (m_isAnimationsCreated)
if (m_isAnimationsCreated)
{
return;
}
Expand All @@ -821,12 +827,13 @@ void AnimatedVisualPlayer::CreateAnimations() {
}

void AnimatedVisualPlayer::DestroyAnimations() {
if (!m_isAnimationsCreated)
if (!m_isAnimationsCreated || m_animatedVisual == nullptr)
{
return;
}

// Call RequestCommit to make sure that previous compositor calls complete before destroying animations.
// RequestCommitAsync is available only for RS4+ but m_animatedVisual is not null guarantees that we are at least RS5+
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this the case? Don't the visuals get created at startup? and then I could call destroy animations on this and hit this code path?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Destroy and Create are private inside AVP, we are exposing only AnimationOptimization property

m_rootVisual.Compositor().RequestCommitAsync().Completed(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestCommitAsync() is only available on Rs4+ we need to gracefully handle the case where this API isn't available on RS2 and RS3.

[&, createAnimationsCounter = m_createAnimationsCounter](auto, auto) {
// Check if there was any CreateAnimations call after DestroyAnimations.
Expand Down Expand Up @@ -947,19 +954,22 @@ void AnimatedVisualPlayer::UpdateContent()
{
animatedVisual = source3.TryCreateAnimatedVisual(m_rootVisual.Compositor(), diagnostics, createAnimations);
m_isAnimationsCreated = createAnimations;
m_animatedVisual.set(animatedVisual);
}
else
{
animatedVisual = source.TryCreateAnimatedVisual(m_rootVisual.Compositor(), diagnostics);
m_isAnimationsCreated = true;

// m_animatedVisual should be updated before DestroyAnimations call
m_animatedVisual.set(animatedVisual);

// Destroy animations if we don't need them.
// Old IAnimatedVisualSource interface always creates them.
if (!createAnimations) {
DestroyAnimations();
}
}
m_animatedVisual.set(animatedVisual);

if (!animatedVisual)
{
Expand Down