Skip to content
This repository has been archived by the owner on Apr 28, 2023. It is now read-only.

Commit

Permalink
Refinements for graphics data nodes. #237
Browse files Browse the repository at this point in the history
  • Loading branch information
tebjan committed Jun 14, 2021
1 parent 53313bb commit 76464c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/VL.Stride.Runtime/VL.Stride.Runtime.TypeForwards.vl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Document xmlns:p="property" Id="TiJxb2oN2LtNWRy2MbJV6Q" LanguageVersion="2021.4.0.118" Version="0.128">
<Document xmlns:p="property" Id="TiJxb2oN2LtNWRy2MbJV6Q" LanguageVersion="2021.4.0.121" Version="0.128">
<NugetDependency Id="LpDzfnL2ypqNzyyOieWuHI" Location="VL.CoreLib" Version="2021.4.0-0106-gd9dd354b49" />
<PlatformDependency Id="JJ0ZRRgadtbPuisZUaeinf" Location="Stride.Graphics.dll" />
<NugetDependency Id="RUpxj8weM25L4I4AlKb6Yw" Location="VL.Core" Version="2021.4.0-0106-gd9dd354b49" />
Expand Down Expand Up @@ -609,7 +609,7 @@
<Choice Kind="TypeFlag" Name="Buffer" />
</p:TypeAnnotation>
<Patch Id="FcMGsopJU0XLMVChu9LcCP">
<Canvas Id="MpGU3R3G7i7O0J10BiK0ku" BordersChecked="false" CanvasType="Group" />
<Canvas Id="MpGU3R3G7i7O0J10BiK0ku" CanvasType="Group" />
<ProcessDefinition Id="SPwmu2gxxiKPHmMdbEeotz" IsHidden="true" />
</Patch>
</Node>
Expand Down
20 changes: 11 additions & 9 deletions packages/VL.Stride.Runtime/src/Graphics/ResourceDataHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ public interface IStrideGraphicsDataProvider
PinnedGraphicsData Pin();
}

public interface IMemoryPinner : IDisposable
public interface IMemoryPinner
{
public IntPtr Pin();
public void Unpin();
}

public class ReadonlyMemoryPinner<T> : IMemoryPinner where T : struct
Expand All @@ -33,7 +34,7 @@ public unsafe IntPtr Pin()
return new IntPtr(memoryHandle.Pointer);
}

public void Dispose()
public void Unpin()
{
memoryHandle.Dispose();
}
Expand All @@ -53,7 +54,7 @@ public unsafe IntPtr Pin()
return new IntPtr(memoryHandle.Pointer);
}

public void Dispose()
public void Unpin()
{
memoryHandle.Dispose();
imageData.Dispose();
Expand All @@ -67,7 +68,7 @@ public IntPtr Pin()
return IntPtr.Zero;
}

public void Dispose()
public void Unpin()
{
}
}
Expand All @@ -77,17 +78,17 @@ public struct PinnedGraphicsData : IDisposable
public static readonly PinnedGraphicsData None = new PinnedGraphicsData(new NonePinner());

public readonly IntPtr Pointer;
readonly IDisposable disposable;
readonly IMemoryPinner pinner;

public PinnedGraphicsData(IMemoryPinner pinner)
{
Pointer = pinner.Pin();
disposable = pinner;
this.pinner = pinner;
}

public void Dispose()
{
disposable.Dispose();
pinner.Unpin();
}
}

Expand All @@ -104,8 +105,9 @@ public void SetMemoryData<T>(ReadOnlyMemory<T> memory, int offsetInBytes = 0, in
Pinner = pnr;

OffsetInBytes = offsetInBytes;
SizeInBytes = sizeInBytes > 0 ? sizeInBytes : memory.Length;
ElementSizeInBytes = elementSizeInBytes > 0 ? elementSizeInBytes : Utilities.SizeOf<T>();
var tSize = Utilities.SizeOf<T>();
SizeInBytes = sizeInBytes > 0 ? sizeInBytes : memory.Length * tSize;
ElementSizeInBytes = elementSizeInBytes > 0 ? elementSizeInBytes : tSize;
RowSizeInBytes = rowSizeInBytes;
SliceSizeInBytes = sliceSizeInBytes;
}
Expand Down

0 comments on commit 76464c5

Please sign in to comment.