summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authora1xd <[email protected]>2020-08-24 04:24:33 -0400
committera1xd <[email protected]>2020-08-24 04:24:33 -0400
commit313ab92531fbfacb955f9de85d3fc611f8064154 (patch)
tree4986f8f58b4144a4ec7e85ae14af045b7c12b3da
parentMerge pull request #16 from JacobPalecki/Misc (diff)
downloadrawaccel-313ab92531fbfacb955f9de85d3fc611f8064154.tar.xz
rawaccel-313ab92531fbfacb955f9de85d3fc611f8064154.zip
clean up wrapper, minimize heap alloc
-rw-r--r--common/rawaccel-io.hpp14
-rw-r--r--grapher/grapher.csproj27
-rw-r--r--rawaccel.sln41
-rw-r--r--wrapper/wrapper.cpp22
-rw-r--r--wrapper/wrapper.hpp33
-rw-r--r--wrapper/wrapper.vcxproj48
-rw-r--r--wrapper/wrapper_io.cpp12
-rw-r--r--wrapper/wrapper_io.hpp8
8 files changed, 52 insertions, 153 deletions
diff --git a/common/rawaccel-io.hpp b/common/rawaccel-io.hpp
index 7f55392..582ea68 100644
--- a/common/rawaccel-io.hpp
+++ b/common/rawaccel-io.hpp
@@ -48,7 +48,7 @@ namespace rawaccel {
}
- void write(mouse_modifier mod) {
+ void write(const mouse_modifier& mod) {
HANDLE ra_handle = INVALID_HANDLE_VALUE;
ra_handle = CreateFileW(L"\\\\.\\rawaccel", 0, 0, 0, OPEN_EXISTING, 0, 0);
@@ -62,12 +62,12 @@ namespace rawaccel {
BOOL success = DeviceIoControl(
ra_handle,
RA_WRITE,
- &mod, // input buffer
- sizeof(mouse_modifier), // input buffer size
- NULL, // output buffer
- 0, // output buffer size
- &dummy, // bytes returned
- NULL // overlapped structure
+ const_cast<mouse_modifier*>(&mod), // input buffer
+ sizeof(mouse_modifier), // input buffer size
+ NULL, // output buffer
+ 0, // output buffer size
+ &dummy, // bytes returned
+ NULL // overlapped structure
);
CloseHandle(ra_handle);
diff --git a/grapher/grapher.csproj b/grapher/grapher.csproj
index 6e03ae0..a700ffe 100644
--- a/grapher/grapher.csproj
+++ b/grapher/grapher.csproj
@@ -13,24 +13,27 @@
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
- <PlatformTarget>x64</PlatformTarget>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
- <DebugType>full</DebugType>
- <Optimize>false</Optimize>
- <OutputPath>bin\Debug\</OutputPath>
+ <OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DebugType>full</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
- <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
- <PlatformTarget>x64</PlatformTarget>
- <DebugType>pdbonly</DebugType>
- <Optimize>true</Optimize>
- <OutputPath>bin\Release\</OutputPath>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
+ <OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
+ <Optimize>true</Optimize>
+ <DebugType>pdbonly</DebugType>
+ <PlatformTarget>x64</PlatformTarget>
+ <LangVersion>7.3</LangVersion>
<ErrorReport>prompt</ErrorReport>
- <WarningLevel>4</WarningLevel>
+ <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
+ <Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
diff --git a/rawaccel.sln b/rawaccel.sln
index 33735fd..9eb1101 100644
--- a/rawaccel.sln
+++ b/rawaccel.sln
@@ -30,69 +30,34 @@ Global
common\common.vcxitems*{ab7b3759-b85f-4067-8935-fb4539b41869}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
- Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
- Debug|x86 = Debug|x86
- Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
- Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {60D6C942-AC20-4C05-A2BE-54B5C966534D}.Debug|Any CPU.ActiveCfg = Debug|x64
{60D6C942-AC20-4C05-A2BE-54B5C966534D}.Debug|x64.ActiveCfg = Debug|x64
{60D6C942-AC20-4C05-A2BE-54B5C966534D}.Debug|x64.Build.0 = Debug|x64
{60D6C942-AC20-4C05-A2BE-54B5C966534D}.Debug|x64.Deploy.0 = Debug|x64
- {60D6C942-AC20-4C05-A2BE-54B5C966534D}.Debug|x86.ActiveCfg = Debug|x64
- {60D6C942-AC20-4C05-A2BE-54B5C966534D}.Release|Any CPU.ActiveCfg = Release|x64
{60D6C942-AC20-4C05-A2BE-54B5C966534D}.Release|x64.ActiveCfg = Release|x64
{60D6C942-AC20-4C05-A2BE-54B5C966534D}.Release|x64.Build.0 = Release|x64
- {60D6C942-AC20-4C05-A2BE-54B5C966534D}.Release|x86.ActiveCfg = Release|x64
- {896950D1-520A-420A-B6B1-73014B92A68C}.Debug|Any CPU.ActiveCfg = Debug|x64
{896950D1-520A-420A-B6B1-73014B92A68C}.Debug|x64.ActiveCfg = Debug|x64
{896950D1-520A-420A-B6B1-73014B92A68C}.Debug|x64.Build.0 = Debug|x64
- {896950D1-520A-420A-B6B1-73014B92A68C}.Debug|x86.ActiveCfg = Debug|x64
- {896950D1-520A-420A-B6B1-73014B92A68C}.Release|Any CPU.ActiveCfg = Release|x64
{896950D1-520A-420A-B6B1-73014B92A68C}.Release|x64.ActiveCfg = Release|x64
{896950D1-520A-420A-B6B1-73014B92A68C}.Release|x64.Build.0 = Release|x64
- {896950D1-520A-420A-B6B1-73014B92A68C}.Release|x86.ActiveCfg = Release|x64
- {AB7B3759-B85F-4067-8935-FB4539B41869}.Debug|Any CPU.ActiveCfg = Debug|x64
{AB7B3759-B85F-4067-8935-FB4539B41869}.Debug|x64.ActiveCfg = Debug|x64
{AB7B3759-B85F-4067-8935-FB4539B41869}.Debug|x64.Build.0 = Debug|x64
- {AB7B3759-B85F-4067-8935-FB4539B41869}.Debug|x86.ActiveCfg = Debug|x64
- {AB7B3759-B85F-4067-8935-FB4539B41869}.Release|Any CPU.ActiveCfg = Release|x64
{AB7B3759-B85F-4067-8935-FB4539B41869}.Release|x64.ActiveCfg = Release|x64
{AB7B3759-B85F-4067-8935-FB4539B41869}.Release|x64.Build.0 = Release|x64
- {AB7B3759-B85F-4067-8935-FB4539B41869}.Release|x86.ActiveCfg = Release|x64
- {A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Debug|Any CPU.ActiveCfg = Debug|x64
{A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Debug|x64.ActiveCfg = Debug|x64
{A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Debug|x64.Build.0 = Debug|x64
- {A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Debug|x86.ActiveCfg = Debug|x64
- {A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Release|Any CPU.ActiveCfg = Release|x64
{A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Release|x64.ActiveCfg = Release|x64
{A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Release|x64.Build.0 = Release|x64
- {A4097FF6-A6F0-44E8-B8D0-538D0FB75936}.Release|x86.ActiveCfg = Release|x64
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Debug|Any CPU.ActiveCfg = Debug|Win32
{28A3656F-A1DE-405C-B547-191C32EC555F}.Debug|x64.ActiveCfg = Debug|x64
{28A3656F-A1DE-405C-B547-191C32EC555F}.Debug|x64.Build.0 = Debug|x64
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Debug|x86.ActiveCfg = Debug|Win32
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Debug|x86.Build.0 = Debug|Win32
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Release|Any CPU.ActiveCfg = Release|Win32
{28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.ActiveCfg = Release|x64
{28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x64.Build.0 = Release|x64
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x86.ActiveCfg = Release|Win32
- {28A3656F-A1DE-405C-B547-191C32EC555F}.Release|x86.Build.0 = Release|Win32
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.ActiveCfg = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.Build.0 = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x86.ActiveCfg = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x86.Build.0 = Debug|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|Any CPU.Build.0 = Release|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.ActiveCfg = Release|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.Build.0 = Release|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x86.ActiveCfg = Release|Any CPU
- {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x86.Build.0 = Release|Any CPU
+ {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Debug|x64.ActiveCfg = Debug|x64
+ {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.ActiveCfg = Release|x64
+ {EF67F71F-ABF5-4760-B50D-D1B9836DF01C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/wrapper/wrapper.cpp b/wrapper/wrapper.cpp
index dcc9606..6dabd7e 100644
--- a/wrapper/wrapper.cpp
+++ b/wrapper/wrapper.cpp
@@ -2,8 +2,9 @@
#include "wrapper.hpp"
-using namespace rawaccel;
-using namespace System;
+void replace(mouse_modifier* mod_ptr, const modifier_args& args) {
+ *mod_ptr = mouse_modifier(args);
+}
Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time)
{
@@ -11,7 +12,7 @@ Tuple<double, double>^ ManagedAccel::Accelerate(int x, int y, double time)
(double)x,
(double)y
};
- vec2d output = (*modifier_instance).modify_with_accel(input_vec2d, (milliseconds)time);
+ vec2d output = modifier_instance->modify_with_accel(input_vec2d, time);
return gcnew Tuple<double, double>(output.x, output.y);
}
@@ -31,7 +32,7 @@ void ManagedAccel::UpdateAccel(
double midpoint,
double gain_cap)
{
- modifier_args args = modifier_args{};
+ modifier_args args{};
args.acc_fn_args.accel_mode = mode;
args.degrees = rotation;
args.sens.x = sensitivityX;
@@ -46,13 +47,9 @@ void ManagedAccel::UpdateAccel(
args.acc_fn_args.acc_args.exponent = lim_exp;
args.acc_fn_args.acc_args.midpoint = midpoint;
args.acc_fn_args.acc_args.gain_cap = gain_cap;
-
- mouse_modifier* temp_modifier = new mouse_modifier(args);
- driverWriter->writeToDriver(temp_modifier);
- delete temp_modifier;
-
- ReadFromDriver();
+ replace(modifier_instance, args);
+ WriteToDriver();
}
double ManagedAccel::SensitivityX::get() { return modifier_instance->sensitivity.x; }
@@ -74,11 +71,10 @@ double ManagedAccel::PowerScale::get() { return modifier_instance->accel_fn.impl
void ManagedAccel::WriteToDriver()
{
- driverWriter->writeToDriver(modifier_instance);
+ wrapper_io::writeToDriver(*modifier_instance);
}
void ManagedAccel::ReadFromDriver()
{
- delete modifier_instance;
- modifier_instance = driverWriter->readFromDriver();
+ wrapper_io::readFromDriver(*modifier_instance);
}
diff --git a/wrapper/wrapper.hpp b/wrapper/wrapper.hpp
index 3643eb5..45647e8 100644
--- a/wrapper/wrapper.hpp
+++ b/wrapper/wrapper.hpp
@@ -1,43 +1,33 @@
#pragma once
-#include <iostream>
-
#include "wrapper_io.hpp"
-using namespace rawaccel;
using namespace System;
public ref class ManagedAccel
{
-protected:
- mouse_modifier* modifier_instance;
- wrapper_io* driverWriter;
+ mouse_modifier* const modifier_instance;
+
public:
- ManagedAccel(mouse_modifier* accel)
- : modifier_instance(accel)
- {
- driverWriter = new wrapper_io();
- }
- ManagedAccel(System::IntPtr args)
- {
- modifier_instance = new mouse_modifier(*reinterpret_cast<modifier_args*>(args.ToPointer()));
- driverWriter = new wrapper_io();
- }
+ ManagedAccel(System::IntPtr args) :
+ modifier_instance(new mouse_modifier(*reinterpret_cast<modifier_args*>(args.ToPointer())))
+ {}
// Empty constructor needed for serialization
- ManagedAccel() {}
+ ManagedAccel() : modifier_instance(nullptr) {}
virtual ~ManagedAccel()
{
- if (modifier_instance!= nullptr)
+ if (modifier_instance != nullptr)
{
delete modifier_instance;
}
}
+
!ManagedAccel()
{
- if (modifier_instance!= nullptr)
+ if (modifier_instance != nullptr)
{
delete modifier_instance;
}
@@ -60,10 +50,6 @@ public:
property double Midpoint { double get(); }
property double MinimumTime { double get(); }
property double PowerScale { double get(); }
- mouse_modifier* GetInstance()
- {
- return modifier_instance;
- }
Tuple<double, double>^ Accelerate(int x, int y, double time);
@@ -82,7 +68,6 @@ public:
double midpoint,
double gain_cap);
-
void WriteToDriver();
void ReadFromDriver();
diff --git a/wrapper/wrapper.vcxproj b/wrapper/wrapper.vcxproj
index 3407d6d..0ea90de 100644
--- a/wrapper/wrapper.vcxproj
+++ b/wrapper/wrapper.vcxproj
@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
- <ProjectConfiguration Include="Debug|Win32">
- <Configuration>Debug</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
- <ProjectConfiguration Include="Release|Win32">
- <Configuration>Release</Configuration>
- <Platform>Win32</Platform>
- </ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
@@ -27,20 +19,6 @@
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseDebugLibraries>true</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
- <CLRSupport>true</CLRSupport>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
- <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
- <ConfigurationType>DynamicLibrary</ConfigurationType>
- <UseDebugLibraries>false</UseDebugLibraries>
- <PlatformToolset>v142</PlatformToolset>
- <CLRSupport>true</CLRSupport>
- <CharacterSet>Unicode</CharacterSet>
- </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
@@ -61,12 +39,6 @@
<ImportGroup Label="Shared">
<Import Project="..\common\common.vcxitems" Label="Shared" />
</ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
- <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
- </ImportGroup>
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
</ImportGroup>
@@ -85,26 +57,6 @@
<AdditionalDependencies />
</Link>
</ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <PreprocessorDefinitions>WIN32;_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <LanguageStandard>stdcpp17</LanguageStandard>
- </ClCompile>
- <Link>
- <AdditionalDependencies />
- </Link>
- </ItemDefinitionGroup>
- <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
- <ClCompile>
- <WarningLevel>Level3</WarningLevel>
- <PreprocessorDefinitions>WIN32;NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
- <LanguageStandard>stdcpp17</LanguageStandard>
- </ClCompile>
- <Link>
- <AdditionalDependencies />
- </Link>
- </ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<ClCompile>
<WarningLevel>Level3</WarningLevel>
diff --git a/wrapper/wrapper_io.cpp b/wrapper/wrapper_io.cpp
index 4284d60..b5727ef 100644
--- a/wrapper/wrapper_io.cpp
+++ b/wrapper/wrapper_io.cpp
@@ -3,16 +3,12 @@
#include <rawaccel-io.hpp>
#include "wrapper_io.hpp"
-void wrapper_io::writeToDriver(rawaccel::mouse_modifier* modifier)
+void wrapper_io::writeToDriver(const mouse_modifier& modifier)
{
- rawaccel::write(*modifier);
+ write(modifier);
}
-rawaccel::mouse_modifier* wrapper_io::readFromDriver()
+void wrapper_io::readFromDriver(mouse_modifier& modifier)
{
- rawaccel::mouse_modifier modifier = rawaccel::read();
- rawaccel::mouse_modifier* mod_pnt = (rawaccel::mouse_modifier*)malloc(sizeof(rawaccel::mouse_modifier));
- memcpy(mod_pnt, &modifier, sizeof(rawaccel::mouse_modifier));
-
- return mod_pnt;
+ modifier = read();
}
diff --git a/wrapper/wrapper_io.hpp b/wrapper/wrapper_io.hpp
index 3427e3f..1873f75 100644
--- a/wrapper/wrapper_io.hpp
+++ b/wrapper/wrapper_io.hpp
@@ -2,7 +2,9 @@
#include <rawaccel.hpp>
+using namespace rawaccel;
+
struct wrapper_io {
- void writeToDriver(rawaccel::mouse_modifier* modifier);
- rawaccel::mouse_modifier* readFromDriver();
-}; \ No newline at end of file
+ static void writeToDriver(const mouse_modifier& modifier);
+ static void readFromDriver(mouse_modifier& modifier);
+};