Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
NickeManarin committed Apr 30, 2021
2 parents 623870e + a04c11e commit 2053269
Show file tree
Hide file tree
Showing 74 changed files with 1,907 additions and 1,056 deletions.
19 changes: 19 additions & 0 deletions GifRecorder.sln
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{840C4813
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PositioningTest", "Other\PositioningTest\PositioningTest.csproj", "{6204EAEF-C4AA-4005-A369-A8E779205696}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScreenToGif.Tests", "ScreenToGif.Tests\ScreenToGif.Tests.csproj", "{95F33D34-1231-49BA-8EE6-645CC2CE481C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -105,6 +107,22 @@ Global
{6204EAEF-C4AA-4005-A369-A8E779205696}.Release|x64.Build.0 = Release|Any CPU
{6204EAEF-C4AA-4005-A369-A8E779205696}.Release|x86.ActiveCfg = Release|Any CPU
{6204EAEF-C4AA-4005-A369-A8E779205696}.Release|x86.Build.0 = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|ARM.ActiveCfg = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|ARM.Build.0 = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|x64.ActiveCfg = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|x64.Build.0 = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|x86.ActiveCfg = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Debug|x86.Build.0 = Debug|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|Any CPU.Build.0 = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|ARM.ActiveCfg = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|ARM.Build.0 = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|x64.ActiveCfg = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|x64.Build.0 = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|x86.ActiveCfg = Release|Any CPU
{95F33D34-1231-49BA-8EE6-645CC2CE481C}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -114,6 +132,7 @@ Global
{8B516DFB-0981-48A2-8A06-35F085C13980} = {13F2A1B9-496A-446E-8B06-776ACAE5CEA4}
{2E037DF4-B0AD-43ED-9B99-4623DDF86F5D} = {840C4813-08E8-42C9-83CB-C0FA8BBBD763}
{6204EAEF-C4AA-4005-A369-A8E779205696} = {13F2A1B9-496A-446E-8B06-776ACAE5CEA4}
{95F33D34-1231-49BA-8EE6-645CC2CE481C} = {840C4813-08E8-42C9-83CB-C0FA8BBBD763}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E505E312-14B9-49C0-AC18-B3B2FB6C1661}
Expand Down
33 changes: 33 additions & 0 deletions ScreenToGif.Tests/ImageMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Drawing;

using ScreenToGif.Model;

using Xunit;

namespace ScreenToGif.Tests
{
public class ImageMethods
{
[Fact]
public void CanCalculateDifference()
{
var f1 = new FrameInfo()
{
Path = "./TestData/b1.bmp",
Index = 0
};

var f2 = new FrameInfo()
{
Path = "./TestData/b2.bmp",
Index = 1
};

var diff = ImageUtil.ImageMethods.CalculateDifference(f1, f2);

Assert.Equal(25, diff);
}
}
}
29 changes: 29 additions & 0 deletions ScreenToGif.Tests/ScreenToGif.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net48</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ScreenToGif\ScreenToGif.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="TestData\b1.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="TestData\b2.bmp">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Binary file added ScreenToGif.Tests/TestData/b1.bmp
Binary file not shown.
Binary file added ScreenToGif.Tests/TestData/b2.bmp
Binary file not shown.
3 changes: 0 additions & 3 deletions ScreenToGif/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,9 +329,6 @@ private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEven

private void App_Exit(object sender, ExitEventArgs e)
{
if (UserSettings.All.DeleteCacheWhenClosing)
StorageUtils.PurgeCache();

try
{
MutexList.RemoveAll();
Expand Down
6 changes: 4 additions & 2 deletions ScreenToGif/Capture/DirectCachedCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -315,10 +315,12 @@ public override int CaptureWithCursor(FrameInfo frame)
}

//Copy the captured desktop texture into a staging texture, in order to show the mouse cursor and not make the captured texture dirty with it.
Device.ImmediateContext.CopyResource(BackingTexture, StagingTexture);
if (info.TotalMetadataBufferSize > 0 || info.LastMouseUpdateTime > 0)
Device.ImmediateContext.CopyResource(BackingTexture, StagingTexture);

//Gets the cursor image and merges with the staging texture.
GetCursor(StagingTexture, info, frame);
if (info.LastMouseUpdateTime > 0)
GetCursor(StagingTexture, info, frame);

//Saves the most recent capture time.
LastProcessTime = Math.Max(info.LastPresentTime, info.LastMouseUpdateTime);
Expand Down
28 changes: 18 additions & 10 deletions ScreenToGif/Capture/DirectImageCapture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using ScreenToGif.Model;
using ScreenToGif.Util;
using ScreenToGif.Util.Exceptions;
using SharpDX;
using SharpDX.Direct3D;
using SharpDX.Direct3D11;
Expand Down Expand Up @@ -186,15 +188,15 @@ internal void Initialize()
}
catch (SharpDXException e) when (e.Descriptor == SharpDX.DXGI.ResultCode.Unsupported)
{
throw new NotSupportedException("The Desktop Duplication API is not supported on this computer. If you have multiple graphic cards, try running ScreenToGif on integrated graphics.", e);
throw new GraphicsConfigurationException("The Desktop Duplication API is not supported on this computer.", e);
}
catch (SharpDXException e) when (e.Descriptor == SharpDX.DXGI.ResultCode.InvalidCall)
{
throw new NotSupportedException("The Desktop Duplication API is not supported on this screen. If you have multiple screens, try capturing content on the first one (main screen connected to the integrated video graphics processor).", e);
throw new GraphicsConfigurationException("The Desktop Duplication API is not supported on this screen.", e);
}
catch (SharpDXException e) when (e.Descriptor.NativeApiCode == "E_INVALIDARG")
{
throw new NotSupportedException("Looks like that the Desktop Duplication API is not supported on this screen. If you have multiple screens, try capturing content on the first one (main screen connected to the integrated video graphics processor).", e);
throw new GraphicsConfigurationException("Looks like that the Desktop Duplication API is not supported on this screen.", e);
}
}
}
Expand Down Expand Up @@ -398,7 +400,8 @@ public override int Capture(FrameInfo frame)
{
LogWriter.Log(ex, "It was not possible to finish capturing the frame with DirectX.");

OnError.Invoke(ex);
MajorCrashHappened = true;
Application.Current.Dispatcher.Invoke(() => OnError.Invoke(ex));
return FrameCount;
}
finally
Expand Down Expand Up @@ -504,10 +507,12 @@ public override int CaptureWithCursor(FrameInfo frame)
}

