Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(682)

Side by Side Diff: webrtc/modules/desktop_capture/win/d3d_device.cc

Issue 2099123002: [Chromoting] Improve DirectX capturer to support multiple outputs (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Resolve review comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "webrtc/modules/desktop_capture/win/d3d_device.h"
12
13 #include <utility>
14
15 #include "webrtc/system_wrappers/include/logging.h"
16
17 namespace webrtc {
18
19 using Microsoft::WRL::ComPtr;
20
21 D3dDevice::D3dDevice() = default;
22 D3dDevice::~D3dDevice() = default;
23
24 bool D3dDevice::Initialize(const ComPtr<IDXGIAdapter>& adapter) {
25 dxgi_adapter_ = adapter;
26 if (!dxgi_adapter_) {
27 LOG(LS_WARNING) << "An empty IDXGIAdapter instance has been received.";
28 return false;
29 }
30
31 D3D_FEATURE_LEVEL feature_level;
32 _com_error error = D3D11CreateDevice(
33 adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr,
34 D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_SINGLETHREADED,
35 nullptr, 0, D3D11_SDK_VERSION, d3d_device_.GetAddressOf(), &feature_level,
36 context_.GetAddressOf());
37 if (error.Error() != S_OK || !d3d_device_ || !context_) {
38 LOG(LS_WARNING) << "D3D11CreateDeivce returns error "
39 << error.ErrorMessage() << " with code " << error.Error();
40 return false;
41 }
42
43 if (feature_level < D3D_FEATURE_LEVEL_11_0) {
44 LOG(LS_WARNING) << "D3D11CreateDevice returns an instance without DirectX "
45 "11 support, level "
46 << feature_level;
47 return false;
48 }
49
50 error = _com_error(d3d_device_.As(&dxgi_device_));
51 if (error.Error() != S_OK || !dxgi_device_) {
52 LOG(LS_WARNING) << "ID3D11Device is not an implementation of IDXGIDevice, "
53 "this usually means the system does not support DirectX "
54 "11";
55 return false;
56 }
57
58 return true;
59 }
60
61 // static
62 std::vector<D3dDevice> D3dDevice::EnumDevices() {
63 ComPtr<IDXGIFactory1> factory;
64 _com_error error = _com_error(CreateDXGIFactory1(__uuidof(IDXGIFactory1),
65 reinterpret_cast<void**>(factory.GetAddressOf())));
66 if (error.Error() != S_OK || !factory) {
67 return std::vector<D3dDevice>();
68 }
69
70 std::vector<D3dDevice> result;
71 for (int i = 0;; i++) {
72 ComPtr<IDXGIAdapter> adapter;
73 error = _com_error(factory->EnumAdapters(i, adapter.GetAddressOf()));
74 if (error.Error() == S_OK) {
75 D3dDevice device;
76 if (!device.Initialize(adapter)) {
77 return std::vector<D3dDevice>();
78 }
79 result.push_back(std::move(device));
80 } else if (error.Error() == DXGI_ERROR_NOT_FOUND) {
81 break;
82 } else {
83 LOG(LS_WARNING) << "IDXGIFactory1::EnumAdapters returns an unexpected "
84 "error " << error.ErrorMessage() << " with code "
85 << error.Error();
86 return std::vector<D3dDevice>();
87 }
88 }
89 return result;
90 }
91
92 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698