1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Merge pull request #322 from DarthAffe/NativeStuff

Native stuff
This commit is contained in:
DarthAffe 2023-05-20 21:27:41 +02:00 committed by GitHub
commit 020f249f9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 18 additions and 13 deletions

View File

@ -27,9 +27,9 @@ public abstract class AbstractBindable : IBindable
/// <typeparam name="T">Type of the property.</typeparam>
/// <param name="storage">Reference to the backing-filed.</param>
/// <param name="value">Value to apply.</param>
/// <returns><c>true</c> if the value needs to be updated; otherweise <c>false</c>.</returns>
/// <returns><c>true</c> if the value needs to be updated; otherwise <c>false</c>.</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
protected virtual bool RequiresUpdate<T>(ref T storage, T value) => !EqualityComparer<T>.Default.Equals(storage, value);
protected bool RequiresUpdate<T>(ref T storage, T value) => !EqualityComparer<T>.Default.Equals(storage, value);
/// <summary>
/// Checks if the property already matches the desired value and updates it if not.
@ -40,7 +40,7 @@ public abstract class AbstractBindable : IBindable
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
{
if (!RequiresUpdate(ref storage, value)) return false;
@ -55,7 +55,7 @@ public abstract class AbstractBindable : IBindable
/// </summary>
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
#endregion

View File

@ -74,9 +74,13 @@ public abstract class AbstractBrush : AbstractDecoratable<IBrushDecorator>, IBru
if (Decorators.Count == 0) return;
lock (Decorators)
foreach (IBrushDecorator decorator in Decorators)
// ReSharper disable once ForCanBeConvertedToForeach - Sadly this does not get optimized reliably and causes allocations if foreached
for (int i = 0; i < Decorators.Count; i++)
{
IBrushDecorator decorator = Decorators[i];
if (decorator.IsEnabled)
decorator.ManipulateColor(rectangle, renderTarget, ref color);
}
}
/// <summary>

View File

@ -32,6 +32,8 @@ public sealed class SolidColorBrush : AbstractBrush
public SolidColorBrush(Color color)
{
this.Color = color;
CalculationMode = RenderMode.Absolute;
}
#endregion

View File

@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
namespace RGB.NET.Core;
@ -41,7 +40,7 @@ public sealed class AverageColorSampler : ISampler<Color>
{
ReadOnlySpan<Color> data = info[y];
fixed (Color* colorPtr = &MemoryMarshal.GetReference(data))
fixed (Color* colorPtr = data)
{
Color* current = colorPtr;
for (int i = 0; i < chunks; i++)

View File

@ -133,7 +133,7 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
/// <summary>
/// Stops the trigger.
/// </summary>
public async void Stop()
public virtual async void Stop()
{
if (!IsRunning) return;
@ -141,7 +141,9 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
UpdateTokenSource?.Cancel();
if (UpdateTask != null)
await UpdateTask;
try { await UpdateTask.ConfigureAwait(false); }
catch (TaskCanceledException) { }
catch (OperationCanceledException) { }
UpdateTask?.Dispose();
UpdateTask = null;

View File

@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using RGB.NET.Core;
namespace RGB.NET.Presets.Textures.Sampler;
@ -42,7 +41,7 @@ public sealed class AverageByteSampler : ISampler<byte>
{
ReadOnlySpan<byte> data = info[y];
fixed (byte* colorPtr = &MemoryMarshal.GetReference(data))
fixed (byte* colorPtr = data)
{
byte* current = colorPtr;
for (int i = 0; i < chunks; i++)

View File

@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using RGB.NET.Core;
namespace RGB.NET.Presets.Textures.Sampler;
@ -33,7 +32,7 @@ public sealed class AverageFloatSampler : ISampler<float>
{
ReadOnlySpan<float> data = info[y];
fixed (float* colorPtr = &MemoryMarshal.GetReference(data))
fixed (float* colorPtr = data)
{
float* current = colorPtr;
for (int i = 0; i < chunks; i++)