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

Unified Diff: webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h

Issue 1845113002: DirectX based screen capturer logic (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Lint errors Created 4 years, 8 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/desktop_frame_win_dxgi.h
diff --git a/webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h b/webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h
new file mode 100644
index 0000000000000000000000000000000000000000..8618d389a096cd9085b97b38f54452d958ab7550
--- /dev/null
+++ b/webrtc/modules/desktop_capture/win/desktop_frame_win_dxgi.h
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#ifndef WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_
+#define WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_
+
+#include <windows.h>
+
+#include <windef.h>
+#include <wrl/client.h>
+
+#include <memory>
+#include <vector>
+
+#include <D3D11.h>
+#include <DXGI.h>
+#include <DXGI1_2.h>
+
+#include "webrtc/modules/desktop_capture/desktop_frame.h"
+#include "webrtc/modules/desktop_capture/desktop_geometry.h"
+
+namespace webrtc {
+
+// DesktopFrame implementation used by screen captures on Windows.
+// Frame data is stored in the IDXGISurface instance and also the SharedMemory.
+// Since Windows does not allow to share memory between a file mapping and
+// IDXGIResource.
+// To avoid memory recreation in ID3D11Texture2D, we reuse DesktopFrameWinDxgi
+// instance. So a Capture function is added.
+// Capture function is thread unsafe.
+class DesktopFrameWinDxgi : public DesktopFrame {
+ public:
+ virtual ~DesktopFrameWinDxgi();
+
+ // Initialize device and context for further use. Thread unsafe.
+ static void Initialize(ID3D11Device* device, ID3D11DeviceContext* context);
+
+ // Creates a DesktopFrameWinDxgi instance, returns nullptr when memory
+ // allocation failed.
+ static std::unique_ptr<DesktopFrameWinDxgi> Create(
+ DesktopSize size,
+ SharedMemoryFactory* shared_memory_factory);
+
+ uint8_t* data() const override { return rect_.pBits; }
Sergey Ulanov 2016/04/08 21:22:26 virtual methods should not be inlined, but I don't
Hzj_jie 2016/04/11 22:19:16 Done.
+
+ // Captures a frame represented by frame_info and resource. Returns false if
+ // anything wrong.
+ // Before the first Capture is called, this instance is still workable, but
+ // the data in underlying buffer (SharedMemory) is undefined.
+ bool Capture(const DXGI_OUTDUPL_FRAME_INFO& frame_info,
Sergey Ulanov 2016/04/08 21:22:26 DesktopFrame is supposed to be a dumb holder of th
Hzj_jie 2016/04/11 22:19:16 The reason to leave capture logic here is because
+ IDXGIResource* resource);
+
+ private:
+ DesktopFrameWinDxgi(DesktopSize size,
+ int stride,
+ SharedMemory* shared_memory);
+
+ // Initializes stage_ from a CPU inaccessible IDXGIResource.
+ // Returns false if it fails to execute windows api.
+ bool CreateTexture(ID3D11Texture2D* texture);
+
+ // Update during Capture (CreateTexture).
+ Microsoft::WRL::ComPtr<ID3D11Texture2D> stage_;
+ Microsoft::WRL::ComPtr<IDXGISurface> surface_;
+ // Always be the mapped rectangle or empty.
+ DXGI_MAPPED_RECT rect_;
+
+ RTC_DISALLOW_COPY_AND_ASSIGN(DesktopFrameWinDxgi);
+};
+
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_DESKTOP_CAPTURE_WIN_DESKTOP_FRAME_WIN_DXGI_H_

Powered by Google App Engine
This is Rietveld 408576698