dxgi_texture_mapping.cc (1767B)
1 /* 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/desktop_capture/win/dxgi_texture_mapping.h" 12 13 #include <comdef.h> 14 #include <d3d11.h> 15 #include <dxgi.h> 16 #include <dxgi1_2.h> 17 #include <winerror.h> 18 19 #include "modules/desktop_capture/win/desktop_capture_utils.h" 20 #include "rtc_base/checks.h" 21 #include "rtc_base/logging.h" 22 23 namespace webrtc { 24 25 DxgiTextureMapping::DxgiTextureMapping(IDXGIOutputDuplication* duplication) 26 : duplication_(duplication) { 27 RTC_DCHECK(duplication_); 28 } 29 30 DxgiTextureMapping::~DxgiTextureMapping() = default; 31 32 bool DxgiTextureMapping::CopyFromTexture( 33 const DXGI_OUTDUPL_FRAME_INFO& frame_info, 34 ID3D11Texture2D* texture) { 35 RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0); 36 RTC_DCHECK(texture); 37 *rect() = {0}; 38 _com_error error = duplication_->MapDesktopSurface(rect()); 39 if (error.Error() != S_OK) { 40 *rect() = {0}; 41 RTC_LOG(LS_ERROR) 42 << "Failed to map the IDXGIOutputDuplication to a bitmap: " 43 << desktop_capture::utils::ComErrorToString(error); 44 return false; 45 } 46 47 return true; 48 } 49 50 bool DxgiTextureMapping::DoRelease() { 51 _com_error error = duplication_->UnMapDesktopSurface(); 52 if (error.Error() != S_OK) { 53 RTC_LOG(LS_ERROR) << "Failed to unmap the IDXGIOutputDuplication: " 54 << desktop_capture::utils::ComErrorToString(error); 55 return false; 56 } 57 return true; 58 } 59 60 } // namespace webrtc