Skip to content

Commit ea08f0e

Browse files
authored
Merge pull request #16 from akon47/develop
Develop
2 parents 9212173 + 7d3a55b commit ea08f0e

File tree

6 files changed

+122
-70
lines changed

6 files changed

+122
-70
lines changed

ScreenRecorder/App.xaml.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ protected override void OnStartup(StartupEventArgs e)
1919
Mutex = new Mutex(true, AppConstants.AppName, out bool isNew);
2020
if (isNew)
2121
{
22-
if (!IsMicrosoftVisualCPlusPlus2019Available())
22+
if (!IsMicrosoftVisualCPlusPlus2019OrNewerAvailable())
2323
{
24-
MessageBox.Show("Please Install \"Microsoft Visual C++ 2017-2019 Redistributable (x64)\"");
24+
MessageBox.Show("Please Install \"Microsoft Visual C++ 2019 or newer Redistributable (x64)\"");
2525
Environment.Exit(-2);
2626
}
2727

@@ -53,15 +53,15 @@ protected override void OnExit(ExitEventArgs e)
5353
base.OnExit(e);
5454
}
5555

56-
private bool IsMicrosoftVisualCPlusPlus2019Available()
56+
private bool IsMicrosoftVisualCPlusPlus2019OrNewerAvailable()
5757
{
5858
using (var depRegistryKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(@"Installer\Dependencies", false))
5959
{
6060
foreach (string subKeyName in depRegistryKey.GetSubKeyNames())
6161
{
6262
using (var registryKey = depRegistryKey.OpenSubKey(subKeyName))
6363
{
64-
if (registryKey.GetValue("DisplayName") is string displayName && Regex.IsMatch(displayName, "[cC]\\+\\+.*2019.*[xX]64"))
64+
if (registryKey.GetValue("DisplayName") is string displayName && Regex.IsMatch(displayName, "[cC]\\+\\+.*(?:2019|2022).*[xX]64"))
6565
{
6666
return true;
6767
}

ScreenRecorder/DirectX/DuplicatorCapture.cs

Lines changed: 89 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ public int Height
3838
}
3939

4040
public string Description
41-
{
42-
get
43-
{
44-
return string.Format("{0}: {1}x{2} @ {3},{4}{5}", AdapterDescription, Width, Height, Left, Top, IsPrimary ? $" ({ScreenRecorder.Properties.Resources.PrimaryDisplay})" : "");
45-
}
46-
}
41+
{
42+
get
43+
{
44+
return string.Format("{0}: {1}x{2} @ {3},{4}{5}", AdapterDescription, Width, Height, Left, Top, IsPrimary ? $" ({ScreenRecorder.Properties.Resources.PrimaryDisplay})" : "");
45+
}
46+
}
4747
}
4848

4949
public sealed class DuplicatorCapture : IDisposable
@@ -113,6 +113,8 @@ static public MonitorInfo[] GetActiveMonitorInfos()
113113
private NV12Converter nv12Converter;
114114

115115
private BitmapTexture cursorTexture;
116+
private Texture2D cursorBackgroundTexture;
117+
private ShaderResourceView cursorBackgroundShaderResourceView;
116118

117119
private SharpDX.Direct3D11.Buffer verticesBuffer;
118120
private VertexBufferBinding vertextBufferBinding;
@@ -343,6 +345,11 @@ private class PointerInfo
343345
public bool Visible;
344346
public int BufferSize;
345347
public long LastTimeStamp;
348+
349+
public int Left { get => Position.X; }
350+
public int Top { get => Position.Y; }
351+
public int Right { get => (Position.X + ShapeInfo.Width); }
352+
public int Bottom { get => (Position.Y + ShapeInfo.Height); }
346353
}
347354

348355
public bool AcquireNextFrame(out IntPtr dataPointer, out int width, out int height, out int stride, out MediaEncoder.PixelFormat pixelFormat)
@@ -370,77 +377,101 @@ public bool AcquireNextFrame(out IntPtr dataPointer, out int width, out int heig
370377
UpdateBuffers(context, (int)destBounds.X, (int)destBounds.Y, (int)destBounds.Width, (int)destBounds.Height);
371378
context.InputAssembler.SetVertexBuffers(0, vertextBufferBinding);
372379
colorShader.Render(context, shaderResourceView);
373-
}
374-
375-
if (duplicateFrameInformation.LastMouseUpdateTime != 0)
376-
{
377-
if (duplicateFrameInformation.PointerPosition.Visible)
378-
{
379-
pointerInfo.Position = new SharpDX.Point((int)((duplicateFrameInformation.PointerPosition.Position.X * destScaleFactor.Width) + destBounds.X), (int)((duplicateFrameInformation.PointerPosition.Position.Y * destScaleFactor.Height) + destBounds.Y));
380-
pointerInfo.LastTimeStamp = duplicateFrameInformation.LastMouseUpdateTime;
381-
pointerInfo.Visible = duplicateFrameInformation.PointerPosition.Visible;
382-
}
383-
else
384-
{
385-
pointerInfo.Visible = false;
386-
}
387380

388-
if (duplicateFrameInformation.PointerShapeBufferSize != 0)
381+
if (duplicateFrameInformation.LastMouseUpdateTime != 0)
389382
{
390-
if (duplicateFrameInformation.PointerShapeBufferSize > pointerInfo.BufferSize)
383+
if (duplicateFrameInformation.PointerPosition.Visible)
384+
{
385+
pointerInfo.Position = new SharpDX.Point((int)((duplicateFrameInformation.PointerPosition.Position.X * destScaleFactor.Width) + destBounds.X), (int)((duplicateFrameInformation.PointerPosition.Position.Y * destScaleFactor.Height) + destBounds.Y));
386+
pointerInfo.LastTimeStamp = duplicateFrameInformation.LastMouseUpdateTime;
387+
pointerInfo.Visible = duplicateFrameInformation.PointerPosition.Visible;
388+
}
389+
else
391390
{
392-
pointerInfo.PtrShapeBuffer = new byte[duplicateFrameInformation.PointerShapeBufferSize];
393-
pointerInfo.BufferSize = duplicateFrameInformation.PointerShapeBufferSize;
391+
pointerInfo.Visible = false;
394392
}
395393

396-
try
394+
if (duplicateFrameInformation.PointerShapeBufferSize != 0)
397395
{
398-
unsafe
396+
if (duplicateFrameInformation.PointerShapeBufferSize > pointerInfo.BufferSize)
399397
{
400-
fixed (byte* ptrShapeBufferPtr = pointerInfo.PtrShapeBuffer)
398+
pointerInfo.PtrShapeBuffer = new byte[duplicateFrameInformation.PointerShapeBufferSize];
399+
pointerInfo.BufferSize = duplicateFrameInformation.PointerShapeBufferSize;
400+
}
401+
402+
try
403+
{
404+
unsafe
401405
{
402-
duplicatedOutput.GetFramePointerShape(duplicateFrameInformation.PointerShapeBufferSize, (IntPtr)ptrShapeBufferPtr, out pointerInfo.BufferSize, out pointerInfo.ShapeInfo);
406+
fixed (byte* ptrShapeBufferPtr = pointerInfo.PtrShapeBuffer)
407+
{
408+
duplicatedOutput.GetFramePointerShape(duplicateFrameInformation.PointerShapeBufferSize, (IntPtr)ptrShapeBufferPtr, out pointerInfo.BufferSize, out pointerInfo.ShapeInfo);
409+
}
403410
}
404411
}
405-
}
406-
catch (SharpDXException ex)
407-
{
408-
if (ex.ResultCode.Failure)
412+
catch (SharpDXException ex)
409413
{
414+
if (ex.ResultCode.Failure)
415+
{
410416

417+
}
411418
}
412419
}
413420
}
414-
}
415-
416-
if (pointerInfo.Visible)
417-
{
418-
if (cursorTexture == null || cursorTexture.TextureWidth != pointerInfo.ShapeInfo.Width || cursorTexture.TextureHeight != pointerInfo.ShapeInfo.Height)
419-
{
420-
cursorTexture?.Dispose();
421-
cursorTexture = new BitmapTexture(device, screenWidth, screenHeight, pointerInfo.ShapeInfo.Width, pointerInfo.ShapeInfo.Height);
422-
}
423421

424-
unsafe
422+
if (pointerInfo.Visible)
425423
{
426-
fixed (byte* ptrShapeBufferPtr = pointerInfo.PtrShapeBuffer)
424+
if (cursorTexture == null || cursorTexture.TextureWidth != pointerInfo.ShapeInfo.Width || cursorTexture.TextureHeight != pointerInfo.ShapeInfo.Height)
427425
{
428-
if (pointerInfo.ShapeInfo.Type == (int)OutputDuplicatePointerShapeType.Monochrome)
426+
cursorTexture?.Dispose();
427+
cursorTexture = new BitmapTexture(device, screenWidth, screenHeight, pointerInfo.ShapeInfo.Width, pointerInfo.ShapeInfo.Height);
428+
429+
cursorBackgroundTexture?.Dispose();
430+
cursorBackgroundTexture = new Texture2D(device, new Texture2DDescription()
429431
{
430-
cursorTexture.SetMonochromeTexture(new IntPtr(ptrShapeBufferPtr), pointerInfo.ShapeInfo.Width, pointerInfo.ShapeInfo.Height, pointerInfo.ShapeInfo.Pitch);
431-
}
432-
else
432+
Format = displayTexture2D.Description.Format,
433+
Width = pointerInfo.ShapeInfo.Width,
434+
Height = pointerInfo.ShapeInfo.Height,
435+
CpuAccessFlags = CpuAccessFlags.None,
436+
Usage = ResourceUsage.Default,
437+
BindFlags = BindFlags.ShaderResource,
438+
ArraySize = 1,
439+
MipLevels = 1,
440+
OptionFlags = ResourceOptionFlags.None,
441+
SampleDescription = new SampleDescription(1, 0)
442+
});
443+
444+
cursorBackgroundShaderResourceView = new ShaderResourceView(device, cursorBackgroundTexture);
445+
}
446+
447+
if (pointerInfo.ShapeInfo.Type != (int)OutputDuplicatePointerShapeType.Color)
448+
{
449+
context.CopySubresourceRegion(displayTexture2D, 0,
450+
new ResourceRegion(pointerInfo.Left, pointerInfo.Top, 0, pointerInfo.Right, pointerInfo.Bottom, 1),
451+
cursorBackgroundTexture, 0);
452+
}
453+
454+
unsafe
455+
{
456+
fixed (byte* ptrShapeBufferPtr = pointerInfo.PtrShapeBuffer)
433457
{
434-
cursorTexture.SetTexture(new IntPtr(ptrShapeBufferPtr), pointerInfo.ShapeInfo.Pitch, pointerInfo.ShapeInfo.Height);
458+
if (pointerInfo.ShapeInfo.Type == (int)OutputDuplicatePointerShapeType.Monochrome)
459+
{
460+
cursorTexture.SetMonochromeTexture(new IntPtr(ptrShapeBufferPtr), pointerInfo.ShapeInfo.Width, pointerInfo.ShapeInfo.Height, pointerInfo.ShapeInfo.Pitch);
461+
}
462+
else
463+
{
464+
cursorTexture.SetTexture(new IntPtr(ptrShapeBufferPtr), pointerInfo.ShapeInfo.Pitch, pointerInfo.ShapeInfo.Height);
465+
}
435466
}
436467
}
468+
469+
cursorTexture.Render(context, pointerInfo.Position.X, pointerInfo.Position.Y, (int)(pointerInfo.ShapeInfo.Width * destScaleFactor.Width), (int)(pointerInfo.ShapeInfo.Height * destScaleFactor.Height));
470+
cursorShader.Render(context, cursorTexture.GetTexture(), cursorBackgroundShaderResourceView, (OutputDuplicatePointerShapeType)pointerInfo.ShapeInfo.Type);
437471
}
438472

439-
cursorTexture.Render(context, pointerInfo.Position.X, pointerInfo.Position.Y, (int)(pointerInfo.ShapeInfo.Width * destScaleFactor.Width), (int)(pointerInfo.ShapeInfo.Height * destScaleFactor.Height));
440-
cursorShader.Render(context, cursorTexture.GetTexture(), (OutputDuplicatePointerShapeType)pointerInfo.ShapeInfo.Type);
473+
nv12Converter.Convert(renderTargetTexture, nv12Texture);
441474
}
442-
443-
nv12Converter.Convert(renderTargetTexture, nv12Texture);
444475
}
445476
else
446477
{
@@ -511,6 +542,12 @@ public void Dispose()
511542
cursorTexture?.Dispose();
512543
cursorTexture = null;
513544

545+
cursorBackgroundShaderResourceView?.Dispose();
546+
cursorBackgroundShaderResourceView = null;
547+
548+
cursorBackgroundTexture?.Dispose();
549+
cursorBackgroundTexture = null;
550+
514551
cursorShader?.Dispose();
515552
cursorShader = null;
516553

ScreenRecorder/DirectX/Shader/CursorShader.cs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ public class CursorShader : IDisposable
1010
private readonly string shaderCode =
1111
@"
1212
Texture2D Texture : register(t0);
13+
Texture2D BackgroundTexture : register(t1);
1314
SamplerState TextureSampler;
1415
1516
cbuffer ShaderArgs
1617
{
1718
int outputDuplicatePointerShapeType;
19+
float4 cursorPositionInBackground;
1820
};
1921
2022
struct VSInput
@@ -42,7 +44,14 @@ float4 PShader(PSInput input) : SV_Target
4244
float4 color = Texture.Sample(TextureSampler, input.uv);
4345
if(outputDuplicatePointerShapeType == 4)
4446
{
45-
color.a = color.a == 0.0 ? 1.0 : 0.0;
47+
color.a = 1.0 - color.a;
48+
}
49+
else if(outputDuplicatePointerShapeType == 1)
50+
{
51+
if(color.a > 0)
52+
{
53+
color = float4(1.0 - BackgroundTexture.Sample(TextureSampler, input.uv).rgb, 1.0);
54+
}
4655
}
4756
return color;
4857
}
@@ -80,7 +89,7 @@ private void InitializeShader(SharpDX.Direct3D11.Device device)
8089

