-
Notifications
You must be signed in to change notification settings - Fork 73
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
Enable image layer with external and embedded image assets. #111
Conversation
…ce, and CS code generator for embedded LoadImageSurface with some hacks.
…st of expected files in LottieViewer and LottieGen in case of external image file.
LottieGen/LottieFileProcessor.cs
Outdated
(float)_lottieComposition.Height, | ||
_lottieComposition.Duration, | ||
_options.DisableCodeGenOptimizer); | ||
CSharpInstantiatorGenerator.CreateFactoryCode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now that we are not using the return value for the code, please have it return a bool and rename the method to TryCreateFactoryCode #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually... let's add a class for the result and shove everything into that class
- CSharpGeneratedCode
- CxGeneratedCode
Return null on failure.
In the CSharp one have properties: CsText, ReferencedAssetPaths
In the Cx one have properties: CxText, HeaderText, ReferencedAssetPaths
In reply to: 283587851 [](ancestors = 283587851)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized that I can get the asset file list from _lottieComposition, which means I don't need to modify CreateFactoryCode at all. Should I revert the function back to its original form and not create the new class?
In reply to: 283991046 [](ancestors = 283991046,283587851)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed, changed to return Tuple instead of adding a new class.
In reply to: 284484652 [](ancestors = 284484652,283991046,283587851)
LottieGen/LottieFileProcessor.cs
Outdated
(float)_lottieComposition.Height, | ||
_lottieComposition.Duration, | ||
out var csText, | ||
out var infoText, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put the outs last in the parameter list. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The disableFieldOptimization parameter is optional and must be the last parameter.
In reply to: 283587899 [](ancestors = 283587899)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LottieGen/LottieFileProcessor.cs
Outdated
|
||
if (result) | ||
{ | ||
_reporter.WriteInfo($"C# code for class {_className} written to {outputFilePath}"); | ||
_reporter.WriteInfo(infoText); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
infoText [](start = 32, length = 8)
The info text should be created by LottieFileProcessor from information given to it by the CSharpInstantiatorGenerator. The CSharpInstantiatorGenerator should not be creating messages for the user. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And it should be in the result object from the Cs/Cx-InstantiatorGenerator. And inside LottieGen (i.e. here!) you should turn it into a nice message.
In reply to: 283588132 [](ancestors = 283588132)
@@ -90,17 +90,22 @@ public string GenerateWinCompXml() | |||
return WinCompData.Tools.CompositionObjectXmlSerializer.ToXml(RootVisual).ToString(); | |||
} | |||
|
|||
public string GenerateCSharpCode() | |||
public void GenerateCSharpCode(out string csText) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public void GenerateCSharpCode(out string csText) [](start = 7, length = 50)
Why is the signature being changed? #Closed
case Wmd.LoadedImageSurface.LoadedImageSurfaceLoadType.FromUri: | ||
result = null; | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} [](start = 11, length = 2)
Add a default case the throws. #Closed
result = Wm.LoadedImageSurface.StartLoadFromStream(bytes.AsBuffer().AsStream().AsRandomAccessStream()); | ||
break; | ||
case Wmd.LoadedImageSurface.LoadedImageSurfaceLoadType.FromUri: | ||
result = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
result = null; [](start = 20, length = 14)
Missing implementation? #Closed
@@ -3,7 +3,7 @@ | |||
// See the LICENSE file in the project root for more information. | |||
|
|||
// Enable use of Image Layer | |||
//#define EnableImageLayer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this #define can die now, right? #Closed
imageAssetHeight = externalImageAsset.Height; | ||
_issues.ExternalImageFilesExpected($"{externalImageAsset.Path}{externalImageAsset.FileName}"); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a default case that throws. Then get rid of the unnecessary initialization of variables that are initialized in the non-throwing cases. #Closed
var surface = LoadedImageSurface.StartLoadFromStream(embeddedImageAsset.Bytes); | ||
var imageBrush = CreateSurfaceBrush(surface); | ||
LoadedImageSurface surface = null; | ||
CompositionSurfaceBrush imageBrush = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imageBrush [](start = 36, length = 10)
Declare at first use rather than up here. #Closed
var grouping = | ||
from item in items | ||
let obj = item.obj | ||
let animators = obj.Animators.ToArray() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ToArray [](start = 50, length = 7)
Is there any case where we would could canonicalize with an animation? If we'll never want to canonicalize with an animation, don't covert to an array, just use "where !animators.Any()" #Closed
new | ||
{ | ||
obj.FilePath, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you need to create this object, or can you just use obj.FilePath directly? #Closed
source/UIData/CodeGen/CodeBuilder.cs
Outdated
@@ -234,6 +235,49 @@ static string GetLine(string text, int maxLineLength, out string remainder) | |||
return text.Substring(0, breakAt); | |||
} | |||
|
|||
internal void BytesToLiteral(byte[] bytes, int maximumColumns = 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
= 100 [](start = 69, length = 6)
Not clear to me why we should have a default value, or why it would be 100. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My point was really that the CodeBuilder should define the default policy. So it shouldn't have a default value.
Also, default values for parameters are usually a bit suspicious
In reply to: 283589741 [](ancestors = 283589741)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is wrong now... talks about the default.
Also, I think the name should be something like WriteLiteralBytes - to be consistent with the rest of the methods on this class.
And move it up with the rest of the Write* methods.
In reply to: 284905129 [](ancestors = 284905129,283589741)
{ | ||
var bytesLines = BytesToBytesList(bytes, maximumColumns - 1 - IndentSize).ToArray(); | ||
|
||
int i; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int i [](start = 11, length = 6)
Please add a comment explaining the intention of this code... the pattern is a bit unusual. #Closed
source/UIData/CodeGen/CodeBuilder.cs
Outdated
WriteLine(bytesLines[i]); | ||
} | ||
|
||
internal IEnumerable<string> BytesToBytesList(byte[] bytes, int maximumWidth) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
internal [](start = 8, length = 8)
Can this be private? Also can it be static? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't mark it with "private" - members are private by default and the rest of the code never includes the accessibility modifier unless it is different from the default.
In reply to: 283589874 [](ancestors = 283589874)
} | ||
} | ||
|
||
static void BytesToCSharpLiteral(CodeBuilder builder, byte[] bytes, int maximumColumns = 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s [](start = 7, length = 2)
This code is also in CodeBuilder. Can it be shared? #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -130,17 +140,31 @@ namespace AnimatedVisuals | |||
builder.WriteLine("using namespace Windows::UI::Composition;"); | |||
builder.WriteLine("using namespace Windows::Graphics;"); | |||
builder.WriteLine("using namespace Microsoft::WRL;"); | |||
if (info.UsesLoadedImageSurfaceFromStream || info.UsesLoadedImageSurfaceFromUri) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can/should we break these flags up so that they refer to the thing that the code needs rather than the thing that is in the code? E.g. UsesWindowsUiXamlMedia
Think about what happens when there's some other feature that we add then the decoding of the flags will get awkward. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UsesNamespaceWindowsUIXamlMedia
UsesNamespaceWindowsStorageStreams
UsesNamespacePlatform
In reply to: 283905663 [](ancestors = 283905663)
switch (obj.LoadType) | ||
{ | ||
case LoadedImageSurface.LoadedImageSurfaceLoadType.FromStream: | ||
builder.WriteLine("InMemoryRandomAccessStream ^ stream = ref new InMemoryRandomAccessStream();"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[](start = 65, length = 1)
No space before the hat. But anyhow, prefer auto in this case. No need for the full name. #Closed
|
||
public virtual string Static => "static"; | ||
|
||
public virtual string ExternalImageFileUri(string className, string filePath) => $"ms-appx:///Assets/{className}/{filePath}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name doesn't seem right - it's an asset, not necessarily an image file. And it's not external. #Closed
} | ||
} | ||
|
||
protected override void WriteBytesField(CodeBuilder builder, string fieldName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to create a virtual method for this? I'm hoping the base class can express this concept. #Closed
} | ||
} | ||
|
||
protected virtual void WriteBytesField(CodeBuilder builder, string fieldName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs comments, especially so because it is now part of the protected interface for the class. #Closed
{ | ||
bool bytesWritten = false; | ||
|
||
foreach (var node in nodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
foreach [](start = 12, length = 7)
Rather than filtering inside a foreach, just do the foreach over a filtered list of nodes. #Closed
Wmd.LoadedImageSurface obj, | ||
string fieldName); | ||
|
||
void WriteBytesFields(CodeBuilder builder, ObjectData[] nodes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems weird to pass in all of the nodes, or are they not all the nodes? #Closed
select grouped; | ||
CanonicalizeGrouping(groupingExternal); | ||
break; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} [](start = 14, length = 3)
Needs a default case. #Closed
/// <summary> | ||
/// Call this to get a list of the asset files referenced by the generated code. | ||
/// </summary> | ||
/// <returns>List of asset files.</returns> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a little more info - are these paths, or just file names? Is the generated code going to load from that path, or is it relative to the assets directory in a UWP, etc. #Closed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're uris. Please return them as an IEnumerable and call it GetAssetsList()
In reply to: 285242356 [](ancestors = 285242356)
source/Lottie/Instantiator.cs
Outdated
result = Wm.LoadedImageSurface.StartLoadFromStream(bytes.AsBuffer().AsStream().AsRandomAccessStream()); | ||
break; | ||
case Wmd.LoadedImageSurface.LoadedImageSurfaceType.FromUri: | ||
// Loading external image asset is not supported yet and it is captured on the issue list. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
captured on the issue list [](start = 83, length = 26)
I don't understand this comment. Is it referring to the list of issues in GitHub? If it's that we output an issue, it might need a bit of explaining about where that is. #Closed
var embeddedImageAsset = (EmbeddedImageAsset)imageAsset; | ||
var surface = LoadedImageSurface.StartLoadFromStream(embeddedImageAsset.Bytes); | ||
LoadedImageSurface surface; | ||
double imageAssetWidth = imageAsset.Width; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double [](start = 12, length = 6)
Use var. #Closed
{ | ||
readonly byte[] _bytes; | ||
protected LoadedImageSurface() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be private protected? Otherwise other assemblies can call it. #Closed
In what regard are these "External"? They're just files aren't they? #Closed Refers to: source/Issues/LT0030.md:5 in b205280. [](commit_id = b205280, deletion_comment = False) |
@@ -468,6 +527,30 @@ into grouped | |||
CanonicalizeGrouping(grouping); | |||
} | |||
|
|||
void CanonicalizeLoadedImageSurface(LoadedImageSurface.LoadedImageSurfaceType type) | |||
{ | |||
// Canonicalize LoadeImageSurfaces. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo
#Closed
public string FailFastWrapper(string value) => $"FFHR({value})"; | ||
|
||
public string Const(string value) => $"const {value}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a Const(...) method that is exactly the same in InstantiatorGeneratorBase. Seeing as const is the same in C# and CX, can this be on the StringifierBase as a non-virtual? #Closed
@@ -1883,6 +2004,10 @@ protected internal abstract class StringifierBase : IStringifier | |||
public abstract string Vector3(Vector3 value); | |||
|
|||
public string Hex(int value) => $"0x{value.ToString("X2")}"; | |||
|
|||
public virtual string Static => "static"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be virtual? I would expect that it is the same in all languages. #Closed
I think this should be "required". ImageFileRequired. Saying "expected" implies that we're reporting the issue because the expectation was not met. It might be worth explaining what this means in the Remarks section because people are going to see this reported as an issue in LottieViewer, be confused, and go to this page to find out what's going on. #Closed Refers to: source/Issues/LT0030.md:3 in c131919. [](commit_id = c131919, deletion_comment = False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…oj to \dll and \source.
…aking it internal on context since the layer property on context is always null.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No description provided.