//Copy the captured desktop texture into a staging texture, in order to show the mouse cursor and not make the captured texture dirty with it.
Device.ImmediateContext.CopyResource(BackingTexture, StagingTexture);
if (info.TotalMetadataBufferSize > 0 || info.LastMouseUpdateTime > 0)
Device.ImmediateContext.CopyResource(BackingTexture, StagingTexture);

//Gets the cursor image and merges with the staging texture.
GetCursor(StagingTexture, info, frame);
if (info.LastMouseUpdateTime > 0)
GetCursor(StagingTexture, info, frame);

//Saves the most recent capture time.
LastProcessTime = Math.Max(info.LastPresentTime, info.LastMouseUpdateTime);
Expand Down Expand Up @@ -578,7 +583,7 @@ public override int CaptureWithCursor(FrameInfo frame)
LogWriter.Log(ex, "It was not possible to finish capturing the frame with DirectX.");

MajorCrashHappened = true;
OnError.Invoke(ex);
Application.Current.Dispatcher.Invoke(() => OnError.Invoke(ex));
return FrameCount;
}
finally
Expand Down Expand Up @@ -774,8 +779,8 @@ protected internal bool GetCursor(Texture2D screenTexture, OutputDuplicateFrameI

//TODO: In a future version, don't merge the cursor image in here, let the editor do that.
//Saves the position of the cursor, so the editor can add the mouse clicks overlay later.
frame.CursorX = PreviousPosition.Position.X - Left;
frame.CursorY = PreviousPosition.Position.Y - Top;
frame.CursorX = PreviousPosition.Position.X - (Left - OffsetLeft);
frame.CursorY = PreviousPosition.Position.Y - (Top - OffsetTop);

//If the method is supposed to simply the get the cursor shape no shape was loaded before, there's nothing else to do.
//if (CursorShapeBuffer?.Length == 0 || (info.LastPresentTime == 0 && info.LastMouseUpdateTime == 0) || !info.PointerPosition.Visible)
Expand All @@ -793,7 +798,7 @@ protected internal bool GetCursor(Texture2D screenTexture, OutputDuplicateFrameI
var rightCut = screenTexture.Description.Width - (frame.CursorX + CursorShapeInfo.Width);
var bottomCut = screenTexture.Description.Height - (frame.CursorY + CursorShapeInfo.Height);

//Adjust the offset, so it's possible to add the highlight correctly later.
//Adjust to the hotspot offset, so it's possible to add the highlight correctly later.
frame.CursorX += CursorShapeInfo.HotSpot.X;
frame.CursorY += CursorShapeInfo.HotSpot.Y;

Expand Down Expand Up @@ -993,6 +998,9 @@ internal void DisposeInternal()
{
Device.Dispose();

if (MajorCrashHappened)
return;

BackingTexture.Dispose();
StagingTexture.Dispose();
DuplicatedOutput.Dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.ComponentModel;
using System.ComponentModel;
using System.Windows;
using System.Windows.Input;
using ScreenToGif.Model;
Expand All @@ -9,10 +9,11 @@ namespace ScreenToGif.Controls
/// <summary>
/// All recorders are derived from this class.
/// </summary>
public class RecorderWindow : Window
public class BaseRecorder : Window
{
public static readonly DependencyProperty StageProperty = DependencyProperty.Register(nameof(Stage), typeof(Stage), typeof(RecorderWindow), new FrameworkPropertyMetadata(Stage.Stopped));
public static readonly DependencyProperty FrameCountProperty = DependencyProperty.Register(nameof(FrameCount), typeof(int), typeof(RecorderWindow), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty StageProperty = DependencyProperty.Register(nameof(Stage), typeof(Stage), typeof(BaseRecorder), new FrameworkPropertyMetadata(Stage.Stopped));
public static readonly DependencyProperty FrameCountProperty = DependencyProperty.Register(nameof(FrameCount), typeof(int), typeof(BaseRecorder), new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty HasImpreciseCaptureProperty = DependencyProperty.Register(nameof(HasImpreciseCapture), typeof(bool), typeof(BaseRecorder), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.AffectsRender));

/// <summary>
/// The actual stage of the recorder.
Expand All @@ -37,6 +38,16 @@ public int FrameCount
set => SetValue(FrameCountProperty, value);
}

/// <summary>
/// The frame count of the current recording.
/// </summary>
[Bindable(true), Category("Common"), Description("True if the recorder is unable to capture with precision.")]
public bool HasImpreciseCapture
{
get => (bool)GetValue(HasImpreciseCaptureProperty);
set => SetValue(HasImpreciseCaptureProperty, value);
}

/// <summary>
/// The project information about the current recording.
/// </summary>
Expand Down
Loading

0 comments on commit 2053269

Please sign in to comment.