8190
inputLayout = new InputLayout(device, inputSignature, elements);
8291

83-
argsBuffer = new SharpDX.Direct3D11.Buffer(device, 16, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
92+
argsBuffer = new SharpDX.Direct3D11.Buffer(device, 32, ResourceUsage.Dynamic, BindFlags.ConstantBuffer, CpuAccessFlags.Write, ResourceOptionFlags.None, 0);
8493

8594
samplerState = new SamplerState(device, new SamplerStateDescription()
8695
{
@@ -97,17 +106,19 @@ private void InitializeShader(SharpDX.Direct3D11.Device device)
97106
});
98107
}
99108

100-
public void Render(DeviceContext deviceContext, ShaderResourceView shaderResourceView, OutputDuplicatePointerShapeType outputDuplicatePointerShapeType)
109+
public void Render(DeviceContext deviceContext, ShaderResourceView cursorShaderResourceView, ShaderResourceView backgroundShaderResourceView, OutputDuplicatePointerShapeType outputDuplicatePointerShapeType)
101110
{
102-
SetShaderParameters(deviceContext, shaderResourceView, outputDuplicatePointerShapeType);
111+
SetShaderParameters(deviceContext, cursorShaderResourceView, backgroundShaderResourceView, outputDuplicatePointerShapeType);
103112
RenderShader(deviceContext);
104113

105-
if (shaderResourceView != null)
114+
if (cursorShaderResourceView != null)
106115
deviceContext.PixelShader.SetShaderResource(0, null);
116+
if (backgroundShaderResourceView != null)
117+
deviceContext.PixelShader.SetShaderResource(1, null);
107118
}
108119

