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

Enable image layer with external and embedded image assets. #111

Merged
merged 12 commits into from
May 20, 2019

Conversation

plaiMS
Copy link
Contributor

@plaiMS plaiMS commented May 10, 2019

No description provided.

plaiMS added 3 commits May 3, 2019 16:50
…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.
(float)_lottieComposition.Height,
_lottieComposition.Duration,
_options.DisableCodeGenOptimizer);
CSharpInstantiatorGenerator.CreateFactoryCode(
Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Contributor Author

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)

Copy link
Contributor Author

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)

(float)_lottieComposition.Height,
_lottieComposition.Duration,
out var csText,
out var infoText,
Copy link
Contributor

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

Copy link
Contributor Author

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)

Copy link
Contributor

Choose a reason for hiding this comment

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

Should it be optional? ANSWER: no!


In reply to: 283956130 [](ancestors = 283956130,283587899)


if (result)
{
_reporter.WriteInfo($"C# code for class {_className} written to {outputFilePath}");
_reporter.WriteInfo(infoText);
Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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;
}
Copy link
Contributor

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;
Copy link
Contributor

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
Copy link
Contributor

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;
}
Copy link
Contributor

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;
Copy link
Contributor

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()
Copy link
Contributor

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,
}
Copy link
Contributor

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

@@ -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)
Copy link
Contributor

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

Copy link
Contributor

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)

Copy link
Contributor

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;
Copy link
Contributor

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

WriteLine(bytesLines[i]);
}

internal IEnumerable<string> BytesToBytesList(byte[] bytes, int maximumWidth)
Copy link
Contributor

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

Copy link
Contributor

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)
Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This code shouldn't be here. Removed.


In reply to: 283590296 [](ancestors = 283590296)

@@ -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)
Copy link
Contributor

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

Copy link
Contributor

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();");
Copy link
Contributor

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}";
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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)
Copy link
Contributor

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;
}
Copy link
Contributor

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>
Copy link
Contributor

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

Copy link
Contributor

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)

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.
Copy link
Contributor

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;
Copy link
Contributor

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()
Copy link
Contributor

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

@simeoncran
Copy link
Contributor

simeoncran commented May 17, 2019

LT0004.md and LT0030.md - can you update them to UTF8 seeing as you're changing them? #Closed


Refers to: source/Issues/LT0004.md:12 in b205280. [](commit_id = b205280, deletion_comment = False)

@simeoncran
Copy link
Contributor

simeoncran commented May 17, 2019

�[�c�o�m�m�e�n�t�]�:� �#� �(�t�e�x�t�:�E�x�t�e�r�n�a�l� �i�m�a�g�e� �f�i�l�e� �e�x�p�e�c�t�e�d� �a�t� �{�f�i�l�e�P�a�t�h�}�)�

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.
Copy link
Contributor

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}";
Copy link
Contributor

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";
Copy link
Contributor

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

@simeoncran
Copy link
Contributor

simeoncran commented May 17, 2019

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)

@simeoncran simeoncran self-assigned this May 20, 2019
simeoncran
simeoncran previously approved these changes May 20, 2019
Copy link
Contributor

@simeoncran simeoncran left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@simeoncran simeoncran left a comment

Choose a reason for hiding this comment

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

:shipit:

simeoncran
simeoncran previously approved these changes May 20, 2019
Copy link
Contributor

@simeoncran simeoncran left a comment

Choose a reason for hiding this comment

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

:shipit:

…aking it internal on context since the layer property on context is always null.
Copy link
Contributor

@simeoncran simeoncran left a comment

Choose a reason for hiding this comment

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

:shipit:

Copy link
Contributor

@simeoncran simeoncran left a comment

Choose a reason for hiding this comment

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

:shipit:

@plaiMS plaiMS merged commit 916aee0 into master May 20, 2019
@delete-merged-branch delete-merged-branch bot deleted the EnableImageLayer branch May 20, 2019 20:51
@michael-hawker michael-hawker added this to the 6.0 milestone Nov 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants