Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 "webrtc/system_wrappers/include/logging.h" | |
| 14 | |
| 15 namespace webrtc { | |
| 16 | |
| 17 using Microsoft::WRL::ComPtr; | |
| 18 | |
| 19 bool D3dDevice::Initialize(const ComPtr<IDXGIAdapter>& adapter) { | |
| 20 dxgi_adapter_ = adapter; | |
| 21 if (!dxgi_adapter_) { | |
| 22 LOG(LS_WARNING) << "An empty IDXGIAdapter instance has been received."; | |
| 23 return false; | |
| 24 } | |
| 25 | |
| 26 D3D_FEATURE_LEVEL feature_level; | |
| 27 _com_error error = D3D11CreateDevice( | |
| 28 adapter.Get(), D3D_DRIVER_TYPE_UNKNOWN, nullptr, | |
| 29 D3D11_CREATE_DEVICE_BGRA_SUPPORT | D3D11_CREATE_DEVICE_SINGLETHREADED, | |
| 30 nullptr, 0, D3D11_SDK_VERSION, d3d_device_.GetAddressOf(), &feature_level, | |
| 31 context_.GetAddressOf()); | |
| 32 if (error.Error() != S_OK || !d3d_device_ || !context_) { | |
| 33 LOG(LS_WARNING) << "D3D11CreateDeivce returns error " | |
| 34 << error.ErrorMessage() << " with code " << error.Error(); | |
| 35 return false; | |
| 36 } | |
| 37 | |
| 38 if (feature_level < D3D_FEATURE_LEVEL_11_0) { | |
| 39 LOG(LS_WARNING) << "D3D11CreateDevice returns an instance without DirectX " | |
| 40 "11 support, level " | |
| 41 << feature_level; | |
| 42 return false; | |
| 43 } | |
| 44 | |
| 45 error = _com_error(d3d_device_.As(&dxgi_device_)); | |
| 46 if (error.Error() != S_OK || !dxgi_device_) { | |
| 47 LOG(LS_WARNING) << "ID3D11Device is not an implementation of IDXGIDevice, " | |
| 48 "this usually means the system does not support DirectX " | |
| 49 "11"; | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 return true; | |
| 54 } | |
| 55 | |
| 56 /* 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.
| |
| 57 ComPtr<IDXGIFactory1> factory; | |
| 58 _com_error error = _com_error(CreateDXGIFactory1(__uuidof(IDXGIFactory1), | |
| 59 reinterpret_cast<void**>(factory.GetAddressOf()))); | |
| 60 if (error.Error() == S_OK && factory) { | |
| 61 std::vector<D3dDevice> result; | |
| 62 for (int i = 0;; i++) { | |
| 63 ComPtr<IDXGIAdapter> adapter; | |
| 64 error = _com_error(factory->EnumAdapters(i, adapter.GetAddressOf())); | |
| 65 if (error.Error() == S_OK) { | |
| 66 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.
| |
| 67 if (!result.back().Initialize(adapter)) { | |
| 68 return std::vector<D3dDevice>(); | |
| 69 } | |
| 70 } else if (error.Error() == DXGI_ERROR_NOT_FOUND) { | |
| 71 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.
| |
| 72 } else { | |
| 73 return std::vector<D3dDevice>(); | |
|
Sergey Ulanov
2016/07/08 22:36:53
log the error?
Hzj_jie
2016/07/11 00:54:59
Done.
| |
| 74 } | |
| 75 } | |
| 76 } else { | |
| 77 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.
| |
| 78 } | |
| 79 } | |
| 80 | |
| 81 } // namespace webrtc | |
| OLD | NEW |