OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" | 11 #include "webrtc/modules/desktop_capture/win/dxgi_texture.h" |
12 | 12 |
13 #include <comdef.h> | 13 #include <comdef.h> |
14 #include <wrl/client.h> | 14 #include <wrl/client.h> |
15 #include <D3D11.h> | 15 #include <D3D11.h> |
16 | 16 |
17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
18 #include "webrtc/modules/desktop_capture/desktop_region.h" | 18 #include "webrtc/modules/desktop_capture/desktop_region.h" |
19 #include "webrtc/system_wrappers/include/logging.h" | |
20 | 19 |
21 using Microsoft::WRL::ComPtr; | 20 using Microsoft::WRL::ComPtr; |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 class DxgiDesktopFrame : public DesktopFrame { | 26 class DxgiDesktopFrame : public DesktopFrame { |
28 public: | 27 public: |
29 explicit DxgiDesktopFrame(const DxgiTexture& texture) | 28 explicit DxgiDesktopFrame(const DxgiTexture& texture) |
(...skipping 11 matching lines...) Expand all Loading... |
41 DxgiTexture::~DxgiTexture() = default; | 40 DxgiTexture::~DxgiTexture() = default; |
42 | 41 |
43 bool DxgiTexture::CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | 42 bool DxgiTexture::CopyFrom(const DXGI_OUTDUPL_FRAME_INFO& frame_info, |
44 IDXGIResource* resource) { | 43 IDXGIResource* resource) { |
45 RTC_DCHECK(resource && frame_info.AccumulatedFrames > 0); | 44 RTC_DCHECK(resource && frame_info.AccumulatedFrames > 0); |
46 ComPtr<ID3D11Texture2D> texture; | 45 ComPtr<ID3D11Texture2D> texture; |
47 _com_error error = resource->QueryInterface( | 46 _com_error error = resource->QueryInterface( |
48 __uuidof(ID3D11Texture2D), | 47 __uuidof(ID3D11Texture2D), |
49 reinterpret_cast<void**>(texture.GetAddressOf())); | 48 reinterpret_cast<void**>(texture.GetAddressOf())); |
50 if (error.Error() != S_OK || !texture) { | 49 if (error.Error() != S_OK || !texture) { |
51 LOG(LS_ERROR) << "Failed to convert IDXGIResource to ID3D11Texture2D, " | |
52 "error " | |
53 << error.ErrorMessage() << ", code " << error.Error(); | |
54 return false; | 50 return false; |
55 } | 51 } |
56 | 52 |
57 D3D11_TEXTURE2D_DESC desc = {0}; | 53 D3D11_TEXTURE2D_DESC desc = {0}; |
58 texture->GetDesc(&desc); | 54 texture->GetDesc(&desc); |
59 desktop_size_.set(desc.Width, desc.Height); | 55 desktop_size_.set(desc.Width, desc.Height); |
60 if (resolution_change_detector_.IsChanged(desktop_size_)) { | 56 if (resolution_change_detector_.IsChanged(desktop_size_)) { |
61 LOG(LS_ERROR) << "Texture size is not consistent with current DxgiTexture."; | |
62 return false; | 57 return false; |
63 } | 58 } |
64 | 59 |
65 return CopyFromTexture(frame_info, texture.Get()); | 60 return CopyFromTexture(frame_info, texture.Get()); |
66 } | 61 } |
67 | 62 |
68 const DesktopFrame& DxgiTexture::AsDesktopFrame() { | 63 const DesktopFrame& DxgiTexture::AsDesktopFrame() { |
69 if (!frame_) { | 64 if (!frame_) { |
70 frame_.reset(new DxgiDesktopFrame(*this)); | 65 frame_.reset(new DxgiDesktopFrame(*this)); |
71 } | 66 } |
72 return *frame_; | 67 return *frame_; |
73 } | 68 } |
74 | 69 |
75 bool DxgiTexture::Release() { | 70 bool DxgiTexture::Release() { |
76 frame_.reset(); | 71 frame_.reset(); |
77 return DoRelease(); | 72 return DoRelease(); |
78 } | 73 } |
79 | 74 |
80 DXGI_MAPPED_RECT* DxgiTexture::rect() { | 75 DXGI_MAPPED_RECT* DxgiTexture::rect() { |
81 return &rect_; | 76 return &rect_; |
82 } | 77 } |
83 | 78 |
84 } // namespace webrtc | 79 } // namespace webrtc |
OLD | NEW |