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