Граф коммитов

44 Коммитов

Автор SHA1 Сообщение Дата
aborziak-ms e37426deaf
AOT compatibility for winui3 package (#554) 2024-04-10 12:36:50 -07:00
aborziak-ms 56f986c233
[LottieGen] Added new AnimationController API support for LottieGen (#488) 2023-02-27 13:51:11 -08:00
aborziak-ms 1a12c88f27
[LottieGen] Refactored effects, added cache for factories (#507) 2022-06-08 13:34:35 -07:00
aborziak-ms 9cec91294d
Namespace migration and WinUI3 package MicrosoftToolkit.WinUI.Lottie (#500) 2022-05-25 10:18:30 -07:00
aborziak-ms 2e80cf6ec8
[LottieGen] Added IAnimatedVisual2 implementation preview. (#477) 2022-02-16 11:25:46 -08:00
aborziak-ms 784b286bbb
[LottieGen] Graph compactor fix. Do not coalesce root container visuals. (#467) 2021-08-23 13:04:38 -07:00
aborziak-ms 7463321424
Enabled blur effect for PreComp layers (#454) 2021-07-29 20:37:29 -07:00
Simeon 7e6f416ce1
Convert to modern null checking now that it works in .NET Native. (#427)
This is mostly a find-and-replace of the == null and != null checks.
This makes the code consistent, modern, and safe from equality overloading errors.
I have not replaced them in the generated code.
I have made the C# generator output the "is not null" pattern.
2021-03-05 16:38:42 -08:00
Simeon 12769c43d3
Fixes for AnimatedIcon (#424)
* Nudge the markers forward by 1/100 of a frame to stop flashing.

Due to floating point imprecision, a marker value may refer to the previous frame, which causes flashing for AnimatedIcon.

This change is a test to see if it helps the problem. If it does, it needs a little more tweaking so that the frame numbers in the comments don't look whacky.

* Remove the decimal place from the frame number. Frame numbers from Lottie are always integer values.

* Remove accidentally added "using".

* Fix bug in visibility optimization.

This was causing some things to be visible when they were not supposed to be.
While I was there I refactored the the types that are used to calculate visibility to make the code a bit easier to understand.
2021-02-16 10:44:12 -08:00
Simeon 349eb46dd0
Convert LottieGen to .NET 5 and create LottieGen.MsBuild package.
With this change, we'll produce a new nuget package that contains the LottieGen.exe executable built into a single file with no dependencies (not even .NET) and an MsBuild task.

This is being done to enable LottieGen to be more easily used in a build.
2021-02-08 11:36:30 -08:00
Simeon 2fdff22adb
Eliminate the default value checks from ConvertTo class. (#403)
The checking for default values should all be in the PropertyValueOptimizer.
Also, fix some bugs in the CX output.
2020-12-04 15:32:22 -08:00
Simeon 6288895c21
Add GuassianBlurEffect to WinCompData. (#397)
* Add GuassianBlurEffect to WinCompData.

This adds the effect and the code to instantiate and codegen it, but the translator does not yet use it.
2020-12-01 14:18:34 -08:00
Simeon 5bb8140bab
Add support for LayerVisual and DropShadow Composition types. Cleanup. (#390)
* Add support for LayerVisual and DropShadow Composition types. Much cleanup.

Getting ready to actually support DropShadow - we need some Composition types added.
As a result of adding the Composition types, I noticed many small cleanup tasks and included them.

Fix issues caused by update to VS 16.8 release.
Remove NullablesAttributes workaround for .NET Core 3.1 projects.
Now that we are building the .dll projects with .NET Core 3.1, the NullablesAttributes project is redundant and conflicts with the built-in nullables support in .NET Core.
2020-11-20 14:37:40 -08:00
Simeon 09224fc42b
Cleanup resulting from enabling nullables. (#372)
Replace Asserts that are now handled by nullable analysis.
Add some more "#nullable enable" to quieten code analysis in VS.
Rename a method in CodeBuilder because it referred to Cpp but is now used by C# as well.
2020-10-20 12:05:23 -07:00
Simeon b624e5588f
Code cleanup: take advantage of C# 8 features. (#370)
* Code cleanup: take advantage of C# 8 features.
2020-10-19 17:38:40 -07:00
Simeon 1832ef714b
Generate a way to convert between marker names and progress values, a… (#367)
* Generate a way to convert between marker names and progress values, and set bound colors.

To use this without having to cast to a particular class type, use the -AdditionalInterface command line option in LottieGen.

Cppwinrt example:

 LottieGen.exe -inp MyLottieFile -AdditionalInterface MyNamespace.IMyInterface -l cppwinrt

...then in your cppwinrt project, add an IDL file that defines MyNamespace.IMyInterface and declares the methods you want to access, e.g.:

namespace MyNamespace
{
    interface IMyInterface
    {
        Windows.Foundation.Collections.IMapView<String, Double> Markers { get; };

        void SetColorProperty(String propertyName, Windows.UI.Color value);
    };
}

...and finally, reference the interface from your code with an include of "MyNamespace.IMyInterface.h".
2020-10-16 12:13:56 -07:00
Simeon b04e5a0a05
Fully enable nullables. (#363)
* Fully enable nullables.
2020-10-13 10:21:17 -07:00
Simeon a79faa9f74
Enable nullable reference types where possible. (#361)
* Enable nullable reference types where possible.

This enables C# 8 nullable reference types. Many files have nullables disabled so I don't have to fix everything at once. I'll get them all enabled bit by bit. All new files default to nullable now.
2020-10-05 18:08:26 -07:00
Simeon 8b4c3287ff
Fixes a hole in the GraphCompactor optimizer wrt visiblity and masks. (#359)
* Fixes a hole in the GraphCompactor optimizer wrt visiblity and masks.

We use CompositionVisualSurface to implement masks. CompositionVisualSurface allows a Visual tree to be used as a brush, however it ignores many of the properties on the root of the Visual tree it hosts.
The GraphCompactor attempts to push IsVisible animations higher up the tree, however before this fix it could push IsVisible into a Visual that was the root of a CompositionVisualSurface's tree, with the result that the IsVisible property would get ignored.
The fix disallows pushing of IsVisible into a Visual that is at the root of a CompositionVisualSurface's tree.
2020-09-29 17:32:00 -07:00
Simeon f725fbbdc3
Fix rendering issue caused by hole in the optimizer. (#358)
* Fix rendering issue caused by hole in the optimizer.
2020-09-26 13:08:35 -07:00
Simeon 22708644ff
Recognize animation subchannels when discovering non-default properties. (#315)
* Recognize animation subchannels when discovering non-default properties.
This problem has always existed but it didn't matter until we started using subchanel animations for Scale (Scale.X and Scale.Y) in order to support multiple easings.
The issue was that we ask which properties have non-default values by looking at whether the property is set, and whether there is an animation for that property.
But when we find animations for a property we need to ignore the subchannel part of the name (the ".X" part).
2020-07-17 11:38:09 -07:00
Simeon a4ebb3f559
Fixes an issue with a visibility optimization. (#282)
An obvious error in the GraphCompactor could result in visibility staying on for too long.
2020-06-05 12:20:00 -07:00
Simeon 34367ced9b
Simplified factories for some common cases. (#278)
* Simplified factories for some common cases.

This simplifies the codegen for the creation of some objects. This results in smaller
outputs and a slight perf improvement.
2020-06-04 09:56:30 -07:00
Simeon de8502ff25
Theme binding (#251)
* Add theme property binding. Code gen improvements.

* Add -Public switch to LottieGen to optionally generate public classes. By default the generated classes are "internal" which is ok for most projects, but if the generated code is being built separately from the code that consumes it then the classes need to show up in metadata, which requires that the classes are "public".

* Restrict the generration of PathKeyFrameAnimations to UAP version 11. PathKeyFrameAnimations are not reliable before version 11.

* Expose the generated ColorAsVector4 method so it can be used by code that hosts the generated code. This makes it clearer to clients how they should convert colors to Vector4 in order to set the values in the theming CompositionPropertySet for colors. (This is about working around the inability for animations to reference the R, G, B, or A subchannels of colors).

* Expose theme property default values as constants. This allows apps to get the values without having to instantiate the source object.

* Give greater details in comments in the generated code to explain the purposes of matrices. We use matrices a lot to do simple scaling and offsetting because it allows us to generated tighter code, but the matrices are hard to read without comments.

* Clean up of the code generator to generalize default-valued properties - we now rely on the optimizer to unset properties with default values. We should only be doing this optimization in one place, and optimizations belong in the optimizer.

* Optimize away some stroke properties that we can prove are not needed (in the GraphCompactor).

* More resilience for the Lottie reader - handle a json exception in a graceful way.

* Order fields in generated code by type name then by name. This became necessary because some of the fields are getting more descriptive type names which caused the types of the fields to be ungrouped.

* Fix bug in miter limit. Would cause very large miters under some rare circumstances. The WUC miter limit is specified differently from the Lottie miter limit and we weren't taking that into consideration. Specifically the WUC miter limit is a ratio relative to half the stroke width, while the Lottie one is relative to the whole stroke width.

* Implement one remaining case for composing visibility in Visual tree chains.

* Give better names to the animations used for shape visibility.

* Add optimization to push visibility up the tree. This increases the chances that we will be able to convert a Shape tree visibility (which is implemented with a Scale) to a Visual tree visibility (which is implemented directly as Visibility), and that we can discover common visibilities further up the tree.

* Generate constexpr and "internal" visibility for constants on CX.

* Expose markers as constants. This should eliminate the risk of a dev integrating generated code from not updating the segment timing after the designer changes the segment timing.

* Make the graph compactor keep iterating as long as the tree changes. Previously it was as long as the tree was getting smaller, however some new optimizations don't make the tree smaller, just better.

* Added ability to "unbind" an animation from a WinCompData object. Needed in order to move an animation while keeping the original object. This is needed to allow animations to be pushed up the tree during graph compacting.

* Added a general table formatting system for generated code. This allow us to easily create comments that contain tables. We currently use it to list markers, theme properties, and the counts of expensive objects.

* Add a lot more detail into the code generation comment at the top of files. The goal is to be able to identify which version of a JSON file, and what switches and build were used. This should help reduce confusion when there is a lot of iterating going on with a design. It makes it clear in diffs if someone changed the codegen options, or if they changed the input, etc. It also gives a command line that can be used to generate the code in the same way next time.

* Add "TestMode" to lottiegen to produce outputs that do not change on each invocation (no tool version, no paths, no timestamps). This is necessary to allow testing via diffing between old and new versions of Lottie-Windows code now that we have timestamps and paths in the generated code.

* Remove old dead code from the translator.

* Make the properties on CompositionClip and InsetClip and all Clip properties nullables, to be consistent with most of WinCompData.

* Add optimization to push shape visibility down the tree. This increases the chance that we can combine visibility with some other property and enable a reduction in size of the graph.

* Canonicalize progress remapping variables. These are the "t1", "t2" etc properties in the root property set that are used to remap time for our spatial animation translations. Previously we could end up generating duplicate properties and animations for time remapping variables.

* Make the graph compactor keep iterating as long as the graph is shrinking. Previously we would iterate some fixed number of times, assuming that it was too expensive to iterate more than necessary, so we erred on the side of under-iterating in some cases. But nobody is complaining about graph compaction time, and for codegen it doesn't matter, so we might as well let it run.

* Improved the ToString() on some CompositionObjects to make them easier to see in the debugger.

* Adding support to WinCompData for BooleanKeyFrameAnimation and Visual.IsVisible.

* Enable IsVisible animation for visiblity on Visuals. Previously we were using opacity, but this now frees up the opacity property for doing group opacity (sometimes, when we get lucky - we can't currently do it in general because the shape tree doesn't support opacity).

* Bug fixes in GraphCompactor. In particular we were being too aggressive about coalescing ContainerVisuals that were directly under CompositionVisualSurface. Turns out that transform properties are always ignored on the visual directly on CompositionVisualSurface, so we always need a ContainerVisual there with no transforming properties.

* Optimize away keyframes for redundant gradient stops.

* Recognize and remove redundant gradient stops. This is especially useful for getting rid of redundant "midpoint" stops that are inserted by After Effects.

* Adding count of Animators to the stats report. This is intended to be a (rough) estimate of costs to help designers know if they are making things more expensive as they change their designs. CPU usage in the animations engine approximately scales with the number of animators, so this number should be a rough indication of animations engine cost.

* Translator refactor: use CompositionSubGraph for Shape layers to defer the decision about whether to translate to a shape or a visual. Previously we would generate a layer to either a shape or a visual then figure out how to combine the generated layers depending on what was generated. Now we ask each layer to generate to a shape or a visual, so the layer combining is in control of what gets generated, rather than being a victim of it.

* Add helpers methods in the codegen to reduce code size. These make a big difference as there are some common patterns that we do a lot.

* Switch to Scale animation rather than TranformMatrix for visiblity on shapes. This is cheaper because it requires only one property to be animated (TransformMatrix required 2). This also allows more optimization in the graph compactor because the graph compactor can recognize this pattern for visibility and can push it up or down the tree.

* Adding optimization to eliminate many "Position" animations. If position is animated but anchor isn't, we can convert it to an Offset animation - which is what we do now. That saves us having to create an ExpressionAnimation to relate the anchor and position to the offset.

* Squish the expression animation strings to save some bytes.

* Added ability to the code generator to lazily create helper methods (and in general to create source out of order via sub-CodeBuilders). This allows helper methods to be inserted in code gen, but only if needed, and without us having to analyze the graph in advance to determine whether they're needed.

* Refactoring many InstantiatorGeneratorBase methods for improved readability.

* Canonicalize brushes used for theming.

* Canonicalize animated paths.

* Support CX codegen for DependencyProperty property bindings.

* Add ToolInfo class to communicator info about how the code was generated from the command line interface through to the code generator.

* Add -GenerateDependencyObject for property binding.

* Support theme property binding of StrokeWidth on any Lottie stroke.

* Get theme properties working for all languages (CX, C#, and cppwinrt).

* Add -namespace options to LottieGen. This allows code to be generated into the namespace of your choice. Defaults to the "::AnimatedVisuals" namespace.

* Add a differentiation to the names of CX files if they're being generated at the same time as cppwinrt. This is needed for testing where we generate files and diff them. Without this change the file names would clash.

* Fix issues discovered during testing.

* CR feedback.

* Fix bugs introduced by CR changes.
Update some incorrect licensing headers in source files.

* Fix build breaks.

* Fix the reference to the package certificate so that it will build.

* Completely turn off signing to allow build to succeed.
It was off before and was turned on accidentally.

* CR feedback.

* Remove unnecessary checks for default values.
These checks were needed before to avoid setting properties that have default values, but now we have an optimizer dedicated to unsetting properties that have been set to default values, so there's no need to check anywhere else.

* PR feedback.

* PR feedback.
Also ran the VS cleanup and analysis tools.

* PR CR feedback.
2020-05-11 21:41:01 -07:00
Simeon 4bcdd79ce2
Add ability to get the type for a given CompositionPropertySet property name. (#236)
* Add ability to get the type for a given CompositionPropertySet property name.
2020-02-03 12:49:20 -08:00
Simeon ecd51d9714
Transfer object descriptions and names during tree reduction. (#229)
* Transfer object descriptions and names during tree reduction.

Tree reduction is an optimization on the Composition graph where we attempt to coalesce and remove redundant visuals and shapes. Previously this resulted in the loss of some descriptions and names on objects. Now we attempt to transfer that information out of the objects that are being removed into the objects that are taking over their roles.
2020-01-24 23:15:29 -08:00
Simeon 3b731941af
Code cleanup. (#221)
These changes do not affect the output in any way. They are mostly
things discovered by the VS automatic code cleanup, or debugging
helpers.
2020-01-21 09:54:12 -08:00
Simeon 216e2cc1f6
Simplify canonicalization. (#215)
Getting ready for multi-pass canonicalization, I realized that things could be made a bit simpler.
2020-01-16 17:34:09 -08:00
Simeon b757eefd37
Make Expression objects have stronger static types. (#213)
* Make Expression objects have stronger static types.

This change allows more static checking for animation expressions.
The Expressions objects previously supported generic types and type inferencing because when this was first written it seemed like they would be used for a more general expression parser, but it meant that the type of an expression wasn't statically known. With this change, every expression has a static type, which allows stronger typing wherever an expression is used, and allows the C# type system to find some bugs in our use of expressions.

I found 2 bugs as a result of this - one that affected 2 Lottie files in our corpus (it produced code that would fail at runtime), and one that affected a codepath we never hit (it made it obvious that this codepath is never hit).

I've run this over all of our corpus and the results are exactly the same as before, apart from the 2 files that were hitting the bug mentioned above. So there are definitely no regressions for all known Lottie files.
2020-01-15 11:44:36 -08:00
Simeon 594c5fb8cf
Enable binding of SolidColorFill to property set values. (#203)
* Enable binding of SolidColorFill to property set values.

Add support for Vector3 and Vector4 in CompositionPropertySet.
Fix bug in CompositionPropertySet.TryGet* logic.
Add IDescribable.Name so that brushes that are bound to property set values can have names that match the property set name.
Add support for scalar subchannel accessors in animation expressions.
Add support for ColorRGB constructor in animation expressions.
Add support for Vector4 in animation expressions.
2019-12-11 11:40:10 -08:00
Simeon 8b76c3c8d1
CompositionColorBrush enhancements. (#202)
* CompositionColorBrush enhancements.
Support ColorBrushes that don't have their Color property set.
Support Color expressions in the ExpressionAnimation language helpers.
Support ColorBrushes animated by ExpresssionAnimations.
2019-12-09 16:05:25 -08:00
Simeon ac2b575140
More support for property bindings. (#200)
* More support for property bindings.

Add support for Color values in CompositionPropertySet.
Add support for TryGet* methods in CompositionPropertySet.
Refactor the CompositionPropertySet implementation so that it's easier to add new types.
Adds a switch to the translator to determine whether or not it recognizes property bindings. Property bindings are only useful for codegen so this switch is off for LottieVisualSource and on for LottieGen.
Translator will now insert a property for a solid color fill that has a property binding for "Color".

* CR feedback.
2019-12-09 11:33:48 -08:00
Simeon 7dc82de085
Move code generator code into its own module (#199)
* Move codegen code into its own module so that projects that don't use codegen don't include it, and so we can start using C# 8.0 in the codegen code.
2019-12-06 12:35:06 -08:00
Simeon cac5a2f4b6
Getting Lottie metadata piped through. (#195)
Adding Lottie metadata to the TranslationResult in GenericData format.
Some improvements of GenericData as a result of using it more.
Adding code to convert from GenericData to Windows.Data.Json. Not yet used but will be added to LottieVisualSource.
Replacing all of our custom empty arrays with Array.Empty<T>().
2019-12-03 14:48:57 -08:00
Simeon 0297d549ba
Add support for WUC Vector4KeyFrameAnimation. (#186)
* Add support for WUC Vector4KeyFrameAnimation.

This is a prerequisite for supporting opacity and color animated at the same time on the same object.
2019-11-15 09:53:06 -08:00
Simeon c2cf5396f8
Refactor codegen to output multiple versions. (#159)
* Refactor codegen to output multiple versions.
This does not output multiple versions - that is coming in
a subsequent change.

* Handle the LoadedImageSurface objects in a way that will allow them to be shared between different versions.

* Fix licensing headers on a couple of source files.

* Stop using C# 8 switch statements.
They're not usable from LottieViewer because UWP doesn't allow C# 8 yet.

* Build break
I missed converting one of the switch expressions.

* CR feedback - comment tweaks.
2019-10-23 11:30:34 -07:00
Simeon 2a7eb97b52
Versioning stage 2. Translate multiple times to support multiple UAP versions. (#157)
* Versioning stage 2. Translate multiple times to support multiple UAP versions.
This translates but does not yet codegen the multiple versions.

* A few small things I noticed in CR.

* CR feedback.

* Fix build break.
2019-10-21 11:38:14 -07:00
Simeon bce52d5d86
Prerequisites for versioning. (#156)
* Work in progress towards versioning.
This adds a number of pieces required to generate version-adaptive code, but doesn't
yet hook those pieces up. This allows testing against a corpus to ensure nothing is
broken. A future commit will add version-adaptivity.

* Fix build break.

* CR style feedback.
I meant to fix this but must have forgotten. It was a byproduct of some experimentation.

* CR feedback.

* CR feedback.

* CR feedback.
2019-10-16 15:32:20 -07:00
Simeon aeb87289e1
Prepare for gradients (#143)
* Preparing for implementation of gradients.

* Make LottieGenCorpus more deterministic.
Previously the output depended on the width of the console, and sorting ignored case.

* Upgrading to SDK 18362 (May 2019) so that we can use RadialGradientBrush.
2019-08-29 10:03:44 -07:00
Phyllis Lai bb5335c6c3 Added two subclasses of LoadedImageSurface, one for LoadFromStream, one for LoadFromUri. Plus other code improvements per code review feedback. 2019-05-16 13:36:30 -07:00
Phyllis Lai 10ceedd6b6 Adding canonicalizer for CompositionSurfaceBrush and LoadedImageSurface, and CS code generator for embedded LoadImageSurface with some hacks. 2019-05-03 16:50:17 -07:00
Phyllis Lai 45ad0998f4 Adding major pieces in Translator, ObjectGraph, and Instantiator to support embedded images. 2019-04-30 17:00:36 -07:00
Phyllis Lai 61db17e1eb Refactoring code that references WinUIXamlMediaData and WinCompData to UIData. 2019-04-25 10:18:48 -07:00
plaiMS c26a0390d4 Adding a new project UIData to reference WinUIXamlMediaData. (#102)
* Added new project to reference WinUIXamlMediaData

* Reorder imports in alphabetical order.
2019-04-24 09:53:20 -07:00