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 <dxgi.h> 15 #include <dxgi1_2.h> 16 17 #include "modules/desktop_capture/win/desktop_capture_utils.h" 18 #include "rtc_base/checks.h" 19 #include "rtc_base/logging.h" 20 21 namespace webrtc { 22 DxgiTextureMapping(IDXGIOutputDuplication * duplication)23DxgiTextureMapping::DxgiTextureMapping(IDXGIOutputDuplication* duplication) 24 : duplication_(duplication) { 25 RTC_DCHECK(duplication_); 26 } 27 28 DxgiTextureMapping::~DxgiTextureMapping() = default; 29 CopyFromTexture(const DXGI_OUTDUPL_FRAME_INFO & frame_info,ID3D11Texture2D * texture)30bool DxgiTextureMapping::CopyFromTexture( 31 const DXGI_OUTDUPL_FRAME_INFO& frame_info, 32 ID3D11Texture2D* texture) { 33 RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0); 34 RTC_DCHECK(texture); 35 *rect() = {0}; 36 _com_error error = duplication_->MapDesktopSurface(rect()); 37 if (error.Error() != S_OK) { 38 *rect() = {0}; 39 RTC_LOG(LS_ERROR) 40 << "Failed to map the IDXGIOutputDuplication to a bitmap: " 41 << desktop_capture::utils::ComErrorToString(error); 42 return false; 43 } 44 45 return true; 46 } 47 DoRelease()48bool DxgiTextureMapping::DoRelease() { 49 _com_error error = duplication_->UnMapDesktopSurface(); 50 if (error.Error() != S_OK) { 51 RTC_LOG(LS_ERROR) << "Failed to unmap the IDXGIOutputDuplication: " 52 << desktop_capture::utils::ComErrorToString(error); 53 return false; 54 } 55 return true; 56 } 57 58 } // namespace webrtc 59