|
|
|
@ -13,13 +13,13 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
{ |
|
|
|
public class SwapOrCopyContent |
|
|
|
{ |
|
|
|
private readonly TestMemoryAllocator MemoryAllocator = new TestMemoryAllocator(); |
|
|
|
private readonly TestMemoryAllocator memoryAllocator = new TestMemoryAllocator(); |
|
|
|
|
|
|
|
[Fact] |
|
|
|
public void SwapOrCopyContent_WhenBothAllocated() |
|
|
|
{ |
|
|
|
using (Buffer2D<int> a = this.MemoryAllocator.Allocate2D<int>(10, 5, AllocationOptions.Clean)) |
|
|
|
using (Buffer2D<int> b = this.MemoryAllocator.Allocate2D<int>(3, 7, AllocationOptions.Clean)) |
|
|
|
using (Buffer2D<int> a = this.memoryAllocator.Allocate2D<int>(10, 5, AllocationOptions.Clean)) |
|
|
|
using (Buffer2D<int> b = this.memoryAllocator.Allocate2D<int>(3, 7, AllocationOptions.Clean)) |
|
|
|
{ |
|
|
|
a[1, 3] = 666; |
|
|
|
b[1, 3] = 444; |
|
|
|
@ -46,7 +46,7 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
using var destData = MemoryGroup<int>.Wrap(new int[100]); |
|
|
|
using var dest = new Buffer2D<int>(destData, 10, 10); |
|
|
|
|
|
|
|
using (Buffer2D<int> source = this.MemoryAllocator.Allocate2D<int>(10, 10, AllocationOptions.Clean)) |
|
|
|
using (Buffer2D<int> source = this.memoryAllocator.Allocate2D<int>(10, 10, AllocationOptions.Clean)) |
|
|
|
{ |
|
|
|
source[0, 0] = 1; |
|
|
|
dest[0, 0] = 2; |
|
|
|
@ -68,9 +68,9 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
[Fact] |
|
|
|
public void WhenBothAreMemoryOwners_ShouldSwap() |
|
|
|
{ |
|
|
|
this.MemoryAllocator.BufferCapacityInBytes = sizeof(int) * 50; |
|
|
|
using Buffer2D<int> a = this.MemoryAllocator.Allocate2D<int>(48, 2); |
|
|
|
using Buffer2D<int> b = this.MemoryAllocator.Allocate2D<int>(50, 2); |
|
|
|
this.memoryAllocator.BufferCapacityInBytes = sizeof(int) * 50; |
|
|
|
using Buffer2D<int> a = this.memoryAllocator.Allocate2D<int>(48, 2); |
|
|
|
using Buffer2D<int> b = this.memoryAllocator.Allocate2D<int>(50, 2); |
|
|
|
|
|
|
|
Memory<int> a0 = a.FastMemoryGroup[0]; |
|
|
|
Memory<int> a1 = a.FastMemoryGroup[1]; |
|
|
|
@ -90,8 +90,8 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
[Fact] |
|
|
|
public void WhenBothAreMemoryOwners_ShouldReplaceViews() |
|
|
|
{ |
|
|
|
using Buffer2D<int> a = this.MemoryAllocator.Allocate2D<int>(100, 1); |
|
|
|
using Buffer2D<int> b = this.MemoryAllocator.Allocate2D<int>(100, 2); |
|
|
|
using Buffer2D<int> a = this.memoryAllocator.Allocate2D<int>(100, 1); |
|
|
|
using Buffer2D<int> b = this.memoryAllocator.Allocate2D<int>(100, 2); |
|
|
|
|
|
|
|
a.FastMemoryGroup[0].Span[42] = 1; |
|
|
|
b.FastMemoryGroup[0].Span[33] = 2; |
|
|
|
@ -121,7 +121,7 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
using var destOwner = new TestMemoryManager<Rgba32>(data); |
|
|
|
using var dest = new Buffer2D<Rgba32>(MemoryGroup<Rgba32>.Wrap(destOwner.Memory), 21, 1); |
|
|
|
|
|
|
|
using Buffer2D<Rgba32> source = this.MemoryAllocator.Allocate2D<Rgba32>(21, 1); |
|
|
|
using Buffer2D<Rgba32> source = this.memoryAllocator.Allocate2D<Rgba32>(21, 1); |
|
|
|
|
|
|
|
source.FastMemoryGroup[0].Span[10] = color; |
|
|
|
|
|
|
|
@ -145,7 +145,7 @@ namespace SixLabors.ImageSharp.Tests.Memory |
|
|
|
using var destOwner = new TestMemoryManager<Rgba32>(data); |
|
|
|
using var dest = new Buffer2D<Rgba32>(MemoryGroup<Rgba32>.Wrap(destOwner.Memory), 21, 1); |
|
|
|
|
|
|
|
using Buffer2D<Rgba32> source = this.MemoryAllocator.Allocate2D<Rgba32>(22, 1); |
|
|
|
using Buffer2D<Rgba32> source = this.memoryAllocator.Allocate2D<Rgba32>(22, 1); |
|
|
|
|
|
|
|
source.FastMemoryGroup[0].Span[10] = color; |
|
|
|
|
|
|
|
|