blob: 66e5e75812aa66a30ce38446f95cbb9ba3309c84 [file] [log] [blame]
zijiehe2d618de2016-08-08 17:50:21 -07001/*
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 "webrtc/modules/desktop_capture/win/dxgi_texture_mapping.h"
12
13#include <comdef.h>
14#include <DXGI.h>
15#include <DXGI1_2.h>
16
Edward Lemurc20978e2017-07-06 19:44:34 +020017#include "webrtc/rtc_base/checks.h"
18#include "webrtc/rtc_base/logging.h"
zijiehe2d618de2016-08-08 17:50:21 -070019
20namespace webrtc {
21
zijiehe5fea5fb2017-02-16 12:07:44 -080022DxgiTextureMapping::DxgiTextureMapping(IDXGIOutputDuplication* duplication)
23 : duplication_(duplication) {
zijiehe2d618de2016-08-08 17:50:21 -070024 RTC_DCHECK(duplication_);
25}
26
27DxgiTextureMapping::~DxgiTextureMapping() = default;
28
zijiehe5fea5fb2017-02-16 12:07:44 -080029bool DxgiTextureMapping::CopyFromTexture(
30 const DXGI_OUTDUPL_FRAME_INFO& frame_info,
31 ID3D11Texture2D* texture) {
kwibergee89e782017-08-09 17:22:01 -070032 RTC_DCHECK_GT(frame_info.AccumulatedFrames, 0);
33 RTC_DCHECK(texture);
zijiehe5fea5fb2017-02-16 12:07:44 -080034 *rect() = {0};
35 _com_error error = duplication_->MapDesktopSurface(rect());
zijiehe2d618de2016-08-08 17:50:21 -070036 if (error.Error() != S_OK) {
zijiehe5fea5fb2017-02-16 12:07:44 -080037 *rect() = {0};
zijiehe2d618de2016-08-08 17:50:21 -070038 LOG(LS_ERROR) << "Failed to map the IDXGIOutputDuplication to a bitmap, "
39 "error "
40 << error.ErrorMessage() << ", code " << error.Error();
41 return false;
42 }
43
44 return true;
45}
46
47bool DxgiTextureMapping::DoRelease() {
48 _com_error error = duplication_->UnMapDesktopSurface();
49 if (error.Error() != S_OK) {
50 LOG(LS_ERROR) << "Failed to unmap the IDXGIOutputDuplication, error "
51 << error.ErrorMessage() << ", code " << error.Error();
52 return false;
53 }
54 return true;
55}
56
57} // namespace webrtc