Skip to content

Commit

Permalink
[NUI] Change SetMinAndMaxFrameByMarker behavior + Fix some async cases
Browse files Browse the repository at this point in the history
Let we allow to call SetMinAndMaxFrameByMarker API even if load is not finished.
Instead, let we just call some log if the file is not loaded yet.

Plus, Some API (GetContentInfo, GetMarkerInfo) might cache wrong values
when we use async load

Before try to get correct value, let we check whether the resource is
loaded or not.

Signed-off-by: Eunki, Hong <[email protected]>
  • Loading branch information
Eunki, Hong authored and hinohie committed Nov 14, 2023
1 parent bf6b5ad commit 70cbc01
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 53 deletions.
24 changes: 15 additions & 9 deletions src/Tizen.NUI/src/public/BaseComponents/AnimatedVectorImageView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,13 @@ public void SetMinAndMaxFrameByMarker(string marker1, string marker2 = null)
break;

case minMaxSetTypes.SetByMinAndMaxFrameByMarkerMethod:
GetFrameValueFromMarkerInfo();
goto case minMaxSetTypes.SetByMinAndMaxFrameMethod;
base.SetMinMaxFrameByMarker(minimumFrameMarker, maximumFrameMarker);
if (GetFrameValueFromMarkerInfo())
{
base.CurrentFrame = minimumFrame;
innerCurrentFrame = minimumFrame;
}
break;

case minMaxSetTypes.SetByMinAndMaxFrameMethod:
base.SetMinMaxFrame(minimumFrame, maximumFrame);
Expand Down Expand Up @@ -609,7 +614,7 @@ public enum AnimationStates


#region Internal
internal void GetFrameValueFromMarkerInfo()
internal bool GetFrameValueFromMarkerInfo()
{
bool minimumMarkerFoundSuccess = false;
bool maximumMarkerFoundSuccess = false;
Expand All @@ -618,12 +623,6 @@ internal void GetFrameValueFromMarkerInfo()

NUILog.Debug($" [{GetId()}] GetFrameValueFromMarkerInfo : marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker})");

// Note : let we insure to get marker frame value only one time per each frame marker setter
if (minimumFrameMarker == null)
{
return;
}

var markerInfoList = GetMarkerInfo();
if (markerInfoList != null)
{
Expand Down Expand Up @@ -661,13 +660,20 @@ internal void GetFrameValueFromMarkerInfo()
{
NUILog.Debug($" [{GetId()}] minimumFrame:{minimumFrame} > maximumFrame:{maximumFrame})");
}

// Note : let we insure to get marker frame value only one time per each frame marker setter
minimumFrameMarker = maximumFrameMarker = null;
isMinMaxFrameSet = minMaxSetTypes.SetByMinAndMaxFrameMethod;
return true;
}
else
{
Tizen.Log.Error("NUI", $"Fail to get frame from marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker}). Maybe file is not loaded yet, or invalid marker used. url : {resourceUrl}\n");

minimumFrame = 0;
maximumFrame = totalFrameNum - 1;
NUILog.Debug($" [{GetId()}] GetFrameValueFromMarkerInfo Failed! frame set as {minimumFrame} ~ {maximumFrame} : marker = (minimumFrameMarker:{minimumFrameMarker}, maximumFrameMarker:{maximumFrameMarker})");
return false;
}
}
#endregion Internal
Expand Down
99 changes: 55 additions & 44 deletions src/Tizen.NUI/src/public/BaseComponents/LottieAnimationView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,11 @@ public int TotalFrame

currentStates.totalFrame = ret;
NUILog.Debug($"TotalFrameNumber get! ret={ret}");

