diff --git a/webrtc/modules/desktop_capture/win/d3d_device.cc b/webrtc/modules/desktop_capture/win/d3d_device.cc index 15233e6f5e..f7c419f891 100644 --- a/webrtc/modules/desktop_capture/win/d3d_device.cc +++ b/webrtc/modules/desktop_capture/win/d3d_device.cc @@ -47,7 +47,7 @@ bool D3dDevice::Initialize(const ComPtr& adapter) { return false; } - error = _com_error(d3d_device_.As(&dxgi_device_)); + error = d3d_device_.As(&dxgi_device_); if (error.Error() != S_OK || !dxgi_device_) { LOG(LS_WARNING) << "ID3D11Device is not an implementation of IDXGIDevice, " "this usually means the system does not support DirectX " @@ -61,9 +61,8 @@ bool D3dDevice::Initialize(const ComPtr& adapter) { // static std::vector D3dDevice::EnumDevices() { ComPtr factory; - _com_error error = _com_error( - CreateDXGIFactory1(__uuidof(IDXGIFactory1), - reinterpret_cast(factory.GetAddressOf()))); + _com_error error = CreateDXGIFactory1(__uuidof(IDXGIFactory1), + reinterpret_cast(factory.GetAddressOf())); if (error.Error() != S_OK || !factory) { return std::vector(); } @@ -71,7 +70,7 @@ std::vector D3dDevice::EnumDevices() { std::vector result; for (int i = 0;; i++) { ComPtr adapter; - error = _com_error(factory->EnumAdapters(i, adapter.GetAddressOf())); + error = factory->EnumAdapters(i, adapter.GetAddressOf()); if (error.Error() == S_OK) { D3dDevice device; if (!device.Initialize(adapter)) { diff --git a/webrtc/modules/desktop_capture/win/d3d_device.h b/webrtc/modules/desktop_capture/win/d3d_device.h index 94a263edcb..fc1533a522 100644 --- a/webrtc/modules/desktop_capture/win/d3d_device.h +++ b/webrtc/modules/desktop_capture/win/d3d_device.h @@ -43,7 +43,7 @@ class D3dDevice { // function. D3dDevice(); - // Initialize the D3dDevice from an IDXGIAdapter. + // Initializes the D3dDevice from an IDXGIAdapter. bool Initialize(const Microsoft::WRL::ComPtr& adapter); Microsoft::WRL::ComPtr d3d_device_; diff --git a/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc b/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc index 1b822161d0..46d4e89652 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_adapter_duplicator.cc @@ -62,11 +62,11 @@ bool DxgiAdapterDuplicator::DoInitialize() { } DXGI_OUTPUT_DESC desc; - error = _com_error(output->GetDesc(&desc)); + error = output->GetDesc(&desc); if (error.Error() == S_OK) { if (desc.AttachedToDesktop && IsValidRect(desc.DesktopCoordinates)) { ComPtr output1; - error = _com_error(output.As(&output1)); + error = output.As(&output1); if (error.Error() != S_OK || !output1) { LOG(LS_WARNING) << "Failed to convert IDXGIOutput to IDXGIOutput1, " "this usually means the system does not support " diff --git a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc index d7eb335fc3..b17c195340 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.cc @@ -147,7 +147,9 @@ bool DxgiOutputDuplicator::Duplicate(Context* context, // after it has been merged to updated_region. DesktopRegion updated_region; updated_region.Swap(&context->updated_region); - if (error.Error() == S_OK && frame_info.AccumulatedFrames > 0) { + if (error.Error() == S_OK && + frame_info.AccumulatedFrames > 0 && + resource) { DetectUpdatedRegion(frame_info, offset, &context->updated_region); if (!texture_->CopyFrom(frame_info, resource.Get(), context->updated_region)) { @@ -224,8 +226,8 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion( DXGI_OUTDUPL_MOVE_RECT* move_rects = reinterpret_cast(metadata.data()); size_t move_rects_count = 0; - _com_error error = _com_error(duplication_->GetFrameMoveRects( - static_cast(metadata.capacity()), move_rects, &buff_size)); + _com_error error = duplication_->GetFrameMoveRects( + static_cast(metadata.capacity()), move_rects, &buff_size); if (error.Error() != S_OK) { LOG(LS_ERROR) << "Failed to get move rectangles, error " << error.ErrorMessage() << ", code " << error.Error(); @@ -235,9 +237,9 @@ bool DxgiOutputDuplicator::DoDetectUpdatedRegion( RECT* dirty_rects = reinterpret_cast(metadata.data() + buff_size); size_t dirty_rects_count = 0; - error = _com_error(duplication_->GetFrameDirtyRects( + error = duplication_->GetFrameDirtyRects( static_cast(metadata.capacity()) - buff_size, dirty_rects, - &buff_size)); + &buff_size); if (error.Error() != S_OK) { LOG(LS_ERROR) << "Failed to get dirty rectangles, error " << error.ErrorMessage() << ", code " << error.Error(); diff --git a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h index 020ca640ed..0d5b134796 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h +++ b/webrtc/modules/desktop_capture/win/dxgi_output_duplicator.h @@ -111,7 +111,7 @@ class DxgiOutputDuplicator { // Returns a DesktopRect in the coordinate of |offset|. DesktopRect TargetRect(DesktopRect rect, DesktopVector offset); - const D3dDevice& device_; + const D3dDevice device_; const Microsoft::WRL::ComPtr output_; const DesktopRect desktop_rect_; Microsoft::WRL::ComPtr duplication_; diff --git a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc index 7478728143..6866d1e4c6 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc +++ b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.cc @@ -38,9 +38,13 @@ bool DxgiTextureStaging::InitializeStage(ID3D11Texture2D* texture) { return false; } + desc.ArraySize = 1; desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; + desc.MipLevels = 1; desc.MiscFlags = 0; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; desc.Usage = D3D11_USAGE_STAGING; if (stage_) { AssertStageAndSurfaceAreSameObject(); @@ -58,15 +62,15 @@ bool DxgiTextureStaging::InitializeStage(ID3D11Texture2D* texture) { RTC_DCHECK(!surface_); } - _com_error error = _com_error(device_.d3d_device()->CreateTexture2D( - &desc, nullptr, stage_.GetAddressOf())); + _com_error error = device_.d3d_device()->CreateTexture2D( + &desc, nullptr, stage_.GetAddressOf()); if (error.Error() != S_OK || !stage_) { LOG(LS_ERROR) << "Failed to create a new ID3D11Texture2D as stage, error " << error.ErrorMessage() << ", code " << error.Error(); return false; } - error = _com_error(stage_.As(&surface_)); + error = stage_.As(&surface_); if (error.Error() != S_OK || !surface_) { LOG(LS_ERROR) << "Failed to convert ID3D11Texture2D to IDXGISurface, error " << error.ErrorMessage() << ", code " << error.Error(); @@ -123,7 +127,7 @@ bool DxgiTextureStaging::CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, } rect_ = {0}; - error = _com_error(surface_->Map(&rect_, DXGI_MAP_READ)); + error = surface_->Map(&rect_, DXGI_MAP_READ); if (error.Error() != S_OK) { rect_ = {0}; LOG(LS_ERROR) << "Failed to map the IDXGISurface to a bitmap, error " @@ -135,7 +139,7 @@ bool DxgiTextureStaging::CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, } bool DxgiTextureStaging::DoRelease() { - _com_error error = _com_error(surface_->Unmap()); + _com_error error = surface_->Unmap(); if (error.Error() != S_OK) { stage_.Reset(); surface_.Reset(); diff --git a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.h b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.h index 2da1600122..47f75fa8c1 100644 --- a/webrtc/modules/desktop_capture/win/dxgi_texture_staging.h +++ b/webrtc/modules/desktop_capture/win/dxgi_texture_staging.h @@ -58,7 +58,7 @@ class DxgiTextureStaging : public DxgiTexture { void AssertStageAndSurfaceAreSameObject(); const DesktopRect desktop_rect_; - const D3dDevice& device_; + const D3dDevice device_; Microsoft::WRL::ComPtr stage_; Microsoft::WRL::ComPtr surface_; };