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 #ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ | |
| 12 #define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ | |
| 13 | |
| 14 #include "webrtc/modules/desktop_capture/screen_capturer.h" | |
| 15 | |
| 16 #include <memory> | |
| 17 #include <vector> | |
| 18 | |
| 19 #include <D3DCommon.h> | |
| 20 #include <D3D11.h> | |
| 21 #include <DXGI1_2.h> | |
| 22 #include <windows.h> | |
| 23 #include <wrl/client.h> | |
| 24 | |
| 25 #include "webrtc/base/scoped_ptr.h" | |
| 26 #include "webrtc/base/thread_annotations.h" | |
| 27 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | |
| 28 #include "webrtc/modules/desktop_capture/desktop_frame.h" | |
| 29 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 30 #include "webrtc/modules/desktop_capture/desktop_region.h" | |
| 31 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 32 | |
| 33 namespace webrtc { | |
| 34 | |
| 35 class Differ; | |
| 36 | |
| 37 // ScreenCapturerWinDirectX captures 32bit RGB using DirectX. | |
| 38 class ScreenCapturerWinDirectX : public ScreenCapturer { | |
| 39 public: | |
| 40 // Initializes DirectX related components. Returns false if any error | |
| 41 // happened, any instance of this class won't be able to work in such status. | |
| 42 // Thread safe, guarded by kInitializeLock. | |
| 43 static bool Initialize(); | |
| 44 | |
| 45 explicit ScreenCapturerWinDirectX(const DesktopCaptureOptions& options); | |
| 46 virtual ~ScreenCapturerWinDirectX(); | |
| 47 | |
| 48 void Start(Callback* callback) override; | |
| 49 void SetSharedMemoryFactory( | |
| 50 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) override; | |
| 51 void Capture(const DesktopRegion& region) override; | |
| 52 bool GetScreenList(ScreenList* screens) override; | |
| 53 bool SelectScreen(ScreenId id) override; | |
| 54 | |
| 55 private: | |
| 56 // In milliseconds, consistent with windows api. | |
| 57 const static uint32_t kAcquireTimeout = 10; | |
| 58 | |
| 59 static bool DoInitialize(); | |
| 60 | |
| 61 // Initializes kDXGIOutputDuplication. Returns false if it fails to execute | |
| 62 // windows api. | |
| 63 static bool DuplicateOutput(); | |
| 64 | |
| 65 // Initializes kStage and kSurface from a CPU inaccessible IDXGIResource. | |
| 66 // Returns false if it fails to execute windows api. | |
| 67 static bool CreateTexture(ID3D11Texture2D* texture); | |
| 68 | |
| 69 // Detect update regions in last frame, if anything wrong, returns false. | |
| 70 // ProcessFrame will insert a whole desktop size as updated region instead. | |
| 71 static bool DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
| 72 DesktopFrame* frame); | |
| 73 | |
| 74 // Windows accepts only one DirectX duplication per application, so most of | |
|
Sergey Ulanov
2016/03/31 18:41:17
Ouch, is it documented anywhere?
This is an issue,
Hzj_jie
2016/04/05 23:15:18
Yes, http://shortn/_geEQFIizM3. We are fine with m
| |
| 75 // these com instances are static. | |
| 76 static bool kInitialized GUARDED_BY(kInitializeLock); | |
| 77 static bool kInitializeResult GUARDED_BY(kInitializeLock); | |
| 78 static ID3D11Device* kD3D11Device GUARDED_BY(kInitializeLock); | |
| 79 static ID3D11DeviceContext* kD3D11Context GUARDED_BY(kInitializeLock); | |
| 80 static IDXGIOutput1* kDXGIOutput1 GUARDED_BY(kInitializeLock); | |
| 81 static Microsoft::WRL::ComPtr<IDXGIOutputDuplication> kDXGIOutputDuplication | |
| 82 GUARDED_BY(kDuplicationLock); | |
| 83 // Update with kDXGIOutputDuplication | |
| 84 static DesktopSize kDesktopSize GUARDED_BY(kAcquireLock); | |
| 85 // Update during ProcessFrame or DuplicateOutput (CreateTexture), they are | |
| 86 // always pointing to the same object (thread unsafely). | |
| 87 static Microsoft::WRL::ComPtr<ID3D11Texture2D> kStage | |
| 88 GUARDED_BY(kAcquireLock); | |
| 89 static Microsoft::WRL::ComPtr<IDXGISurface> kSurface GUARDED_BY(kAcquireLock); | |
| 90 // Update during ProcessFrame (DetectUpdatedRegion). | |
| 91 static std::vector<BYTE> kMetaDataBuffer GUARDED_BY(kAcquireLock); | |
| 92 | |
| 93 // Lock in Initialize function. | |
| 94 static CriticalSectionWrapper kInitializeLock; | |
| 95 // Lock when kDXGIOutputDuplication needs to be updated. | |
| 96 static CriticalSectionWrapper kDuplicationLock; | |
| 97 // Lock when kDXGIOutputDuplication is acquiring a frame or is being updated. | |
| 98 static CriticalSectionWrapper kAcquireLock; | |
| 99 | |
| 100 // Process one frame received from AcquireNextFrame function, returns false if | |
| 101 // anything wrong, and Capture function will call | |
| 102 // callback_->OnCaptureCompleted(nullptr), otherwise | |
| 103 // callback_->OnCaptureCompleted(frame) will be called. | |
| 104 static bool ProcessFrame(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
| 105 IDXGIResource* resource, | |
| 106 DesktopFrame** frame); | |
| 107 | |
| 108 void CallbackUnchanged(); | |
| 109 void CallbackError(); | |
| 110 | |
| 111 // std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | |
| 112 Callback* callback_; | |
| 113 | |
| 114 bool set_thread_execution_state_failed_; | |
| 115 | |
| 116 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinDirectX); | |
| 117 }; | |
| 118 | |
| 119 } // namespace webrtc | |
| 120 | |
| 121 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ | |
| OLD | NEW |