Add ability to load dynamics resources and consequently images from external C# code

This commit is contained in:
Yoshi Askharoun
2023-05-21 18:45:58 -05:00
parent 22b4b39ebc
commit 2a7bc680c4
3 changed files with 60 additions and 11 deletions
@@ -23,10 +23,16 @@ namespace Microsoft.Iris.Drawing
Size maxSize,
bool flippable,
bool antialiasEdges)
: base(renderSession, source, maxSize, flippable, antialiasEdges)
: this(renderSession, ResourceManager.Instance.GetResource(source), maxSize, source, flippable, antialiasEdges)
{
_source = source;
_resource = ResourceManager.Instance.GetResource(_source);
}
internal ResourceImageItem(IRenderSession renderSession, Resource resource, Size maxSize, string identifier, bool flippable, bool antialiasEdges)
: base(renderSession, identifier, maxSize, flippable, antialiasEdges)
{
_source = identifier;
_resource = resource;
}
protected override void OnDispose()
+17 -8
View File
@@ -11,26 +11,28 @@ using Microsoft.Iris.Session;
namespace Microsoft.Iris.Drawing
{
internal sealed class UriImage : UIImage
public sealed class UriImage : UIImage
{
private ImageCacheKey _cacheKey;
private Resource _resource;
public UriImage()
: base(Inset.Zero, Size.Zero, false, false)
{
}
public UriImage(Resource resource, string identifier, Inset nineGrid, Size maximumSize, bool flippable)
: this(identifier, nineGrid, maximumSize, flippable, false)
{
_resource = resource;
}
public UriImage(string source, Inset nineGrid, Size maximumSize, bool flippable)
: this(source, nineGrid, maximumSize, flippable, false)
{
}
public UriImage(
string source,
Inset nineGrid,
Size maximumSize,
bool flippable,
bool antialiasEdges)
public UriImage(string source, Inset nineGrid, Size maximumSize, bool flippable, bool antialiasEdges)
: base(nineGrid, maximumSize, flippable, antialiasEdges)
{
Source = source;
@@ -41,8 +43,15 @@ namespace Microsoft.Iris.Drawing
ResourceImageItem resourceImageItem = GetResourceFromCache();
if (resourceImageItem == null)
{
resourceImageItem = new ResourceImageItem(UISession.Default.RenderSession, Source, ClampSize(_maximumSize), IsFlipped, _antialiasEdges);
var renderSession = UISession.Default.RenderSession;
var size = ClampSize(_maximumSize);
if (_resource != null)
resourceImageItem = new ResourceImageItem(renderSession, _resource, size, Source, IsFlipped, _antialiasEdges);
else
resourceImageItem = new ResourceImageItem(renderSession, Source, size, IsFlipped, _antialiasEdges);
resourceImageItem.LoadCompleteHandler += new ContentLoadCompleteHandler(OnLoadComplete);
ScavengeImageCache.Instance.Add(_cacheKey, resourceImageItem);
SetStatus(resourceImageItem.Status);
_contentSize = new Size(0, 0);
+34
View File
@@ -0,0 +1,34 @@
using Microsoft.Iris.Data;
using System.Runtime.InteropServices;
namespace Microsoft.Iris.OS;
public class BytesResource : Resource
{
private byte[] _bytes;
private string _identifier;
private GCHandle _handle;
public BytesResource(string uri, byte[] bytes, string identifier, bool forceSynchronous)
: base(uri, forceSynchronous)
{
_bytes = bytes;
_identifier = identifier;
}
public override string Identifier => _identifier;
protected override void StartAcquisition(bool forceSynchronous)
{
_handle = GCHandle.Alloc(_bytes, GCHandleType.Pinned);
NotifyAcquisitionComplete(_handle.AddrOfPinnedObject(), (uint)_bytes.Length, true, null);
}
protected override void CancelAcquisition()
{
if (!_handle.IsAllocated)
return;
_handle.Free();
}
}