if (ret <= 0)
{
Tizen.Log.Error("NUI", $"Fail to get TotalFrame. Maybe file is not loaded yet, or invalid url used. url : {currentStates.url}\n");
}
}
return ret;
}
Expand Down Expand Up @@ -606,38 +611,41 @@ public List<Tuple<string, int, int>> GetContentInfo()
PropertyMap imageMap = base.Image;
if (imageMap != null)
{
PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
PropertyMap contentMap = new PropertyMap();
if (val?.Get(ref contentMap) == true)
if (TotalFrame > 0) // Check whether image file loaded successfuly.
{
currentStates.contentInfo = new List<Tuple<string, int, int>>();
for (uint i = 0; i < contentMap.Count(); i++)
PropertyValue val = imageMap.Find(ImageVisualProperty.ContentInfo);
PropertyMap contentMap = new PropertyMap();
if (val?.Get(ref contentMap) == true)
{
using PropertyKey propertyKey = contentMap.GetKeyAt(i);
string key = propertyKey.StringKey;

using PropertyValue arrVal = contentMap.GetValue(i);
using PropertyArray arr = new PropertyArray();
if (arrVal.Get(arr))
currentStates.contentInfo = new List<Tuple<string, int, int>>();
for (uint i = 0; i < contentMap.Count(); i++)
{
int startFrame = -1;
using PropertyValue start = arr.GetElementAt(0);
start?.Get(out startFrame);
using PropertyKey propertyKey = contentMap.GetKeyAt(i);
string key = propertyKey.StringKey;

using PropertyValue arrVal = contentMap.GetValue(i);
using PropertyArray arr = new PropertyArray();
if (arrVal.Get(arr))
{
int startFrame = -1;
using PropertyValue start = arr.GetElementAt(0);
start?.Get(out startFrame);

int endFrame = -1;
using PropertyValue end = arr.GetElementAt(1);
end?.Get(out endFrame);
int endFrame = -1;
using PropertyValue end = arr.GetElementAt(1);
end?.Get(out endFrame);

NUILog.Debug($"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");
NUILog.Debug($"[{i}] layer name={key}, startFrame={startFrame}, endFrame={endFrame}");

Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);

currentStates.contentInfo?.Add(item);
currentStates.contentInfo?.Add(item);
}
}
}
contentMap.Dispose();
val?.Dispose();
}
contentMap.Dispose();
val?.Dispose();
}
NUILog.Debug($">");

Expand All @@ -662,38 +670,41 @@ public List<Tuple<string, int, int>> GetMarkerInfo()
PropertyMap imageMap = base.Image;
if (imageMap != null)
{
PropertyValue val = imageMap.Find(ImageVisualProperty.MarkerInfo);
PropertyMap markerMap = new PropertyMap();
if (val?.Get(ref markerMap) == true)
if (TotalFrame > 0) // Check whether image file loaded successfuly.
{
currentStates.markerInfo = new List<Tuple<string, int, int>>();
for (uint i = 0; i < markerMap.Count(); i++)
PropertyValue val = imageMap.Find(ImageVisualProperty.MarkerInfo);
PropertyMap markerMap = new PropertyMap();
if (val?.Get(ref markerMap) == true)
{
using PropertyKey propertyKey = markerMap.GetKeyAt(i);
string key = propertyKey.StringKey;

using PropertyValue arrVal = markerMap.GetValue(i);
using PropertyArray arr = new PropertyArray();
if (arrVal.Get(arr))
currentStates.markerInfo = new List<Tuple<string, int, int>>();
for (uint i = 0; i < markerMap.Count(); i++)
{
int startFrame = -1;
using PropertyValue start = arr.GetElementAt(0);
start?.Get(out startFrame);
using PropertyKey propertyKey = markerMap.GetKeyAt(i);
string key = propertyKey.StringKey;

int endFrame = -1;
using PropertyValue end = arr.GetElementAt(1);
end?.Get(out endFrame);
using PropertyValue arrVal = markerMap.GetValue(i);
using PropertyArray arr = new PropertyArray();
if (arrVal.Get(arr))
{
int startFrame = -1;
using PropertyValue start = arr.GetElementAt(0);
start?.Get(out startFrame);

NUILog.Debug($"[{i}] marker name={key}, startFrame={startFrame}, endFrame={endFrame}");
int endFrame = -1;
using PropertyValue end = arr.GetElementAt(1);
end?.Get(out endFrame);

Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);
NUILog.Debug($"[{i}] marker name={key}, startFrame={startFrame}, endFrame={endFrame}");

currentStates.markerInfo?.Add(item);
Tuple<string, int, int> item = new Tuple<string, int, int>(key, startFrame, endFrame);

currentStates.markerInfo?.Add(item);
}
}
}
markerMap.Dispose();
val?.Dispose();
}
markerMap.Dispose();
val?.Dispose();
}
NUILog.Debug($">");

Expand Down

0 comments on commit 70cbc01

Please sign in to comment.