public IAnimatedVisual TryCreateAnimatedVisual(Compositor compositor, out object diagnostics)
        {
            // Clone the Diagnostics object so that the data from the translation is captured, then we
            // will update the clone with information about this particular instantiation.
            var diags = _diagnostics?.Clone();

            diagnostics = diags;

            if (!CanInstantiate)
            {
                return(null);
            }
            else
            {
                var sw = Stopwatch.StartNew();

                var instantiator = new Instantiator(compositor);

                var result = new DisposableAnimatedVisual()
                {
                    RootVisual = (Visual)instantiator.GetInstance(_wincompDataRootVisual),
                    Size       = new System.Numerics.Vector2((float)_width, (float)_height),
                    Duration   = _duration,
                };

                if (diags != null)
                {
                    if (_wincompDataThemingPropertySet != null && _themingPropertySet is null)
                    {
                        // Instantiate the theming property set. This is shared by all of the instantiations.
                        _themingPropertySet      = (CompositionPropertySet)instantiator.GetInstance(_wincompDataThemingPropertySet);
                        diags.ThemingPropertySet = _diagnostics.ThemingPropertySet = _themingPropertySet;
                    }

                    diags.InstantiationTime = sw.Elapsed;
                }

                return(result);
            }
        }
Example #2
0
        public IAnimatedVisual?TryCreateAnimatedVisual(Compositor compositor, [MaybeNull] out object diagnostics)
        {
            // Clone the Diagnostics object so that the data from the translation is captured, then we
            // will update the clone with information about this particular instantiation.
            var diags = _diagnostics?.Clone();

            diagnostics = diags;

            if (!CanInstantiate)
            {
                return(null);
            }
            else
            {
                var sw = Stopwatch.StartNew();

                var instantiator = new Instantiator(compositor, surfaceResolver: LoadImageFromUri);

                // _wincompDataRootVisual is not null is implied by CanInstantiate.
                var result = new DisposableAnimatedVisual((Visual)instantiator.GetInstance(_wincompDataRootVisual !))
                {
                    Size     = new System.Numerics.Vector2((float)_width, (float)_height),
                    Duration = _duration,
                };

                if (diags is not null)
                {
                    if (_wincompDataThemingPropertySet is not null && _themingPropertySet is null)
                    {
                        // Instantiate the theming property set. This is shared by all of the instantiations.
                        _themingPropertySet = (CompositionPropertySet)instantiator.GetInstance(_wincompDataThemingPropertySet);

                        // _diagnostics is not null is implied by diags is not null;
                        diags.ThemingPropertySet = _diagnostics !.ThemingPropertySet = _themingPropertySet;
                    }

                    diags.InstantiationTime = sw.Elapsed;
                }

                // After the first instantiation, all the images are cached so the
                // loader is no longer needed.
                _loader?.Dispose();
                _loader = null;

                return(result);
            }
        }