-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(reg): Fix CI build - iteration 3: Disable tests that relies on …
…screenshots
- Loading branch information
Showing
7 changed files
with
135 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
#if !__ANDROID__ | ||
#nullable enable | ||
using System; | ||
using System.Buffers; | ||
using System.Linq; | ||
using System.Runtime.InteropServices; | ||
|
||
namespace Microsoft.UI.Xaml.Media.Imaging; | ||
|
||
public partial class RenderTargetBitmap | ||
{ | ||
private unsafe class UnmanagedArrayOfBytes | ||
{ | ||
public nint Pointer; | ||
public int Length { get; } | ||
|
||
public UnmanagedArrayOfBytes(int length) | ||
{ | ||
Length = length; | ||
Pointer = Marshal.AllocHGlobal(length); | ||
GC.AddMemoryPressure(length); | ||
} | ||
|
||
public byte this[int index] | ||
{ | ||
get | ||
{ | ||
return ((byte*)Pointer.ToPointer())[index]; | ||
} | ||
set | ||
{ | ||
((byte*)Pointer.ToPointer())[index] = value; | ||
} | ||
} | ||
|
||
~UnmanagedArrayOfBytes() | ||
{ | ||
Marshal.FreeHGlobal(Pointer); | ||
GC.RemoveMemoryPressure(Length); | ||
} | ||
} | ||
|
||
// This is to avoid LOH array allocations | ||
// https://stackoverflow.com/questions/52190423/c-sharp-access-unmanaged-array-using-memoryt-or-arraysegmentt | ||
private sealed unsafe class UnmanagedMemoryManager<T> : MemoryManager<T> | ||
where T : unmanaged | ||
{ | ||
private readonly T* _pointer; | ||
private readonly int _length; | ||
|
||
/// <summary> | ||
/// Create a new UnmanagedMemoryManager instance at the given pointer and size | ||
/// </summary> | ||
public UnmanagedMemoryManager(T* pointer, int length) | ||
{ | ||
if (length < 0) throw new ArgumentOutOfRangeException(nameof(length)); | ||
Check failure on line 56 in src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs Codacy Production / Codacy Static Code Analysissrc/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs#L56
|
||
_pointer = pointer; | ||
_length = length; | ||
} | ||
/// <summary> | ||
/// Obtains a span that represents the region | ||
/// </summary> | ||
public override Span<T> GetSpan() => new(_pointer, _length); | ||
|
||
/// <summary> | ||
/// Provides access to a pointer that represents the data (note: no actual pin occurs) | ||
/// </summary> | ||
public override MemoryHandle Pin(int elementIndex = 0) | ||
{ | ||
if (elementIndex < 0 || elementIndex >= _length) | ||
Check failure on line 70 in src/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs Codacy Production / Codacy Static Code Analysissrc/Uno.UI/UI/Xaml/Media/Imaging/RenderTargetBitmap.UnmanagedArrayOfBytes.cs#L70
|
||
throw new ArgumentOutOfRangeException(nameof(elementIndex)); | ||
return new MemoryHandle(_pointer + elementIndex); | ||
} | ||
|
||
/// <summary> | ||
/// Has no effect | ||
/// </summary> | ||
public override void Unpin() { } | ||
|
||
/// <summary> | ||
/// Releases all resources associated with this object | ||
/// </summary> | ||
protected override void Dispose(bool disposing) { } | ||
} | ||
} | ||
#endif |
Oops, something went wrong.