109120
private int oldOutputDuplicatePointerShapeType = -1;
110-
private void SetShaderParameters(DeviceContext deviceContext, ShaderResourceView shaderResourceView, OutputDuplicatePointerShapeType outputDuplicatePointerShapeType)
121+
private void SetShaderParameters(DeviceContext deviceContext, ShaderResourceView cursorShaderResourceView, ShaderResourceView backgroundShaderResourceView, OutputDuplicatePointerShapeType outputDuplicatePointerShapeType)
111122
{
112123
if (oldOutputDuplicatePointerShapeType != (int)outputDuplicatePointerShapeType)
113124
{
@@ -119,7 +130,11 @@ private void SetShaderParameters(DeviceContext deviceContext, ShaderResourceView
119130
}
120131

121132
deviceContext.PixelShader.SetConstantBuffer(0, argsBuffer);
122-
deviceContext.PixelShader.SetShaderResource(0, shaderResourceView);
133+
134+
if (cursorShaderResourceView != null)
135+
deviceContext.PixelShader.SetShaderResource(0, cursorShaderResourceView);
136+
if (backgroundShaderResourceView != null)
137+
deviceContext.PixelShader.SetShaderResource(1, backgroundShaderResourceView);
123138
}
124139

125140
private void RenderShader(DeviceContext deviceContext)

ScreenRecorder/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,5 +49,5 @@
4949
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
5050
// 기본값으로 할 수 있습니다.
5151
// [assembly: AssemblyVersion("1.0.*")]
52-
[assembly: AssemblyVersion("1.0.7.0")]
53-
[assembly: AssemblyFileVersion("1.0.7.0")]
52+
[assembly: AssemblyVersion("1.0.8.0")]
53+
[assembly: AssemblyFileVersion("1.0.8.0")]

ScreenRecorder/VideoSource/ScreenVideoSource.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private void WorkerThreadHandler(object argument)
7979
}
8080
}
8181
}
82-
catch
82+
catch(Exception ex)
8383
{
8484
if (needToStop.WaitOne(1000, false))
8585
break;

0 commit comments

Comments
 (0)