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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: webrtc/modules/desktop_capture/win/d3d_device.cc
diff --git a/webrtc/modules/desktop_capture/win/d3d_device.cc b/webrtc/modules/desktop_capture/win/d3d_device.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d5d3d05e32e5099eab0cb0438809e782c3ad7b31
--- /dev/null
+++ b/webrtc/modules/desktop_capture/win/d3d_device.cc
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "webrtc/modules/desktop_capture/win/d3d_device.h"
+
+#include "webrtc/system_wrappers/include/logging.h"
+
+namespace webrtc {
+
+using Microsoft::WRL::ComPtr;
+
+bool D3dDevice::Initialize(const ComPtr<IDXGIAdapter>& adapter) {
+ dxgi_adapter_ = adapter;
+ if (!dxgi_adapter_) {
+ LOG(LS_WARNING) << "An empty IDXGIAdapter instance has been received.";
+ return false;
+ }
+
+ D3D_FEATURE_LEVEL feature_level;
+ _com_error error = D3D11CreateDevice(
+ adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr,
+ D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_SINGLETHREADED,
+ nullptr, 0, D3D11_SDK_VERSION, d3d_device_.GetAddressOf(), &feature_level,
+ context_.GetAddressOf());
+ if (error.Error() != S_OK || !d3d_device_ || !context_) {
+ LOG(LS_WARNING) << "D3D11CreateDeivce returns error "
+ << error.ErrorMessage() << " with code " << error.Error();
+ return false;
+ }
+
+ if (feature_level < D3D_FEATURE_LEVEL_11_0) {
+ LOG(LS_WARNING) << "D3D11CreateDevice returns an instance without DirectX "
+ "11 support, level "
+ << feature_level;
+ return false;
+ }
+
+ error = _com_error(d3d_device_.As(&dxgi_device_));
+ if (error.Error() != S_OK || !dxgi_device_) {
+ LOG(LS_WARNING) << "ID3D11Device is not an implementation of IDXGIDevice, "
+ "this usually means the system does not support DirectX "
+ "11";
+ return false;
+ }
+
+ return true;
+}
+
+/* static */ std::vector<D3dDevice> D3dDevice::EnumDevices() {
Sergey Ulanov 2016/07/08 22:36:53 Normally we use the following style for static com
Hzj_jie 2016/07/11 00:54:59 Done.
+ ComPtr<IDXGIFactory1> factory;
+ _com_error error = _com_error(CreateDXGIFactory1(__uuidof(IDXGIFactory1),
+ reinterpret_cast<void**>(factory.GetAddressOf())));
+ if (error.Error() == S_OK && factory) {
+ std::vector<D3dDevice> result;
+ for (int i = 0;; i++) {
+ ComPtr<IDXGIAdapter> adapter;
+ error = _com_error(factory->EnumAdapters(i, adapter.GetAddressOf()));
+ if (error.Error() == S_OK) {
+ result.emplace_back();
Sergey Ulanov 2016/07/08 22:36:53 emplace_back() is discouraged, see https://chromiu
Hzj_jie 2016/07/11 00:54:59 Done.
+ if (!result.back().Initialize(adapter)) {
+ return std::vector<D3dDevice>();
+ }
+ } else if (error.Error() == DXGI_ERROR_NOT_FOUND) {
+ return result;
Sergey Ulanov 2016/07/08 22:36:53 break; and then return result at the end.
Hzj_jie 2016/07/11 00:54:59 Done.
+ } else {
+ return std::vector<D3dDevice>();
Sergey Ulanov 2016/07/08 22:36:53 log the error?
Hzj_jie 2016/07/11 00:54:59 Done.
+ }
+ }
+ } else {
+ return std::vector<D3dDevice>();
Sergey Ulanov 2016/07/08 22:36:53 move error handling to the beginning if (error.Er
Hzj_jie 2016/07/11 00:54:59 Done.
+ }
+}
+
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698