Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native stuff #322

Merged
merged 6 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions RGB.NET.Core/MVVM/AbstractBindable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;

Expand All @@ -55,7 +55,7 @@ protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName]
/// </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
Expand Down
6 changes: 5 additions & 1 deletion RGB.NET.Core/Rendering/Brushes/AbstractBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,13 @@ protected virtual void ApplyDecorators(in Rectangle rectangle, in RenderTarget r
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>
Expand Down
2 changes: 2 additions & 0 deletions RGB.NET.Core/Rendering/Brushes/SolidColorBrush.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public Color Color
public SolidColorBrush(Color color)
{
this.Color = color;

CalculationMode = RenderMode.Absolute;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;

namespace RGB.NET.Core;

Expand Down Expand Up @@ -41,7 +40,7 @@ public unsafe void Sample(in SamplerInfo<Color> info, in Span<Color> pixelData)
{
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++)
Expand Down
6 changes: 4 additions & 2 deletions RGB.NET.Core/Update/Devices/DeviceUpdateTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,17 @@ public override void Start()
/// <summary>
/// Stops the trigger.
/// </summary>
public async void Stop()
public virtual async void Stop()
{
if (!IsRunning) return;

IsRunning = false;

UpdateTokenSource?.Cancel();
if (UpdateTask != null)
await UpdateTask;
try { await UpdateTask.ConfigureAwait(false); }
catch (TaskCanceledException) { }
catch (OperationCanceledException) { }

UpdateTask?.Dispose();
UpdateTask = null;
Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Presets/Textures/Sampler/AverageByteSampler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using RGB.NET.Core;

namespace RGB.NET.Presets.Textures.Sampler;
Expand Down Expand Up @@ -42,7 +41,7 @@ public unsafe void Sample(in SamplerInfo<byte> info, in Span<byte> pixelData)
{
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++)
Expand Down
3 changes: 1 addition & 2 deletions RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.Numerics;
using System.Runtime.InteropServices;
using RGB.NET.Core;

namespace RGB.NET.Presets.Textures.Sampler;
Expand Down Expand Up @@ -33,7 +32,7 @@ public unsafe void Sample(in SamplerInfo<float> info, in Span<float> pixelData)
{
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++)
Expand Down