@@ -314,7 +314,9 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
314
314
_multiMonitor = (selectedDeviceName == multiName);
315
315
316
316
IDXGIOutput* pOutput;
317
- for (UINT j = 0 ; pAdapter->EnumOutputs (j, &pOutput) != DXGI_ERROR_NOT_FOUND && (!exitNow || _multiMonitor); j++)
317
+
318
+
319
+ for (UINT j = 0 ; pAdapter->EnumOutputs (j, &pOutput) != DXGI_ERROR_NOT_FOUND && (!exitNow || (_multiMonitor && result)); j++)
318
320
{
319
321
DXGI_OUTPUT_DESC oDesc{};
320
322
pOutput->GetDesc (&oDesc);
@@ -329,38 +331,46 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
329
331
330
332
if (CHECK (pOutput->QueryInterface (__uuidof (IDXGIOutput6), reinterpret_cast <void **>(&pOutput6))))
331
333
{
332
- HRESULT findDriver = E_FAIL;
333
- D3D_FEATURE_LEVEL featureLevel;
334
- std::vector<D3D_DRIVER_TYPE> driverTypes{
335
- D3D_DRIVER_TYPE_HARDWARE,
336
- D3D_DRIVER_TYPE_WARP,
337
- D3D_DRIVER_TYPE_REFERENCE,
338
- D3D_DRIVER_TYPE_UNKNOWN
339
- };
340
-
341
- CLEAR (featureLevel);
342
-
343
- for (auto & driverType : driverTypes)
334
+ if (_d3dDevice == nullptr )
344
335
{
345
- findDriver = D3D11CreateDevice (pAdapter, driverType,
346
- nullptr , D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr , 0 ,
347
- D3D11_SDK_VERSION, &_d3dDevice, &featureLevel, &_d3dContext);
348
-
349
- if (SUCCEEDED (findDriver))
336
+ HRESULT findDriver = E_FAIL;
337
+ D3D_FEATURE_LEVEL featureLevel;
338
+ std::vector<D3D_DRIVER_TYPE> driverTypes{
339
+ D3D_DRIVER_TYPE_HARDWARE,
340
+ D3D_DRIVER_TYPE_WARP,
341
+ D3D_DRIVER_TYPE_REFERENCE,
342
+ D3D_DRIVER_TYPE_UNKNOWN
343
+ };
344
+
345
+ CLEAR (featureLevel);
346
+
347
+ for (auto & driverType : driverTypes)
350
348
{
351
- switch (driverType)
349
+ findDriver = D3D11CreateDevice (pAdapter, driverType,
350
+ nullptr , D3D11_CREATE_DEVICE_BGRA_SUPPORT, nullptr , 0 ,
351
+ D3D11_SDK_VERSION, &_d3dDevice, &featureLevel, &_d3dContext);
352
+
353
+ if (SUCCEEDED (findDriver))
352
354
{
353
- case D3D_DRIVER_TYPE_HARDWARE: Info (_log, " Selected D3D_DRIVER_TYPE_HARDWARE" ); break ;
354
- case D3D_DRIVER_TYPE_WARP: Info (_log, " Selected D3D_DRIVER_TYPE_WARP" ); break ;
355
- case D3D_DRIVER_TYPE_REFERENCE: Info (_log, " Selected D3D_DRIVER_TYPE_REFERENCE" ); break ;
356
- case D3D_DRIVER_TYPE_UNKNOWN: Info (_log, " Selected D3D_DRIVER_TYPE_UNKNOWN" ); break ;
355
+ switch (driverType)
356
+ {
357
+ case D3D_DRIVER_TYPE_HARDWARE: Info (_log, " Selected D3D_DRIVER_TYPE_HARDWARE" ); break ;
358
+ case D3D_DRIVER_TYPE_WARP: Info (_log, " Selected D3D_DRIVER_TYPE_WARP" ); break ;
359
+ case D3D_DRIVER_TYPE_REFERENCE: Info (_log, " Selected D3D_DRIVER_TYPE_REFERENCE" ); break ;
360
+ case D3D_DRIVER_TYPE_UNKNOWN: Info (_log, " Selected D3D_DRIVER_TYPE_UNKNOWN" ); break ;
361
+ }
362
+
363
+ break ;
357
364
}
365
+ }
358
366
359
- break ;
367
+ if (!SUCCEEDED (findDriver))
368
+ {
369
+ _d3dContext = nullptr ;
360
370
}
361
371
}
362
372
363
- if (CHECK (findDriver) && _d3dDevice != nullptr )
373
+ if (_d3dDevice != nullptr )
364
374
{
365
375
HRESULT status = E_FAIL;
366
376
DXGI_OUTPUT_DESC1 descGamut;
@@ -420,7 +430,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
420
430
421
431
if (!display->wideGamut )
422
432
{
423
- int maxSize = std::max (( display->actualWidth - _cropLeft - _cropRight), ( display->actualHeight - _cropTop - _cropBottom) );
433
+ int maxSize = std::max (display->actualWidth , display->actualHeight );
424
434
425
435
display->actualDivide = 0 ;
426
436
while (maxSize > _width)
@@ -435,7 +445,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
435
445
else
436
446
{
437
447
display->actualDivide = -1 ;
438
- getTargetSystemFrameDimension (targetSizeX, targetSizeY);
448
+ getTargetSystemFrameDimension (display-> actualWidth , display-> actualHeight , targetSizeX, targetSizeY);
439
449
}
440
450
}
441
451
@@ -479,6 +489,7 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
479
489
else
480
490
{
481
491
result = true ;
492
+ _handles.emplace_back (std::move (display));
482
493
Info (_log, " The DX11 device has been initialized. Hardware acceleration is disabled" );
483
494
}
484
495
}
@@ -517,6 +528,11 @@ bool DxGrabber::initDirectX(QString selectedDeviceName)
517
528
518
529
SafeRelease (&pFactory);
519
530
531
+ if (!result && _handles.size () > 0 )
532
+ {
533
+ uninit ();
534
+ }
535
+
520
536
return result;
521
537
}
522
538
@@ -760,8 +776,11 @@ void DxGrabber::grabFrame()
760
776
images.push_back (std::pair<int , Image<ColorRgb>>(width, image));
761
777
}
762
778
763
- width += display->actualWidth ;
764
- height = std::max (display->actualHeight , height);
779
+ int targetSizeX = 0 , targetSizeY = 0 ;
780
+ int divide = getTargetSystemFrameDimension (display->actualWidth , display->actualHeight , targetSizeX, targetSizeY);
781
+
782
+ width += targetSizeX;
783
+ height = std::max (targetSizeY, height);
765
784
}
766
785
767
786
if (useCache && (_cacheImage.width () != width || _cacheImage.height () != height))
@@ -911,7 +930,7 @@ int DxGrabber::captureFrame(DisplayHandle& display, Image<ColorRgb>& image)
911
930
int divide = getTargetSystemFrameDimension (display.actualWidth , display.actualHeight , targetSizeX, targetSizeY);
912
931
913
932
image = Image<ColorRgb>(targetSizeX, targetSizeY);
914
- FrameDecoder::processSystemImageBGRA (image, targetSizeX, targetSizeY, _cropLeft, _cropTop , (uint8_t *)internalMap.pData , display.actualWidth , display.actualHeight , divide, (_hdrToneMappingEnabled == 0 || !_lutBufferInit || !useLut) ? nullptr : _lut.data (), lineSize);
933
+ FrameDecoder::processSystemImageBGRA (image, targetSizeX, targetSizeY, 0 , 0 , (uint8_t *)internalMap.pData , display.actualWidth , display.actualHeight , divide, (_hdrToneMappingEnabled == 0 || !_lutBufferInit || !useLut) ? nullptr : _lut.data (), lineSize);
915
934
916
935
result = 1 ;
917
936
_d3dContext->Unmap (display.d3dSourceTexture , 0 );
0 commit comments