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 <comdef.h> | |
| 17 #include <D3DCommon.h> | |
| 18 #include <D3D11.h> | |
| 19 #include <DXGI.h> | |
| 20 #include <DXGI1_2.h> | |
| 21 #include <windows.h> | |
| 22 #include <wrl/client.h> | |
| 23 | |
| 24 #include <memory> | |
| 25 #include <vector> | |
| 26 | |
| 27 #include "webrtc/base/scoped_ptr.h" | |
|
Sergey Ulanov
2016/05/13 19:38:11
don't need this
Hzj_jie
2016/05/16 18:17:29
Updated, also the SetSharedMemoryFactory function.
| |
| 28 #include "webrtc/base/thread_annotations.h" | |
| 29 #include "webrtc/modules/desktop_capture/desktop_capture_options.h" | |
| 30 #include "webrtc/modules/desktop_capture/desktop_geometry.h" | |
| 31 #include "webrtc/modules/desktop_capture/desktop_region.h" | |
| 32 #include "webrtc/modules/desktop_capture/screen_capture_frame_queue.h" | |
| 33 #include "webrtc/modules/desktop_capture/shared_desktop_frame.h" | |
| 34 | |
| 35 namespace webrtc { | |
| 36 | |
| 37 // ScreenCapturerWinDirectx captures 32bit RGBA 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 initialize_lock. | |
| 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 // Texture is a pair of an ID3D11Texture2D and an IDXGISurface. Refer to its | |
| 57 // implementation in source code for details. | |
| 58 class Texture; | |
| 59 | |
| 60 // An implementation of DesktopFrame to return data from a Texture instance. | |
| 61 class DxgiDesktopFrame; | |
| 62 | |
| 63 static bool DoInitialize(); | |
| 64 | |
| 65 // Initializes dxgi_output_duplication. Returns false if it fails to execute | |
| 66 // windows api. | |
| 67 static bool DuplicateOutput(); | |
| 68 | |
| 69 // Detects 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 DesktopRegion* updated_region); | |
| 73 | |
| 74 // A helper function to handle _com_error result in DetectUpdatedRegion. | |
| 75 // Returns false if the _com_error shows an error. | |
| 76 static bool HandleDetectUpdatedRegionError(const _com_error& error, | |
| 77 const char* stage); | |
| 78 | |
| 79 // Processes one frame received from AcquireNextFrame function, returns a | |
| 80 // nullptr if anything wrong, and Capture function will call | |
| 81 // callback_->OnCaptureCompleted(nullptr), otherwise | |
| 82 // callback_->OnCaptureCompleted(frame) will be called. | |
| 83 DesktopFrame* ProcessFrame( | |
| 84 const DXGI_OUTDUPL_FRAME_INFO& frame_info, | |
| 85 IDXGIResource* resource); | |
| 86 | |
| 87 // A shortcut to execute callback with current frame in frames. | |
| 88 void EmitCurrentFrame(); | |
| 89 | |
| 90 ScreenCaptureFrameQueue<rtc::scoped_refptr<Texture>> surfaces_; | |
| 91 ScreenCaptureFrameQueue<SharedDesktopFrame> frames_; | |
| 92 std::unique_ptr<SharedMemoryFactory> shared_memory_factory_; | |
| 93 Callback* callback_ = nullptr; | |
| 94 | |
| 95 bool set_thread_execution_state_failed_ = false; | |
| 96 | |
| 97 RTC_DISALLOW_COPY_AND_ASSIGN(ScreenCapturerWinDirectx); | |
| 98 }; | |
| 99 | |
| 100 } // namespace webrtc | |
| 101 | |
| 102 #endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_SCREEN_CAPTURER_WIN_DIRECTX_H_ | |
| OLD | NEW |