@@ -38,12 +38,12 @@ public int Height
38
38
}
39
39
40
40
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
+ }
47
47
}
48
48
49
49
public sealed class DuplicatorCapture : IDisposable
@@ -113,6 +113,8 @@ static public MonitorInfo[] GetActiveMonitorInfos()
113
113
private NV12Converter nv12Converter ;
114
114
115
115
private BitmapTexture cursorTexture ;
116
+ private Texture2D cursorBackgroundTexture ;
117
+ private ShaderResourceView cursorBackgroundShaderResourceView ;
116
118
117
119
private SharpDX . Direct3D11 . Buffer verticesBuffer ;
118
120
private VertexBufferBinding vertextBufferBinding ;
@@ -343,6 +345,11 @@ private class PointerInfo
343
345
public bool Visible ;
344
346
public int BufferSize ;
345
347
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 ) ; }
346
353
}
347
354
348
355
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
370
377
UpdateBuffers ( context , ( int ) destBounds . X , ( int ) destBounds . Y , ( int ) destBounds . Width , ( int ) destBounds . Height ) ;
371
378
context . InputAssembler . SetVertexBuffers ( 0 , vertextBufferBinding ) ;
372
379
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
- }
387
380
388
- if ( duplicateFrameInformation . PointerShapeBufferSize != 0 )
381
+ if ( duplicateFrameInformation . LastMouseUpdateTime != 0 )
389
382
{
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
391
390
{
392
- pointerInfo . PtrShapeBuffer = new byte [ duplicateFrameInformation . PointerShapeBufferSize ] ;
393
- pointerInfo . BufferSize = duplicateFrameInformation . PointerShapeBufferSize ;
391
+ pointerInfo . Visible = false ;
394
392
}
395
393
396
- try
394
+ if ( duplicateFrameInformation . PointerShapeBufferSize != 0 )
397
395
{
398
- unsafe
396
+ if ( duplicateFrameInformation . PointerShapeBufferSize > pointerInfo . BufferSize )
399
397
{
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
401
405
{
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
+ }
403
410
}
404
411
}
405
- }
406
- catch ( SharpDXException ex )
407
- {
408
- if ( ex . ResultCode . Failure )
412
+ catch ( SharpDXException ex )
409
413
{
414
+ if ( ex . ResultCode . Failure )
415
+ {
410
416
417
+ }
411
418
}
412
419
}
413
420
}
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
- }
423
421
424
- unsafe
422
+ if ( pointerInfo . Visible )
425
423
{
426
- fixed ( byte * ptrShapeBufferPtr = pointerInfo . PtrShapeBuffer )
424
+ if ( cursorTexture == null || cursorTexture . TextureWidth ! = pointerInfo . ShapeInfo . Width || cursorTexture . TextureHeight != pointerInfo . ShapeInfo . Height )
427
425
{
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 ( )
429
431
{
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 )
433
457
{
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
+ }
435
466
}
436
467
}
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 ) ;
437
471
}
438
472
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 ) ;
441
474
}
442
-
443
- nv12Converter . Convert ( renderTargetTexture , nv12Texture ) ;
444
475
}
445
476
else
446
477
{
@@ -511,6 +542,12 @@ public void Dispose()
511
542
cursorTexture ? . Dispose ( ) ;
512
543
cursorTexture = null ;
513
544
545
+ cursorBackgroundShaderResourceView ? . Dispose ( ) ;
546
+ cursorBackgroundShaderResourceView = null ;
547
+
548
+ cursorBackgroundTexture ? . Dispose ( ) ;
549
+ cursorBackgroundTexture = null ;
550
+
514
551
cursorShader ? . Dispose ( ) ;
515
552
cursorShader = null ;
516
553
0 commit comments