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 <windows.h> | |
| 17 #include <wrl/client.h> | |
| 18 | |
| 19 #include <memory> | |
| 20 #include <vector> | |
| 21 | |
| 22 #include <D3DCommon.h> | |
| 23 #include <D3D11.h> | |
| 24 #include <DXGI1_2.h> | |
| 25 | |
| 26 #include "webrtc/base/scoped_ptr.h" | |
| 27 #include "webrtc/base/thread_annotations.h" | |
| 28 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | |
| 29 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 30 #include "webrtc/modules/desktop_capture/desktop_region.h" | |
| 31 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | |
| 32 #include "webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h" | |
| 33 | |
| 34 namespace webrtc { | |
| 35 | |
| 36 // ScreenCapturerWinDirectX captures 32bit RGBA using DirectX. | |
| 37 class ScreenCapturerWinDirectX : public ScreenCapturer { | |
|
Sergey Ulanov
2016/04/08 21:22:26
please call it ScreenCapturerWinDirectx, with lowe
Hzj_jie
2016/04/11 22:19:16
Done.
| |
| 38 public: | |
| 39 // Initializes DirectX related components. Returns false if any error | |
| 40 // happened, any instance of this class won't be able to work in such status. | |
| 41 // Thread safe, guarded by initialize_lock. | |
| 42 static bool Initialize(); | |
| 43 | |
| 44 explicit ScreenCapturerWinDirectX(const DesktopCaptureOptions& options); | |
| 45 virtual ~ScreenCapturerWinDirectX(); | |
| 46 | |
| 47 void Start(Callback* callback) override; | |
| 48 void SetSharedMemoryFactory( | |
| 49 rtc::scoped_ptr<SharedMemoryFactory> shared_memory_factory) override; | |
| 50 void Capture(const DesktopRegion& region) override; | |
| 51 bool GetScreenList(ScreenList* screens) override; | |
| 52 bool SelectScreen(ScreenId id) override; | |
| 53 | |
| 54 private: | |
| 55 // In milliseconds, consistent with windows api. | |
| 56 static const uint32_t kAcquireTimeout = 10; | |
| 57 // Wait time between two DuplicateOutput operations, DuplicateOutput may fail | |
| 58 // if display mode is changing. | |
| 59 static const uint32_t kDuplicateOutputWait = 50; | |
| 60 // How many times we attempt to DuplicateOutput before returning an error to | |
| 61 // upstream components. | |
| 62 static const int kDuplicateOutputAttempts = 10; | |
| 63 | |
| 64 static bool DoInitialize(); | |
| 65 | |
| 66 // Initializes dxgi_output_duplication. Returns false if it fails to execute | |
| 67 // windows api. | |
| 68 static bool DuplicateOutput(); | |
| 69 | |
| 70 // Detect update regions in last frame, if anything wrong, returns false. | |
| 71 // ProcessFrame will insert a whole desktop size as updated region instead. | |
| 72 static bool DetectUpdatedRegion(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
| 73 DesktopFrame* frame); | |
| 74 | |
| 75 // Process one frame received from AcquireNextFrame function, returns false if | |
| 76 // anything wrong, and Capture function will call | |
| 77 // callback_->OnCaptureCompleted(nullptr), otherwise | |
| 78 // callback_->OnCaptureCompleted(frame) will be called. | |
| 79 bool ProcessFrame(const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
| 80 IDXGIResource* resource); | |
| 81 | |
| 82 void EmitCurrentFrame(); | |
| 83 | |
| 84 // A shortcut to replace current frame to DesktopFrameWinDxgi if it is null. | |
| 85 // Returns the created or original DesktopFrameWinDxgi instance. Never returns | |
| 86 // nullptr. | |
| 87 DesktopFrameWinDxgi* ReplaceCurrentFrameIfEmpty(); | |
| 88 | |
| 89 ScreenCaptureFrameQueue frames_; | |
| 90 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | |
| 91 Callback* callback_; | |
| 92 | |
| 93 bool set_thread_execution_state_failed_; | |
| 94 | |
| 95 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinDirectX); | |
| 96 }; | |
| 97 | |
| 98 } // namespace webrtc | |
| 99 | |
| 100 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ | |
| OLD | NEW |